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:
h31ix committed 2013-10-13 22:49:32 -04:00
1 parent fd1e5232e0
commit e5a2051aee
15 files changed
+150 -163

No files matched your search

@@ -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());
}
}
}
}