Bleeding: Add capability to replace ActionFactory and actions.

This commit is contained in:
asofold 2012-10-21 07:13:29 +02:00
parent 318372b000
commit a3eb7f576d
6 changed files with 50 additions and 10 deletions

View File

@ -25,7 +25,7 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
* Helps with creating Actions out of text string definitions.
*/
public class ActionFactory {
private static final Map<String, Object> lib = new HashMap<String, Object>();
protected static final Map<String, Object> lib = new HashMap<String, Object>();
/**
* Instantiates a new action factory.
@ -133,7 +133,7 @@ public class ActionFactory {
* the definition
* @return the action
*/
private Action parseCmdAction(final String definition) {
protected Action parseCmdAction(final String definition) {
final String[] parts = definition.split(":");
final String name = parts[0];
final Object command = lib.get(parts[0]);
@ -165,7 +165,7 @@ public class ActionFactory {
* the definition
* @return the action
*/
private Action parseLogAction(final String definition) {
protected Action parseLogAction(final String definition) {
final String[] parts = definition.split(":");
final String name = parts[0];
final Object message = lib.get(parts[0]);

View File

@ -28,7 +28,7 @@ import fr.neatmonster.nocheatplus.checks.ViolationData;
*/
public abstract class ActionWithParameters extends Action {
/** The parts of the message. */
private final ArrayList<Object> messageParts;
protected final ArrayList<Object> messageParts;
/**
* Instantiates a new action with parameters.
@ -83,7 +83,7 @@ public abstract class ActionWithParameters extends Action {
* @param message
* the message
*/
private void parseMessage(final String message) {
protected void parseMessage(final String message) {
final String parts[] = message.split("\\[", 2);
// No opening braces left.

View File

@ -19,7 +19,7 @@ import fr.neatmonster.nocheatplus.checks.ViolationData;
*/
public class DummyAction extends Action {
/** The original string used for this action definition. */
private final String definition;
protected final String definition;
/**
* Instantiates a new dummy.

View File

@ -27,13 +27,13 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
public class LogAction extends ActionWithParameters {
// Some flags to decide where the log message should show up, based on the configuration file.
/** Log to chat? */
private final boolean toChat;
public final boolean toChat;
/** Log to console? */
private final boolean toConsole;
public final boolean toConsole;
/** Log to file? */
private final boolean toFile;
public final boolean toFile;
/**
* Instantiates a new log action.
@ -59,6 +59,7 @@ public class LogAction extends ActionWithParameters {
this.toChat = toChat;
this.toConsole = toConsole;
this.toFile = toFile;
// TODO: already use && flagfromconfig.
}
/* (non-Javadoc)

View File

@ -111,7 +111,7 @@ public class ConfigFile extends YamlConfiguration {
* Do this after reading new data.
*/
public void regenerateActionLists() {
factory = new ActionFactory(((MemorySection) this.get(ConfPaths.STRINGS)).getValues(false));
factory = ConfigManager.getActionFactory(((MemorySection) this.get(ConfPaths.STRINGS)).getValues(false));
}
/* (non-Javadoc)

View File

@ -18,6 +18,7 @@ import org.bukkit.Bukkit;
import org.bukkit.configuration.MemoryConfiguration;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ActionFactory;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -93,6 +94,43 @@ public class ConfigManager {
/** The log file. */
public static File logFile = null;
public static interface ActionFactoryFactory{
public ActionFactory newActionFactory(Map<String, Object> library);
}
private static ActionFactoryFactory actionFactoryFactory = new ActionFactoryFactory() {
@Override
public final ActionFactory newActionFactory(final Map<String, Object> library) {
return new ActionFactory(library);
}
};
/**
* Factory method.
* @param library
* @return
*/
public static ActionFactory getActionFactory(final Map<String, Object> library){
return actionFactoryFactory.newActionFactory(library);
}
/**
* Set the factory to get actions from.
* @param factory
*/
public static void setActionFactoryFactory(ActionFactoryFactory factory){
if (factory != null) actionFactoryFactory = factory;
else actionFactoryFactory = new ActionFactoryFactory() {
@Override
public final ActionFactory newActionFactory(final Map<String, Object> library) {
return new ActionFactory(library);
}
};
for (final ConfigFile config : worldsMap.values()){
config.regenerateActionLists();
}
}
/**
* Cleanup.
@ -103,6 +141,7 @@ public class ConfigManager {
final Logger logger = Logger.getLogger("NoCheatPlus");
logger.removeHandler(fileHandler);
fileHandler = null;
setActionFactoryFactory(null);
}
/**