Add cmdc action - like cmd just with replacing color codes.
This commit is contained in:
parent
b0161dfac8
commit
b5b6e782ed
|
@ -21,6 +21,7 @@ import java.util.Map;
|
|||
|
||||
import fr.neatmonster.nocheatplus.actions.AbstractActionList.ActionListFactory;
|
||||
import fr.neatmonster.nocheatplus.actions.types.CommandAction;
|
||||
import fr.neatmonster.nocheatplus.actions.types.CommandActionWithColor;
|
||||
import fr.neatmonster.nocheatplus.actions.types.DummyAction;
|
||||
import fr.neatmonster.nocheatplus.logging.StaticLog;
|
||||
|
||||
|
@ -117,6 +118,18 @@ public abstract class AbstractActionFactory <D extends ActionData, L extends Abs
|
|||
return (Action<D, L>[]) actions.toArray(new Action<?, ?>[actions.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default: without replacing color codes.
|
||||
*
|
||||
* @param definition
|
||||
* @return
|
||||
*/
|
||||
protected <PH extends ParameterHolder, LPH extends AbstractActionList<PH, LPH>> Action<PH, LPH> parseCmdAction(
|
||||
final String definition) {
|
||||
return parseCmdAction(definition, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the cmd action.
|
||||
*
|
||||
|
@ -124,7 +137,8 @@ public abstract class AbstractActionFactory <D extends ActionData, L extends Abs
|
|||
* the definition
|
||||
* @return the action
|
||||
*/
|
||||
protected <PH extends ParameterHolder, LPH extends AbstractActionList<PH, LPH>> Action<PH, LPH> parseCmdAction(final String definition) {
|
||||
protected <PH extends ParameterHolder, LPH extends AbstractActionList<PH, LPH>> Action<PH, LPH> parseCmdAction(
|
||||
final String definition, final boolean replaceColor) {
|
||||
final String[] parts = definition.split(":");
|
||||
final String name = parts[0];
|
||||
final Object command = lib.get(parts[0]);
|
||||
|
@ -146,6 +160,7 @@ public abstract class AbstractActionFactory <D extends ActionData, L extends Abs
|
|||
repeat = 0;
|
||||
}
|
||||
|
||||
return new CommandAction<PH, LPH>(name, delay, repeat, command.toString());
|
||||
return replaceColor ? new CommandActionWithColor<PH, LPH>(name, delay, repeat, command.toString())
|
||||
: new CommandAction<PH, LPH>(name, delay, repeat, command.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,18 +46,23 @@ public class ActionFactory extends AbstractActionFactory<ViolationData, ActionLi
|
|||
public Action<ViolationData, ActionList> createAction(String actionDefinition) {
|
||||
actionDefinition = actionDefinition.toLowerCase();
|
||||
|
||||
if (actionDefinition.equals("cancel"))
|
||||
if (actionDefinition.equals("cancel")) {
|
||||
return new CancelAction<ViolationData, ActionList>();
|
||||
}
|
||||
|
||||
if (actionDefinition.startsWith("cmd:"))
|
||||
if (actionDefinition.startsWith("cmd:")) {
|
||||
return parseCmdAction(actionDefinition.split(":", 2)[1]);
|
||||
}
|
||||
|
||||
if (actionDefinition.startsWith("log:"))
|
||||
if (actionDefinition.startsWith("cmdc:")) {
|
||||
return parseCmdAction(actionDefinition.split(":", 2)[1], true);
|
||||
}
|
||||
|
||||
if (actionDefinition.startsWith("log:")) {
|
||||
return parseLogAction(actionDefinition.split(":", 2)[1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
throw new IllegalArgumentException("NoCheatPlus doesn't understand action '" + actionDefinition + "' at all");
|
||||
throw new IllegalArgumentException("NoCheatPlus doesn't understand action '" + actionDefinition + "' at all.");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package fr.neatmonster.nocheatplus.actions.types;
|
||||
|
||||
import fr.neatmonster.nocheatplus.actions.AbstractActionList;
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterHolder;
|
||||
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
|
||||
|
||||
public class CommandActionWithColor<D extends ParameterHolder, L extends AbstractActionList<D, L>> extends CommandAction<D, L> {
|
||||
|
||||
public CommandActionWithColor(String name, int delay, int repeat, String command) {
|
||||
super(name, delay, repeat, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMessage(D violationData) {
|
||||
return ColorUtil.replaceColors(super.getMessage(violationData));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the commands data into a string that can be used in the configuration files.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "cmdc:" + name + ":" + delay + ":" + repeat;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue