Fixed bug related to new action handling + finished implementing

custom Actions
This commit is contained in:
Evenprime 2011-05-13 14:00:00 +02:00
parent cc5c946141
commit 29361d0867
7 changed files with 75 additions and 65 deletions

View File

@ -37,7 +37,7 @@ import org.bukkit.plugin.Plugin;
*
* @author Evenprime
*/
public class NoCheat extends JavaPlugin {
public class NoCheat extends JavaPlugin implements CommandSender {
private MovingCheck movingCheck;
private BedteleportCheck bedteleportCheck;
@ -360,7 +360,23 @@ public class NoCheat extends JavaPlugin {
}
public void handleCustomAction(CustomAction a, Player player) {
Bukkit.getServer().dispatchCommand(this, a.command.replace("[player]", player.getName()));
System.out.println("Would execute "+a.command + " now for Player " + player.getName() );
}
@Override
public void sendMessage(String message) {
// we don't receive messages
}
@Override
public boolean isOp() {
// We declare ourselves to be OP to be allowed to do more commands
return true;
}
}

View File

@ -18,4 +18,16 @@ public class CustomAction extends Action {
public String getName() {
return "custom";
}
public String getValue() {
if(firstAfter <= 1 && repeat) {
return command;
}
else if(repeat) {
return "["+firstAfter+"] "+ command;
}
else {
return "["+firstAfter+","+repeat+"] "+ command;
}
}
}

View File

@ -81,7 +81,7 @@ public class AirbuildCheck extends Check {
// Execute actions in order
for(Action a : actions) {
if(a.firstAfter >= violations) {
if(a.firstAfter <= violations) {
if(a.firstAfter == violations || a.repeat) {
if(a instanceof LogAction) {
final Location l = event.getBlockPlaced().getLocation();

View File

@ -453,7 +453,7 @@ public class MovingCheck extends Check {
for(Action a : actions) {
if(a.firstAfter >= violations) {
if(a.firstAfter <= violations) {
if(a.firstAfter == violations || a.repeat) {
if(a instanceof LogAction) {
// prepare log message if necessary

View File

@ -128,7 +128,7 @@ public class SpeedhackCheck extends Check {
if(actions == null) return;
for(Action a : actions) {
if(a.firstAfter >= violations) {
if(a.firstAfter <= violations) {
if(a.firstAfter == violations || a.repeat) {
if(a instanceof LogAction) {
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);

View File

@ -16,27 +16,26 @@ public class CustomActionOption extends ChildOption {
this.parseCommand(command);
}
private void parseCommand(String com) {
private void parseCommand(String command) {
if(command.matches("\\[[0-9]*,[a-z]*\\] .*")) {
String s[] = command.split(" ", 2);
if(com.matches("\\[[0-9]*,[a-z]*\\] .*")) {
String s[] = com.split(" ", 2);
String s2[] = s[0].replace("[", "").replace("]", "").split(",");
this.firstAfter = Integer.parseInt(s2[0]);
this.repeat = Boolean.parseBoolean(s2[1]);
this.command = s[1];
firstAfter = Integer.parseInt(s2[0]);
repeat = Boolean.parseBoolean(s2[1]);
command = s[1];
}
else if(command.matches("\\[[0-9]*\\] .*")) {
String s[] = command.split(" ", 2);
this.firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
this.repeat = true;
this.command = s[1];
else if(com.matches("\\[[0-9]*\\] .*")) {
String s[] = com.split(" ", 2);
firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
repeat = true;
command = s[1];
}
else
{
this.command = command;
this.firstAfter = 1;
this.repeat = true;
firstAfter = 1;
repeat = true;
command = com;
}
}

View File

@ -4,8 +4,10 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -31,6 +33,8 @@ public class NoCheatConfiguration {
private ParentOption root;
private Map<String, Action> actionMap = new HashMap<String,Action>();
// Our personal logger
private final static String loggerName = "cc.co.evenprime.nocheat";
public final Logger logger = Logger.getLogger(loggerName);
@ -214,14 +218,16 @@ public class NoCheatConfiguration {
ParentOption customActionsNode = new ParentOption("customactions");
root.add(customActionsNode);
customActionsNode.add(new CustomActionOption("mycommand",
CONFIG.getString("customactions.mycommand", "[4,8] TESTCOMMAND")));
List<String> customs = CONFIG.getKeys("customactions");
if(customs != null) {
for(String s : customs) {
customActionsNode.add(new CustomActionOption("mycommand2",
CONFIG.getString("customactions.mycommand2", "TESTCOMMAND2")));
CustomActionOption o = new CustomActionOption(s, CONFIG.getString("customactions."+s, "unknown"));
customActionsNode.add(new CustomActionOption("mycommand3",
CONFIG.getString("customactions.mycommand3", "[7] TESTCOMMAND3")));
customActionsNode.add(o);
actionMap.put(s, o.getCustomActionValue());
}
}
}
if(!configurationFile.exists()) {
@ -261,7 +267,7 @@ public class NoCheatConfiguration {
}
}
public static Action[] stringToActions(String string) {
public Action[] stringToActions(String string) {
List<Action> as = new LinkedList<Action>();
String[] parts = string.split(" ");
@ -273,42 +279,19 @@ public class NoCheatConfiguration {
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);
else if(actionMap.get(s) != null)
as.add(actionMap.get(s));
else
{
System.out.println("NC: Couldn't parse custom action '" + s + "'");
}
}
return as.toArray(new Action[as.size()]);
}
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();
}
/**
* Write configuration file to specific filename
* @param f