From e5a2051aee1c1c460fa674586d1239ee6f4892eb Mon Sep 17 00:00:00 2001 From: h31ix Date: Sun, 13 Oct 2013 22:49:32 -0400 Subject: [PATCH] Refactor Level to Group for sanity and allow custom groups in commands. This is a breaking configuration change. There will continue to be breaking configurations until I'm satisfied with the overall sanity of the system. I'm not providing upgrade scripts at this time, and won't promise them in the future. Please stay aware of the fact that these are dev builds, and are subject to change at any time. --- .../anticheat/CommandHandler.java | 96 +++++++------------ .../anticheat/api/AnticheatAPI.java | 2 +- .../anticheat/config/Configuration.java | 20 ++-- ...entsHolder.java => MySQLGroupsHolder.java} | 20 ++-- ...ventsHolder.java => YamlGroupsHolder.java} | 49 ++++------ .../config/holders/yaml/YamlRulesHolder.java | 2 +- .../providers/{Events.java => Groups.java} | 6 +- .../anticheat/manage/User.java | 37 +++---- .../anticheat/manage/UserManager.java | 29 ++++-- .../anticheat/util/{Level.java => Group.java} | 23 ++--- .../anticheat/util/rule/Rule.java | 9 ++ src/main/resources/enterprise.yml | 6 +- src/main/resources/{events.yml => groups.yml} | 7 +- src/main/resources/lang.yml | 2 +- src/main/resources/rules.yml | 5 + 15 files changed, 150 insertions(+), 163 deletions(-) rename src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/{MySQLEventsHolder.java => MySQLGroupsHolder.java} (83%) rename src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/{YamlEventsHolder.java => YamlGroupsHolder.java} (51%) rename src/main/java/net/gravitydevelopment/anticheat/config/providers/{Events.java => Groups.java} (88%) rename src/main/java/net/gravitydevelopment/anticheat/util/{Level.java => Group.java} (86%) rename src/main/resources/{events.yml => groups.yml} (62%) create mode 100644 src/main/resources/rules.yml diff --git a/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java b/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java index dcc6c4d..8ffd276 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java +++ b/src/main/java/net/gravitydevelopment/anticheat/CommandHandler.java @@ -45,12 +45,7 @@ public class CommandHandler implements CommandExecutor { private static final ChatColor GREEN = ChatColor.GREEN; private static final ChatColor WHITE = ChatColor.WHITE; private static final ChatColor GRAY = ChatColor.GRAY; - private List high = new ArrayList(); - private List med = new ArrayList(); - private List low = new ArrayList(); private static final Server SERVER = Bukkit.getServer(); - private static final int MED_THRESHOLD = 20; - private static final int HIGH_THRESHOLD = 50; private static final String PERMISSIONS_ERROR = RED + "Insufficient Permissions."; private static final String MENU_END = "-----------------------------------------------------"; @@ -79,12 +74,7 @@ public class CommandHandler implements CommandExecutor { } public void handleDebug(CommandSender cs) { - if (hasPermission(cs, Permission.SYSTEM_DEBUG)) { - cs.sendMessage(GRAY + "Please wait while I collect some data..."); - PastebinReport report = new PastebinReport(cs); - cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL()); - cs.sendMessage(GREEN + "Please include this link when making bug reports."); - } + handleDebug(cs, null); } public void handleDebug(CommandSender cs, Player tp) { @@ -199,7 +189,7 @@ public class CommandHandler implements CommandExecutor { String base = "/AntiCheat "; String[] lines = { "log [Enable/Disable]" + WHITE + " - toggle logging", - "report [low/medium/high]" + WHITE + " - show users in groups", + "report [group]" + WHITE + " - show users in groups", "report [user]" + WHITE + " - get a player's cheat report", "reload" + WHITE + " - reload AntiCheat configuration", "reset [user]" + WHITE + " - reset user's hack level", @@ -247,30 +237,26 @@ public class CommandHandler implements CommandExecutor { public void handleReport(CommandSender cs, String[] args) { if (hasPermission(cs, Permission.SYSTEM_REPORT)) { - getPlayers(); if (args.length > 1) { String group = args[1]; + int num = getReportPageNum(args); if (group.equalsIgnoreCase("low")) { - int num = getReportPageNum(args); if (num > 0) { - sendReport(cs, low, "Low", GREEN, num); + sendReport(cs, null, num); } else { cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]); } - } else if (group.equalsIgnoreCase("medium")) { - int num = getReportPageNum(args); - if (num > 0) { - sendReport(cs, med, "Medium", YELLOW, num); - } else { - cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]); + } else { + boolean sent = false; + for (Group g : CONFIG.getGroups().getGroups()) { + if (g.getName().equalsIgnoreCase(group)) { + sendReport(cs, g, num); + sent = true; + break; + } } - } - if (group.equalsIgnoreCase("high")) { - int num = getReportPageNum(args); - if (num > 0) { - sendReport(cs, high, "High", RED, num); - } else { - cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]); + if (!sent) { + cs.sendMessage(RED + "Not a valid group: " + WHITE + group); } } } @@ -287,15 +273,17 @@ public class CommandHandler implements CommandExecutor { } } - public void sendReport(CommandSender cs, List players, String group, ChatColor color, int page) { - int pages = (int) Math.ceil(((float) players.size()) / 7); + public void sendReport(CommandSender cs, Group group, int page) { + List users = USER_MANAGER.getUsersInGroup(group); + ChatColor color = group == null ? GREEN : group.getColor(); + int pages = (int) Math.ceil(((float) users.size()) / 7); if (page <= pages && page > 0) { cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------"); cs.sendMessage(GRAY + "Group: " + color + group); for (int x = 0; x < 7; x++) { int index = ((page - 1) * 6) + (x + ((page - 1) * 1)); - if (index < players.size()) { - String player = players.get(index); + if (index < users.size()) { + String player = users.get(index).getName(); cs.sendMessage(GRAY + player); } } @@ -346,25 +334,25 @@ public class CommandHandler implements CommandExecutor { public void handleDeveloper(CommandSender cs) { AntiCheat.setDeveloperMode(!AntiCheat.developerMode()); - cs.sendMessage(ChatColor.GREEN + "Developer mode " + (AntiCheat.developerMode() ? "ON" : "OFF")); + cs.sendMessage(GREEN + "Developer mode " + (AntiCheat.developerMode() ? "ON" : "OFF")); } public void sendPlayerReport(CommandSender cs, List types, User user, int page) { String name = user.getName(); int pages = (int) Math.ceil(((float) types.size()) / 6); - Level level = user.getNamedLevel(); - String levelString = ChatColor.GREEN + "Low"; + Group group = user.getGroup(); + String groupString = GREEN + "Low"; - if (level != null) { - levelString = level.getColor() + level.getName(); + if (group != null) { + groupString = group.getColor() + group.getName(); } - levelString += " (" + user.getLevel() + ")"; + groupString += " (" + user.getLevel() + ")"; if (page <= pages && page > 0) { cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------"); cs.sendMessage(GRAY + "Player: " + WHITE + name); - cs.sendMessage(GRAY + "Level: " + levelString); + cs.sendMessage(GRAY + "Group: " + groupString); for (int x = 0; x < 6; x++) { int index = ((page - 1) * 5) + (x + ((page - 1))); if (index < types.size()) { @@ -383,7 +371,7 @@ public class CommandHandler implements CommandExecutor { if (pages == 0) { cs.sendMessage("--------------------[" + GREEN + "REPORT[1/1]" + WHITE + "]---------------------"); cs.sendMessage(GRAY + "Player: " + WHITE + name); - cs.sendMessage(GRAY + "Level: " + levelString); + cs.sendMessage(GRAY + "Group: " + groupString); cs.sendMessage(GRAY + "This user has not failed any checks."); cs.sendMessage(MENU_END); } else { @@ -403,8 +391,8 @@ public class CommandHandler implements CommandExecutor { public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) { if (args.length == 3) { if (args[0].equalsIgnoreCase("report")) { - for (Level level : CONFIG.getEvents().getLevels()) { - if (args[1].equalsIgnoreCase(level.getName())) { + for (Group group : CONFIG.getGroups().getGroups()) { + if (args[1].equalsIgnoreCase(group.getName())) { handleReport(cs, args); return true; } @@ -437,12 +425,8 @@ public class CommandHandler implements CommandExecutor { } else if (args[0].equalsIgnoreCase("debug")) { handleDebug(cs); } else if (args[0].equalsIgnoreCase("report")) { - cs.sendMessage(ChatColor.GREEN + "To see the report of a specific user, type their name, like so:"); - cs.sendMessage(ChatColor.WHITE + "/anticheat report [user]"); - cs.sendMessage(ChatColor.GRAY + " - This will allow you to see the checks that user has failed."); - cs.sendMessage(ChatColor.GREEN + "To see the report of an AntiCheat group, type it's name, like so:"); - cs.sendMessage(ChatColor.WHITE + "/anticheat report [low/medium/high]"); - cs.sendMessage(ChatColor.GRAY + " - This will allow you to see which players are good, and which could be hacking."); + cs.sendMessage(GREEN + "To see a user's report, use " + WHITE + "/anticheat report [user]"); + cs.sendMessage(GREEN + "To see all users in a group, use " + WHITE + "/anticheat report [group]"); } else if (args[0].equalsIgnoreCase("reload")) { handleReload(cs); } else if (args[0].equalsIgnoreCase("update")) { @@ -462,22 +446,6 @@ public class CommandHandler implements CommandExecutor { return true; } - public void getPlayers() { - high.clear(); - med.clear(); - low.clear(); - for (Player player : SERVER.getOnlinePlayers()) { - int level = USER_MANAGER.safeGetLevel(player.getName()); - if (level <= MED_THRESHOLD) { - low.add(player.getName()); - } else if (level <= HIGH_THRESHOLD) { - med.add(player.getName()); - } else { - high.add(player.getName()); - } - } - } - public boolean hasPermission(CommandSender cs, Permission perm) { if (perm.get(cs)) { return true; diff --git a/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java b/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java index 0201eb8..80066d2 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java +++ b/src/main/java/net/gravitydevelopment/anticheat/api/AnticheatAPI.java @@ -124,7 +124,7 @@ public class AnticheatAPI { * Set a player's hack level (Min = 0, Max = 50) * * @param player Player to set - * @param level Level to set to + * @param level Group to set to */ public static void setLevel(Player player, int level) { umr.safeSetLevel(player.getName(), level); diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java index 461ddbb..c9b2a53 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java @@ -23,13 +23,13 @@ import net.gravitydevelopment.anticheat.config.files.Config; import net.gravitydevelopment.anticheat.config.files.Enterprise; import net.gravitydevelopment.anticheat.config.files.Lang; import net.gravitydevelopment.anticheat.config.files.Magic; -import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLEventsHolder; +import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLGroupsHolder; import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLLevelsHolder; import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLRulesHolder; -import net.gravitydevelopment.anticheat.config.holders.yaml.YamlEventsHolder; +import net.gravitydevelopment.anticheat.config.holders.yaml.YamlGroupsHolder; import net.gravitydevelopment.anticheat.config.holders.yaml.YamlLevelsHolder; import net.gravitydevelopment.anticheat.config.holders.yaml.YamlRulesHolder; -import net.gravitydevelopment.anticheat.config.providers.Events; +import net.gravitydevelopment.anticheat.config.providers.Groups; import net.gravitydevelopment.anticheat.config.providers.Levels; import net.gravitydevelopment.anticheat.config.providers.Rules; @@ -42,7 +42,7 @@ public class Configuration { private Lang lang; private Magic magic; - private Events events; + private Groups groups; private Levels levels; private Rules rules; @@ -67,11 +67,11 @@ public class Configuration { // The following values can be configuration from a database, or from flatfile. if (config.enterprise.getValue() && enterprise.configEvents.getValue()) { - events = new MySQLEventsHolder(this); - dbfiles.add((MySQLEventsHolder) events); + groups = new MySQLGroupsHolder(this); + dbfiles.add((MySQLGroupsHolder) groups); } else { - events = new YamlEventsHolder(plugin, this); - flatfiles.add((YamlEventsHolder) events); + groups = new YamlGroupsHolder(plugin, this); + flatfiles.add((YamlGroupsHolder) groups); } if (config.enterprise.getValue() && enterprise.configRules.getValue()) { @@ -118,8 +118,8 @@ public class Configuration { return config; } - public Events getEvents() { - return events; + public Groups getGroups() { + return groups; } public Rules getRules() { diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLEventsHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLGroupsHolder.java similarity index 83% rename from src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLEventsHolder.java rename to src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLGroupsHolder.java index 054f150..31d45a6 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLEventsHolder.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLGroupsHolder.java @@ -20,8 +20,8 @@ package net.gravitydevelopment.anticheat.config.holders.mysql; import net.gravitydevelopment.anticheat.config.Configuration; import net.gravitydevelopment.anticheat.config.ConfigurationTable; -import net.gravitydevelopment.anticheat.config.providers.Events; -import net.gravitydevelopment.anticheat.util.Level; +import net.gravitydevelopment.anticheat.config.providers.Groups; +import net.gravitydevelopment.anticheat.util.Group; import java.sql.ResultSet; import java.sql.SQLException; @@ -29,21 +29,21 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class MySQLEventsHolder extends ConfigurationTable implements Events { +public class MySQLGroupsHolder extends ConfigurationTable implements Groups { - private static final String TABLE = "events"; + private static final String TABLE = "groups"; - private List levels; + private List groups; private int highestLevel; - public MySQLEventsHolder(Configuration config) { + public MySQLGroupsHolder(Configuration config) { super(config, TABLE); } @Override public void open() { highestLevel = 0; - levels = new ArrayList(); + groups = new ArrayList(); String sqlCreate = "CREATE TABLE IF NOT EXISTS " + getFullTable() + "(" + " `id` INT NOT NULL," + @@ -65,7 +65,7 @@ public class MySQLEventsHolder extends ConfigurationTable implements Events { String color = set.getString("color"); List actions = Arrays.asList(set.getString("actions").split(",")); - levels.add(new Level(name, level, color, actions)); + groups.add(new Group(name, level, color, actions)); if (level > highestLevel) { highestLevel = level; } @@ -76,8 +76,8 @@ public class MySQLEventsHolder extends ConfigurationTable implements Events { } @Override - public List getLevels() { - return levels; + public List getGroups() { + return groups; } @Override diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlEventsHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlGroupsHolder.java similarity index 51% rename from src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlEventsHolder.java rename to src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlGroupsHolder.java index 1070108..c3aaee3 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlEventsHolder.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlGroupsHolder.java @@ -21,26 +21,26 @@ package net.gravitydevelopment.anticheat.config.holders.yaml; import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.config.Configuration; import net.gravitydevelopment.anticheat.config.ConfigurationFile; -import net.gravitydevelopment.anticheat.config.providers.Events; -import net.gravitydevelopment.anticheat.util.Level; +import net.gravitydevelopment.anticheat.config.providers.Groups; +import net.gravitydevelopment.anticheat.util.Group; import java.util.*; -public class YamlEventsHolder extends ConfigurationFile implements Events { +public class YamlGroupsHolder extends ConfigurationFile implements Groups { - public static final String FILENAME = "events.yml"; + public static final String FILENAME = "groups.yml"; - private List levels; + private List groups; private int highestLevel; - public YamlEventsHolder(AntiCheat plugin, Configuration config) { + public YamlGroupsHolder(AntiCheat plugin, Configuration config) { super(plugin, config, FILENAME); } @Override - public List getLevels() { - return levels; + public List getGroups() { + return groups; } @Override @@ -50,33 +50,26 @@ public class YamlEventsHolder extends ConfigurationFile implements Events { @Override public void open() { - ConfigValue> levels = new ConfigValue>("events"); + ConfigValue> groups = new ConfigValue>("groups"); - // Clean up old values - if(levels.didLoadDefault()) { - new ConfigValue>("levels").setValue(null); - new ConfigValue>("actions").setValue(null); - save(); - } - - // Convert levels list to Levels - this.levels = new ArrayList(); - for (String string : levels.getValue()) { - Level level = Level.load(string); - if (level == null || level.getValue() < 0) { + // Convert groups list to Levels + this.groups = new ArrayList(); + for (String string : groups.getValue()) { + Group group = Group.load(string); + if (group == null || group.getLevel() < 0) { continue; } - this.levels.add(level); - highestLevel = level.getValue() > highestLevel ? level.getValue() : highestLevel; + this.groups.add(group); + highestLevel = group.getLevel() > highestLevel ? group.getLevel() : highestLevel; } - // Sort levels - Collections.sort(this.levels, new Comparator() { - public int compare(Level l1, Level l2) { - if (l1.getValue() == l2.getValue()) { + // Sort groups + Collections.sort(this.groups, new Comparator() { + public int compare(Group l1, Group l2) { + if (l1.getLevel() == l2.getLevel()) { return 0; - } else if (l1.getValue() < l2.getValue()) { + } else if (l1.getLevel() < l2.getLevel()) { return -1; } return 1; diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlRulesHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlRulesHolder.java index 136013a..f425f1b 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlRulesHolder.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlRulesHolder.java @@ -29,7 +29,7 @@ import java.util.List; public class YamlRulesHolder extends ConfigurationFile implements Rules { - public static final String FILENAME = "events.yml"; + public static final String FILENAME = "rules.yml"; private List rules; diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/providers/Events.java b/src/main/java/net/gravitydevelopment/anticheat/config/providers/Groups.java similarity index 88% rename from src/main/java/net/gravitydevelopment/anticheat/config/providers/Events.java rename to src/main/java/net/gravitydevelopment/anticheat/config/providers/Groups.java index 554333e..77b6f1f 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/providers/Events.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/providers/Groups.java @@ -18,13 +18,13 @@ package net.gravitydevelopment.anticheat.config.providers; -import net.gravitydevelopment.anticheat.util.Level; +import net.gravitydevelopment.anticheat.util.Group; import java.util.List; -public interface Events { +public interface Groups { - public List getLevels(); + public List getGroups(); public int getHighestLevel(); } diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/User.java b/src/main/java/net/gravitydevelopment/anticheat/manage/User.java index 586dcce..1ae70a0 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/User.java +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/User.java @@ -20,7 +20,7 @@ package net.gravitydevelopment.anticheat.manage; import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.config.Configuration; -import net.gravitydevelopment.anticheat.util.Level; +import net.gravitydevelopment.anticheat.util.Group; import net.gravitydevelopment.anticheat.util.Utilities; import net.gravitydevelopment.anticheat.util.rule.Rule; import org.bukkit.Bukkit; @@ -93,12 +93,17 @@ public class User { return level; } - public Level getNamedLevel() { - List levels = config.getEvents().getLevels(); - for (int i = 0; i < levels.size(); i++) { - if (i == 0 && level < levels.get(i).getValue()) break; - else if (i == levels.size() - 1) return levels.get(i); - else if (level >= levels.get(i).getValue() && level < levels.get(i + 1).getValue()) return levels.get(i); + /** + * Get the user's group + * + * @return group + */ + public Group getGroup() { + List groups = config.getGroups().getGroups(); + for (int i = 0; i < groups.size(); i++) { + if (i == 0 && level < groups.get(i).getLevel()) break; + else if (i == groups.size() - 1) return groups.get(i); + else if (level >= groups.get(i).getLevel() && level < groups.get(i + 1).getLevel()) return groups.get(i); } return null; } @@ -115,15 +120,15 @@ public class User { // Prevent silent mode from increasing the level way too fast return false; } else { - if (level < config.getEvents().getHighestLevel()) { + if (level < config.getGroups().getHighestLevel()) { level++; // Check levels - for (Level l : getLevels()) { - if (l.getValue() == level) { + for (Group l : getLevels()) { + if (l.getLevel() == level) { AntiCheat.getManager().getUserManager().alert(this, l, type); - if (l.getValue() == config.getEvents().getHighestLevel()) { - level = l.getValue() - 10; + if (l.getLevel() == config.getGroups().getHighestLevel()) { + level = l.getLevel() - 10; } } } @@ -157,11 +162,11 @@ public class User { public boolean setLevel(int level) { isWaitingOnLevelSync = false; if (level >= 0) { - if (level <= config.getEvents().getHighestLevel()) { + if (level <= config.getGroups().getHighestLevel()) { this.level = level; return true; } else { - this.level = config.getEvents().getHighestLevel(); + this.level = config.getGroups().getHighestLevel(); return false; } } else { @@ -320,8 +325,8 @@ public class User { return getMessageTime(0) == null ? -1 : getMessageTime(0); } - private List getLevels() { - return config.getEvents().getLevels(); + private List getLevels() { + return config.getGroups().getGroups(); } private boolean silentMode() { diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java b/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java index b40d9a8..496126f 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java @@ -20,7 +20,7 @@ package net.gravitydevelopment.anticheat.manage; import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.config.Configuration; -import net.gravitydevelopment.anticheat.util.Level; +import net.gravitydevelopment.anticheat.util.Group; import net.gravitydevelopment.anticheat.util.Utilities; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -33,7 +33,6 @@ public class UserManager { private static Configuration config; private static final ChatColor GRAY = ChatColor.GRAY; private static final ChatColor GOLD = ChatColor.GOLD; - private static final ChatColor YELLOW = ChatColor.YELLOW; private static final ChatColor RED = ChatColor.RED; private static List alert; @@ -102,6 +101,21 @@ public class UserManager { config.getLevels().saveLevelFromUser(user); } + /** + * Get users in group + * + * @param group Group to find users of + */ + public List getUsersInGroup(Group group) { + List list = new ArrayList(); + for (User u : users) { + if (u.getGroup() == group) { + list.add(u); + } + } + return list; + } + /** * Get a user's level, or 0 if the player isn't found * @@ -121,7 +135,7 @@ public class UserManager { * Set a user's level * * @param name Name of the player - * @param level Level to set + * @param level Group to set */ public void safeSetLevel(String name, int level) { User user = getUser(name); @@ -146,22 +160,23 @@ public class UserManager { * Fire an alert * * @param user The user to alert - * @param level The user's level + * @param group The user's group * @param type The CheckType that triggered the alert */ - public void alert(User user, Level level, CheckType type) { + public void alert(User user, Group group, CheckType type) { ArrayList messageArray = new ArrayList(); for (int i = 0; i < alert.size(); i++) { String message = alert.get(i); if (!message.equals("")) { message = message.replaceAll("&player", GOLD + user.getName() + GRAY); message = message.replaceAll("&check", GOLD + CheckType.getName(type) + GRAY); - message = message.replaceAll("&level", level.getColor() + level.getName() + GRAY); + message = message.replaceAll("&group", group.getColor() + group.getName() + GRAY); + message = message.replaceAll("&level", "" + user.getLevel() + GRAY); messageArray.add(message); } } Utilities.alert(messageArray); - execute(user, level.getActions(), type); + execute(user, group.getActions(), type); } /** diff --git a/src/main/java/net/gravitydevelopment/anticheat/util/Level.java b/src/main/java/net/gravitydevelopment/anticheat/util/Group.java similarity index 86% rename from src/main/java/net/gravitydevelopment/anticheat/util/Level.java rename to src/main/java/net/gravitydevelopment/anticheat/util/Group.java index 0cf0a41..f5679c6 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/Level.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/Group.java @@ -25,17 +25,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class Level { +public class Group { private String name; - private int value; + private int level; private ChatColor color = ChatColor.RED; private List actions = new ArrayList(); - public Level(String name, int value, String color, List actions) { + public Group(String name, int level, String color, List actions) { this.name = name; - this.value = value; + this.level = level; this.actions = actions; ChatColor c = ChatColor.valueOf(color); @@ -46,17 +46,12 @@ public class Level { this.color = c; } } - - public void setValue(int value) { - this.value = value; - } - public String getName() { return name; } - public int getValue() { - return value; + public int getLevel() { + return level; } public ChatColor getColor() { @@ -67,7 +62,7 @@ public class Level { return actions; } - public static Level load(String string) { + public static Group load(String string) { try { if (string.split(":").length == 4) { string = Utilities.removeWhitespace(string); @@ -75,7 +70,7 @@ public class Level { int level = Integer.parseInt(string.split(":")[1]); String color = string.split(":")[2]; List actions = Arrays.asList(string.split(":")[3].split(",")); - return new Level(name, level, color, actions); + return new Group(name, level, color, actions); } else { throw new Exception(); } @@ -89,6 +84,6 @@ public class Level { @Override public String toString() { - return name + " : " + value + " : " + color.name() + " : " + Utilities.listToCommaString(actions); + return name + " : " + level + " : " + color.name() + " : " + Utilities.listToCommaString(actions); } } 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 2a5ba09..ef6560c 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java +++ b/src/main/java/net/gravitydevelopment/anticheat/util/rule/Rule.java @@ -21,6 +21,7 @@ package net.gravitydevelopment.anticheat.util.rule; import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.manage.CheckType; import net.gravitydevelopment.anticheat.manage.User; +import net.gravitydevelopment.anticheat.util.Group; import net.gravitydevelopment.anticheat.util.Utilities; import java.lang.reflect.Constructor; @@ -139,6 +140,8 @@ public class Rule { SortedMap map = new TreeMap(); map.put("player_check", type.name().toLowerCase()); map.put("player_level", user.getLevel()); + map.put("player_group", user.getGroup().getName()); + map.put("player_name", user.getName()); for (CheckType t : CheckType.values()) { map.put("check_" + t.name().toLowerCase(), t.getUses(user.getName())); } @@ -150,6 +153,12 @@ public class Rule { // others wouldn't make any sense to set if (variable.equals("player_level") && Utilities.isInt(value)) { user.setLevel(Integer.parseInt(value)); + } else if (variable.equals("player_group") && Utilities.isInt(value)) { + for (Group group : AntiCheat.getManager().getConfiguration().getGroups().getGroups()) { + if (group.getName().equalsIgnoreCase(value)) { + user.setLevel(group.getLevel()); + } + } } } diff --git a/src/main/resources/enterprise.yml b/src/main/resources/enterprise.yml index 71e3c70..a2562e1 100644 --- a/src/main/resources/enterprise.yml +++ b/src/main/resources/enterprise.yml @@ -31,10 +31,10 @@ log: # Syncing settings sync: # Keep user's levels synced in the database? - users: true + levels: true # Configuration settings config: - # Load events configuration from the database? - events: true + # Load groups configuration from the database? + groups: true # Load rules configuration from the database? rules: true \ No newline at end of file diff --git a/src/main/resources/events.yml b/src/main/resources/groups.yml similarity index 62% rename from src/main/resources/events.yml rename to src/main/resources/groups.yml index e6a44a1..aa63e18 100644 --- a/src/main/resources/events.yml +++ b/src/main/resources/groups.yml @@ -1,9 +1,6 @@ # AntiCheat configuration file # Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/ -events: +groups: - 'Medium : 20 : YELLOW : WARN' - 'High : 50 : RED : KICK' - - 'Custom : -1 : GREEN : COMMAND[ban &player;say hello world]' -rules: - # if spider check is less than 0, set level to 20. otherwise, do nothing - - 'Check_SPIDER < 0 ? Player.KICK : null' \ No newline at end of file + - 'Custom : -1 : GREEN : COMMAND[ban &player;say hello world]' \ No newline at end of file diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 2c20f11..1055348 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -1,7 +1,7 @@ # AntiCheat language file # Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/ alert: -- '&player has just entered the &level hack level.' +- '&player has just entered the &group hack group.' - '&player''s last failed check was: &check.' - 'Type ''/anticheat report &player'' for more information.' warning: diff --git a/src/main/resources/rules.yml b/src/main/resources/rules.yml new file mode 100644 index 0000000..207fe57 --- /dev/null +++ b/src/main/resources/rules.yml @@ -0,0 +1,5 @@ +# AntiCheat configuration file +# Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/ +rules: + # if spider check is less than 0, set group to 20. otherwise, do nothing + - 'Check_SPIDER < 0 ? Player.KICK : null' \ No newline at end of file