Probably fixed flaircheater NPE

This commit is contained in:
Norbi Peti 2016-12-16 14:10:02 +01:00
parent e54b54bac0
commit ab4097c669

View file

@ -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);
}
/**
* <p>
* Gets a player data entry for the caller plugin returning a boolean.<br>
* Usage:
* </p>
*
* <pre>
* {@code
* public String getFlairCheater() {
* return getBoolData();
* }
* </pre>
*
* @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
*