Removed Bedteleport check, workaround for bogusitems pickup check

(bukkit has a nasty bug here), adapted moving and speedhack check for
new system.
This commit is contained in:
Evenprime 2011-06-24 14:10:54 +02:00
parent 669f730fd4
commit 61d89d78d8
8 changed files with 46 additions and 168 deletions

View File

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

View File

@ -17,7 +17,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import cc.co.evenprime.bukkit.nocheat.actions.CustomAction; 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.BogusitemsCheck; import cc.co.evenprime.bukkit.nocheat.checks.BogusitemsCheck;
import cc.co.evenprime.bukkit.nocheat.checks.Check; import cc.co.evenprime.bukkit.nocheat.checks.Check;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck; import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
@ -41,7 +40,6 @@ import org.bukkit.plugin.Plugin;
public class NoCheat extends JavaPlugin implements CommandSender { public class NoCheat extends JavaPlugin implements CommandSender {
private MovingCheck movingCheck; private MovingCheck movingCheck;
private BedteleportCheck bedteleportCheck;
private SpeedhackCheck speedhackCheck; private SpeedhackCheck speedhackCheck;
private AirbuildCheck airbuildCheck; private AirbuildCheck airbuildCheck;
private BogusitemsCheck bogusitemsCheck; private BogusitemsCheck bogusitemsCheck;
@ -136,13 +134,12 @@ public class NoCheat extends JavaPlugin implements CommandSender {
setupConfig(); setupConfig();
movingCheck = new MovingCheck(this, config); movingCheck = new MovingCheck(this, config);
bedteleportCheck = new BedteleportCheck(this, config);
speedhackCheck = new SpeedhackCheck(this, config); speedhackCheck = new SpeedhackCheck(this, config);
airbuildCheck = new AirbuildCheck(this, config); airbuildCheck = new AirbuildCheck(this, config);
bogusitemsCheck = new BogusitemsCheck(this, config); bogusitemsCheck = new BogusitemsCheck(this, config);
// just for convenience // just for convenience
checks = new Check[] { movingCheck, bedteleportCheck, speedhackCheck, airbuildCheck, bogusitemsCheck }; checks = new Check[] { movingCheck, speedhackCheck, airbuildCheck, bogusitemsCheck };
if(!allowFlightSet && movingCheck.isActive()) { if(!allowFlightSet && 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\""); 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\"");

View File

@ -1,56 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
import cc.co.evenprime.bukkit.nocheat.listeners.BedteleportPlayerListener;
/**
*
* @author Evenprime
*
*/
public class BedteleportCheck extends Check {
public BedteleportCheck(NoCheat plugin, NoCheatConfiguration config) {
super(plugin, "bedteleport", PermissionData.PERMISSION_BEDTELEPORT, config);
}
public void check(PlayerMoveEvent event) {
// Should we check at all?
if(skipCheck(event.getPlayer()))
return;
if(event.getPlayer().isSleeping())
event.setCancelled(true);
}
@Override
public void configure(NoCheatConfiguration config) {
try {
setActive(config.getBooleanValue("active.bedteleport"));
} catch (ConfigurationException e) {
setActive(false);
e.printStackTrace();
}
}
@Override
protected void registerListeners() {
PluginManager pm = Bukkit.getServer().getPluginManager();
// Register listeners for bedteleport check
pm.registerEvent(Event.Type.PLAYER_TELEPORT, new BedteleportPlayerListener(this), Priority.Lowest, plugin);
}
}

View File

@ -36,7 +36,7 @@ public class BogusitemsCheck extends Check {
if(i != null) { if(i != null) {
ItemStack s = i.getItemStack(); ItemStack s = i.getItemStack();
if(s != null) { if(s != null) {
if(s.getAmount() <= 0) {// buggy item if(s.getAmount() < 0) {// buggy item
event.getItem().remove(); event.getItem().remove();
event.setCancelled(true); event.setCancelled(true);
plugin.log(Level.WARNING, event.getPlayer().getName() + " tried to pick up an invalid item. Item was removed."); plugin.log(Level.WARNING, event.getPlayer().getName() + " tried to pick up an invalid item. Item was removed.");

View File

@ -63,7 +63,7 @@ public class MovingCheck extends Check {
public boolean allowFakeSneak; public boolean allowFakeSneak;
public boolean allowFastSwim; public boolean allowFastSwim;
public boolean checkOPs; public boolean checkOPs;
private boolean waterElevators; private boolean waterElevators;
private String logMessage; private String logMessage;
@ -96,7 +96,7 @@ public class MovingCheck extends Check {
// Should we check at all // Should we check at all
if(skipCheck(player)) { return; } if(skipCheck(player)) { return; }
final long startTime = System.nanoTime(); final long startTime = System.nanoTime();
// Get the player-specific data // Get the player-specific data
@ -109,14 +109,14 @@ public class MovingCheck extends Check {
Location from = data.lastLocation; Location from = data.lastLocation;
updateVelocity(player.getVelocity(), data); updateVelocity(player.getVelocity(), data);
// event.getFrom() is intentional here // event.getFrom() is intentional here
if(shouldBeIgnored(player, data, event.getFrom(), to)) { if(shouldBeIgnored(player, data, event.getFrom(), to)) {
statisticElapsedTimeNano += System.nanoTime() - startTime; statisticElapsedTimeNano += System.nanoTime() - startTime;
statisticTotalEvents++; statisticTotalEvents++;
return; return;
} }
/**** Horizontal movement check START ****/ /**** Horizontal movement check START ****/
// First check the distance the player has moved horizontally // First check the distance the player has moved horizontally
@ -135,7 +135,7 @@ public class MovingCheck extends Check {
final int onGroundFrom = playerIsOnGround(from, 0.0D); final int onGroundFrom = playerIsOnGround(from, 0.0D);
// Do various checks on the players horizontal movement // Do various checks on the players horizontal movement
int sn = getSneakingViolationLevel(combined, data, player); int sn = getSneakingViolationLevel(combined, data, player);
int sw = getSwimmingViolationLevel(combined, data, onGroundFrom == MovingData.LIQUID, player); int sw = getSwimmingViolationLevel(combined, data, onGroundFrom == MovingData.LIQUID, player);
@ -384,10 +384,10 @@ public class MovingCheck extends Check {
private boolean shouldBeIgnored(final Player player, final MovingData data, final Location from, final Location to) { private boolean shouldBeIgnored(final Player player, final MovingData data, final Location from, final Location to) {
// First the simple yes/no checks // First the simple yes/no checks
if(/*data.respawned ||*/ data.insideVehicle || player.isInsideVehicle()) { if(data.insideVehicle || player.isInsideVehicle()) {
return true; return true;
} }
// More sophisticated checks // More sophisticated checks
final Location l = data.lastLocation; final Location l = data.lastLocation;
@ -395,11 +395,11 @@ public class MovingCheck extends Check {
if(l.getWorld() != from.getWorld()) { if(l.getWorld() != from.getWorld()) {
return true; return true;
} }
final double x = from.getX(); final double x = from.getX();
final double y = from.getY(); final double y = from.getY();
final double z = from.getZ(); final double z = from.getZ();
// Player didn't move at all // Player didn't move at all
if(x == to.getX() && z == to.getZ() && y == to.getY() ) { if(x == to.getX() && z == to.getZ() && y == to.getY() ) {
return true; return true;
@ -408,7 +408,7 @@ public class MovingCheck extends Check {
else if(!(x == l.getX() && z == l.getZ() && y == l.getY())){ else if(!(x == l.getX() && z == l.getZ() && y == l.getY())){
return true; return true;
} }
return false; return false;
} }
@ -451,14 +451,14 @@ public class MovingCheck extends Check {
* @param event * @param event
*/ */
public void teleported(PlayerTeleportEvent event) { public void teleported(PlayerTeleportEvent event) {
MovingData data = MovingData.get(event.getPlayer()); MovingData data = MovingData.get(event.getPlayer());
// We can enforce a teleport, if that flag is explicitly set // We can enforce a teleport, if that flag is explicitly set
if(event.isCancelled() && enforceTeleport && event.getTo().equals(data.teleportTo)) { if(event.isCancelled() && enforceTeleport && event.getTo().equals(data.teleportTo)) {
event.setCancelled(false); event.setCancelled(false);
} }
if(!event.isCancelled()) { if(!event.isCancelled()) {
data.lastLocation = event.getTo(); data.lastLocation = event.getTo();
data.jumpPhase = 0; data.jumpPhase = 0;
@ -518,8 +518,26 @@ public class MovingCheck extends Check {
if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level; if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level;
} }
else if(!cancelled && a instanceof CancelAction) { else if(!cancelled && a instanceof CancelAction) {
resetPlayer(event); // Make a modified copy of the setBackPoint to prevent other plugins from accidentally modifying it
cancelled = true; // and keep the current pitch and yaw (setbacks "feel" better that way). Plus try to adapt the Y-coord
// to place the player close to ground
double y = data.setBackPoint.getY();
// search for the first solid block up to 5 blocks below the setbackpoint and teleport the player there
for(int i = 0; i < 20; i++) {
if(playerIsOnGround(data.setBackPoint, -0.5*i) != MovingData.NONSOLID) {
y -= 0.5*i;
break;
}
}
// Remember the location we send the player to, to identify teleports that were started by us
data.teleportTo = new Location(data.setBackPoint.getWorld(), data.setBackPoint.getX(), y, data.setBackPoint.getZ(), event.getTo().getYaw(), event.getTo().getPitch());
event.setTo(data.teleportTo);
cancelled = true; // just prevent us from treating more than one "cancel" action, which would make no sense
} }
else if(a instanceof CustomAction) else if(a instanceof CustomAction)
plugin.handleCustomAction((CustomAction)a, player); plugin.handleCustomAction((CustomAction)a, player);
@ -546,42 +564,6 @@ public class MovingCheck extends Check {
return -1; return -1;
} }
/**
* Return the player to the stored setBackPoint location
* @param event
*/
private void resetPlayer(PlayerMoveEvent event) {
MovingData data = MovingData.get(event.getPlayer());
// Make a modified copy of the setBackPoint to prevent other plugins from accidentally modifying it
// and keep the current pitch and yaw (setbacks "feel" better that way).
double y = data.setBackPoint.getY();
// search for the first solid block up to 5 blocks below the setbackpoint and teleport the player there
for(int i = 0; i < 20; i++) {
if(playerIsOnGround(data.setBackPoint, -0.5*i) != MovingData.NONSOLID) {
y -= 0.5*i;
break;
}
}
Location t = new Location(data.setBackPoint.getWorld(), data.setBackPoint.getX(), y, data.setBackPoint.getZ(), event.getTo().getYaw(), event.getTo().getPitch());
data.teleportTo = t;
// Only reset player and cancel event if teleport is successful
if(event.getPlayer().teleport(t)) {
// Put the player back to the chosen location
event.setFrom(t);
event.setTo(t);
event.setCancelled(true);
data.teleportTo = null;
}
}
/** /**
* Check if certain coordinates are considered "on ground" * Check if certain coordinates are considered "on ground"
@ -712,7 +694,7 @@ public class MovingCheck extends Check {
allowFlying = config.getBooleanValue("moving.allowflying"); allowFlying = config.getBooleanValue("moving.allowflying");
allowFakeSneak = config.getBooleanValue("moving.allowfakesneak"); allowFakeSneak = config.getBooleanValue("moving.allowfakesneak");
allowFastSwim = config.getBooleanValue("moving.allowfastswim"); allowFastSwim = config.getBooleanValue("moving.allowfastswim");
waterElevators = config.getBooleanValue("moving.waterelevators"); waterElevators = config.getBooleanValue("moving.waterelevators");
logMessage = config.getStringValue("moving.logmessage"). logMessage = config.getStringValue("moving.logmessage").
@ -721,7 +703,7 @@ public class MovingCheck extends Check {
replace("[from]", "(%4$.1f, %5$.1f, %6$.1f)"). replace("[from]", "(%4$.1f, %5$.1f, %6$.1f)").
replace("[to]", "(%7$.1f, %8$.1f, %9$.1f)"). replace("[to]", "(%7$.1f, %8$.1f, %9$.1f)").
replace("[distance]", "(%10$.1f, %11$.1f, %12$.1f)"); replace("[distance]", "(%10$.1f, %11$.1f, %12$.1f)");
summaryMessage = config.getStringValue("moving.summarymessage"). summaryMessage = config.getStringValue("moving.summarymessage").
replace("[timeframe]", "%2$d"). replace("[timeframe]", "%2$d").
replace("[player]", "%1$s"). replace("[player]", "%1$s").
@ -734,9 +716,9 @@ public class MovingCheck extends Check {
actions[2] = config.getActionValue("moving.action.high"); actions[2] = config.getActionValue("moving.action.high");
setActive(config.getBooleanValue("active.moving")); setActive(config.getBooleanValue("active.moving"));
enforceTeleport = config.getBooleanValue("moving.enforceteleport"); enforceTeleport = config.getBooleanValue("moving.enforceteleport");
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
setActive(false); setActive(false);
e.printStackTrace(); e.printStackTrace();

View File

@ -63,8 +63,8 @@ public class SpeedhackCheck extends Check {
// Get the player-specific data // Get the player-specific data
SpeedhackData data = SpeedhackData.get(player); SpeedhackData data = SpeedhackData.get(player);
// Count the event // Count the event (twice, to interpolate from 0.5 seconds to 1 second
data.eventsSinceLastCheck++; data.eventsSinceLastCheck += 2;
// Get the ticks of the server // Get the ticks of the server
int ticks = plugin.getServerTicks(); int ticks = plugin.getServerTicks();
@ -82,15 +82,12 @@ public class SpeedhackCheck extends Check {
resetData(data, event.getFrom()); resetData(data, event.getFrom());
} }
else { else {
final int low = (limits[0]+1) / 2;
final int med = (limits[1]+1) / 2;
final int high = (limits[2]+1) / 2;
int level = -1; int level = -1;
if(data.eventsSinceLastCheck > high) level = 2; if(data.eventsSinceLastCheck > limits[2]) level = 2;
else if(data.eventsSinceLastCheck > med) level = 1; else if(data.eventsSinceLastCheck > limits[1]) level = 1;
else if(data.eventsSinceLastCheck > low) level = 0; else if(data.eventsSinceLastCheck > limits[0]) level = 0;
else { else {
resetData(data, event.getFrom()); resetData(data, event.getFrom());
} }
@ -154,12 +151,7 @@ public class SpeedhackCheck extends Check {
if(data.setBackPoint == null) data.setBackPoint = event.getFrom(); if(data.setBackPoint == null) data.setBackPoint = event.getFrom();
// If we have stored a location for the player, we put him back there // If we have stored a location for the player, we put him back there
event.setTo(data.setBackPoint);
if(event.getPlayer().teleport(data.setBackPoint)) {
event.setFrom(data.setBackPoint);
event.setTo(data.setBackPoint);
event.setCancelled(true);
}
} }
@Override @Override

View File

@ -102,8 +102,6 @@ public class NoCheatConfiguration {
SimpleYaml.getBoolean("active.moving", true, yamlContent))); SimpleYaml.getBoolean("active.moving", true, yamlContent)));
activeNode.add(new BooleanOption("airbuild", activeNode.add(new BooleanOption("airbuild",
SimpleYaml.getBoolean("active.airbuild", false, yamlContent))); SimpleYaml.getBoolean("active.airbuild", false, yamlContent)));
activeNode.add(new BooleanOption("bedteleport",
SimpleYaml.getBoolean("active.bedteleport", true, yamlContent)));
activeNode.add(new BooleanOption("bogusitems", activeNode.add(new BooleanOption("bogusitems",
SimpleYaml.getBoolean("active.bogusitems", false, yamlContent))); SimpleYaml.getBoolean("active.bogusitems", false, yamlContent)));
} }
@ -223,15 +221,6 @@ public class NoCheatConfiguration {
} }
/*** BEDTELEPORT section ***/
{
ParentOption bedteleportNode = new ParentOption("bedteleport", false);
root.add(bedteleportNode);
bedteleportNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("bedteleport.checkops", false, yamlContent)));
}
/*** BOGUSITEMS section ***/ /*** BOGUSITEMS section ***/
{ {
ParentOption bogusitemsNode = new ParentOption("bogusitems", false); ParentOption bogusitemsNode = new ParentOption("bogusitems", false);

View File

@ -1,26 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerTeleportEvent;
import cc.co.evenprime.bukkit.nocheat.checks.BedteleportCheck;
/**
*
* @author Evenprime
*
*/
public class BedteleportPlayerListener extends PlayerListener {
private BedteleportCheck check;
public BedteleportPlayerListener(BedteleportCheck check) {
this.check = check;
}
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
if(!event.isCancelled()) check.check(event);
}
}