From ab4097c6694cabd44d44482162050c066d0eac56 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 16 Dec 2016 14:10:02 +0100 Subject: [PATCH] Probably fixed flaircheater NPE --- .../java/buttondevteam/lib/TBMCPlayer.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/buttondevteam/lib/TBMCPlayer.java b/src/main/java/buttondevteam/lib/TBMCPlayer.java index be2950b..3008e94 100644 --- a/src/main/java/buttondevteam/lib/TBMCPlayer.java +++ b/src/main/java/buttondevteam/lib/TBMCPlayer.java @@ -57,6 +57,8 @@ public class TBMCPlayer implements AutoCloseable { Object ret = getLoadedPlayers().get(uuid).data.get(mname.substring("get".length()).toLowerCase()); if (ret != null && Integer.class.isAssignableFrom(ret.getClass())) throw new UnsupportedOperationException("For integers use getIntData()"); + if (ret != null && Boolean.class.isAssignableFrom(ret.getClass())) + throw new UnsupportedOperationException("For booleans use getBoolData()"); return (T) ret; } @@ -194,6 +196,34 @@ public class TBMCPlayer implements AutoCloseable { getLoadedPlayers().get(uuid).data.put(mname.substring("set".length()).toLowerCase(), value); } + /** + *

+ * Gets a player data entry for the caller plugin returning a boolean.
+ * Usage: + *

+ * + *
+	 * {@code
+	 * public String getFlairCheater() {
+	 * 	return getBoolData();
+	 * }
+	 * 
+ * + * @return The value or false if not found + */ + protected boolean getBoolData() { + StackTraceElement st = new Exception().getStackTrace()[1]; + String mname = st.getMethodName(); + if (!mname.startsWith("get")) + throw new UnsupportedOperationException("Can only use getData from a getXYZ method"); + Object ret = getLoadedPlayers().get(uuid).data.get(mname.substring("get".length()).toLowerCase()); + if (ret != null && !Boolean.class.isAssignableFrom(ret.getClass())) + throw new UnsupportedOperationException("Not a boolean!"); + if (ret == null) + return false; + return (boolean) ret; + } + /** * Gets the player's Minecraft name *