mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-29 03:48:50 +01:00
Potential fix for teleporting by other plugins + also log worlds with
coordinates.
This commit is contained in:
parent
3075e79d83
commit
53c9dd50f1
@ -3,7 +3,7 @@ name: NoCheatPlugin
|
||||
author: Evenprime
|
||||
|
||||
main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin
|
||||
version: 0.7
|
||||
version: 0.7.1
|
||||
|
||||
commands:
|
||||
nocheat:
|
||||
|
@ -20,6 +20,8 @@ public class NoCheatData {
|
||||
public int movingNormalViolationsInARow = 0;
|
||||
public int movingHeavyViolationsInARow = 0;
|
||||
|
||||
public boolean reset = false;
|
||||
|
||||
public int movingHorizFreeMoves = 4;
|
||||
public Location movingSetBackPoint = null;
|
||||
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatBlockListener;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatPlayerListener;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatPlayerListenerMonitor;
|
||||
|
||||
import com.ensifera.animosity.craftirc.CraftIRC;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
@ -35,6 +36,7 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
|
||||
// Various listeners needed for different Checks
|
||||
private NoCheatPlayerListener playerListener;
|
||||
private NoCheatPlayerListenerMonitor playerListenerMonitor;
|
||||
private NoCheatBlockListener blockListener;
|
||||
|
||||
// My main logger
|
||||
@ -135,6 +137,7 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
// Create our listeners and feed them with neccessary information
|
||||
playerListener = new NoCheatPlayerListener();
|
||||
playerListenerMonitor = new NoCheatPlayerListenerMonitor();
|
||||
blockListener = new NoCheatBlockListener();
|
||||
|
||||
fileLogger = NoCheatConfiguration.logger;
|
||||
@ -144,7 +147,8 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Lowest, this); // used for speedhack and moving checks
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this); // used to delete old data of users
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Low, this); // used for airbuild check
|
||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.Lowest, this); // used for moving, speedhack and teleportfrombed check
|
||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.Lowest, this); // used for teleportfrombed check
|
||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListenerMonitor, Priority.Monitor, this); // used for moving, speedhack check
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class MovingCheck {
|
||||
// Get the two locations of the event
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
|
||||
|
||||
if(from.getWorld() != to.getWorld()) {
|
||||
// Moving between different worlds is considered ok
|
||||
// Also prevent accidential back teleporting by discarding old-world coordinates
|
||||
@ -153,7 +153,6 @@ public class MovingCheck {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// First check the distance the player has moved horizontally
|
||||
// TODO: Make this check much more precise
|
||||
double xDistance = Math.abs(from.getX() - to.getX());
|
||||
@ -193,7 +192,6 @@ public class MovingCheck {
|
||||
boolean onGroundFrom = playerIsOnGround(from.getWorld(), fromValues, from);
|
||||
boolean onGroundTo = playerIsOnGround(to.getWorld(), toValues, to);
|
||||
|
||||
|
||||
// Both locations seem to be on solid ground or at a ladder
|
||||
if(onGroundFrom && onGroundTo)
|
||||
{
|
||||
@ -273,7 +271,7 @@ public class MovingCheck {
|
||||
double offset = (to.getY() - l.getY()) - limit;
|
||||
|
||||
if(offset > 2D) vl = max(vl, Level.SEVERE);
|
||||
else if(offset > 0.5D) vl = max(vl, Level.WARNING);
|
||||
else if(offset > 0.5D) vl = max(vl, Level.WARNING);
|
||||
else vl = max(vl, Level.INFO);
|
||||
}
|
||||
else {
|
||||
@ -351,7 +349,7 @@ public class MovingCheck {
|
||||
if(actions == null) return;
|
||||
// LOGGING IF NEEDED
|
||||
if(log && actions.contains("log")) {
|
||||
NoCheatPlugin.logAction(actions, "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()));
|
||||
NoCheatPlugin.logAction(actions, "Moving violation: "+event.getPlayer().getName()+" from " + String.format("%s (%.5f, %.5f, %.5f) to %s (%.5f, %.5f, %.5f)", event.getFrom().getWorld().getName(), event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getWorld().getName(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()));
|
||||
}
|
||||
|
||||
// RESET IF NEEDED
|
||||
@ -410,6 +408,8 @@ public class MovingCheck {
|
||||
data.movingJumpPhase = 0;
|
||||
|
||||
Location l = data.movingSetBackPoint;
|
||||
|
||||
data.reset = true;
|
||||
// If we have stored a location for the player, we put him back there
|
||||
if(l != null) {
|
||||
// Lets try it that way. Maybe now people don't "disappear" any longer
|
||||
|
@ -87,6 +87,8 @@ public class SpeedhackCheck {
|
||||
private static void resetPlayer(PlayerMoveEvent event, NoCheatData data) {
|
||||
|
||||
Location l = data.speedhackSetBackPoint;
|
||||
|
||||
data.reset = true;
|
||||
// If we have stored a location for the player, we put him back there
|
||||
if(l != null) {
|
||||
event.setFrom(l);
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlugin;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.BedteleportCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
|
||||
@ -42,19 +41,9 @@ public class NoCheatPlayerListener extends PlayerListener {
|
||||
}
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerMoveEvent event) {
|
||||
|
||||
if(!event.isCancelled() && NoCheatConfiguration.bedteleportCheckActive) {
|
||||
BedteleportCheck.check(event);
|
||||
}
|
||||
|
||||
if(!event.isCancelled()) {
|
||||
NoCheatData data = NoCheatPlugin.getPlayerData(event.getPlayer());
|
||||
// If it wasn't our plugin that ordered the teleport, forget all our information to start from scratch at the new location
|
||||
if(!event.getTo().equals(data.movingSetBackPoint) && !event.getTo().equals(data.speedhackSetBackPoint)) {
|
||||
data.speedhackSetBackPoint = null;
|
||||
data.movingSetBackPoint = null;
|
||||
data.movingJumpPhase = 0;
|
||||
}
|
||||
if(!event.isCancelled() && NoCheatConfiguration.bedteleportCheckActive) {
|
||||
BedteleportCheck.check(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.listeners;
|
||||
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlugin;
|
||||
|
||||
public class NoCheatPlayerListenerMonitor extends PlayerListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerMoveEvent event) {
|
||||
|
||||
NoCheatData data = NoCheatPlugin.getPlayerData(event.getPlayer());
|
||||
|
||||
if(data.reset) { // My plugin requested this teleport, so we allow it
|
||||
data.reset = false;
|
||||
}
|
||||
else if(!event.isCancelled()) {
|
||||
// If it wasn't our plugin that ordered the teleport, forget all our information and start from scratch at the new location
|
||||
data.speedhackSetBackPoint = event.getTo().clone();
|
||||
data.movingSetBackPoint = event.getTo().clone();
|
||||
data.movingJumpPhase = 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user