From b0a2e82ac6c9b26f107947111818aa981f6a17e6 Mon Sep 17 00:00:00 2001 From: gravitylow Date: Tue, 25 Feb 2014 20:40:18 -0500 Subject: [PATCH] Added more rule variables and updated JavaDoc --- .../anticheat/util/Utilities.java | 15 ++++++++ .../anticheat/util/rule/Rule.java | 35 +++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java b/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java index 59746cb..7a344b6 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/Utilities.java @@ -335,6 +335,21 @@ public final class Utilities { } } + /** + * Determine whether a String can be cast to a Double + * + * @param string text to check + * @return true if double + */ + public static boolean isDouble(String string) { + try { + Double.parseDouble(string); + return true; + } catch (Exception ex) { + return false; + } + } + /** * Calculate the time in milliseconds that it should take to break the given block with the given tool * diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java b/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java index 62261a9..75d10d4 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java @@ -23,6 +23,7 @@ import net.gravitydevelopment.anticheat.check.CheckType; import net.gravitydevelopment.anticheat.util.User; import net.gravitydevelopment.anticheat.util.Group; import net.gravitydevelopment.anticheat.util.Utilities; +import org.bukkit.GameMode; import java.lang.reflect.Constructor; import java.util.ArrayList; @@ -40,9 +41,26 @@ import java.util.TreeMap; *

*

* Types of variables:
- * - Check: Contains all valid checks as listed in {@link net.gravitydevelopment.anticheat.check.CheckType}, and will return the number of times this user has failed the given check
- * - Player: Contains LEVEL, the player's current level and CHECK, the check that was just failed - *

+ *

*

* There are also functions you can use to execute an action within AntiCheat
* Functions are denoted with the type followed by a period followed by the function name.
@@ -142,6 +160,9 @@ public class Rule { map.put("player_level", user.getLevel()); map.put("player_group", user.getGroup() != null ? user.getGroup().getName().toLowerCase() : "low"); map.put("player_name", user.getName().toLowerCase()); + map.put("player_gamemode", user.getPlayer().getGameMode().toString()); + map.put("player_world", user.getPlayer().getWorld().getName()); + map.put("player_health", user.getPlayer().getHealth()); for (CheckType t : CheckType.values()) { map.put("check_" + t.name().toLowerCase(), t.getUses(user.getName())); } @@ -157,6 +178,14 @@ public class Rule { user.setLevel(group.getLevel()); } } + } else if (variable.equals("player_gamemode")) { + try { + GameMode mode = GameMode.valueOf(value); + user.getPlayer().setGameMode(mode); + } catch (IllegalArgumentException ex) { + } + } else if (variable.equals("player_health") && Utilities.isDouble(value)) { + user.getPlayer().setHealth(Double.parseDouble(value)); } }