mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-16 08:57:32 +02:00
Integration of custom actions into existing checks
This commit is contained in:
parent
c5f910de21
commit
d10b85c12d
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
import cc.co.evenprime.bukkit.nocheat.actions.CustomAction;
|
||||||
import cc.co.evenprime.bukkit.nocheat.checks.AirbuildCheck;
|
import cc.co.evenprime.bukkit.nocheat.checks.AirbuildCheck;
|
||||||
import cc.co.evenprime.bukkit.nocheat.checks.BedteleportCheck;
|
import cc.co.evenprime.bukkit.nocheat.checks.BedteleportCheck;
|
||||||
import cc.co.evenprime.bukkit.nocheat.checks.BogusitemsCheck;
|
import cc.co.evenprime.bukkit.nocheat.checks.BogusitemsCheck;
|
||||||
@ -359,8 +359,8 @@ public class NoCheat extends JavaPlugin {
|
|||||||
return this.serverLagInMilliSeconds;
|
return this.serverLagInMilliSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleCustomAction(Action a, Player player) {
|
public void handleCustomAction(CustomAction a, Player player) {
|
||||||
// TODO Auto-generated method stub
|
System.out.println("Would execute "+a.command + " now for Player " + player.getName() );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ public class LogAction extends Action {
|
|||||||
|
|
||||||
public final Level level;
|
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 loglow = new LogAction(1, 0, Level.INFO);
|
||||||
public final static LogAction logmed = new LogAction(1, 0, Level.WARNING);
|
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 loghigh = new LogAction(1, 0, Level.SEVERE);
|
||||||
|
@ -59,52 +59,42 @@ public class AirbuildCheck extends Check {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Give a summary in 20 ticks ~ 1 second
|
// Give a summary in 100 ticks ~ 1 second
|
||||||
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, data.summaryTask, 20);
|
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, data.summaryTask, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.perSecond++;
|
data.perFiveSeconds++;
|
||||||
|
|
||||||
// which limit has been reached
|
// which limit has been reached
|
||||||
for(int i = limits.length-1; i >= 0; i--) {
|
for(int i = limits.length-1; i >= 0; i--) {
|
||||||
if(data.perSecond >= limits[i]) {
|
if(data.perFiveSeconds >= limits[i]) {
|
||||||
// Only explicitly log certain "milestones"
|
action(actions[i], event, data.perFiveSeconds - limits[i]+1);
|
||||||
if(data.perSecond == limits[i]) {
|
|
||||||
action(actions[i], event, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
action(actions[i], event, false);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void action(Action actions[], BlockPlaceEvent event, boolean loggingAllowed) {
|
private void action(Action actions[], BlockPlaceEvent event, int violations) {
|
||||||
|
|
||||||
if(actions == null) return;
|
if(actions == null) return;
|
||||||
|
|
||||||
boolean cancelled = false;
|
|
||||||
|
|
||||||
// Prepare log message if needed
|
|
||||||
String logMessage = null;
|
|
||||||
if(loggingAllowed) {
|
|
||||||
final Location l = event.getBlockPlaced().getLocation();
|
|
||||||
logMessage = "Airbuild: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " in the air at " + l.getBlockX() + "," + l.getBlockY() +"," + l.getBlockZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute actions in order
|
// Execute actions in order
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
if(loggingAllowed && a instanceof LogAction) {
|
if(a.firstAfter >= violations) {
|
||||||
plugin.log(((LogAction)a).level, logMessage);
|
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
|
||||||
}
|
if(a instanceof LogAction) {
|
||||||
else if(!cancelled && a instanceof CancelAction) {
|
final Location l = event.getBlockPlaced().getLocation();
|
||||||
event.setCancelled(true);
|
String logMessage = "Airbuild: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " in the air at " + l.getBlockX() + "," + l.getBlockY() +"," + l.getBlockZ();
|
||||||
cancelled = true;
|
plugin.log(((LogAction)a).level, logMessage);
|
||||||
}
|
}
|
||||||
else if(a instanceof CustomAction) {
|
else if(a instanceof CancelAction) {
|
||||||
plugin.handleCustomAction(a, event.getPlayer());
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
else if(a instanceof CustomAction) {
|
||||||
|
plugin.handleCustomAction((CustomAction)a, event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,13 +103,13 @@ public class AirbuildCheck extends Check {
|
|||||||
|
|
||||||
// Give a summary according to the highest violation level we encountered in that second
|
// Give a summary according to the highest violation level we encountered in that second
|
||||||
for(int i = limits.length-1; i >= 0; i--) {
|
for(int i = limits.length-1; i >= 0; i--) {
|
||||||
if(data.perSecond >= limits[i]) {
|
if(data.perFiveSeconds >= limits[i]) {
|
||||||
plugin.log(LogAction.log[i].level, "Airbuild summary: " +player.getName() + " total violations per second: " + data.perSecond);
|
plugin.log(LogAction.log[i].level, "Airbuild summary: " +player.getName() + " total violations per 5 seconds: " + data.perFiveSeconds);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.perSecond = 0;
|
data.perFiveSeconds = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -127,13 +117,13 @@ public class AirbuildCheck extends Check {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
limits = new int[3];
|
limits = new int[3];
|
||||||
|
|
||||||
limits[0] = config.getIntegerValue("airbuild.limits.low");
|
limits[0] = config.getIntegerValue("airbuild.limits.low");
|
||||||
limits[1] = config.getIntegerValue("airbuild.limits.med");
|
limits[1] = config.getIntegerValue("airbuild.limits.med");
|
||||||
limits[2] = config.getIntegerValue("airbuild.limits.high");
|
limits[2] = config.getIntegerValue("airbuild.limits.high");
|
||||||
|
|
||||||
actions = new Action[3][];
|
actions = new Action[3][];
|
||||||
|
|
||||||
actions[0] = config.getActionValue("airbuild.action.low");
|
actions[0] = config.getActionValue("airbuild.action.low");
|
||||||
actions[1] = config.getActionValue("airbuild.action.med");
|
actions[1] = config.getActionValue("airbuild.action.med");
|
||||||
actions[2] = config.getActionValue("airbuild.action.high");
|
actions[2] = config.getActionValue("airbuild.action.high");
|
||||||
|
@ -259,10 +259,9 @@ public class MovingCheck extends Check {
|
|||||||
if(violationLevel >= 0) {
|
if(violationLevel >= 0) {
|
||||||
setupSummaryTask(event.getPlayer(), data);
|
setupSummaryTask(event.getPlayer(), data);
|
||||||
|
|
||||||
boolean log = !(data.violationsInARow[violationLevel] > 0);
|
|
||||||
data.violationsInARow[violationLevel]++;
|
data.violationsInARow[violationLevel]++;
|
||||||
|
|
||||||
action(event, event.getPlayer(), from, to, actions[violationLevel], log, data);
|
action(event, event.getPlayer(), from, to, actions[violationLevel], data.violationsInARow[violationLevel], data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****** Violation Handling END *****/
|
/****** Violation Handling END *****/
|
||||||
@ -447,30 +446,33 @@ public class MovingCheck extends Check {
|
|||||||
* @param event
|
* @param event
|
||||||
* @param action
|
* @param action
|
||||||
*/
|
*/
|
||||||
private void action(PlayerMoveEvent event, Player player, Location from, Location to, Action[] actions, boolean loggingAllowed, MovingData data) {
|
private void action(PlayerMoveEvent event, Player player, Location from, Location to, Action[] actions, int violations, MovingData data) {
|
||||||
|
|
||||||
if(actions == null) return;
|
if(actions == null) return;
|
||||||
boolean cancelled = false;
|
boolean cancelled = false;
|
||||||
|
|
||||||
// prepare log message if necessary
|
|
||||||
String log = null;
|
|
||||||
|
|
||||||
if(loggingAllowed) {
|
|
||||||
log = String.format(logMessage, player.getName(), from.getWorld().getName(), to.getWorld().getName(), from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
if(loggingAllowed && a instanceof LogAction) {
|
if(a.firstAfter >= violations) {
|
||||||
plugin.log(((LogAction)a).level, log);
|
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
|
||||||
if(data.highestLogLevel == null) data.highestLogLevel = Level.ALL;
|
if(a instanceof LogAction) {
|
||||||
if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level;
|
// 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());
|
||||||
|
|
||||||
|
plugin.log(((LogAction)a).level, log);
|
||||||
|
|
||||||
|
// Remember the highest log level we encountered to determine what level the summary log message should have
|
||||||
|
if(data.highestLogLevel == null) data.highestLogLevel = Level.ALL;
|
||||||
|
if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level;
|
||||||
|
}
|
||||||
|
else if(!cancelled && a instanceof CancelAction) {
|
||||||
|
resetPlayer(event, from);
|
||||||
|
cancelled = true;
|
||||||
|
}
|
||||||
|
else if(a instanceof CustomAction)
|
||||||
|
plugin.handleCustomAction((CustomAction)a, player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(!cancelled && a instanceof CancelAction) {
|
|
||||||
resetPlayer(event, from);
|
|
||||||
cancelled = true;
|
|
||||||
}
|
|
||||||
else if(a instanceof CustomAction)
|
|
||||||
plugin.handleCustomAction(a, player);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,16 +83,21 @@ public class SpeedhackCheck extends Check {
|
|||||||
final int med = (limits[1]+1) / 2;
|
final int med = (limits[1]+1) / 2;
|
||||||
final int high = (limits[2]+1) / 2;
|
final int high = (limits[2]+1) / 2;
|
||||||
|
|
||||||
if(data.eventsSinceLastCheck > high) action = actions[2];
|
int level = -1;
|
||||||
else if(data.eventsSinceLastCheck > med) action = actions[1];
|
|
||||||
else if(data.eventsSinceLastCheck > low) action = actions[0];
|
if(data.eventsSinceLastCheck > high) level = 2;
|
||||||
|
else if(data.eventsSinceLastCheck > med) level = 1;
|
||||||
|
else if(data.eventsSinceLastCheck > low) level = 0;
|
||||||
else resetData(data, event.getFrom(), ticks);
|
else resetData(data, event.getFrom(), ticks);
|
||||||
|
|
||||||
|
|
||||||
if(action != null) data.violationsInARow++;
|
if(level >= 0) {
|
||||||
|
data.violationsInARowTotal++;
|
||||||
|
}
|
||||||
|
|
||||||
if(data.violationsInARow >= violationsLimit) {
|
if(data.violationsInARowTotal >= violationsLimit) {
|
||||||
action(action, event, data);
|
data.violationsInARow[level]++;
|
||||||
|
action(action, event, data.violationsInARow[level], data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset value for next check
|
// Reset value for next check
|
||||||
@ -109,25 +114,34 @@ public class SpeedhackCheck extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void resetData(SpeedhackData data, Location l, int ticks) {
|
private static void resetData(SpeedhackData data, Location l, int ticks) {
|
||||||
data.violationsInARow = 0;
|
data.violationsInARow[0] = 0;
|
||||||
|
data.violationsInARow[1] = 0;
|
||||||
|
data.violationsInARow[2] = 0;
|
||||||
|
data.violationsInARowTotal = 0;
|
||||||
data.eventsSinceLastCheck = 0;
|
data.eventsSinceLastCheck = 0;
|
||||||
data.setBackPoint = l;
|
data.setBackPoint = l;
|
||||||
data.lastCheckTicks = ticks;
|
data.lastCheckTicks = ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void action(Action actions[], PlayerMoveEvent event, SpeedhackData data) {
|
private void action(Action actions[], PlayerMoveEvent event, int violations, SpeedhackData data) {
|
||||||
|
|
||||||
if(actions == null) return;
|
if(actions == null) return;
|
||||||
|
|
||||||
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);
|
|
||||||
|
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
if(a instanceof LogAction)
|
if(a.firstAfter >= violations) {
|
||||||
plugin.log(((LogAction)a).level, log);
|
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
|
||||||
else if(a instanceof CancelAction)
|
if(a instanceof LogAction) {
|
||||||
resetPlayer(event, data);
|
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);
|
||||||
else if(a instanceof CustomAction)
|
plugin.log(((LogAction)a).level, log);
|
||||||
plugin.handleCustomAction(a, event.getPlayer());
|
}
|
||||||
|
else if(a instanceof CancelAction) {
|
||||||
|
resetPlayer(event, data);
|
||||||
|
}
|
||||||
|
else if(a instanceof CustomAction) {
|
||||||
|
plugin.handleCustomAction((CustomAction)a, event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +164,7 @@ public class SpeedhackCheck extends Check {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
limits = new int[3];
|
limits = new int[3];
|
||||||
|
|
||||||
limits[0] = config.getIntegerValue("speedhack.limits.low");
|
limits[0] = config.getIntegerValue("speedhack.limits.low");
|
||||||
limits[1] = config.getIntegerValue("speedhack.limits.med");
|
limits[1] = config.getIntegerValue("speedhack.limits.med");
|
||||||
limits[2] = config.getIntegerValue("speedhack.limits.high");
|
limits[2] = config.getIntegerValue("speedhack.limits.high");
|
||||||
@ -158,11 +172,11 @@ public class SpeedhackCheck extends Check {
|
|||||||
logMessage = config.getStringValue("speedhack.logmessage");
|
logMessage = config.getStringValue("speedhack.logmessage");
|
||||||
|
|
||||||
actions = new Action[3][];
|
actions = new Action[3][];
|
||||||
|
|
||||||
actions[0] = config.getActionValue("speedhack.action.low");
|
actions[0] = config.getActionValue("speedhack.action.low");
|
||||||
actions[1] = config.getActionValue("speedhack.action.med");
|
actions[1] = config.getActionValue("speedhack.action.med");
|
||||||
actions[2] = config.getActionValue("speedhack.action.high");
|
actions[2] = config.getActionValue("speedhack.action.high");
|
||||||
|
|
||||||
setActive(config.getBooleanValue("active.speedhack"));
|
setActive(config.getBooleanValue("active.speedhack"));
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
|
@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
|
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
|
||||||
|
|
||||||
public class AirbuildData {
|
public class AirbuildData {
|
||||||
public int perSecond = 0;
|
public int perFiveSeconds = 0;
|
||||||
public Runnable summaryTask = null;
|
public Runnable summaryTask = null;
|
||||||
|
|
||||||
public static AirbuildData get(Player p) {
|
public static AirbuildData get(Player p) {
|
||||||
|
@ -10,7 +10,8 @@ public class SpeedhackData {
|
|||||||
public int lastCheckTicks = 0; // timestamp of last check for speedhacks
|
public int lastCheckTicks = 0; // timestamp of last check for speedhacks
|
||||||
public Location setBackPoint = null;
|
public Location setBackPoint = null;
|
||||||
public int eventsSinceLastCheck = 0; // used to identify speedhacks
|
public int eventsSinceLastCheck = 0; // used to identify speedhacks
|
||||||
public int violationsInARow = 0;
|
public final int violationsInARow[] = { 0, 0, 0 };
|
||||||
|
public int violationsInARowTotal = 0;
|
||||||
|
|
||||||
public static SpeedhackData get(Player p) {
|
public static SpeedhackData get(Player p) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user