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 *