mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-03 01:00:20 +01: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.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.BedteleportCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.BogusitemsCheck;
|
||||
@ -359,8 +359,8 @@ public class NoCheat extends JavaPlugin {
|
||||
return this.serverLagInMilliSeconds;
|
||||
}
|
||||
|
||||
public void handleCustomAction(Action a, Player player) {
|
||||
// TODO Auto-generated method stub
|
||||
public void handleCustomAction(CustomAction a, Player player) {
|
||||
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;
|
||||
|
||||
// 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);
|
||||
|
@ -59,52 +59,42 @@ public class AirbuildCheck extends Check {
|
||||
}
|
||||
};
|
||||
|
||||
// Give a summary in 20 ticks ~ 1 second
|
||||
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, data.summaryTask, 20);
|
||||
// Give a summary in 100 ticks ~ 1 second
|
||||
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, data.summaryTask, 100);
|
||||
}
|
||||
|
||||
data.perSecond++;
|
||||
data.perFiveSeconds++;
|
||||
|
||||
// which limit has been reached
|
||||
for(int i = limits.length-1; i >= 0; i--) {
|
||||
if(data.perSecond >= limits[i]) {
|
||||
// Only explicitly log certain "milestones"
|
||||
if(data.perSecond == limits[i]) {
|
||||
action(actions[i], event, true);
|
||||
}
|
||||
else {
|
||||
action(actions[i], event, false);
|
||||
}
|
||||
if(data.perFiveSeconds >= limits[i]) {
|
||||
action(actions[i], event, data.perFiveSeconds - limits[i]+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void action(Action actions[], BlockPlaceEvent event, boolean loggingAllowed) {
|
||||
private void action(Action actions[], BlockPlaceEvent event, int violations) {
|
||||
|
||||
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
|
||||
for(Action a : actions) {
|
||||
if(loggingAllowed && a instanceof LogAction) {
|
||||
plugin.log(((LogAction)a).level, logMessage);
|
||||
}
|
||||
else if(!cancelled && a instanceof CancelAction) {
|
||||
event.setCancelled(true);
|
||||
cancelled = true;
|
||||
}
|
||||
else if(a instanceof CustomAction) {
|
||||
plugin.handleCustomAction(a, event.getPlayer());
|
||||
if(a.firstAfter >= violations) {
|
||||
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
|
||||
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();
|
||||
plugin.log(((LogAction)a).level, logMessage);
|
||||
}
|
||||
else if(a instanceof CancelAction) {
|
||||
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
|
||||
for(int i = limits.length-1; i >= 0; i--) {
|
||||
if(data.perSecond >= limits[i]) {
|
||||
plugin.log(LogAction.log[i].level, "Airbuild summary: " +player.getName() + " total violations per second: " + data.perSecond);
|
||||
if(data.perFiveSeconds >= limits[i]) {
|
||||
plugin.log(LogAction.log[i].level, "Airbuild summary: " +player.getName() + " total violations per 5 seconds: " + data.perFiveSeconds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
data.perSecond = 0;
|
||||
data.perFiveSeconds = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -259,10 +259,9 @@ public class MovingCheck extends Check {
|
||||
if(violationLevel >= 0) {
|
||||
setupSummaryTask(event.getPlayer(), data);
|
||||
|
||||
boolean log = !(data.violationsInARow[violationLevel] > 0);
|
||||
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 *****/
|
||||
@ -447,30 +446,33 @@ public class MovingCheck extends Check {
|
||||
* @param event
|
||||
* @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;
|
||||
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) {
|
||||
if(loggingAllowed && a instanceof LogAction) {
|
||||
plugin.log(((LogAction)a).level, log);
|
||||
if(data.highestLogLevel == null) data.highestLogLevel = Level.ALL;
|
||||
if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level;
|
||||
if(a.firstAfter >= violations) {
|
||||
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
|
||||
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());
|
||||
|
||||
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 high = (limits[2]+1) / 2;
|
||||
|
||||
if(data.eventsSinceLastCheck > high) action = actions[2];
|
||||
else if(data.eventsSinceLastCheck > med) action = actions[1];
|
||||
else if(data.eventsSinceLastCheck > low) action = actions[0];
|
||||
int level = -1;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
if(action != null) data.violationsInARow++;
|
||||
if(level >= 0) {
|
||||
data.violationsInARowTotal++;
|
||||
}
|
||||
|
||||
if(data.violationsInARow >= violationsLimit) {
|
||||
action(action, event, data);
|
||||
if(data.violationsInARowTotal >= violationsLimit) {
|
||||
data.violationsInARow[level]++;
|
||||
action(action, event, data.violationsInARow[level], data);
|
||||
}
|
||||
|
||||
// Reset value for next check
|
||||
@ -109,25 +114,34 @@ public class SpeedhackCheck extends Check {
|
||||
}
|
||||
|
||||
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.setBackPoint = l;
|
||||
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;
|
||||
|
||||
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);
|
||||
|
||||
for(Action a : actions) {
|
||||
if(a instanceof LogAction)
|
||||
plugin.log(((LogAction)a).level, log);
|
||||
else if(a instanceof CancelAction)
|
||||
resetPlayer(event, data);
|
||||
else if(a instanceof CustomAction)
|
||||
plugin.handleCustomAction(a, event.getPlayer());
|
||||
if(a.firstAfter >= violations) {
|
||||
if(a.firstAfter == violations || (a.repeat > 0 && (violations - a.firstAfter) % a.repeat == 0)) {
|
||||
if(a instanceof LogAction) {
|
||||
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);
|
||||
plugin.log(((LogAction)a).level, log);
|
||||
}
|
||||
else if(a instanceof CancelAction) {
|
||||
resetPlayer(event, data);
|
||||
}
|
||||
else if(a instanceof CustomAction) {
|
||||
plugin.handleCustomAction((CustomAction)a, event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
|
||||
|
||||
public class AirbuildData {
|
||||
public int perSecond = 0;
|
||||
public int perFiveSeconds = 0;
|
||||
public Runnable summaryTask = null;
|
||||
|
||||
public static AirbuildData get(Player p) {
|
||||
|
@ -10,7 +10,8 @@ public class SpeedhackData {
|
||||
public int lastCheckTicks = 0; // timestamp of last check for speedhacks
|
||||
public Location setBackPoint = null;
|
||||
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) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user