mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-07 04:28:00 +02:00
Moved and renamed "ActionManager" to "ActionMapper", as that's what it
does
This commit is contained in:
parent
747e5bcdce
commit
6a5a9e0834
@ -1,4 +1,4 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.actions;
|
package cc.co.evenprime.bukkit.nocheat.config;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -9,11 +9,11 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
|
|||||||
* @author Evenprime
|
* @author Evenprime
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ActionManager {
|
public class ActionMapper {
|
||||||
|
|
||||||
private final Map<String, Action> actions;
|
private final Map<String, Action> actions;
|
||||||
|
|
||||||
public ActionManager() {
|
public ActionMapper() {
|
||||||
this.actions = new HashMap<String, Action>();
|
this.actions = new HashMap<String, Action>();
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,6 @@ import java.io.PrintWriter;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.FileHandler;
|
import java.util.logging.FileHandler;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
@ -15,8 +14,6 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.ActionManager;
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,19 +72,20 @@ public class ConfigurationManager {
|
|||||||
|
|
||||||
public ConfigurationManager(String rootConfigFolder) {
|
public ConfigurationManager(String rootConfigFolder) {
|
||||||
|
|
||||||
ActionManager actionManager = new ActionManager();
|
ActionMapper actionMapper = new ActionMapper();
|
||||||
|
|
||||||
// Parse actions file
|
// Parse actions file
|
||||||
// MOVE TO ACTIONMANAGER PARSER OR SOMETHING
|
initializeActions(rootConfigFolder, actionMapper);
|
||||||
initializeActions(rootConfigFolder, actionManager);
|
|
||||||
|
|
||||||
defaultConfig = new DefaultConfiguration(actionManager);
|
// Create a default configuration
|
||||||
|
defaultConfig = new DefaultConfiguration(actionMapper);
|
||||||
|
|
||||||
// Setup the configuration tree
|
// Setup the real configuration
|
||||||
initializeConfig(rootConfigFolder, actionManager);
|
initializeConfig(rootConfigFolder, actionMapper);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeActions(String rootConfigFolder, ActionManager actionManager) {
|
private void initializeActions(String rootConfigFolder, ActionMapper actionManager) {
|
||||||
|
|
||||||
File defaultActionsFile = new File(rootConfigFolder, defaultActionFileName);
|
File defaultActionsFile = new File(rootConfigFolder, defaultActionFileName);
|
||||||
|
|
||||||
@ -96,11 +94,7 @@ public class ConfigurationManager {
|
|||||||
|
|
||||||
// now parse that file again
|
// now parse that file again
|
||||||
FlatFileAction parser = new FlatFileAction(defaultActionsFile);
|
FlatFileAction parser = new FlatFileAction(defaultActionsFile);
|
||||||
List<Action> defaultActions = parser.read();
|
parser.read(actionManager);
|
||||||
|
|
||||||
for(Action a : defaultActions) {
|
|
||||||
actionManager.addAction(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the "custom" action file exists, if not, create one
|
// Check if the "custom" action file exists, if not, create one
|
||||||
File customActionsFile = new File(rootConfigFolder, actionFileName);
|
File customActionsFile = new File(rootConfigFolder, actionFileName);
|
||||||
@ -109,11 +103,7 @@ public class ConfigurationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parser = new FlatFileAction(customActionsFile);
|
parser = new FlatFileAction(customActionsFile);
|
||||||
List<Action> customActions = parser.read();
|
parser.read(actionManager);
|
||||||
|
|
||||||
for(Action a : customActions) {
|
|
||||||
actionManager.addAction(a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +112,7 @@ public class ConfigurationManager {
|
|||||||
*
|
*
|
||||||
* @param configurationFile
|
* @param configurationFile
|
||||||
*/
|
*/
|
||||||
private void initializeConfig(String rootConfigFolder, ActionManager action) {
|
private void initializeConfig(String rootConfigFolder, ActionMapper action) {
|
||||||
|
|
||||||
// First try to obtain and parse the global config file
|
// First try to obtain and parse the global config file
|
||||||
FlatFileConfiguration root;
|
FlatFileConfiguration root;
|
||||||
|
@ -6,7 +6,6 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
|
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.ActionManager;
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +17,7 @@ import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
|||||||
*/
|
*/
|
||||||
public class DefaultConfiguration extends Configuration {
|
public class DefaultConfiguration extends Configuration {
|
||||||
|
|
||||||
public DefaultConfiguration(ActionManager action) {
|
public DefaultConfiguration(ActionMapper action) {
|
||||||
super(null, false);
|
super(null, false);
|
||||||
|
|
||||||
/*** LOGGING ***/
|
/*** LOGGING ***/
|
||||||
|
@ -22,7 +22,7 @@ public class FlatFileAction {
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Action> read() {
|
public void read(ActionMapper mapper) {
|
||||||
|
|
||||||
List<Action> actions = new ArrayList<Action>();
|
List<Action> actions = new ArrayList<Action>();
|
||||||
|
|
||||||
@ -48,7 +48,10 @@ public class FlatFileAction {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return actions;
|
for(Action a : actions) {
|
||||||
|
mapper.addAction(a);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Action parseLine(String line) {
|
private Action parseLine(String line) {
|
||||||
|
@ -9,7 +9,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
|
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.ActionManager;
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
|
import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
|
||||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ public class FlatFileConfiguration extends Configuration {
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load(ActionManager action) throws IOException {
|
public void load(ActionMapper action) throws IOException {
|
||||||
|
|
||||||
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ public class FlatFileConfiguration extends Configuration {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parse(String line, ActionManager action) throws IOException {
|
private void parse(String line, ActionMapper action) throws IOException {
|
||||||
|
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ public class FlatFileConfiguration extends Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionList parseActionList(OptionNode node, String key, String value, ActionManager action) {
|
private ActionList parseActionList(OptionNode node, String key, String value, ActionMapper action) {
|
||||||
|
|
||||||
String[] s = key.split("\\.");
|
String[] s = key.split("\\.");
|
||||||
String treshold = s[s.length - 1];
|
String treshold = s[s.length - 1];
|
||||||
|
Loading…
Reference in New Issue
Block a user