From 2b48aba75eacfb4bc69242fca33adff5ee378aa1 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 30 Jun 2017 18:08:24 +0200 Subject: [PATCH] Fixed F NPE a whiile ago & fixed now getOrDefault, then get --- .../java/buttondevteam/chat/ChatPlayer.java | 23 ++++++++----------- .../buttondevteam/chat/ChatProcessing.java | 5 ++-- .../java/buttondevteam/chat/PluginMain.java | 2 +- .../chat/listener/PlayerListener.java | 6 ++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatPlayer.java b/src/main/java/buttondevteam/chat/ChatPlayer.java index a79633b..3eb9338 100644 --- a/src/main/java/buttondevteam/chat/ChatPlayer.java +++ b/src/main/java/buttondevteam/chat/ChatPlayer.java @@ -15,34 +15,31 @@ import buttondevteam.lib.player.TBMCPlayerBase; @PlayerClass(pluginname = "ButtonChat") public class ChatPlayer extends TBMCPlayerBase { public PlayerData UserName() { - return data(); + return data(null); } public List UserNames() { - PlayerData> data = data(); - if (data.get() == null) - data.set(new ArrayList()); - return data.get(); + return data(new ArrayList()).get(); } public PlayerData FlairTime() { - return data(); + return data(FlairTimeNone); } public EnumPlayerData FlairState() { - return dataEnum(FlairStates.class); + return dataEnum(FlairStates.class, FlairStates.NoComment); } public PlayerData FCount() { - return data(); + return data(0); } public PlayerData FDeaths() { - return data(); + return data(0); } public PlayerData FlairCheater() { - return data(); + return data(false); } public boolean RPMode = true; @@ -68,7 +65,7 @@ public class ChatPlayer extends TBMCPlayerBase { * @return The flair */ public String GetFormattedFlair(boolean noformats) { - int time = FlairTime().getOrDefault(FlairTimeNone); + int time = FlairTime().get(); if (time == FlairTimeCantPress) return String.format(noformats ? "(can't press)" : "§r(--s)§r"); if (time == FlairTimeNonPresser) @@ -108,9 +105,9 @@ public class ChatPlayer extends TBMCPlayerBase { } public short GetFlairColor() { - if (FlairCheater().getOrDefault(false)) + if (FlairCheater().get()) return 0x5; - final int flairTime = FlairTime().getOrDefault(FlairTimeNone); + final int flairTime = FlairTime().get(); if (flairTime == FlairTimeNonPresser) return 0x7; else if (flairTime == FlairTimeCantPress) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index c245189..467f987 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -186,8 +186,9 @@ public class ChatProcessing { : "-")))) .addExtra(new TellrawPart(String.format( "Respect: %s%s%s", - (mp != null ? (mp.FCount().getOrDefault(0) - / (double) mp.FDeaths().getOrDefault(0)) + (mp != null + ? (mp.FCount().get() + / (double) mp.FDeaths().get()) : "Infinite"), (mp != null && mp.UserName().get() != null && !mp.UserName().get().isEmpty() diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index ffac187..5d0c496 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -144,7 +144,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. */ if (!mp.UserNames().contains(author)) mp.UserNames().add(author); - if (mp.FlairState().getOrDefault(FlairStates.NoComment).equals(FlairStates.NoComment)) { + if (mp.FlairState().get().equals(FlairStates.NoComment)) { mp.FlairState().set(FlairStates.Commented); ConfirmUserMessage(mp); } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 2664777..ce56d5c 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -156,8 +156,8 @@ public class PlayerListener implements Listener { public void run() { if (ActiveF) { ActiveF = false; - if (FPlayer != null && FPlayer.FCount().getOrDefault(0) < Integer.MAX_VALUE - 1) - FPlayer.FCount().set(FPlayer.FCount().getOrDefault(0) + Fs.size()); + if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1) + FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size()); Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people") + " paid their respects.§r"); Fs.clear(); @@ -263,7 +263,7 @@ public class PlayerListener implements Listener { final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand); if (flair.length() > 0) e.addInfo("/r/TheButton flair: " + flair); - e.addInfo("Respect: " + (double) cp.FCount().getOrDefault(0) / (double) cp.FDeaths().getOrDefault(0)); + e.addInfo("Respect: " + (double) cp.FCount().get() / (double) cp.FDeaths().get()); } catch (Exception ex) { TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex); }