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

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) {
ItemStack s = i.getItemStack();
if(s != null) {
if(s.getAmount() <= 0) {// buggy item
if(s.getAmount() < 0) {// buggy item
event.getItem().remove();
event.setCancelled(true);
plugin.log(Level.WARNING, event.getPlayer().getName() + " tried to pick up an invalid item. Item was removed.");

View File

@ -384,7 +384,7 @@ public class MovingCheck extends Check {
private boolean shouldBeIgnored(final Player player, final MovingData data, final Location from, final Location to) {
// First the simple yes/no checks
if(/*data.respawned ||*/ data.insideVehicle || player.isInsideVehicle()) {
if(data.insideVehicle || player.isInsideVehicle()) {
return true;
}
@ -518,8 +518,26 @@ public class MovingCheck extends Check {
if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level;
}
else if(!cancelled && a instanceof CancelAction) {
resetPlayer(event);
cancelled = true;
// 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). 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)
plugin.handleCustomAction((CustomAction)a, player);
@ -546,42 +564,6 @@ public class MovingCheck extends Check {
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"

View File

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

View File

@ -102,8 +102,6 @@ public class NoCheatConfiguration {
SimpleYaml.getBoolean("active.moving", true, yamlContent)));
activeNode.add(new BooleanOption("airbuild",
SimpleYaml.getBoolean("active.airbuild", false, yamlContent)));
activeNode.add(new BooleanOption("bedteleport",
SimpleYaml.getBoolean("active.bedteleport", true, yamlContent)));
activeNode.add(new BooleanOption("bogusitems",
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 ***/
{
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);
}
}