mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-29 03:48:50 +01:00
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:
parent
669f730fd4
commit
61d89d78d8
@ -3,7 +3,7 @@ name: NoCheat
|
||||
author: Evenprime
|
||||
|
||||
main: cc.co.evenprime.bukkit.nocheat.NoCheat
|
||||
version: 1.05a
|
||||
version: 1.06
|
||||
|
||||
softdepend: [ Permissions, CraftIRC ]
|
||||
|
||||
|
@ -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\"");
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
@ -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.");
|
||||
|
@ -63,7 +63,7 @@ public class MovingCheck extends Check {
|
||||
public boolean allowFakeSneak;
|
||||
public boolean allowFastSwim;
|
||||
public boolean checkOPs;
|
||||
|
||||
|
||||
private boolean waterElevators;
|
||||
|
||||
private String logMessage;
|
||||
@ -96,7 +96,7 @@ public class MovingCheck extends Check {
|
||||
// Should we check at all
|
||||
if(skipCheck(player)) { return; }
|
||||
|
||||
|
||||
|
||||
final long startTime = System.nanoTime();
|
||||
|
||||
// Get the player-specific data
|
||||
@ -109,14 +109,14 @@ public class MovingCheck extends Check {
|
||||
Location from = data.lastLocation;
|
||||
|
||||
updateVelocity(player.getVelocity(), data);
|
||||
|
||||
|
||||
// event.getFrom() is intentional here
|
||||
if(shouldBeIgnored(player, data, event.getFrom(), to)) {
|
||||
statisticElapsedTimeNano += System.nanoTime() - startTime;
|
||||
statisticTotalEvents++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**** Horizontal movement check START ****/
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
|
||||
// Do various checks on the players horizontal movement
|
||||
int sn = getSneakingViolationLevel(combined, data, 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) {
|
||||
|
||||
// First the simple yes/no checks
|
||||
if(/*data.respawned ||*/ data.insideVehicle || player.isInsideVehicle()) {
|
||||
if(data.insideVehicle || player.isInsideVehicle()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// More sophisticated checks
|
||||
final Location l = data.lastLocation;
|
||||
|
||||
@ -395,11 +395,11 @@ public class MovingCheck extends Check {
|
||||
if(l.getWorld() != from.getWorld()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
final double x = from.getX();
|
||||
final double y = from.getY();
|
||||
final double z = from.getZ();
|
||||
|
||||
|
||||
// Player didn't move at all
|
||||
if(x == to.getX() && z == to.getZ() && y == to.getY() ) {
|
||||
return true;
|
||||
@ -408,7 +408,7 @@ public class MovingCheck extends Check {
|
||||
else if(!(x == l.getX() && z == l.getZ() && y == l.getY())){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -451,14 +451,14 @@ public class MovingCheck extends Check {
|
||||
* @param event
|
||||
*/
|
||||
public void teleported(PlayerTeleportEvent event) {
|
||||
|
||||
|
||||
MovingData data = MovingData.get(event.getPlayer());
|
||||
|
||||
|
||||
// We can enforce a teleport, if that flag is explicitly set
|
||||
if(event.isCancelled() && enforceTeleport && event.getTo().equals(data.teleportTo)) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
|
||||
if(!event.isCancelled()) {
|
||||
data.lastLocation = event.getTo();
|
||||
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;
|
||||
}
|
||||
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"
|
||||
@ -712,7 +694,7 @@ public class MovingCheck extends Check {
|
||||
allowFlying = config.getBooleanValue("moving.allowflying");
|
||||
allowFakeSneak = config.getBooleanValue("moving.allowfakesneak");
|
||||
allowFastSwim = config.getBooleanValue("moving.allowfastswim");
|
||||
|
||||
|
||||
waterElevators = config.getBooleanValue("moving.waterelevators");
|
||||
|
||||
logMessage = config.getStringValue("moving.logmessage").
|
||||
@ -721,7 +703,7 @@ public class MovingCheck extends Check {
|
||||
replace("[from]", "(%4$.1f, %5$.1f, %6$.1f)").
|
||||
replace("[to]", "(%7$.1f, %8$.1f, %9$.1f)").
|
||||
replace("[distance]", "(%10$.1f, %11$.1f, %12$.1f)");
|
||||
|
||||
|
||||
summaryMessage = config.getStringValue("moving.summarymessage").
|
||||
replace("[timeframe]", "%2$d").
|
||||
replace("[player]", "%1$s").
|
||||
@ -734,9 +716,9 @@ public class MovingCheck extends Check {
|
||||
actions[2] = config.getActionValue("moving.action.high");
|
||||
|
||||
setActive(config.getBooleanValue("active.moving"));
|
||||
|
||||
|
||||
enforceTeleport = config.getBooleanValue("moving.enforceteleport");
|
||||
|
||||
|
||||
} catch (ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
|
@ -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);
|
||||
}
|
||||
event.setTo(data.setBackPoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user