mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-03 01:00:20 +01:00
Further integration of the new configuration system + package
refactoring
This commit is contained in:
parent
c989b9f025
commit
fe9a868169
@ -0,0 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
public class ConfigurationException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -457634587532590464L;
|
||||
|
||||
public ConfigurationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -20,6 +21,7 @@ import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.ItemdupeCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.SpeedhackCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
|
||||
import com.ensifera.animosity.craftirc.CraftIRC;
|
||||
@ -37,12 +39,12 @@ import org.bukkit.plugin.Plugin;
|
||||
*/
|
||||
public class NoCheat extends JavaPlugin {
|
||||
|
||||
public MovingCheck movingCheck;
|
||||
public BedteleportCheck bedteleportCheck;
|
||||
public SpeedhackCheck speedhackCheck;
|
||||
public AirbuildCheck airbuildCheck;
|
||||
public ItemdupeCheck itemdupeCheck;
|
||||
public BogusitemsCheck bogusitemsCheck;
|
||||
private MovingCheck movingCheck;
|
||||
private BedteleportCheck bedteleportCheck;
|
||||
private SpeedhackCheck speedhackCheck;
|
||||
private AirbuildCheck airbuildCheck;
|
||||
private ItemdupeCheck itemdupeCheck;
|
||||
private BogusitemsCheck bogusitemsCheck;
|
||||
|
||||
private Check[] checks;
|
||||
|
||||
@ -63,6 +65,12 @@ public class NoCheat extends JavaPlugin {
|
||||
// CraftIRC 2.x, if available
|
||||
private CraftIRC irc;
|
||||
|
||||
private Level chatLevel;
|
||||
private Level ircLevel;
|
||||
private Level consoleLevel;
|
||||
private String ircTag;
|
||||
|
||||
|
||||
public NoCheat() {
|
||||
|
||||
}
|
||||
@ -116,20 +124,19 @@ public class NoCheat extends JavaPlugin {
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
movingCheck = new MovingCheck(this);
|
||||
bedteleportCheck = new BedteleportCheck(this);
|
||||
speedhackCheck = new SpeedhackCheck(this);
|
||||
airbuildCheck = new AirbuildCheck(this);
|
||||
itemdupeCheck = new ItemdupeCheck(this);
|
||||
bogusitemsCheck = new BogusitemsCheck(this);
|
||||
// parse the nocheat.yml config file
|
||||
setupConfig();
|
||||
|
||||
movingCheck = new MovingCheck(this, config);
|
||||
bedteleportCheck = new BedteleportCheck(this, config);
|
||||
speedhackCheck = new SpeedhackCheck(this, config);
|
||||
airbuildCheck = new AirbuildCheck(this, config);
|
||||
itemdupeCheck = new ItemdupeCheck(this, config);
|
||||
bogusitemsCheck = new BogusitemsCheck(this, config);
|
||||
|
||||
// just for convenience
|
||||
checks = new Check[] { movingCheck, bedteleportCheck, speedhackCheck, airbuildCheck, itemdupeCheck, bogusitemsCheck };
|
||||
|
||||
// parse the nocheat.yml config file
|
||||
setupConfig();
|
||||
|
||||
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
|
||||
// Get, if available, the Permissions and irc plugin
|
||||
@ -236,7 +243,7 @@ public class NoCheat extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void logToChat(Level l, String message) {
|
||||
if(config.chatLevel.intValue() <= l.intValue()) {
|
||||
if(chatLevel.intValue() <= l.intValue()) {
|
||||
for(Player player : getServer().getOnlinePlayers()) {
|
||||
if(hasPermission(player, PermissionData.PERMISSION_NOTIFY)) {
|
||||
player.sendMessage("["+l.getName()+"] " + message);
|
||||
@ -246,13 +253,13 @@ public class NoCheat extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void logToIRC(Level l, String message) {
|
||||
if(irc != null && config.ircLevel.intValue() <= l.intValue()) {
|
||||
irc.sendMessageToTag("["+l.getName()+"] " + message , config.ircTag);
|
||||
if(irc != null && ircLevel.intValue() <= l.intValue()) {
|
||||
irc.sendMessageToTag("["+l.getName()+"] " + message , ircTag);
|
||||
}
|
||||
}
|
||||
|
||||
private void logToConsole(Level l, String message) {
|
||||
if( config.consoleLevel.intValue() <= l.intValue()) {
|
||||
if( consoleLevel.intValue() <= l.intValue()) {
|
||||
Logger.getLogger("Minecraft").log(l, message);
|
||||
}
|
||||
}
|
||||
@ -295,9 +302,22 @@ public class NoCheat extends JavaPlugin {
|
||||
*/
|
||||
private void setupConfig() {
|
||||
if(this.config == null)
|
||||
this.config = new NoCheatConfiguration(this);
|
||||
this.config = new NoCheatConfiguration(new File(NoCheatConfiguration.configFile));
|
||||
else
|
||||
this.config.config();
|
||||
this.config.config(new File(NoCheatConfiguration.configFile));
|
||||
|
||||
config.setupFileLogger();
|
||||
|
||||
try {
|
||||
this.chatLevel = config.getLogLevelValue("logging.logtochat");
|
||||
this.ircLevel = config.getLogLevelValue("logging.logtoirc");
|
||||
this.consoleLevel = config.getLogLevelValue("logging.logtoconsole");
|
||||
this.ircTag = config.getStringValue("logging.logtoirctag");
|
||||
} catch (ConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
this.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,302 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CancelAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.LogAction;
|
||||
|
||||
/**
|
||||
* Central location for everything that's described in the configuration file
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class NoCheatConfiguration {
|
||||
|
||||
|
||||
private final static String configFile = "plugins/NoCheat/nocheat.yml";
|
||||
|
||||
// Our personal logger
|
||||
private final static String loggerName = "cc.co.evenprime.nocheat";
|
||||
public final Logger logger = Logger.getLogger(loggerName);
|
||||
|
||||
// The log level above which information gets logged to the specified logger
|
||||
public Level chatLevel = Level.WARNING;
|
||||
public Level ircLevel = Level.WARNING;
|
||||
public Level consoleLevel = Level.SEVERE;
|
||||
public Level fileLevel = Level.INFO;
|
||||
|
||||
public String fileName = "plugins/NoCheat/nocheat.log";
|
||||
|
||||
public String ircTag = "nocheat";
|
||||
|
||||
// Our log output to a file
|
||||
private FileHandler fh = null;
|
||||
|
||||
private final NoCheat plugin;
|
||||
|
||||
public NoCheatConfiguration(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
|
||||
config();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the configuration file and assign either standard values or whatever is declared in the file
|
||||
* @param configurationFile
|
||||
*/
|
||||
public void config() {
|
||||
|
||||
File configurationFile = new File(configFile);
|
||||
|
||||
if(!configurationFile.exists()) {
|
||||
createStandardConfigFile(configurationFile);
|
||||
}
|
||||
|
||||
Configuration c = new Configuration(configurationFile);
|
||||
c.load();
|
||||
|
||||
logger.setLevel(Level.INFO);
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
chatLevel = stringToLevel(c.getString("logging.logtochat"), chatLevel);
|
||||
consoleLevel = stringToLevel(c.getString("logging.logtoconsole"), consoleLevel);
|
||||
fileLevel = stringToLevel(c.getString("logging.logtofile"), fileLevel);
|
||||
ircLevel = stringToLevel(c.getString("logging.logtoirc"), ircLevel);
|
||||
ircTag = c.getString("logging.logtoirctag", ircTag);
|
||||
|
||||
if(fh == null) {
|
||||
try {
|
||||
fh = new FileHandler(fileName, true);
|
||||
fh.setLevel(fileLevel);
|
||||
fh.setFormatter(Logger.getLogger("Minecraft").getHandlers()[0].getFormatter());
|
||||
logger.addHandler(fh);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
plugin.speedhackCheck.limits[0] = c.getInt("speedhack.limits.low", plugin.speedhackCheck.limits[0]);
|
||||
plugin.speedhackCheck.limits[1] = c.getInt("speedhack.limits.med", plugin.speedhackCheck.limits[1]);
|
||||
plugin.speedhackCheck.limits[2] = c.getInt("speedhack.limits.high", plugin.speedhackCheck.limits[2]);
|
||||
|
||||
plugin.speedhackCheck.logMessage = c.getString("speedhack.logmessage", plugin.speedhackCheck.logMessage);
|
||||
|
||||
plugin.movingCheck.actions[0] = stringToActions(c.getString("moving.action.low"), plugin.movingCheck.actions[0]);
|
||||
plugin.movingCheck.actions[1] = stringToActions(c.getString("moving.action.med"), plugin.movingCheck.actions[1]);
|
||||
plugin.movingCheck.actions[2] = stringToActions(c.getString("moving.action.high"), plugin.movingCheck.actions[2]);
|
||||
|
||||
|
||||
plugin.movingCheck.logMessage = c.getString("moving.logmessage", plugin.movingCheck.logMessage);
|
||||
plugin.movingCheck.summaryMessage = c.getString("moving.summarymessage", plugin.movingCheck.summaryMessage);
|
||||
|
||||
plugin.movingCheck.allowFlying = c.getBoolean("moving.allowflying", plugin.movingCheck.allowFlying);
|
||||
plugin.movingCheck.allowFakeSneak = c.getBoolean("moving.allowfakesneak", plugin.movingCheck.allowFakeSneak);
|
||||
|
||||
plugin.speedhackCheck.actions[0] = stringToActions(c.getString("speedhack.action.low"), plugin.speedhackCheck.actions[0]);
|
||||
plugin.speedhackCheck.actions[1] = stringToActions(c.getString("speedhack.action.med"), plugin.speedhackCheck.actions[1]);
|
||||
plugin.speedhackCheck.actions[2] = stringToActions(c.getString("speedhack.action.high"), plugin.speedhackCheck.actions[2]);
|
||||
|
||||
plugin.airbuildCheck.limits[0] = c.getInt("airbuild.limits.low", plugin.airbuildCheck.limits[0]);
|
||||
plugin.airbuildCheck.limits[1] = c.getInt("airbuild.limits.med", plugin.airbuildCheck.limits[1]);
|
||||
plugin.airbuildCheck.limits[2] = c.getInt("airbuild.limits.high", plugin.airbuildCheck.limits[2]);
|
||||
|
||||
plugin.airbuildCheck.actions[0] = stringToActions(c.getString("airbuild.action.low"), plugin.airbuildCheck.actions[0]);
|
||||
plugin.airbuildCheck.actions[1] = stringToActions(c.getString("airbuild.action.med"), plugin.airbuildCheck.actions[1]);
|
||||
plugin.airbuildCheck.actions[2] = stringToActions(c.getString("airbuild.action.high"), plugin.airbuildCheck.actions[2]);
|
||||
|
||||
plugin.speedhackCheck.setActive(c.getBoolean("active.speedhack", true));
|
||||
plugin.movingCheck.setActive(c.getBoolean("active.moving", true));
|
||||
plugin.airbuildCheck.setActive(c.getBoolean("active.airbuild", false));
|
||||
plugin.bedteleportCheck.setActive(c.getBoolean("active.bedteleport", true));
|
||||
plugin.itemdupeCheck.setActive(c.getBoolean("active.itemdupe", true));
|
||||
plugin.bogusitemsCheck.setActive(c.getBoolean("active.bogusitems", false));
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
|
||||
if(fh != null) {
|
||||
try {
|
||||
logger.removeHandler(fh);
|
||||
fh.flush();
|
||||
fh.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Action[] stringToActions(String string, Action[] def) {
|
||||
|
||||
if(string == null) return def;
|
||||
|
||||
List<Action> as = new LinkedList<Action>();
|
||||
String[] parts = string.split(" ");
|
||||
|
||||
for(String s : parts) {
|
||||
if(s.equals("loglow"))
|
||||
as.add(LogAction.loglow);
|
||||
else if(s.equals("logmed"))
|
||||
as.add(LogAction.logmed);
|
||||
else if(s.equals("loghigh"))
|
||||
as.add(LogAction.loghigh);
|
||||
else if(s.equals("deny"))
|
||||
as.add(CancelAction.cancel);
|
||||
else if(s.equals("reset"))
|
||||
as.add(CancelAction.cancel);
|
||||
else if(s.equals("cancel"))
|
||||
as.add(CancelAction.cancel);
|
||||
else if(s.startsWith("custom")) {
|
||||
try {
|
||||
// TODO: Implement Custom Action
|
||||
//as.add(new CustomAction(Integer.parseInt(s.substring(6))));
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println("NC: Couldn't parse number of custom action '" + s + "'");
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("NC: Can't parse action "+ s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return as.toArray(def);
|
||||
}
|
||||
|
||||
private String actionsToString(Action[] actions) {
|
||||
|
||||
StringBuffer s = new StringBuffer();
|
||||
|
||||
if(actions != null) {
|
||||
for(Action a : actions) {
|
||||
s.append(' ').append(a.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return s.toString().trim();
|
||||
}
|
||||
/**
|
||||
* Convert a string into a log level
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
private static Level stringToLevel(String string, Level def) {
|
||||
|
||||
if(string == null) {
|
||||
return def;
|
||||
}
|
||||
|
||||
if(string.trim().equals("info") || string.trim().equals("low")) return Level.INFO;
|
||||
if(string.trim().equals("warn") || string.trim().equals("med")) return Level.WARNING;
|
||||
if(string.trim().equals("severe")|| string.trim().equals("high")) return Level.SEVERE;
|
||||
|
||||
return Level.OFF;
|
||||
}
|
||||
|
||||
private static String levelToString(Level level) {
|
||||
|
||||
if(level == null) {
|
||||
return "off";
|
||||
}
|
||||
|
||||
if(level.equals(Level.INFO)) return "low";
|
||||
else if(level.equals(Level.WARNING)) return "med";
|
||||
else if(level.equals(Level.SEVERE)) return "high";
|
||||
|
||||
return "off";
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard configuration file for people who haven't got one yet
|
||||
* @param f
|
||||
*/
|
||||
private void createStandardConfigFile(File f) {
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
BufferedWriter w = new BufferedWriter(new FileWriter(f));
|
||||
|
||||
w.write("# Logging: potential log levels are low (info), med (warn), high (severe), off"); w.newLine();
|
||||
w.write("logging:"); w.newLine();
|
||||
w.write(" filename: "+fileName); w.newLine();
|
||||
w.write(" logtofile: "+levelToString(fileLevel)); w.newLine();
|
||||
w.write(" logtoconsole: "+levelToString(consoleLevel)); w.newLine();
|
||||
w.write(" logtochat: "+levelToString(chatLevel)); w.newLine();
|
||||
w.write(" logtoirc: "+levelToString(ircLevel)); w.newLine();
|
||||
w.write(" logtoirctag: "+ircTag); w.newLine();
|
||||
w.write("# Checks and Bugfixes that are activated (true or false)"); w.newLine();
|
||||
w.write("active:"); w.newLine();
|
||||
w.write(" speedhack: true"); w.newLine();
|
||||
w.write(" moving: true"); w.newLine();
|
||||
w.write(" airbuild: false"); w.newLine();
|
||||
w.write(" bedteleport: true"); w.newLine();
|
||||
w.write(" itemdupe: true"); w.newLine();
|
||||
w.write(" bogusitems: false"); w.newLine();
|
||||
w.write("# Speedhack specific options"); w.newLine();
|
||||
w.write("speedhack:"); w.newLine();
|
||||
w.write(" logmessage: \"" + plugin.speedhackCheck.logMessage+"\""); w.newLine();
|
||||
w.write(" limits:"); w.newLine();
|
||||
w.write(" low: "+plugin.speedhackCheck.limits[0]); w.newLine();
|
||||
w.write(" med: "+plugin.speedhackCheck.limits[1]); w.newLine();
|
||||
w.write(" high: "+plugin.speedhackCheck.limits[2]); w.newLine();
|
||||
w.write("# Speedhack Action, one or more of 'loglow logmed loghigh cancel'"); w.newLine();
|
||||
w.write(" action:"); w.newLine();
|
||||
w.write(" low: "+actionsToString(plugin.speedhackCheck.actions[0])); w.newLine();
|
||||
w.write(" med: "+actionsToString(plugin.speedhackCheck.actions[1])); w.newLine();
|
||||
w.write(" high: "+actionsToString(plugin.speedhackCheck.actions[2])); w.newLine();
|
||||
w.write("# Moving specific options") ; w.newLine();
|
||||
w.write("moving:"); w.newLine();
|
||||
w.write(" logmessage: \"" + plugin.movingCheck.logMessage+"\""); w.newLine();
|
||||
w.write(" summarymessage: \"" + plugin.movingCheck.summaryMessage+"\""); w.newLine();
|
||||
w.write("# Should (normal speed) flying be generally allowed?"); w.newLine();
|
||||
w.write(" allowflying: " + plugin.movingCheck.allowFlying); w.newLine();
|
||||
w.write("# Should sneaking with normal walking speed be generally allowed?"); w.newLine();
|
||||
w.write(" allowfakesneak: " + plugin.movingCheck.allowFakeSneak); w.newLine();
|
||||
w.write("# Moving Action, one or more of 'loglow logmed loghigh cancel'"); w.newLine();
|
||||
w.write(" action:"); w.newLine();
|
||||
w.write(" low: "+actionsToString(plugin.movingCheck.actions[0])); w.newLine();
|
||||
w.write(" med: "+actionsToString(plugin.movingCheck.actions[1])); w.newLine();
|
||||
w.write(" high: "+actionsToString(plugin.movingCheck.actions[2])); w.newLine();
|
||||
w.write("# Airbuild specific options"); w.newLine();
|
||||
w.write("airbuild:"); w.newLine();
|
||||
w.write("# How many blocks per second are placed by the player in midair to trigger corresponding action"); w.newLine();
|
||||
w.write(" limits:"); w.newLine();
|
||||
w.write(" low: "+plugin.airbuildCheck.limits[0]); w.newLine();
|
||||
w.write(" med: "+plugin.airbuildCheck.limits[1]); w.newLine();
|
||||
w.write(" high: "+plugin.airbuildCheck.limits[2]); w.newLine();
|
||||
w.write("# Airbuild Action, one or more of 'loglow logmed loghigh cancel'"); w.newLine();
|
||||
w.write(" action:"); w.newLine();
|
||||
w.write(" low: "+actionsToString(plugin.airbuildCheck.actions[0])); w.newLine();
|
||||
w.write(" med: "+actionsToString(plugin.airbuildCheck.actions[1])); w.newLine();
|
||||
w.write(" high: "+actionsToString(plugin.airbuildCheck.actions[2])); w.newLine();
|
||||
w.write("# Bedteleport specific options (none exist yet)"); w.newLine();
|
||||
w.write("bedteleport:"); w.newLine();
|
||||
w.write("# Itemdupe specific options (none exist yet)"); w.newLine();
|
||||
w.write("itemdupe:"); w.newLine();
|
||||
w.write("# Bogusitems specific options (none exist yet)"); w.newLine();
|
||||
w.write("bogusitems:"); w.newLine();
|
||||
|
||||
w.flush(); w.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,11 +9,13 @@ import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CancelAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CustomAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.LogAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.AirbuildData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.AirbuildBlockListener;
|
||||
@ -28,15 +30,15 @@ import cc.co.evenprime.bukkit.nocheat.listeners.AirbuildBlockListener;
|
||||
public class AirbuildCheck extends Check {
|
||||
|
||||
// How should airbuild violations be treated?
|
||||
public final Action actions[][] = {
|
||||
private final Action actions[][] = {
|
||||
{ LogAction.loglow, CancelAction.cancel },
|
||||
{ LogAction.logmed, CancelAction.cancel },
|
||||
{ LogAction.loghigh, CancelAction.cancel } };
|
||||
|
||||
public final int limits[] = { 1, 3, 10 };
|
||||
private int limits[];
|
||||
|
||||
public AirbuildCheck(NoCheat plugin) {
|
||||
super(plugin, "airbuild", PermissionData.PERMISSION_AIRBUILD);
|
||||
public AirbuildCheck(NoCheat plugin, NoCheatConfiguration config) {
|
||||
super(plugin, "airbuild", PermissionData.PERMISSION_AIRBUILD, config);
|
||||
}
|
||||
|
||||
public void check(BlockPlaceEvent event) {
|
||||
@ -123,6 +125,24 @@ public class AirbuildCheck extends Check {
|
||||
data.perSecond = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(NoCheatConfiguration config) {
|
||||
|
||||
try {
|
||||
limits = new int[3];
|
||||
|
||||
limits[0] = config.getIntegerValue("airbuild.limits.low");
|
||||
limits[1] = config.getIntegerValue("airbuild.limits.med");
|
||||
limits[2] = config.getIntegerValue("airbuild.limits.high");
|
||||
|
||||
setActive(config.getBooleanValue("active.airbuild"));
|
||||
|
||||
} catch (ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||
|
@ -6,7 +6,9 @@ import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.BedteleportPlayerListener;
|
||||
|
||||
@ -18,8 +20,8 @@ import cc.co.evenprime.bukkit.nocheat.listeners.BedteleportPlayerListener;
|
||||
|
||||
public class BedteleportCheck extends Check {
|
||||
|
||||
public BedteleportCheck(NoCheat plugin) {
|
||||
super(plugin, "bedteleport", PermissionData.PERMISSION_BEDTELEPORT);
|
||||
public BedteleportCheck(NoCheat plugin, NoCheatConfiguration config) {
|
||||
super(plugin, "bedteleport", PermissionData.PERMISSION_BEDTELEPORT, config);
|
||||
}
|
||||
|
||||
public void check(PlayerMoveEvent event) {
|
||||
@ -31,7 +33,18 @@ public class BedteleportCheck extends Check {
|
||||
if(event.getPlayer().isSleeping())
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configure(NoCheatConfiguration config) {
|
||||
|
||||
try {
|
||||
setActive(config.getBooleanValue("active.bedteleport"));
|
||||
} catch (ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||
|
@ -15,14 +15,16 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.BogusitemsPlayerListener;
|
||||
|
||||
public class BogusitemsCheck extends Check {
|
||||
|
||||
public BogusitemsCheck(NoCheat plugin){
|
||||
super(plugin, "bogusitems", PermissionData.PERMISSION_BOGUSITEMS);
|
||||
public BogusitemsCheck(NoCheat plugin, NoCheatConfiguration config){
|
||||
super(plugin, "bogusitems", PermissionData.PERMISSION_BOGUSITEMS, config);
|
||||
}
|
||||
|
||||
public void check(PlayerPickupItemEvent event) {
|
||||
@ -86,11 +88,22 @@ public class BogusitemsCheck extends Check {
|
||||
for(int i = 0; i < stacks.length; i++) {
|
||||
if(stacks[i] != null && stacks[i].getAmount() <= 0) {
|
||||
inv.clear(i);
|
||||
plugin.log(Level.WARNING, "Removed illegal item from inventory of " + player.getName());
|
||||
plugin.log(Level.WARNING, "Removed invalid item from inventory of " + player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(NoCheatConfiguration config) {
|
||||
|
||||
try {
|
||||
setActive(config.getBooleanValue("active.bogusitems"));
|
||||
} catch (ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||
|
@ -4,6 +4,7 @@ package cc.co.evenprime.bukkit.nocheat.checks;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -18,16 +19,20 @@ public abstract class Check {
|
||||
private String name;
|
||||
protected NoCheat plugin;
|
||||
|
||||
public Check(NoCheat plugin, String name, int permission) {
|
||||
protected Check(NoCheat plugin, String name, int permission, NoCheatConfiguration config) {
|
||||
this.plugin = plugin;
|
||||
this.permission = permission;
|
||||
this.name = name;
|
||||
|
||||
configure(config);
|
||||
}
|
||||
|
||||
public boolean skipCheck(Player player) {
|
||||
// Should we check at all?
|
||||
return !active || plugin.hasPermission(player, permission);
|
||||
}
|
||||
|
||||
protected abstract void configure(NoCheatConfiguration config);
|
||||
|
||||
protected abstract void registerListeners();
|
||||
|
||||
@ -35,7 +40,7 @@ public abstract class Check {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
protected void setActive(boolean active) {
|
||||
synchronized(this) {
|
||||
if(active && !listenersRegistered) {
|
||||
listenersRegistered = true;
|
||||
@ -50,4 +55,6 @@ public abstract class Check {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,14 +8,16 @@ import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.ItemdupeEntityListener;
|
||||
|
||||
public class ItemdupeCheck extends Check {
|
||||
|
||||
public ItemdupeCheck(NoCheat plugin){
|
||||
super(plugin, "itemdupe", PermissionData.PERMISSION_ITEMDUPE);
|
||||
public ItemdupeCheck(NoCheat plugin, NoCheatConfiguration config){
|
||||
super(plugin, "itemdupe", PermissionData.PERMISSION_ITEMDUPE, config);
|
||||
}
|
||||
|
||||
|
||||
@ -28,6 +30,16 @@ public class ItemdupeCheck extends Check {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(NoCheatConfiguration config) {
|
||||
|
||||
try {
|
||||
setActive(config.getBooleanValue("active.itemdupe"));
|
||||
} catch (ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
|
@ -16,11 +16,13 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CancelAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CustomAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.LogAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.MovingEntityListener;
|
||||
@ -35,8 +37,9 @@ import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerMonitor;
|
||||
*/
|
||||
public class MovingCheck extends Check {
|
||||
|
||||
public MovingCheck(NoCheat plugin) {
|
||||
super(plugin, "moving", PermissionData.PERMISSION_MOVING);
|
||||
public MovingCheck(NoCheat plugin, NoCheatConfiguration config) {
|
||||
super(plugin, "moving", PermissionData.PERMISSION_MOVING, config);
|
||||
|
||||
}
|
||||
|
||||
// How many move events can a player have in air before he is expected to lose altitude (or land somewhere)
|
||||
@ -51,22 +54,22 @@ public class MovingCheck extends Check {
|
||||
private final static double stepWidth = 0.6D;
|
||||
private final static double sneakStepWidth = 0.25D;
|
||||
|
||||
public int ticksBeforeSummary = 100;
|
||||
private int ticksBeforeSummary = 100;
|
||||
|
||||
public long statisticElapsedTimeNano = 0;
|
||||
|
||||
public boolean allowFlying = false;
|
||||
public boolean allowFakeSneak = true;
|
||||
public boolean allowFlying;
|
||||
public boolean allowFakeSneak;
|
||||
|
||||
private String logMessage;
|
||||
private String summaryMessage;
|
||||
|
||||
// How should moving violations be treated?
|
||||
public final Action actions[][] = {
|
||||
private final Action actions[][] = {
|
||||
{ LogAction.loglow, CancelAction.cancel },
|
||||
{ LogAction.logmed, CancelAction.cancel },
|
||||
{ LogAction.loghigh, CancelAction.cancel } };
|
||||
|
||||
public String logMessage = "Moving violation: %1$s from %2$s (%4$.1f, %5$.1f, %6$.1f) to %3$s (%7$.1f, %8$.1f, %9$.1f)";
|
||||
public String summaryMessage = "Moving summary of last ~%2$d seconds: %1$s total Violations: (%3$d,%4$d,%5$d)";
|
||||
|
||||
public long statisticTotalEvents = 1; // Prevent accidental division by 0 at some point
|
||||
|
||||
private static final double magic = 0.30000001192092896D;
|
||||
@ -646,6 +649,24 @@ public class MovingCheck extends Check {
|
||||
data.teleportTo = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(NoCheatConfiguration config) {
|
||||
|
||||
try {
|
||||
allowFlying = config.getBooleanValue("moving.allowflying");
|
||||
allowFakeSneak = config.getBooleanValue("moving.allowfakesneak");
|
||||
|
||||
logMessage = config.getStringValue("moving.logmessage");
|
||||
summaryMessage = config.getStringValue("moving.summarymessage");
|
||||
|
||||
setActive(config.getBooleanValue("active.moving"));
|
||||
} catch (ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||
|
@ -10,11 +10,13 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CancelAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CustomAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.LogAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SpeedhackData;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.SpeedhackPlayerListener;
|
||||
@ -27,23 +29,23 @@ import cc.co.evenprime.bukkit.nocheat.listeners.SpeedhackPlayerListener;
|
||||
*/
|
||||
public class SpeedhackCheck extends Check {
|
||||
|
||||
public SpeedhackCheck(NoCheat plugin) {
|
||||
super(plugin, "speedhack", PermissionData.PERMISSION_SPEEDHACK);
|
||||
public SpeedhackCheck(NoCheat plugin, NoCheatConfiguration config) {
|
||||
super(plugin, "speedhack", PermissionData.PERMISSION_SPEEDHACK, config);
|
||||
}
|
||||
|
||||
private static final int violationsLimit = 2;
|
||||
|
||||
// Limits for the speedhack check per second
|
||||
public int limits[] = { 30, 45, 60 };
|
||||
private int limits[];
|
||||
|
||||
private String logMessage;
|
||||
|
||||
// How should speedhack violations be treated?
|
||||
public Action actions[][] = {
|
||||
private Action actions[][] = {
|
||||
{ LogAction.loglow, CancelAction.cancel },
|
||||
{ LogAction.logmed, CancelAction.cancel },
|
||||
{ LogAction.loghigh, CancelAction.cancel } };
|
||||
|
||||
public String logMessage = "%1$s sent %2$d move events, but only %3$d were allowed. Speedhack?";
|
||||
|
||||
public void check(PlayerMoveEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
@ -145,6 +147,28 @@ public class SpeedhackCheck extends Check {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(NoCheatConfiguration config) {
|
||||
|
||||
try {
|
||||
|
||||
limits = new int[3];
|
||||
|
||||
limits[0] = config.getIntegerValue("speedhack.limits.low");
|
||||
limits[1] = config.getIntegerValue("speedhack.limits.med");
|
||||
limits[2] = config.getIntegerValue("speedhack.limits.high");
|
||||
|
||||
logMessage = config.getStringValue("speedhack.logmessage");
|
||||
|
||||
setActive(config.getBooleanValue("active.speedhack"));
|
||||
} catch (ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
|
||||
public class BooleanOption extends ChildOption {
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
public abstract class ChildOption extends Option {
|
||||
|
||||
@ -14,4 +14,9 @@ public abstract class ChildOption extends Option {
|
||||
|
||||
|
||||
public abstract String getValue();
|
||||
|
||||
@Override
|
||||
public String toYAMLString(String prefix) {
|
||||
return prefix + getIdentifier() + ": \"" + getValue() + "\"\r\n";
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
|
||||
public class IntegerOption extends TextFieldOption {
|
||||
@ -26,4 +26,8 @@ public class IntegerOption extends TextFieldOption {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int getIntegerValue() {
|
||||
return Integer.parseInt(this.getValue());
|
||||
}
|
||||
}
|
82
src/cc/co/evenprime/bukkit/nocheat/config/LevelOption.java
Normal file
82
src/cc/co/evenprime/bukkit/nocheat/config/LevelOption.java
Normal file
@ -0,0 +1,82 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class LevelOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1609308017422576285L;
|
||||
|
||||
private LogLevel option;
|
||||
|
||||
public enum LogLevel {
|
||||
|
||||
|
||||
OFF("off", "never", Level.OFF),
|
||||
LOW("low", "all messages", Level.INFO),
|
||||
MED("med", "important messages", Level.WARNING),
|
||||
HIGH("high", "very important messages", Level.SEVERE);
|
||||
|
||||
private final String value;
|
||||
private String description;
|
||||
private Level level;
|
||||
|
||||
private LogLevel(String value, String description, Level level) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String asString() { return this.value; }
|
||||
|
||||
public static LogLevel getLogLevelFromString(String s) {
|
||||
if(s == null) return OFF;
|
||||
if("off".equals(s))
|
||||
return OFF;
|
||||
else if("low".equals(s))
|
||||
return LOW;
|
||||
else if("med".equals(s))
|
||||
return MED;
|
||||
else if("high".equals(s))
|
||||
return HIGH;
|
||||
else
|
||||
return OFF;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return this.name() + ": " + description;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
public LevelOption(String identifier, LogLevel initialValue) {
|
||||
|
||||
super(identifier);
|
||||
this.option = initialValue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return option.asString();
|
||||
}
|
||||
|
||||
public void setValue(LogLevel value) {
|
||||
this.option = value;
|
||||
}
|
||||
|
||||
public LogLevel getOptionValue() {
|
||||
return this.option;
|
||||
}
|
||||
|
||||
public Level getLevelValue() {
|
||||
return this.option.getLevel();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
public class LongStringOption extends TextFieldOption {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
public class MediumStringOption extends TextFieldOption {
|
||||
|
@ -0,0 +1,434 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.CancelAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.LogAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.LevelOption.LogLevel;
|
||||
|
||||
/**
|
||||
* Central location for everything that's described in the configuration file
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class NoCheatConfiguration {
|
||||
|
||||
|
||||
public final static String configFile = "plugins/NoCheat/nocheat.yml";
|
||||
|
||||
private ParentOption root;
|
||||
|
||||
// Our personal logger
|
||||
private final static String loggerName = "cc.co.evenprime.nocheat";
|
||||
public final Logger logger = Logger.getLogger(loggerName);
|
||||
|
||||
// Our log output to a file
|
||||
private FileHandler fh = null;
|
||||
|
||||
public NoCheatConfiguration(File configurationFile) {
|
||||
|
||||
// Setup the configuration tree
|
||||
config(configurationFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the configuration file and assign either standard values or whatever is declared in the file
|
||||
* @param configurationFile
|
||||
*/
|
||||
public void config(File configurationFile) {
|
||||
|
||||
Configuration CONFIG = new Configuration(configurationFile);
|
||||
CONFIG.load();
|
||||
|
||||
root = new ParentOption("");
|
||||
|
||||
|
||||
/*** LOGGING section ***/
|
||||
{
|
||||
ParentOption loggingNode = new ParentOption("logging");
|
||||
root.add(loggingNode);
|
||||
|
||||
loggingNode.add(new MediumStringOption("filename",
|
||||
CONFIG.getString("logging.filename", "plugins/NoCheat/nocheat.log")));
|
||||
|
||||
loggingNode.add(new LevelOption("logtofile",
|
||||
LogLevel.getLogLevelFromString(CONFIG.getString("logging.logtofile", LogLevel.LOW.asString()))));
|
||||
loggingNode.add(new LevelOption("logtoconsole",
|
||||
LogLevel.getLogLevelFromString(CONFIG.getString("logging.logtoconsole", LogLevel.HIGH.asString()))));
|
||||
loggingNode.add(new LevelOption("logtochat",
|
||||
LogLevel.getLogLevelFromString(CONFIG.getString("logging.logtochat", LogLevel.MED.asString()))));
|
||||
loggingNode.add(new LevelOption("logtoirc",
|
||||
LogLevel.getLogLevelFromString(CONFIG.getString("logging.logtoirc", LogLevel.MED.asString()))));
|
||||
|
||||
loggingNode.add(new ShortStringOption("logtoirctag",
|
||||
CONFIG.getString("logging.logtoirctag", "nocheat")));
|
||||
}
|
||||
|
||||
/*** ACTIVE section ***/
|
||||
{
|
||||
ParentOption activeNode = new ParentOption("active");
|
||||
root.add(activeNode);
|
||||
|
||||
activeNode.add(new BooleanOption("speedhack",
|
||||
CONFIG.getBoolean("active.speedhack", true)));
|
||||
activeNode.add(new BooleanOption("moving",
|
||||
CONFIG.getBoolean("active.moving", true)));
|
||||
activeNode.add(new BooleanOption("airbuild",
|
||||
CONFIG.getBoolean("active.airbuild", false)));
|
||||
activeNode.add(new BooleanOption("bedteleport",
|
||||
CONFIG.getBoolean("active.bedteleport", true)));
|
||||
activeNode.add(new BooleanOption("itemdupe",
|
||||
CONFIG.getBoolean("active.itemdupe", true)));
|
||||
activeNode.add(new BooleanOption("bogusitems",
|
||||
CONFIG.getBoolean("active.bogusitems", false)));
|
||||
}
|
||||
|
||||
/*** SPEEDHACK section ***/
|
||||
{
|
||||
ParentOption speedhackNode = new ParentOption("speedhack");
|
||||
root.add(speedhackNode);
|
||||
|
||||
speedhackNode.add(new LongStringOption("logmessage",
|
||||
CONFIG.getString("logging.filename", "%1$s sent %2$d move events, but only %3$d were allowed. Speedhack?")));
|
||||
|
||||
/*** SPEEDHACK LIMITS section ***/
|
||||
{
|
||||
ParentOption speedhackLimitsNode = new ParentOption("limits");
|
||||
speedhackNode.add(speedhackLimitsNode);
|
||||
|
||||
speedhackLimitsNode.add(new IntegerOption("low",
|
||||
CONFIG.getInt("speedhack.limits.low", 30)));
|
||||
speedhackLimitsNode.add(new IntegerOption("med",
|
||||
CONFIG.getInt("speedhack.limits.med", 45)));
|
||||
speedhackLimitsNode.add(new IntegerOption("high",
|
||||
CONFIG.getInt("speedhack.limits.high", 60)));
|
||||
}
|
||||
|
||||
/*** SPEEDHACK ACTIONS section ***/
|
||||
{
|
||||
ParentOption speedhackActionNode = new ParentOption("action");
|
||||
speedhackNode.add(speedhackActionNode);
|
||||
|
||||
speedhackActionNode.add(new MediumStringOption("low",
|
||||
CONFIG.getString("speedhack.action.low", "loglow cancel")));
|
||||
speedhackActionNode.add(new MediumStringOption("med",
|
||||
CONFIG.getString("speedhack.action.med", "logmed cancel")));
|
||||
speedhackActionNode.add(new MediumStringOption("high",
|
||||
CONFIG.getString("speedhack.action.high", "loghigh cancel")));
|
||||
}
|
||||
}
|
||||
|
||||
/*** MOVING section ***/
|
||||
{
|
||||
ParentOption movingNode = new ParentOption("moving");
|
||||
root.add(movingNode);
|
||||
|
||||
movingNode.add(new LongStringOption("logmessage",
|
||||
CONFIG.getString("moving.logmessage", "Moving violation: %1$s from %2$s (%4$.1f, %5$.1f, %6$.1f) to %3$s (%7$.1f, %8$.1f, %9$.1f)")));
|
||||
movingNode.add(new LongStringOption("summarymessage",
|
||||
CONFIG.getString("moving.summarymessage", "Moving summary of last ~%2$d seconds: %1$s total Violations: (%3$d,%4$d,%5$d)")));
|
||||
movingNode.add(new BooleanOption("allowflying",
|
||||
CONFIG.getBoolean("moving.allowflying", false)));
|
||||
movingNode.add(new BooleanOption("allowfakesneak",
|
||||
CONFIG.getBoolean("moving.allowfakesneak", true)));
|
||||
|
||||
/*** MOVING ACTION section ***/
|
||||
{
|
||||
ParentOption movingActionNode = new ParentOption("action");
|
||||
movingNode.add(movingActionNode);
|
||||
|
||||
movingActionNode.add(new MediumStringOption("low",
|
||||
CONFIG.getString("moving.action.low", "loglow cancel")));
|
||||
movingActionNode.add(new MediumStringOption("med",
|
||||
CONFIG.getString("moving.action.med", "logmed cancel")));
|
||||
movingActionNode.add(new MediumStringOption("high",
|
||||
CONFIG.getString("moving.action.high", "loghigh cancel")));
|
||||
}
|
||||
}
|
||||
|
||||
/*** AIRBUILD section ***/
|
||||
{
|
||||
ParentOption airbuildNode = new ParentOption("airbuild");
|
||||
root.add(airbuildNode);
|
||||
|
||||
/*** AIRBUILD LIMITS section ***/
|
||||
{
|
||||
ParentOption airbuildLimitsNode = new ParentOption("limits");
|
||||
airbuildNode.add(airbuildLimitsNode);
|
||||
|
||||
airbuildLimitsNode.add(new IntegerOption("low",
|
||||
CONFIG.getInt("airbuild.limits.low", 1)));
|
||||
airbuildLimitsNode.add(new IntegerOption("med",
|
||||
CONFIG.getInt("airbuild.limits.med", 3)));
|
||||
airbuildLimitsNode.add(new IntegerOption("high",
|
||||
CONFIG.getInt("airbuild.limits.high", 10)));
|
||||
}
|
||||
|
||||
/*** AIRBUILD ACTION section ***/
|
||||
{
|
||||
ParentOption airbuildActionNode = new ParentOption("action");
|
||||
airbuildNode.add(airbuildActionNode);
|
||||
|
||||
airbuildActionNode.add(new MediumStringOption("low",
|
||||
CONFIG.getString("airbuild.action.low", "loglow cancel")));
|
||||
airbuildActionNode.add(new MediumStringOption("med",
|
||||
CONFIG.getString("airbuild.action.med", "logmed cancel")));
|
||||
airbuildActionNode.add(new MediumStringOption("high",
|
||||
CONFIG.getString("airbuild.action.high", "loghigh cancel")));
|
||||
}
|
||||
}
|
||||
|
||||
/*** BEDTELEPORT section ***/
|
||||
{
|
||||
ParentOption bedteleportNode = new ParentOption("bedteleport");
|
||||
root.add(bedteleportNode);
|
||||
}
|
||||
|
||||
/*** ITEMDUPE section ***/
|
||||
{
|
||||
ParentOption itemdupeNode = new ParentOption("itemdupe");
|
||||
root.add(itemdupeNode);
|
||||
}
|
||||
|
||||
/*** BOGUSITEMS section ***/
|
||||
{
|
||||
ParentOption bogusitemsNode = new ParentOption("bogusitems");
|
||||
root.add(bogusitemsNode);
|
||||
}
|
||||
|
||||
if(!configurationFile.exists()) {
|
||||
writeConfigFile(configurationFile, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setupFileLogger() {
|
||||
|
||||
logger.setLevel(Level.INFO);
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
if(fh == null) {
|
||||
try {
|
||||
fh = new FileHandler(getStringValue("logging.filename"), true);
|
||||
fh.setLevel(getLogLevelValue("logging.logtofile"));
|
||||
fh.setFormatter(Logger.getLogger("Minecraft").getHandlers()[0].getFormatter());
|
||||
logger.addHandler(fh);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
|
||||
if(fh != null) {
|
||||
try {
|
||||
logger.removeHandler(fh);
|
||||
fh.flush();
|
||||
fh.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Action[] stringToActions(String string, Action[] def) {
|
||||
|
||||
if(string == null) return def;
|
||||
|
||||
List<Action> as = new LinkedList<Action>();
|
||||
String[] parts = string.split(" ");
|
||||
|
||||
for(String s : parts) {
|
||||
if(s.equals("loglow"))
|
||||
as.add(LogAction.loglow);
|
||||
else if(s.equals("logmed"))
|
||||
as.add(LogAction.logmed);
|
||||
else if(s.equals("loghigh"))
|
||||
as.add(LogAction.loghigh);
|
||||
else if(s.equals("deny"))
|
||||
as.add(CancelAction.cancel);
|
||||
else if(s.equals("reset"))
|
||||
as.add(CancelAction.cancel);
|
||||
else if(s.equals("cancel"))
|
||||
as.add(CancelAction.cancel);
|
||||
else if(s.startsWith("custom")) {
|
||||
try {
|
||||
// TODO: Implement Custom Action
|
||||
//as.add(new CustomAction(Integer.parseInt(s.substring(6))));
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println("NC: Couldn't parse number of custom action '" + s + "'");
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("NC: Can't parse action "+ s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return as.toArray(def);
|
||||
}
|
||||
|
||||
private String actionsToString(Action[] actions) {
|
||||
|
||||
StringBuffer s = new StringBuffer();
|
||||
|
||||
if(actions != null) {
|
||||
for(Action a : actions) {
|
||||
s.append(' ').append(a.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return s.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string into a log level
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
private static Level stringToLevel(String string, Level def) {
|
||||
|
||||
if(string == null) {
|
||||
return def;
|
||||
}
|
||||
|
||||
if(string.trim().equals("info") || string.trim().equals("low")) return Level.INFO;
|
||||
if(string.trim().equals("warn") || string.trim().equals("med")) return Level.WARNING;
|
||||
if(string.trim().equals("severe")|| string.trim().equals("high")) return Level.SEVERE;
|
||||
|
||||
return Level.OFF;
|
||||
}
|
||||
|
||||
private static String levelToString(Level level) {
|
||||
|
||||
if(level == null) {
|
||||
return "off";
|
||||
}
|
||||
|
||||
if(level.equals(Level.INFO)) return "low";
|
||||
else if(level.equals(Level.WARNING)) return "med";
|
||||
else if(level.equals(Level.SEVERE)) return "high";
|
||||
|
||||
return "off";
|
||||
}
|
||||
|
||||
/**
|
||||
* Write configuration file to specific filename
|
||||
* @param f
|
||||
*/
|
||||
public static void writeConfigFile(File f, NoCheatConfiguration configuration) {
|
||||
try {
|
||||
if(f.getParentFile() != null)
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
BufferedWriter w = new BufferedWriter(new FileWriter(f));
|
||||
|
||||
w.write(configuration.getRoot().toYAMLString(""));
|
||||
|
||||
w.flush(); w.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getIntegerValue(String optionName) throws ConfigurationException {
|
||||
return getIntegerOption(optionName).getIntegerValue();
|
||||
}
|
||||
public IntegerOption getIntegerOption(String optionName) throws ConfigurationException {
|
||||
|
||||
Option o = getOption(optionName) ;
|
||||
if(o instanceof IntegerOption) {
|
||||
return (IntegerOption)o;
|
||||
}
|
||||
|
||||
throw new ConfigurationException("Config Node " + optionName + " is not an integer");
|
||||
}
|
||||
|
||||
public String getStringValue(String optionName) throws ConfigurationException {
|
||||
return getStringOption(optionName).getValue();
|
||||
}
|
||||
public TextFieldOption getStringOption(String optionName) throws ConfigurationException {
|
||||
|
||||
Option o = getOption(optionName);
|
||||
if(o instanceof TextFieldOption) {
|
||||
return (TextFieldOption)o;
|
||||
}
|
||||
|
||||
throw new ConfigurationException("Config Node " + optionName + " is not a string");
|
||||
}
|
||||
|
||||
public Level getLogLevelValue(String optionName) throws ConfigurationException {
|
||||
return getLogLevelOption(optionName).getLevelValue();
|
||||
}
|
||||
public LevelOption getLogLevelOption(String optionName) throws ConfigurationException {
|
||||
|
||||
Option o = getOption(optionName);
|
||||
if(o instanceof LevelOption) {
|
||||
return (LevelOption)o;
|
||||
}
|
||||
|
||||
throw new ConfigurationException("Config Node " + optionName + " is not a loglevel");
|
||||
}
|
||||
|
||||
|
||||
public boolean getBooleanValue(String optionName) throws ConfigurationException {
|
||||
return getBooleanOption(optionName).getBooleanValue();
|
||||
}
|
||||
public BooleanOption getBooleanOption(String optionName) throws ConfigurationException {
|
||||
|
||||
Option o = getOption(optionName);
|
||||
if(o instanceof BooleanOption) {
|
||||
return (BooleanOption)o;
|
||||
}
|
||||
|
||||
throw new ConfigurationException("Config Node " + optionName + " is not a boolean");
|
||||
}
|
||||
|
||||
|
||||
private Option getOption(String optionName) throws ConfigurationException {
|
||||
LinkedList<String> l = new LinkedList<String>();
|
||||
for(String s : optionName.split("\\.")) {
|
||||
l.addLast(s);
|
||||
}
|
||||
return getOption(root, l);
|
||||
}
|
||||
|
||||
private Option getOption(Option parent, LinkedList<String> names) throws ConfigurationException {
|
||||
|
||||
if(names.size() == 0) {
|
||||
return parent;
|
||||
}
|
||||
else if(parent instanceof ParentOption) {
|
||||
for(Option o2 : ((ParentOption)parent).getChildOptions()) {
|
||||
if(o2.getIdentifier().equals(names.getFirst())) {
|
||||
|
||||
names.removeFirst();
|
||||
return getOption(o2, names);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new ConfigurationException("Config Node doesn't exist");
|
||||
}
|
||||
|
||||
public ParentOption getRoot() {
|
||||
return root;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
|
||||
public class Option {
|
||||
public abstract class Option {
|
||||
|
||||
private final String identifier;
|
||||
|
||||
@ -12,4 +12,8 @@ public class Option {
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public String toYAMLString(String prefix) {
|
||||
return prefix + "\r\n";
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -23,9 +23,28 @@ public class ParentOption extends Option {
|
||||
}
|
||||
|
||||
public final void add(Option option) {
|
||||
|
||||
|
||||
children.addLast(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toYAMLString(String prefix) {
|
||||
|
||||
|
||||
String s = "";
|
||||
if(getIdentifier().length() > 0) {
|
||||
s += prefix + getIdentifier() + ":\r\n";
|
||||
|
||||
for(Option o : getChildOptions()) {
|
||||
s += o.toYAMLString(prefix + " ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Option o : getChildOptions()) {
|
||||
s += o.toYAMLString(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
public class ShortStringOption extends TextFieldOption {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
public abstract class TextFieldOption extends ChildOption {
|
||||
|
@ -2,6 +2,7 @@ package cc.co.evenprime.bukkit.nocheat.wizard;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
@ -10,16 +11,8 @@ import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.gui.ParentOptionGui;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.BooleanOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.IntegerOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.LogLevelOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.MediumStringOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.Option;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ParentOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.LongStringOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ShortStringOption;
|
||||
|
||||
public class Wizard extends JFrame {
|
||||
|
||||
@ -28,7 +21,6 @@ public class Wizard extends JFrame {
|
||||
*/
|
||||
private static final long serialVersionUID = 8798111079958779207L;
|
||||
|
||||
private static final String pre = " ";
|
||||
|
||||
public Wizard() {
|
||||
|
||||
@ -43,97 +35,9 @@ public class Wizard extends JFrame {
|
||||
|
||||
inside.setLayout(new BoxLayout(inside,BoxLayout.Y_AXIS));
|
||||
|
||||
final ParentOption root = new ParentOption("");
|
||||
final NoCheatConfiguration config = new NoCheatConfiguration(new File("config.yml"));
|
||||
|
||||
ParentOption loggingNode = new ParentOption("logging");
|
||||
root.add(loggingNode);
|
||||
|
||||
loggingNode.add(new MediumStringOption("filename", "plugins/NoCheat/nocheat.log"));
|
||||
loggingNode.add(new LogLevelOption("logtofile", LogLevelOption.Options.LOW));
|
||||
loggingNode.add(new LogLevelOption("logtoconsole", LogLevelOption.Options.HIGH));
|
||||
loggingNode.add(new LogLevelOption("logtochat", LogLevelOption.Options.MED));
|
||||
loggingNode.add(new LogLevelOption("logtoirc", LogLevelOption.Options.MED));
|
||||
loggingNode.add(new ShortStringOption("logtoirctag", "nocheat"));
|
||||
|
||||
ParentOption activeNode = new ParentOption("active");
|
||||
root.add(activeNode);
|
||||
|
||||
activeNode.add(new BooleanOption("speedhack", true));
|
||||
activeNode.add(new BooleanOption("moving", true));
|
||||
activeNode.add(new BooleanOption("airbuild", false));
|
||||
activeNode.add(new BooleanOption("bedteleport", true));
|
||||
activeNode.add(new BooleanOption("itemdupe", true));
|
||||
activeNode.add(new BooleanOption("bogusitems", false));
|
||||
|
||||
ParentOption speedhackNode = new ParentOption("speedhack");
|
||||
root.add(speedhackNode);
|
||||
|
||||
speedhackNode.add(new LongStringOption("logmessage", "\"%1$s sent %2$d move events, but only %3$d were allowed. Speedhack?\""));
|
||||
|
||||
{
|
||||
ParentOption speedhackLimitsNode = new ParentOption("limits");
|
||||
speedhackNode.add(speedhackLimitsNode);
|
||||
|
||||
speedhackLimitsNode.add(new IntegerOption("low", 30));
|
||||
speedhackLimitsNode.add(new IntegerOption("med", 45));
|
||||
speedhackLimitsNode.add(new IntegerOption("high", 60));
|
||||
|
||||
ParentOption speedhackActionNode = new ParentOption("action");
|
||||
speedhackNode.add(speedhackActionNode);
|
||||
|
||||
speedhackActionNode.add(new MediumStringOption("low", "loglow cancel"));
|
||||
speedhackActionNode.add(new MediumStringOption("med", "logmed cancel"));
|
||||
speedhackActionNode.add(new MediumStringOption("high", "loghigh cancel"));
|
||||
}
|
||||
|
||||
ParentOption movingNode = new ParentOption("moving");
|
||||
root.add(movingNode);
|
||||
|
||||
movingNode.add(new LongStringOption("logmessage", "\"Moving violation: %1$s from %2$s (%4$.1f, %5$.1f, %6$.1f) to %3$s (%7$.1f, %8$.1f, %9$.1f)\""));
|
||||
movingNode.add(new LongStringOption("summarymessage", "\"Moving summary of last ~%2$d seconds: %1$s total Violations: (%3$d,%4$d,%5$d)\""));
|
||||
movingNode.add(new BooleanOption("allowflying", false));
|
||||
movingNode.add(new BooleanOption("allowfakesneak", true));
|
||||
|
||||
{
|
||||
ParentOption movingActionNode = new ParentOption("action");
|
||||
movingNode.add(movingActionNode);
|
||||
|
||||
movingActionNode.add(new MediumStringOption("low", "loglow cancel"));
|
||||
movingActionNode.add(new MediumStringOption("med", "logmed cancel"));
|
||||
movingActionNode.add(new MediumStringOption("high", "loghigh cancel"));
|
||||
}
|
||||
|
||||
ParentOption airbuildNode = new ParentOption("airbuild");
|
||||
root.add(airbuildNode);
|
||||
|
||||
{
|
||||
ParentOption airbuildLimitsNode = new ParentOption("limits");
|
||||
airbuildNode.add(airbuildLimitsNode);
|
||||
|
||||
airbuildLimitsNode.add(new IntegerOption("low", 30));
|
||||
airbuildLimitsNode.add(new IntegerOption("med", 45));
|
||||
airbuildLimitsNode.add(new IntegerOption("high", 60));
|
||||
|
||||
ParentOption airbuildActionNode = new ParentOption("action");
|
||||
airbuildNode.add(airbuildActionNode);
|
||||
|
||||
airbuildActionNode.add(new MediumStringOption("low", "loglow cancel"));
|
||||
airbuildActionNode.add(new MediumStringOption("med", "logmed cancel"));
|
||||
airbuildActionNode.add(new MediumStringOption("high", "loghigh cancel"));
|
||||
}
|
||||
|
||||
ParentOption bedteleportNode = new ParentOption("bedteleport");
|
||||
root.add(bedteleportNode);
|
||||
|
||||
|
||||
ParentOption itemdupeNode = new ParentOption("itemdupe");
|
||||
root.add(itemdupeNode);
|
||||
|
||||
|
||||
ParentOption bogusitemsNode = new ParentOption("bogusitems");
|
||||
root.add(bogusitemsNode);
|
||||
|
||||
ParentOptionGui root2 = new ParentOptionGui(root);
|
||||
ParentOptionGui root2 = new ParentOptionGui(config.getRoot());
|
||||
|
||||
inside.add(root2);
|
||||
|
||||
@ -143,9 +47,11 @@ public class Wizard extends JFrame {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
String s = parseParent(root, "");
|
||||
String s = config.getRoot().toYAMLString("");
|
||||
|
||||
JOptionPane.showMessageDialog(null, s);
|
||||
|
||||
NoCheatConfiguration.writeConfigFile(new File("config.yml"), config);
|
||||
} });
|
||||
|
||||
b.setAlignmentY(0.0F);
|
||||
@ -155,33 +61,4 @@ public class Wizard extends JFrame {
|
||||
|
||||
this.pack();
|
||||
}
|
||||
|
||||
private String parseParent(ParentOption option, String prefix) {
|
||||
|
||||
String s = "";
|
||||
if(option.getIdentifier().length() > 0) {
|
||||
s += prefix + option.getIdentifier() + ":\r\n";
|
||||
}
|
||||
|
||||
for(Option o : option.getChildOptions()) {
|
||||
if(o instanceof ChildOption)
|
||||
s += parseChild((ChildOption)o, prefix + pre);
|
||||
else if(o instanceof ParentOption)
|
||||
s += parseParent((ParentOption)o, prefix + pre);
|
||||
else
|
||||
parse(o, prefix + " ");
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private String parseChild(ChildOption option, String prefix) {
|
||||
|
||||
return prefix + option.getIdentifier() + ": " + option.getValue() + "\r\n";
|
||||
}
|
||||
|
||||
private String parse(Object option, String prefix) {
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.BooleanOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.LogLevelOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.TextFieldOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.BooleanOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.LevelOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.TextFieldOption;
|
||||
|
||||
public class ChildOptionGuiFactory {
|
||||
|
||||
@ -25,18 +25,18 @@ public class ChildOptionGuiFactory {
|
||||
else if(option instanceof TextFieldOption) {
|
||||
return createTextField((TextFieldOption)option);
|
||||
}
|
||||
else if(option instanceof LogLevelOption) {
|
||||
return createLogLevel((LogLevelOption)option);
|
||||
else if(option instanceof LevelOption) {
|
||||
return createLogLevel((LevelOption)option);
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unknown ChildOption " + option);
|
||||
}
|
||||
|
||||
private static JComboBox createLogLevel(final LogLevelOption option) {
|
||||
private static JComboBox createLogLevel(final LevelOption option) {
|
||||
|
||||
final JComboBox comboBox = new JComboBox();
|
||||
|
||||
for(LogLevelOption.Options o : LogLevelOption.Options.values())
|
||||
for(LevelOption.LogLevel o : LevelOption.LogLevel.values())
|
||||
comboBox.addItem(o);
|
||||
|
||||
comboBox.setSelectedItem(option.getOptionValue());
|
||||
@ -45,7 +45,7 @@ public class ChildOptionGuiFactory {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
option.setValue((LogLevelOption.Options)comboBox.getSelectedItem());
|
||||
option.setValue((LevelOption.LogLevel)comboBox.getSelectedItem());
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.Option;
|
||||
import cc.co.evenprime.bukkit.nocheat.wizard.options.ParentOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ChildOption;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Option;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ParentOption;
|
||||
|
||||
public class ParentOptionGui extends JPanel {
|
||||
|
||||
@ -31,7 +31,7 @@ public class ParentOptionGui extends JPanel {
|
||||
if(option.getIdentifier().length() > 0) {
|
||||
this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(2, 2,
|
||||
2, 2, Color.BLACK), " " + option.getIdentifier() + " "),
|
||||
2, 2, Color.BLACK), " " + option.getIdentifier() + ": "),
|
||||
BorderFactory.createEmptyBorder(5,5,5,5))));
|
||||
}
|
||||
this.setLayout(new GridBagLayout());
|
||||
@ -42,7 +42,7 @@ public class ParentOptionGui extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Option option) {
|
||||
private void add(Option option) {
|
||||
if(option instanceof ParentOption) {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.wizard.options;
|
||||
|
||||
|
||||
public class LogLevelOption extends ChildOption {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1609308017422576285L;
|
||||
|
||||
private Options value;
|
||||
|
||||
|
||||
public enum Options {
|
||||
OFF("never"), LOW("all messages"), MED("important messages"), HIGH("very important messages");
|
||||
|
||||
private final String value;
|
||||
|
||||
private Options(String s) {
|
||||
this.value = s;
|
||||
}
|
||||
|
||||
public String getValue() { return this.value; }
|
||||
|
||||
public static Options getOption(String s) {
|
||||
if("off".equals(s))
|
||||
return OFF;
|
||||
else if("low".equals(s))
|
||||
return LOW;
|
||||
else if("med".equals(s))
|
||||
return MED;
|
||||
else if("high".equals(s))
|
||||
return HIGH;
|
||||
else
|
||||
return OFF;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return this.name() + ": " + getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public LogLevelOption(String identifier, Options initialValue) {
|
||||
|
||||
super(identifier);
|
||||
this.value = initialValue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value.getValue();
|
||||
}
|
||||
|
||||
public void setValue(Options value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Options getOptionValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user