mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-28 11:28:11 +01:00
Fixed bug related to new action handling + finished implementing
custom Actions
This commit is contained in:
parent
cc5c946141
commit
29361d0867
@ -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;
|
||||
@ -70,7 +70,7 @@ public class NoCheat extends JavaPlugin {
|
||||
private Level consoleLevel;
|
||||
private String ircTag;
|
||||
|
||||
|
||||
|
||||
public NoCheat() {
|
||||
|
||||
}
|
||||
@ -126,7 +126,7 @@ public class NoCheat extends JavaPlugin {
|
||||
|
||||
// parse the nocheat.yml config file
|
||||
setupConfig();
|
||||
|
||||
|
||||
movingCheck = new MovingCheck(this, config);
|
||||
bedteleportCheck = new BedteleportCheck(this, config);
|
||||
speedhackCheck = new SpeedhackCheck(this, config);
|
||||
@ -136,7 +136,7 @@ public class NoCheat extends JavaPlugin {
|
||||
|
||||
// just for convenience
|
||||
checks = new Check[] { movingCheck, bedteleportCheck, speedhackCheck, airbuildCheck, itemdupeCheck, bogusitemsCheck };
|
||||
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
|
||||
// Get, if available, the Permissions and irc plugin
|
||||
@ -305,7 +305,7 @@ public class NoCheat extends JavaPlugin {
|
||||
this.config = new NoCheatConfiguration(new File(NoCheatConfiguration.configFile));
|
||||
else
|
||||
this.config.config(new File(NoCheatConfiguration.configFile));
|
||||
|
||||
|
||||
config.setupFileLogger();
|
||||
|
||||
try {
|
||||
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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]);
|
||||
|
@ -15,28 +15,27 @@ public class CustomActionOption extends ChildOption {
|
||||
|
||||
this.parseCommand(command);
|
||||
}
|
||||
|
||||
|
||||
private void parseCommand(String command) {
|
||||
private void parseCommand(String com) {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
@ -208,20 +212,22 @@ public class NoCheatConfiguration {
|
||||
ParentOption bogusitemsNode = new ParentOption("bogusitems");
|
||||
root.add(bogusitemsNode);
|
||||
}
|
||||
|
||||
|
||||
/*** CUSTOMACTIONS section ***/
|
||||
{
|
||||
ParentOption customActionsNode = new ParentOption("customactions");
|
||||
root.add(customActionsNode);
|
||||
|
||||
customActionsNode.add(new CustomActionOption("mycommand",
|
||||
CONFIG.getString("customactions.mycommand", "[4,8] TESTCOMMAND")));
|
||||
|
||||
customActionsNode.add(new CustomActionOption("mycommand2",
|
||||
CONFIG.getString("customactions.mycommand2", "TESTCOMMAND2")));
|
||||
|
||||
customActionsNode.add(new CustomActionOption("mycommand3",
|
||||
CONFIG.getString("customactions.mycommand3", "[7] TESTCOMMAND3")));
|
||||
|
||||
List<String> customs = CONFIG.getKeys("customactions");
|
||||
if(customs != null) {
|
||||
for(String s : customs) {
|
||||
|
||||
CustomActionOption o = new CustomActionOption(s, CONFIG.getString("customactions."+s, "unknown"));
|
||||
|
||||
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
|
||||
@ -317,7 +300,7 @@ public class NoCheatConfiguration {
|
||||
try {
|
||||
if(f.getParentFile() != null)
|
||||
f.getParentFile().mkdirs();
|
||||
|
||||
|
||||
f.createNewFile();
|
||||
BufferedWriter w = new BufferedWriter(new FileWriter(f));
|
||||
|
||||
@ -332,8 +315,8 @@ public class NoCheatConfiguration {
|
||||
public Action[] getActionValue(String optionName) throws ConfigurationException {
|
||||
return stringToActions(getStringOption(optionName).getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int getIntegerValue(String optionName) throws ConfigurationException {
|
||||
return getIntegerOption(optionName).getIntegerValue();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user