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

@@ -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,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;
@@ -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;