mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-15 16:38:57 +02:00
Fixed logging + new anticheat mechanism
Logging of moving violations (previously reset coordinates of event before logging, therefore the logged information was not useful at all). Added check for building. Building against thin air is not permitted in the client singleplayer game, so why should it be on a server?
This commit is contained in:
parent
f338325bd9
commit
62dfce532d
@ -3,5 +3,5 @@ name: NoCheatPlugin
|
||||
author: Evenprime
|
||||
|
||||
main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin
|
||||
version: 0.5.2
|
||||
version: 0.5.2a
|
||||
|
||||
|
24
src/cc/co/evenprime/bukkit/nocheat/BlockPlacingCheck.java
Normal file
24
src/cc/co/evenprime/bukkit/nocheat/BlockPlacingCheck.java
Normal file
@ -0,0 +1,24 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class BlockPlacingCheck {
|
||||
|
||||
public static void check(BlockPlaceEvent event) {
|
||||
|
||||
|
||||
if(NoCheatPlugin.Permissions != null && NoCheatPlugin.Permissions.has(event.getPlayer(), "nocheat.airbuild")) {
|
||||
return;
|
||||
}
|
||||
else if(NoCheatPlugin.Permissions == null && event.getPlayer().isOp() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getBlockAgainst().getType() == Material.AIR) {
|
||||
event.setCancelled(true);
|
||||
NoCheatPlugin.log.warning("NoCheatPlugin: Airbuild violation: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " against air");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPluginPlayerListener.NoCheatPluginData;
|
||||
|
||||
public class MovingCheck {
|
||||
|
||||
@ -134,7 +133,6 @@ public class MovingCheck {
|
||||
|
||||
// First check the distance the player has moved horizontally
|
||||
// TODO: Make this check much more precise
|
||||
if(!event.isCancelled()) {
|
||||
double xDistance = Math.abs(from.getX() - to.getX());
|
||||
double zDistance = Math.abs(from.getZ() - to.getZ());
|
||||
|
||||
@ -148,10 +146,7 @@ public class MovingCheck {
|
||||
else if(xDistance > NoCheatConfiguration.movingDistanceLow || zDistance > NoCheatConfiguration.movingDistanceLow) {
|
||||
vl = vl > MINOR ? vl : MINOR;
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't already cancel the event, check the vertical movement
|
||||
if(!event.isCancelled()) {
|
||||
|
||||
// pre-calculate boundary values that are needed multiple times in the following checks
|
||||
// the array each contains [lowerX, higherX, Y, lowerZ, higherZ]
|
||||
@ -240,7 +235,6 @@ public class MovingCheck {
|
||||
if(!(data.phase < jumpingPhases.length)) {
|
||||
data.phase = jumpingPhases.length - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Treat the violation(s)
|
||||
switch(vl) {
|
||||
@ -273,27 +267,30 @@ public class MovingCheck {
|
||||
}
|
||||
else if(data.minorViolationsInARow % 2 == 0) {
|
||||
// now we need it
|
||||
resetPlayer(data, event);
|
||||
NoCheatPlugin.log.info("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()));
|
||||
resetPlayer(data, event);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void normalViolation(NoCheatPluginData data, PlayerMoveEvent event) {
|
||||
resetPlayer(data, event);
|
||||
|
||||
data.normalViolationsInARow++;
|
||||
// Log the first violation in a row
|
||||
if(data.normalViolationsInARow <= 1)
|
||||
NoCheatPlugin.log.warning("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()));
|
||||
|
||||
resetPlayer(data, event);
|
||||
|
||||
data.normalViolationsInARow++;
|
||||
}
|
||||
|
||||
protected static void heavyViolation(NoCheatPluginData data, PlayerMoveEvent event) {
|
||||
|
||||
if(data.heavyViolationsInARow == 0)
|
||||
NoCheatPlugin.log.severe("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()));
|
||||
|
||||
resetPlayer(data, event);
|
||||
|
||||
data.heavyViolationsInARow++;
|
||||
// Log the first violation in a row
|
||||
if(data.heavyViolationsInARow <= 1)
|
||||
NoCheatPlugin.log.severe("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()));
|
||||
}
|
||||
|
||||
protected static void legitimateMove(NoCheatPluginData data, PlayerMoveEvent event) {
|
||||
|
@ -1,8 +1,11 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
@ -25,18 +28,40 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
|
||||
private final NoCheatPluginPlayerListener playerListener;
|
||||
private final NoCheatPluginVehicleListener vehicleListener;
|
||||
private final NoCheatPluginBlockListener blockListener;
|
||||
|
||||
public static Logger log;
|
||||
public static PermissionHandler Permissions = null;
|
||||
|
||||
// Store data between Events
|
||||
public static Map<Player, NoCheatPluginData> playerData = new HashMap<Player, NoCheatPluginData>();
|
||||
|
||||
public NoCheatPlugin() {
|
||||
|
||||
playerListener = new NoCheatPluginPlayerListener(this);
|
||||
vehicleListener = new NoCheatPluginVehicleListener(this, playerListener);
|
||||
playerListener = new NoCheatPluginPlayerListener();
|
||||
vehicleListener = new NoCheatPluginVehicleListener(playerListener);
|
||||
blockListener = new NoCheatPluginBlockListener();
|
||||
|
||||
log = NoCheatConfiguration.logger;
|
||||
}
|
||||
|
||||
public static NoCheatPluginData getPlayerData(Player p) {
|
||||
NoCheatPluginData data = null;
|
||||
|
||||
if((data = playerData.get(p)) == null ) {
|
||||
synchronized(playerData) {
|
||||
data = playerData.get(p);
|
||||
if(data == null) {
|
||||
// If we have no data for the player, create some
|
||||
data = new NoCheatPluginData();
|
||||
playerData.put(p, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
@ -47,6 +72,7 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.VEHICLE_EXIT, vehicleListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.VEHICLE_DAMAGE, vehicleListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Low, this);
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
Logger.getLogger("Minecraft").info( "NoCheat version " + pdfFile.getVersion() + " is enabled!" );
|
||||
@ -58,16 +84,13 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
public void setupPermissions() {
|
||||
Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
|
||||
|
||||
|
||||
if(Permissions == null) {
|
||||
if(test != null) {
|
||||
Permissions = ((Permissions)test).getHandler();
|
||||
} else {
|
||||
log.info("Nocheat couldn't find Permissions plugin. Fallback to OP -> all allowed.");
|
||||
log.info("Nocheat couldn't find Permissions plugin. Fallback to 'isOp()' equals 'all allowed'.");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setupConfig() {
|
||||
NoCheatConfiguration.config(new File("plugins/NoCheat/nocheat.yml"));
|
||||
|
@ -0,0 +1,19 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class NoCheatPluginBlockListener extends BlockListener {
|
||||
|
||||
|
||||
public NoCheatPluginBlockListener() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
|
||||
if(!event.isCancelled() && NoCheatConfiguration.speedhackCheckActive)
|
||||
BlockPlacingCheck.check(event);
|
||||
}
|
||||
}
|
26
src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginData.java
Normal file
26
src/cc/co/evenprime/bukkit/nocheat/NoCheatPluginData.java
Normal file
@ -0,0 +1,26 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Storage for data persistence between events
|
||||
*
|
||||
*/
|
||||
public class NoCheatPluginData {
|
||||
|
||||
/**
|
||||
* Don't rely on any of these yet, they are likely going to
|
||||
* change their name/functionality
|
||||
*/
|
||||
int phase = 0; // current jumpingPhase
|
||||
long lastSpeedHackCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks
|
||||
int eventsSinceLastSpeedHackCheck = 0; // used to identify speedhacks
|
||||
int ignoreNextXEvents = 0;
|
||||
|
||||
int minorViolationsInARow = 0;
|
||||
int normalViolationsInARow = 0;
|
||||
int heavyViolationsInARow = 0;
|
||||
Location movingSetBackPoint = null;
|
||||
|
||||
NoCheatPluginData() { }
|
||||
}
|
@ -1,12 +1,8 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@ -18,47 +14,18 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
|
||||
/**
|
||||
* Storage for data persistence between events
|
||||
*
|
||||
*/
|
||||
public class NoCheatPluginData {
|
||||
|
||||
/**
|
||||
* Don't rely on any of these yet, they are likely going to
|
||||
* change their name/functionality
|
||||
*/
|
||||
int phase = 0; // current jumpingPhase
|
||||
long lastSpeedHackCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks
|
||||
int eventsSinceLastSpeedHackCheck = 0; // used to identify speedhacks
|
||||
int ignoreNextXEvents = 0;
|
||||
|
||||
int minorViolationsInARow = 0;
|
||||
int normalViolationsInARow = 0;
|
||||
int heavyViolationsInARow = 0;
|
||||
Location movingSetBackPoint = null;
|
||||
|
||||
private NoCheatPluginData() { }
|
||||
}
|
||||
|
||||
private final NoCheatPlugin plugin;
|
||||
|
||||
// Store data between Events
|
||||
private static Map<Player, NoCheatPluginData> playerData = new HashMap<Player, NoCheatPluginData>();
|
||||
|
||||
|
||||
public NoCheatPluginPlayerListener(NoCheatPlugin instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
public NoCheatPluginPlayerListener() { }
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerEvent event) {
|
||||
playerData.remove(event.getPlayer());
|
||||
NoCheatPlugin.playerData.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
public void ingoreNextXEvents(Entity player, int count) {
|
||||
|
||||
NoCheatPluginData data = playerData.get(player);
|
||||
NoCheatPluginData data = NoCheatPlugin.playerData.get(player);
|
||||
if(data != null) {
|
||||
data.ignoreNextXEvents = count;
|
||||
}
|
||||
@ -68,13 +35,7 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
|
||||
// Get the player-specific data
|
||||
NoCheatPluginData data = null;
|
||||
|
||||
if((data = playerData.get(event.getPlayer())) == null ) {
|
||||
// If we have no data for the player, create some
|
||||
data = new NoCheatPluginData();
|
||||
playerData.put(event.getPlayer(), data);
|
||||
}
|
||||
NoCheatPluginData data = NoCheatPlugin.getPlayerData(event.getPlayer());
|
||||
|
||||
if(data.ignoreNextXEvents > 0 ) {
|
||||
data.ignoreNextXEvents--;
|
||||
|
@ -12,11 +12,9 @@ import org.bukkit.event.vehicle.VehicleListener;
|
||||
|
||||
public class NoCheatPluginVehicleListener extends VehicleListener {
|
||||
|
||||
private final NoCheatPlugin plugin;
|
||||
private final NoCheatPluginPlayerListener playerListener;
|
||||
|
||||
public NoCheatPluginVehicleListener(NoCheatPlugin plugin, NoCheatPluginPlayerListener playerListener) {
|
||||
this.plugin = plugin;
|
||||
public NoCheatPluginVehicleListener(NoCheatPluginPlayerListener playerListener) {
|
||||
this.playerListener = playerListener;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPluginPlayerListener.NoCheatPluginData;
|
||||
|
||||
public class SpeedhackCheck {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user