Updated for CB #1046. Use new PlayerVelocity event + adapt to new

player move events + use new method to find out if "allow-flight" was
set.
This commit is contained in:
Evenprime 2011-08-09 08:32:37 +02:00
parent 91c77a1aab
commit 33e9c46716
7 changed files with 362 additions and 421 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 1.11d
version: 1.12
softdepend: [ Permissions, CraftIRC ]

View File

@ -1,8 +1,6 @@
package cc.co.evenprime.bukkit.nocheat;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -66,7 +64,6 @@ public class NoCheat extends JavaPlugin {
// CraftIRC, if available
private CraftIRC irc;
private boolean allowFlightSet;
private Level chatLevel;
private Level ircLevel;
@ -85,7 +82,7 @@ public class NoCheat extends JavaPlugin {
public String[] getMessagesOfTheDay() {
return new String[] {"NoCheat now supports the new Bukkit-Permission system. You can activate it in the config file.", "There will be a change in the near future to how movement in CraftBukkit works, which will break NoCheats moving-check(s) completely, causing tons of false positives. Be careful if you tend to run bleeding edge builds of CraftBukkit.", "This version of NoCheat was written for CraftBukkit RB 1000, but may still work for some older or newer versions.", "You can find detailed information about all configuration options of NoCheat in the file \"descriptions.txt\" in your \"plugins/NoCheat\" folder", "You can deactivate these Messages in the config file, if they annoy you."};
return new String[] {"This version of NoCheat was written for CraftBukkit CB #1046, it will NOT work on older versions.", "NoCheat supports the new SuperPerms system. You can activate it in the config file.", "You can find detailed information about all configuration options of NoCheat in the file \"descriptions.txt\" in your \"plugins/NoCheat\" folder", "You can deactivate these Messages in the config file, if they annoy you."};
}
@Override
@ -153,7 +150,7 @@ public class NoCheat extends JavaPlugin {
// just for convenience
checks = new Check[] {movingCheck, speedhackCheck, airbuildCheck, bogusitemsCheck, nukeCheck};
if(!allowFlightSet && movingCheck.isActive()) {
if(!this.getServer().getAllowFlight() && movingCheck.isActive()) {
Logger.getLogger("Minecraft").warning("[NoCheat] you have set \"allow-flight=false\" in your server.properties file. That builtin anti-flying-mechanism will likely conflict with this plugin. Please consider deactivating it by setting it to \"true\"");
}
@ -385,24 +382,6 @@ public class NoCheat extends JavaPlugin {
e.printStackTrace();
this.setEnabled(false);
}
try {
BufferedReader reader = new BufferedReader(new FileReader(new File("server.properties")));
allowFlightSet = true;
String s = null;
while((s = reader.readLine()) != null) {
if(s.startsWith("allow-flight=false")) {
allowFlightSet = false;
}
}
} catch(Exception e) {
e.printStackTrace();
// ignore errors
}
}
private String getActiveChecksAsString() {

View File

@ -88,18 +88,12 @@ public class FlyingCheck {
// its movement, plus additional events if the "velocity" was big and can cause longer flights
// The server sent the player a "velocity" packet a short time ago
if(data.maxYVelocity > 0.0D) {
data.vertFreedomCounter = 30;
// Be generous with the height limit for the client
data.vertFreedom += data.maxYVelocity*2D;
data.maxYVelocity = 0.0D;
}
// consume a counter for this client
if(data.vertFreedomCounter > 0) {
data.vertFreedomCounter--;
data.vertFreedom += data.maxYVelocity*2D;
data.maxYVelocity *= 0.90D;
}
final double limit = data.vertFreedom;

View File

@ -23,7 +23,6 @@ import cc.co.evenprime.bukkit.nocheat.actions.LogAction;
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
import cc.co.evenprime.bukkit.nocheat.listeners.MovingEntityListener;
import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerListener;
import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerMonitor;
@ -83,8 +82,6 @@ public class MovingCheck extends Check {
public Location check(Player player, Location from, Location to,
MovingData data) {
updateVelocity(player.getVelocity(), data);
Location newToLocation = null;
final long startTime = System.nanoTime();
@ -277,8 +274,9 @@ public class MovingCheck extends Check {
if(tmp > data.horizFreedom)
data.horizFreedom = tmp;
if(v.getY() > data.maxYVelocity) {
data.maxYVelocity = v.getY();
if(v.getY() > 0.0D) {
data.vertFreedomCounter = 50;
data.maxYVelocity += v.getY();
}
}
@ -416,11 +414,10 @@ public class MovingCheck extends Check {
// Register listeners for moving check
pm.registerEvent(Event.Type.PLAYER_MOVE, new MovingPlayerListener(plugin.getDataManager(), this), Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_INTERACT, movingPlayerMonitor, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_MOVE, movingPlayerMonitor, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, new MovingEntityListener(plugin.getDataManager(), this), Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_TELEPORT, movingPlayerMonitor, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_PORTAL, movingPlayerMonitor, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, movingPlayerMonitor, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_VELOCITY, movingPlayerMonitor, Priority.Monitor, plugin);
}
}

View File

@ -1,26 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityListener;
import cc.co.evenprime.bukkit.nocheat.DataManager;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
public class MovingEntityListener extends EntityListener {
private final MovingCheck check;
private final DataManager dataManager;
public MovingEntityListener(DataManager dataManager, MovingCheck check) {
this.dataManager = dataManager;
this.check = check;
}
@Override
public void onEntityDamage(EntityDamageEvent event) {
if(event.getEntity() instanceof Player) {
check.updateVelocity(event.getEntity().getVelocity(), dataManager.getMovingData((Player)event.getEntity()));
}
}
}

View File

@ -37,7 +37,7 @@ public class MovingPlayerListener extends PlayerListener {
if(!check.skipCheck(player)) {
final MovingData data = dataManager.getMovingData(player);
final Location from = event.getFrom();
final Location from = player.getLocation();
final Location to = event.getTo();
Location newTo = null;

View File

@ -1,11 +1,11 @@
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import cc.co.evenprime.bukkit.nocheat.DataManager;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
@ -44,20 +44,17 @@ public class MovingPlayerMonitor extends PlayerListener {
check.teleported(event);
}
@Override
public void onPlayerInteract(PlayerInteractEvent event) {
check.updateVelocity(event.getPlayer().getVelocity(), dataManager.getMovingData(event.getPlayer()));
public void onPlayerVelocity(PlayerVelocityEvent event) {
check.updateVelocity(event.getVelocity(), dataManager.getMovingData(event.getPlayer()));
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
MovingData data = dataManager.getMovingData(event.getPlayer());
check.updateVelocity(event.getPlayer().getVelocity(), data);
if(!event.isCancelled()) {
if( event.getPlayer().isInsideVehicle()) {
MovingData data = dataManager.getMovingData(event.getPlayer());
data.setBackPoint = event.getTo();
}
}