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
|
* @author Evenprime
|
||||||
*/
|
*/
|
||||||
public class NoCheat extends JavaPlugin {
|
public class NoCheat extends JavaPlugin implements CommandSender {
|
||||||
|
|
||||||
private MovingCheck movingCheck;
|
private MovingCheck movingCheck;
|
||||||
private BedteleportCheck bedteleportCheck;
|
private BedteleportCheck bedteleportCheck;
|
||||||
@ -70,7 +70,7 @@ public class NoCheat extends JavaPlugin {
|
|||||||
private Level consoleLevel;
|
private Level consoleLevel;
|
||||||
private String ircTag;
|
private String ircTag;
|
||||||
|
|
||||||
|
|
||||||
public NoCheat() {
|
public NoCheat() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ public class NoCheat extends JavaPlugin {
|
|||||||
|
|
||||||
// parse the nocheat.yml config file
|
// parse the nocheat.yml config file
|
||||||
setupConfig();
|
setupConfig();
|
||||||
|
|
||||||
movingCheck = new MovingCheck(this, config);
|
movingCheck = new MovingCheck(this, config);
|
||||||
bedteleportCheck = new BedteleportCheck(this, config);
|
bedteleportCheck = new BedteleportCheck(this, config);
|
||||||
speedhackCheck = new SpeedhackCheck(this, config);
|
speedhackCheck = new SpeedhackCheck(this, config);
|
||||||
@ -136,7 +136,7 @@ public class NoCheat extends JavaPlugin {
|
|||||||
|
|
||||||
// just for convenience
|
// just for convenience
|
||||||
checks = new Check[] { movingCheck, bedteleportCheck, speedhackCheck, airbuildCheck, itemdupeCheck, bogusitemsCheck };
|
checks = new Check[] { movingCheck, bedteleportCheck, speedhackCheck, airbuildCheck, itemdupeCheck, bogusitemsCheck };
|
||||||
|
|
||||||
PluginDescriptionFile pdfFile = this.getDescription();
|
PluginDescriptionFile pdfFile = this.getDescription();
|
||||||
|
|
||||||
// Get, if available, the Permissions and irc plugin
|
// 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));
|
this.config = new NoCheatConfiguration(new File(NoCheatConfiguration.configFile));
|
||||||
else
|
else
|
||||||
this.config.config(new File(NoCheatConfiguration.configFile));
|
this.config.config(new File(NoCheatConfiguration.configFile));
|
||||||
|
|
||||||
config.setupFileLogger();
|
config.setupFileLogger();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -360,7 +360,23 @@ public class NoCheat extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleCustomAction(CustomAction a, Player player) {
|
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() );
|
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() {
|
public String getName() {
|
||||||
return "custom";
|
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
|
// Execute actions in order
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
if(a.firstAfter >= violations) {
|
if(a.firstAfter <= violations) {
|
||||||
if(a.firstAfter == violations || a.repeat) {
|
if(a.firstAfter == violations || a.repeat) {
|
||||||
if(a instanceof LogAction) {
|
if(a instanceof LogAction) {
|
||||||
final Location l = event.getBlockPlaced().getLocation();
|
final Location l = event.getBlockPlaced().getLocation();
|
||||||
|
@ -453,7 +453,7 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
|
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
if(a.firstAfter >= violations) {
|
if(a.firstAfter <= violations) {
|
||||||
if(a.firstAfter == violations || a.repeat) {
|
if(a.firstAfter == violations || a.repeat) {
|
||||||
if(a instanceof LogAction) {
|
if(a instanceof LogAction) {
|
||||||
// prepare log message if necessary
|
// prepare log message if necessary
|
||||||
|
@ -128,7 +128,7 @@ public class SpeedhackCheck extends Check {
|
|||||||
if(actions == null) return;
|
if(actions == null) return;
|
||||||
|
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
if(a.firstAfter >= violations) {
|
if(a.firstAfter <= violations) {
|
||||||
if(a.firstAfter == violations || a.repeat) {
|
if(a.firstAfter == violations || a.repeat) {
|
||||||
if(a instanceof LogAction) {
|
if(a instanceof LogAction) {
|
||||||
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);
|
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);
|
this.parseCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void parseCommand(String command) {
|
private void parseCommand(String com) {
|
||||||
|
|
||||||
if(command.matches("\\[[0-9]*,[a-z]*\\] .*")) {
|
if(com.matches("\\[[0-9]*,[a-z]*\\] .*")) {
|
||||||
String s[] = command.split(" ", 2);
|
String s[] = com.split(" ", 2);
|
||||||
String s2[] = s[0].replace("[", "").replace("]", "").split(",");
|
String s2[] = s[0].replace("[", "").replace("]", "").split(",");
|
||||||
this.firstAfter = Integer.parseInt(s2[0]);
|
firstAfter = Integer.parseInt(s2[0]);
|
||||||
this.repeat = Boolean.parseBoolean(s2[1]);
|
repeat = Boolean.parseBoolean(s2[1]);
|
||||||
this.command = s[1];
|
command = s[1];
|
||||||
}
|
}
|
||||||
else if(command.matches("\\[[0-9]*\\] .*")) {
|
else if(com.matches("\\[[0-9]*\\] .*")) {
|
||||||
String s[] = command.split(" ", 2);
|
String s[] = com.split(" ", 2);
|
||||||
this.firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
|
firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
|
||||||
this.repeat = true;
|
repeat = true;
|
||||||
this.command = s[1];
|
command = s[1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.command = command;
|
firstAfter = 1;
|
||||||
this.firstAfter = 1;
|
repeat = true;
|
||||||
this.repeat = true;
|
command = com;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@ import java.io.BufferedWriter;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.FileHandler;
|
import java.util.logging.FileHandler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -31,6 +33,8 @@ public class NoCheatConfiguration {
|
|||||||
|
|
||||||
private ParentOption root;
|
private ParentOption root;
|
||||||
|
|
||||||
|
private Map<String, Action> actionMap = new HashMap<String,Action>();
|
||||||
|
|
||||||
// Our personal logger
|
// Our personal logger
|
||||||
private final static String loggerName = "cc.co.evenprime.nocheat";
|
private final static String loggerName = "cc.co.evenprime.nocheat";
|
||||||
public final Logger logger = Logger.getLogger(loggerName);
|
public final Logger logger = Logger.getLogger(loggerName);
|
||||||
@ -208,20 +212,22 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption bogusitemsNode = new ParentOption("bogusitems");
|
ParentOption bogusitemsNode = new ParentOption("bogusitems");
|
||||||
root.add(bogusitemsNode);
|
root.add(bogusitemsNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** CUSTOMACTIONS section ***/
|
/*** CUSTOMACTIONS section ***/
|
||||||
{
|
{
|
||||||
ParentOption customActionsNode = new ParentOption("customactions");
|
ParentOption customActionsNode = new ParentOption("customactions");
|
||||||
root.add(customActionsNode);
|
root.add(customActionsNode);
|
||||||
|
|
||||||
customActionsNode.add(new CustomActionOption("mycommand",
|
List<String> customs = CONFIG.getKeys("customactions");
|
||||||
CONFIG.getString("customactions.mycommand", "[4,8] TESTCOMMAND")));
|
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",
|
customActionsNode.add(o);
|
||||||
CONFIG.getString("customactions.mycommand3", "[7] TESTCOMMAND3")));
|
actionMap.put(s, o.getCustomActionValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!configurationFile.exists()) {
|
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>();
|
List<Action> as = new LinkedList<Action>();
|
||||||
String[] parts = string.split(" ");
|
String[] parts = string.split(" ");
|
||||||
@ -273,42 +279,19 @@ public class NoCheatConfiguration {
|
|||||||
as.add(LogAction.logmed);
|
as.add(LogAction.logmed);
|
||||||
else if(s.equals("loghigh"))
|
else if(s.equals("loghigh"))
|
||||||
as.add(LogAction.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"))
|
else if(s.equals("cancel"))
|
||||||
as.add(CancelAction.cancel);
|
as.add(CancelAction.cancel);
|
||||||
else if(s.startsWith("custom")) {
|
else if(actionMap.get(s) != null)
|
||||||
try {
|
as.add(actionMap.get(s));
|
||||||
// TODO: Implement Custom Action
|
else
|
||||||
//as.add(new CustomAction(Integer.parseInt(s.substring(6))));
|
{
|
||||||
}
|
System.out.println("NC: Couldn't parse custom action '" + s + "'");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return as.toArray(new Action[as.size()]);
|
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
|
* Write configuration file to specific filename
|
||||||
* @param f
|
* @param f
|
||||||
@ -317,7 +300,7 @@ public class NoCheatConfiguration {
|
|||||||
try {
|
try {
|
||||||
if(f.getParentFile() != null)
|
if(f.getParentFile() != null)
|
||||||
f.getParentFile().mkdirs();
|
f.getParentFile().mkdirs();
|
||||||
|
|
||||||
f.createNewFile();
|
f.createNewFile();
|
||||||
BufferedWriter w = new BufferedWriter(new FileWriter(f));
|
BufferedWriter w = new BufferedWriter(new FileWriter(f));
|
||||||
|
|
||||||
@ -332,8 +315,8 @@ public class NoCheatConfiguration {
|
|||||||
public Action[] getActionValue(String optionName) throws ConfigurationException {
|
public Action[] getActionValue(String optionName) throws ConfigurationException {
|
||||||
return stringToActions(getStringOption(optionName).getValue());
|
return stringToActions(getStringOption(optionName).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getIntegerValue(String optionName) throws ConfigurationException {
|
public int getIntegerValue(String optionName) throws ConfigurationException {
|
||||||
return getIntegerOption(optionName).getIntegerValue();
|
return getIntegerOption(optionName).getIntegerValue();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user