mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
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.
This commit is contained in:
1 parent
fd1e5232e0
commit
e5a2051aee
15 files changed
+150
-163
No files matched your search
@@ -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<String> high = new ArrayList<String>();
|
||||
private List<String> med = new ArrayList<String>();
|
||||
private List<String> low = new ArrayList<String>();
|
||||
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<String> 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<User> 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<CheckType> 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
+10
-10
@@ -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<Level> levels;
|
||||
private List<Group> groups;
|
||||
private int highestLevel;
|
||||
|
||||
public MySQLEventsHolder(Configuration config) {
|
||||
public MySQLGroupsHolder(Configuration config) {
|
||||
super(config, TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
highestLevel = 0;
|
||||
levels = new ArrayList<Level>();
|
||||
groups = new ArrayList<Group>();
|
||||
|
||||
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<String> 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<Level> getLevels() {
|
||||
return levels;
|
||||
public List<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
+21
-28
@@ -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<Level> levels;
|
||||
private List<Group> groups;
|
||||
|
||||
private int highestLevel;
|
||||
|
||||
public YamlEventsHolder(AntiCheat plugin, Configuration config) {
|
||||
public YamlGroupsHolder(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Level> getLevels() {
|
||||
return levels;
|
||||
public List<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,33 +50,26 @@ public class YamlEventsHolder extends ConfigurationFile implements Events {
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
ConfigValue<List<String>> levels = new ConfigValue<List<String>>("events");
|
||||
ConfigValue<List<String>> groups = new ConfigValue<List<String>>("groups");
|
||||
|
||||
// Clean up old values
|
||||
if(levels.didLoadDefault()) {
|
||||
new ConfigValue<List<String>>("levels").setValue(null);
|
||||
new ConfigValue<List<String>>("actions").setValue(null);
|
||||
save();
|
||||
}
|
||||
|
||||
// Convert levels list to Levels
|
||||
this.levels = new ArrayList<Level>();
|
||||
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<Group>();
|
||||
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<Level>() {
|
||||
public int compare(Level l1, Level l2) {
|
||||
if (l1.getValue() == l2.getValue()) {
|
||||
// Sort groups
|
||||
Collections.sort(this.groups, new Comparator<Group>() {
|
||||
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;
|
||||
+1
-1
@@ -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<Rule> rules;
|
||||
|
||||
|
||||
+3
-3
@@ -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<Level> getLevels();
|
||||
public List<Group> getGroups();
|
||||
|
||||
public int getHighestLevel();
|
||||
}
|
||||
@@ -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<Level> 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<Group> 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<Level> getLevels() {
|
||||
return config.getEvents().getLevels();
|
||||
private List<Group> getLevels() {
|
||||
return config.getGroups().getGroups();
|
||||
}
|
||||
|
||||
private boolean silentMode() {
|
||||
|
||||
@@ -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<String> 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<User> getUsersInGroup(Group group) {
|
||||
List<User> list = new ArrayList<User>();
|
||||
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<String> messageArray = new ArrayList<String>();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+9
-14
@@ -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<String> actions = new ArrayList<String>();
|
||||
|
||||
public Level(String name, int value, String color, List<String> actions) {
|
||||
public Group(String name, int level, String color, List<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<String, Object> map = new TreeMap<String, Object>();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user