Moved and renamed "ActionManager" to "ActionMapper", as that's what it

does
This commit is contained in:
Evenprime 2011-10-11 16:12:32 +02:00
parent 747e5bcdce
commit 6a5a9e0834
5 changed files with 26 additions and 35 deletions

View File

@ -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.Map;
@ -9,26 +9,26 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
* @author Evenprime
*
*/
public class ActionManager {
public class ActionMapper {
private final Map<String, Action> actions;
public ActionManager() {
public ActionMapper() {
this.actions = new HashMap<String, Action>();
}
public void addAction(Action action) {
this.actions.put(action.name.toLowerCase(), action);
}
public Action[] getActions(String[] actionNames) {
Action[] result = new Action[actionNames.length];
for(int i = 0; i < actionNames.length; i++) {
result[i] = this.actions.get(actionNames[i].toLowerCase());
}
return result;
}
}

View File

@ -6,7 +6,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
@ -15,8 +14,6 @@ import java.util.logging.Level;
import java.util.logging.LogRecord;
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;
/**
@ -75,19 +72,20 @@ public class ConfigurationManager {
public ConfigurationManager(String rootConfigFolder) {
ActionManager actionManager = new ActionManager();
ActionMapper actionMapper = new ActionMapper();
// Parse actions file
// MOVE TO ACTIONMANAGER PARSER OR SOMETHING
initializeActions(rootConfigFolder, actionManager);
initializeActions(rootConfigFolder, actionMapper);
defaultConfig = new DefaultConfiguration(actionManager);
// Create a default configuration
defaultConfig = new DefaultConfiguration(actionMapper);
// Setup the configuration tree
initializeConfig(rootConfigFolder, actionManager);
// Setup the real configuration
initializeConfig(rootConfigFolder, actionMapper);
}
private void initializeActions(String rootConfigFolder, ActionManager actionManager) {
private void initializeActions(String rootConfigFolder, ActionMapper actionManager) {
File defaultActionsFile = new File(rootConfigFolder, defaultActionFileName);
@ -96,11 +94,7 @@ public class ConfigurationManager {
// now parse that file again
FlatFileAction parser = new FlatFileAction(defaultActionsFile);
List<Action> defaultActions = parser.read();
for(Action a : defaultActions) {
actionManager.addAction(a);
}
parser.read(actionManager);
// Check if the "custom" action file exists, if not, create one
File customActionsFile = new File(rootConfigFolder, actionFileName);
@ -109,11 +103,7 @@ public class ConfigurationManager {
}
parser = new FlatFileAction(customActionsFile);
List<Action> customActions = parser.read();
for(Action a : customActions) {
actionManager.addAction(a);
}
parser.read(actionManager);
}
/**
@ -122,7 +112,7 @@ public class ConfigurationManager {
*
* @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
FlatFileConfiguration root;

View File

@ -6,7 +6,6 @@ import java.io.FileWriter;
import java.io.IOException;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.actions.ActionManager;
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 DefaultConfiguration(ActionManager action) {
public DefaultConfiguration(ActionMapper action) {
super(null, false);
/*** LOGGING ***/

View File

@ -22,7 +22,7 @@ public class FlatFileAction {
this.file = file;
}
public List<Action> read() {
public void read(ActionMapper mapper) {
List<Action> actions = new ArrayList<Action>();
@ -48,7 +48,10 @@ public class FlatFileAction {
e.printStackTrace();
}
return actions;
for(Action a : actions) {
mapper.addAction(a);
}
}
private Action parseLine(String line) {

View File

@ -9,7 +9,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
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.log.LogLevel;
@ -23,7 +22,7 @@ public class FlatFileConfiguration extends Configuration {
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"));
@ -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();
@ -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 treshold = s[s.length - 1];