Simpified custom commands - only allow choice if repetition is wanted

or not, but no longer choice about intervals for repetition.
This commit is contained in:
Evenprime 2011-05-12 18:05:19 +02:00
parent d10b85c12d
commit cc5c946141
9 changed files with 26 additions and 36 deletions

View File

@ -9,9 +9,9 @@ package cc.co.evenprime.bukkit.nocheat.actions;
public abstract class Action {
public final int firstAfter;
public final int repeat;
public final boolean repeat;
public Action(int firstAfter, int repeat) {
public Action(int firstAfter, boolean repeat) {
this.firstAfter = firstAfter;
this.repeat = repeat;
}

View File

@ -9,7 +9,7 @@ public class CancelAction extends Action {
public final static CancelAction cancel = new CancelAction();
private CancelAction() { super(1, 1); }
private CancelAction() { super(1, true); }
public String getName() {
return "cancel";

View File

@ -10,7 +10,7 @@ public class CustomAction extends Action {
public final String command;
public CustomAction(int firstAfter, int repeat, String command) {
public CustomAction(int firstAfter, boolean repeat, String command) {
super(firstAfter, repeat);
this.command = command;
}

View File

@ -12,13 +12,13 @@ public class LogAction extends Action {
public final Level level;
// Log messages are shown after 1 violation and don't get repeated
public final static LogAction loglow = new LogAction(1, 0, Level.INFO);
public final static LogAction logmed = new LogAction(1, 0, Level.WARNING);
public final static LogAction loghigh = new LogAction(1, 0, Level.SEVERE);
public final static LogAction loglow = new LogAction(1, false, Level.INFO);
public final static LogAction logmed = new LogAction(1, false, Level.WARNING);
public final static LogAction loghigh = new LogAction(1, false, Level.SEVERE);
public final static LogAction[] log = { loglow, logmed, loghigh };
public LogAction(int firstAfter, int repeat, Level level) {
public LogAction(int firstAfter, boolean repeat, Level level) {
super(firstAfter, repeat);
this.level = level;
}

View File

@ -82,7 +82,7 @@ public class AirbuildCheck extends Check {
// Execute actions in order
for(Action a : actions) {
if(a.firstAfter >= violations) {
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
if(a.firstAfter == violations || a.repeat) {
if(a instanceof LogAction) {
final Location l = event.getBlockPlaced().getLocation();
String logMessage = "Airbuild: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " in the air at " + l.getBlockX() + "," + l.getBlockY() +"," + l.getBlockZ();

View File

@ -454,7 +454,7 @@ public class MovingCheck extends Check {
for(Action a : actions) {
if(a.firstAfter >= violations) {
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
if(a.firstAfter == violations || a.repeat) {
if(a instanceof LogAction) {
// prepare log message if necessary
String log = String.format(logMessage, player.getName(), from.getWorld().getName(), to.getWorld().getName(), from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ());

View File

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

View File

@ -5,7 +5,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.CustomAction;
public class CustomActionOption extends ChildOption {
private int firstAfter;
private int repeat;
private boolean repeat;
private String command;
@ -19,33 +19,33 @@ public class CustomActionOption extends ChildOption {
private void parseCommand(String command) {
if(command.matches("\\[[0-9]*,[0-9]*\\] .*")) {
if(command.matches("\\[[0-9]*,[a-z]*\\] .*")) {
String s[] = command.split(" ", 2);
String s2[] = s[0].replace("[", "").replace("]", "").split(",");
this.firstAfter = Integer.parseInt(s2[0]);
this.repeat = Integer.parseInt(s2[1]);
this.repeat = Boolean.parseBoolean(s2[1]);
this.command = s[1];
}
else if(command.matches("\\[[0-9]*\\] .*")) {
String s[] = command.split(" ", 2);
this.firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
this.repeat = 1;
this.repeat = true;
this.command = s[1];
}
else
{
this.command = command;
this.firstAfter = 1;
this.repeat = 1;
this.repeat = true;
}
}
@Override
public String getValue() {
if(firstAfter <= 1) {
if(firstAfter <= 1 && repeat) {
return command;
}
else if(repeat <= 0) {
else if(repeat) {
return "["+firstAfter+"] "+ command;
}
else {
@ -66,12 +66,12 @@ public class CustomActionOption extends ChildOption {
this.command = command;
}
public void setRepeatValue(int value) {
public void setRepeatValue(boolean value) {
this.repeat = value;
}
public int getRepeatValue() {
public boolean getRepeatValue() {
return repeat;
}

View File

@ -79,26 +79,16 @@ public class ChildOptionGuiFactory {
}
});
final JTextField repeat = new JTextField(String.valueOf(option.getRepeatValue()));
final JCheckBox repeat = new JCheckBox();
repeat.setSelected(option.getRepeatValue());
repeat.setColumns(3);
repeat.setInputVerifier(new InputVerifier() {
repeat.addActionListener(new ActionListener() {
@Override
public boolean verify(JComponent arg0) {
int value;
try {
value = Integer.parseInt(repeat.getText());
option.setRepeatValue(value);
return true;
}
catch(Exception e) {
JOptionPane.showMessageDialog(repeat, "Illegal value for this field");
repeat.setText(String.valueOf(option.getRepeatValue()));
return false;
}
public void actionPerformed(ActionEvent arg0) {
option.setRepeatValue(repeat.isSelected());
}
});
final JTextField firstAfter = new JTextField(String.valueOf(option.getFirstAfterValue()));