No NSH this time. New FastClick check!

This commit is contained in:
NeatMonster 2012-08-22 19:34:01 +02:00
parent 50e3d02e5d
commit a97bda6d7f
16 changed files with 329 additions and 644 deletions

View File

@ -1,618 +0,0 @@
package fr.neatmonster.nocheatplus;
import java.lang.reflect.Field;
import net.minecraft.server.AxisAlignedBB;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.NetServerHandler;
import net.minecraft.server.Packet;
import net.minecraft.server.Packet0KeepAlive;
import net.minecraft.server.Packet101CloseWindow;
import net.minecraft.server.Packet102WindowClick;
import net.minecraft.server.Packet106Transaction;
import net.minecraft.server.Packet107SetCreativeSlot;
import net.minecraft.server.Packet108ButtonClick;
import net.minecraft.server.Packet10Flying;
import net.minecraft.server.Packet130UpdateSign;
import net.minecraft.server.Packet13PlayerLookMove;
import net.minecraft.server.Packet14BlockDig;
import net.minecraft.server.Packet15Place;
import net.minecraft.server.Packet16BlockItemSwitch;
import net.minecraft.server.Packet18ArmAnimation;
import net.minecraft.server.Packet19EntityAction;
import net.minecraft.server.Packet202Abilities;
import net.minecraft.server.Packet203TabComplete;
import net.minecraft.server.Packet204LocaleAndViewDistance;
import net.minecraft.server.Packet205ClientCommand;
import net.minecraft.server.Packet250CustomPayload;
import net.minecraft.server.Packet255KickDisconnect;
import net.minecraft.server.Packet3Chat;
import net.minecraft.server.Packet7UseEntity;
import net.minecraft.server.Packet9Respawn;
import net.minecraft.server.WorldServer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
/*
* M"""""""`YM dP MP""""""`MM
* M mmmm. M 88 M mmmmm..M
* M MMMMM M .d8888b. d8888P M. `YM .d8888b. 88d888b. dP .dP .d8888b. 88d888b.
* M MMMMM M 88ooood8 88 MMMMMMM. M 88ooood8 88' `88 88 d8' 88ooood8 88' `88
* M MMMMM M 88. ... 88 M. .MMM' M 88. ... 88 88 .88' 88. ... 88
* M MMMMM M `88888P' dP Mb. .dM `88888P' dP 8888P' `88888P' dP
* MMMMMMMMMMM MMMMMMMMMMM
*
* M""MMMMM""MM dP dP MM"""""""`YM
* M MMMMM MM 88 88 MM mmmmm M
* M `M .d8888b. 88d888b. .d888b88 88 .d8888b. 88d888b. M' .M 88d888b. .d8888b. dP. .dP dP dP
* M MMMMM MM 88' `88 88' `88 88' `88 88 88ooood8 88' `88 MM MMMMMMMM 88' `88 88' `88 `8bd8' 88 88
* M MMMMM MM 88. .88 88 88 88. .88 88 88. ... 88 MM MMMMMMMM 88 88. .88 .d88b. 88. .88
* M MMMMM MM `88888P8 dP dP `88888P8 dP `88888P' dP MM MMMMMMMM dP `88888P' dP' `dP `8888P88
* MMMMMMMMMMMM MMMMMMMMMMMM .88
* d8888P
*/
/**
* A proxy used to fix Bukkit preventing players from using fly mods.
*/
public class NetServerHandlerProxy extends NetServerHandler {
/** The default stance of a player. */
private static final double STANCE = 1.6200000047683716D;
private Field hField;
private final MinecraftServer minecraftServer;
private final NetServerHandler netServerHandler;
private double bukkitX = Double.MAX_VALUE;
private double bukkitY = Double.MAX_VALUE;
private double bukkitZ = Double.MAX_VALUE;
private float bukkitPitch = Float.MAX_VALUE;
private float bukkitYaw = Float.MAX_VALUE;
private boolean checkMovement;
private int flying;
private boolean justTeleported = false;
private double vanillaX;
private double vanillaY;
private double vanillaZ;
/**
* Instantiates a new net server handler proxy.
*
* @param minecraftServer
* the minecraft server
* @param netServerHandler
* the net server handler
*/
public NetServerHandlerProxy(final MinecraftServer minecraftServer, final NetServerHandler netServerHandler) {
super(minecraftServer, netServerHandler.networkManager, netServerHandler.player);
this.minecraftServer = minecraftServer;
this.netServerHandler = netServerHandler;
try {
hField = NetServerHandler.class.getDeclaredField("h");
hField.setAccessible(true);
} catch (final Exception e) {
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a()
*/
@Override
public boolean a() {
return netServerHandler.a();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(double, double, double, float, float)
*/
@Override
public void a(final double x, final double y, final double z, final float yaw, final float pitch) {
netServerHandler.a(x, y, z, yaw, pitch);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet0KeepAlive)
*/
@Override
public void a(final Packet0KeepAlive packet0keepalive) {
netServerHandler.a(packet0keepalive);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet102WindowClick)
*/
@Override
public void a(final Packet102WindowClick packet102windowclick) {
netServerHandler.a(packet102windowclick);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet106Transaction)
*/
@Override
public void a(final Packet106Transaction packet106transaction) {
netServerHandler.a(packet106transaction);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet107SetCreativeSlot)
*/
@Override
public void a(final Packet107SetCreativeSlot packet107setcreativeslot) {
netServerHandler.a(packet107setcreativeslot);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet108ButtonClick)
*/
@Override
public void a(final Packet108ButtonClick packet108buttonclick) {
netServerHandler.a(packet108buttonclick);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet10Flying)
*/
@Override
public void a(final Packet10Flying packet10flying) {
if (player.getBukkitEntity().hasPermission(Permissions.MOVING_OVERRIDEBUKKIT)) {
final WorldServer worldserver = minecraftServer.getWorldServer(player.dimension);
try {
hField.set(netServerHandler, true);
} catch (final Exception e) {
e.printStackTrace();
}
if (!player.viewingCredits) {
double d0;
if (!checkMovement) {
d0 = packet10flying.y - vanillaY;
if (packet10flying.x == vanillaX && d0 * d0 < 0.01D && packet10flying.z == vanillaZ)
checkMovement = true;
}
final Player bPlayer = getPlayer();
final Location from = new Location(bPlayer.getWorld(), bukkitX, bukkitY, bukkitZ, bukkitYaw,
bukkitPitch);
final Location to = bPlayer.getLocation().clone();
if (packet10flying.hasPos && (packet10flying.y != -999.0D || packet10flying.stance != -999.0D)) {
to.setX(packet10flying.x);
to.setY(packet10flying.y);
to.setZ(packet10flying.z);
}
if (packet10flying.hasLook) {
to.setYaw(packet10flying.yaw);
to.setPitch(packet10flying.pitch);
}
final double delta = Math.pow(bukkitX - to.getX(), 2) + Math.pow(bukkitY - to.getY(), 2)
+ Math.pow(bukkitZ - to.getZ(), 2);
final float deltaAngle = Math.abs(bukkitYaw - to.getYaw()) + Math.abs(bukkitPitch - to.getPitch());
if ((delta > 1f / 256 || deltaAngle > 10f) && checkMovement && !player.dead) {
bukkitX = to.getX();
bukkitY = to.getY();
bukkitZ = to.getZ();
bukkitYaw = to.getYaw();
bukkitPitch = to.getPitch();
if (from.getX() != Double.MAX_VALUE) {
final PlayerMoveEvent event = new PlayerMoveEvent(bPlayer, from, to);
minecraftServer.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
netServerHandler.sendPacket(new Packet13PlayerLookMove(from.getX(), from.getY() + STANCE,
from.getY(), from.getZ(), from.getYaw(), from.getPitch(), false));
return;
}
if (!to.equals(event.getTo()) && !event.isCancelled()) {
player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
return;
}
if (!from.equals(getPlayer().getLocation()) && justTeleported) {
justTeleported = false;
return;
}
}
}
if (Double.isNaN(packet10flying.x) || Double.isNaN(packet10flying.y) || Double.isNaN(packet10flying.z)
|| Double.isNaN(packet10flying.stance)) {
bPlayer.teleport(bPlayer.getWorld().getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
System.err.println(bPlayer.getName()
+ " was caught trying to crash the server with an invalid position.");
bPlayer.kickPlayer("Nope!");
return;
}
if (checkMovement && !player.dead) {
double d1;
double d2;
double d3;
double d4;
if (player.vehicle != null) {
float f = player.yaw;
float f1 = player.pitch;
player.vehicle.V();
d1 = player.locX;
d2 = player.locY;
d3 = player.locZ;
double d5 = 0.0D;
d4 = 0.0D;
if (packet10flying.hasLook) {
f = packet10flying.yaw;
f1 = packet10flying.pitch;
}
if (packet10flying.hasPos && packet10flying.y == -999.0D && packet10flying.stance == -999.0D) {
if (Math.abs(packet10flying.x) > 1 || Math.abs(packet10flying.z) > 1) {
System.err.println(bPlayer.getName()
+ " was caught trying to crash the server with an invalid position.");
bPlayer.kickPlayer("Nope!");
return;
}
d5 = packet10flying.x;
d4 = packet10flying.z;
}
player.onGround = packet10flying.g;
player.g();
player.move(d5, 0.0D, d4);
player.setLocation(d1, d2, d3, f, f1);
player.motX = d5;
player.motZ = d4;
if (player.vehicle != null)
worldserver.vehicleEnteredWorld(player.vehicle, true);
if (player.vehicle != null)
player.vehicle.V();
minecraftServer.getServerConfigurationManager().d(player);
vanillaX = player.locX;
vanillaY = player.locY;
vanillaZ = player.locZ;
worldserver.playerJoinedWorld(player);
return;
}
if (player.isSleeping()) {
player.g();
player.setLocation(vanillaX, vanillaY, vanillaZ, player.yaw, player.pitch);
worldserver.playerJoinedWorld(player);
return;
}
d0 = player.locY;
vanillaX = player.locX;
vanillaY = player.locY;
vanillaZ = player.locZ;
d1 = player.locX;
d2 = player.locY;
d3 = player.locZ;
float f2 = player.yaw;
float f3 = player.pitch;
if (packet10flying.hasPos && packet10flying.y == -999.0D && packet10flying.stance == -999.0D)
packet10flying.hasPos = false;
if (packet10flying.hasPos) {
d1 = packet10flying.x;
d2 = packet10flying.y;
d3 = packet10flying.z;
d4 = packet10flying.stance - packet10flying.y;
if (!player.isSleeping() && (d4 > 1.65D || d4 < 0.1D)) {
disconnect("Illegal stance");
logger.warning(player.name + " had an illegal stance: " + d4);
return;
}
if (Math.abs(packet10flying.x) > 3.2E7D || Math.abs(packet10flying.z) > 3.2E7D) {
disconnect("Illegal position");
return;
}
}
if (packet10flying.hasLook) {
f2 = packet10flying.yaw;
f3 = packet10flying.pitch;
}
player.g();
player.V = 0.0F;
player.setLocation(vanillaX, vanillaY, vanillaZ, f2, f3);
if (!checkMovement)
return;
d4 = d1 - player.locX;
double d6 = d2 - player.locY;
double d7 = d3 - player.locZ;
final float f4 = 0.0625F;
final boolean flag = worldserver.getCubes(player, player.boundingBox.clone().shrink(f4, f4, f4))
.isEmpty();
if (player.onGround && !packet10flying.g && d6 > 0.0D)
player.j(0.2F);
player.move(d4, d6, d7);
player.onGround = packet10flying.g;
player.checkMovement(d4, d6, d7);
final double d12 = d6;
d4 = d1 - player.locX;
d6 = d2 - player.locY;
if (d6 > -0.5D || d6 < 0.5D)
d6 = 0.0D;
d7 = d3 - player.locZ;
player.setLocation(d1, d2, d3, f2, f3);
final boolean flag2 = worldserver.getCubes(player, player.boundingBox.clone().shrink(f4, f4, f4))
.isEmpty();
if (flag && !flag2 && !player.isSleeping()) {
this.a(vanillaX, vanillaY, vanillaZ, f2, f3);
return;
}
final AxisAlignedBB axisalignedbb = player.boundingBox.clone().grow(f4, f4, f4)
.a(0.0D, -0.55D, 0.0D);
if (!minecraftServer.getAllowFlight() && !player.abilities.canFly && !worldserver.c(axisalignedbb)) {
if (d12 >= -0.03125D) {
flying++;
if (flying > 80) {
logger.warning(player.name + " was kicked for floating too long!");
disconnect("Flying is not enabled on this server");
return;
}
}
} else
flying = 0;
player.onGround = packet10flying.g;
minecraftServer.getServerConfigurationManager().d(player);
if (player.itemInWorldManager.isCreative())
return;
player.b(player.locY - d0, packet10flying.g);
}
}
} else
netServerHandler.a(packet10flying);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet130UpdateSign)
*/
@Override
public void a(final Packet130UpdateSign packet130updatesign) {
netServerHandler.a(packet130updatesign);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet14BlockDig)
*/
@Override
public void a(final Packet14BlockDig packet14blockdig) {
netServerHandler.a(packet14blockdig);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet15Place)
*/
@Override
public void a(final Packet15Place packet15place) {
netServerHandler.a(packet15place);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet16BlockItemSwitch)
*/
@Override
public void a(final Packet16BlockItemSwitch packet16blockitemswitch) {
netServerHandler.a(packet16blockitemswitch);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet18ArmAnimation)
*/
@Override
public void a(final Packet18ArmAnimation packet18armanimation) {
netServerHandler.a(packet18armanimation);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet19EntityAction)
*/
@Override
public void a(final Packet19EntityAction packet19entityaction) {
netServerHandler.a(packet19entityaction);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet202Abilities)
*/
@Override
public void a(final Packet202Abilities packet202abilities) {
netServerHandler.a(packet202abilities);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet203TabComplete)
*/
@Override
public void a(final Packet203TabComplete packet203tabcomplete) {
netServerHandler.a(packet203tabcomplete);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet204LocaleAndViewDistance)
*/
@Override
public void a(final Packet204LocaleAndViewDistance packet204localeandviewdistance) {
netServerHandler.a(packet204localeandviewdistance);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet205ClientCommand)
*/
@Override
public void a(final Packet205ClientCommand packet205clientcommand) {
netServerHandler.a(packet205clientcommand);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet250CustomPayload)
*/
@Override
public void a(final Packet250CustomPayload packet250custompayload) {
netServerHandler.a(packet250custompayload);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet255KickDisconnect)
*/
@Override
public void a(final Packet255KickDisconnect packet255kickdisconnect) {
netServerHandler.a(packet255kickdisconnect);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet3Chat)
*/
@Override
public void a(final Packet3Chat packet3chat) {
netServerHandler.a(packet3chat);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet7UseEntity)
*/
@Override
public void a(final Packet7UseEntity packet7useentity) {
netServerHandler.a(packet7useentity);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet9Respawn)
*/
@Override
public void a(final Packet9Respawn packet9respawn) {
netServerHandler.a(packet9respawn);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(java.lang.String, java.lang.Object[])
*/
@Override
public void a(final String s, final Object[] aobject) {
netServerHandler.a(s, aobject);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#b()
*/
@Override
public boolean b() {
return netServerHandler.b();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#chat(java.lang.String, boolean)
*/
@Override
public void chat(final String s, final boolean async) {
netServerHandler.chat(s, async);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#d()
*/
@Override
public void d() {
netServerHandler.d();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#disconnect(java.lang.String)
*/
@Override
public void disconnect(final String s) {
netServerHandler.disconnect(s);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#getPlayer()
*/
@Override
public CraftPlayer getPlayer() {
return netServerHandler.getPlayer();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#handleContainerClose(net.minecraft.server.Packet101CloseWindow)
*/
@Override
public void handleContainerClose(final Packet101CloseWindow packet101closewindow) {
netServerHandler.handleContainerClose(packet101closewindow);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#lowPriorityCount()
*/
@Override
public int lowPriorityCount() {
return netServerHandler.lowPriorityCount();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#onUnhandledPacket(net.minecraft.server.Packet)
*/
@Override
public void onUnhandledPacket(final Packet packet) {
netServerHandler.onUnhandledPacket(packet);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#sendPacket(net.minecraft.server.Packet)
*/
@Override
public void sendPacket(final Packet packet) {
netServerHandler.sendPacket(packet);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#teleport(org.bukkit.Location)
*/
@Override
public void teleport(final Location destination) {
if (player.getBukkitEntity().hasPermission(Permissions.MOVING_OVERRIDEBUKKIT)) {
final double x = bukkitX = vanillaX = destination.getX();
final double y = bukkitY = vanillaY = destination.getY();
final double z = bukkitZ = vanillaZ = destination.getZ();
final float yaw = bukkitYaw = Float.isNaN(destination.getYaw()) ? 0f : destination.getYaw();
final float pitch = bukkitPitch = Float.isNaN(destination.getPitch()) ? 0f : destination.getPitch();
checkMovement = !(justTeleported = true);
player.setLocation(x, y, z, yaw, pitch);
netServerHandler.sendPacket(new Packet13PlayerLookMove(x, y + STANCE, y, z, yaw, pitch, false));
} else
netServerHandler.teleport(destination);
}
}

View File

@ -7,12 +7,8 @@ import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -38,6 +34,7 @@ import fr.neatmonster.nocheatplus.metrics.Metrics.Graph;
import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter;
import fr.neatmonster.nocheatplus.metrics.MetricsData;
import fr.neatmonster.nocheatplus.metrics.MetricsData.TicksPlotter;
import fr.neatmonster.nocheatplus.packets.PacketsWorkaround;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
@ -74,6 +71,9 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
// Stop the lag measuring task.
LagMeasureTask.cancel();
// Disable the packets workaround.
PacketsWorkaround.disable();
// Cleanup the configuration manager.
ConfigManager.cleanup();
@ -102,6 +102,10 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
listeners.add(new MovingListener());
listeners.add(new Workarounds());
// Enable the packets workaround.
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_NOMOVEDTOOQUICKLY))
PacketsWorkaround.enable();
// Set up a task to monitor server lag.
LagMeasureTask.start(this);
@ -205,14 +209,6 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
public void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
// Set the NetServerHandler proxy if enabled in the configuration.
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_FIXMOVEDTOOQUICKLY)) {
final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final NetServerHandlerProxy proxy = new NetServerHandlerProxy(MinecraftServer.getServer(),
entityPlayer.netServerHandler);
entityPlayer.netServerHandler = proxy;
}
// Send a message to the player if a new update is available.
if (updateAvailable && player.hasPermission(Permissions.ADMINISTRATION_NOTIFY))
player.sendMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE

View File

@ -68,6 +68,7 @@ public enum CheckType {
INVENTORY(InventoryConfig.factory, InventoryData.factory),
INVENTORY_DROP(INVENTORY, Permissions.INVENTORY_DROP),
INVENTORY_FASTCLICK(INVENTORY, Permissions.INVENTORY_FASTCLICK),
INVENTORY_INSTANTBOW(INVENTORY, Permissions.INVENTORY_INSTANTBOW),
INVENTORY_INSTANTEAT(INVENTORY, Permissions.INVENTORY_INSTANTEAT),

View File

@ -3,6 +3,7 @@ package fr.neatmonster.nocheatplus.checks.fight;
import net.minecraft.server.Entity;
import org.bukkit.GameMode;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.Check;
@ -60,10 +61,14 @@ public class Reach extends Check {
// Distance is calculated from eye location to center of targeted. If the player is further away from his target
// than allowed, the difference will be assigned to "distance".
final double distance = CheckUtils.distance(player.getEyeLocation(), damaged.getBukkitEntity().getLocation()
.add(0D, damaged.getHeadHeight(), 0D))
double distance = CheckUtils.distance(player.getEyeLocation(),
damaged.getBukkitEntity().getLocation().add(0D, damaged.getHeadHeight(), 0D))
- distanceLimit;
// Handle the EnderDragon differently.
if (damaged.getBukkitEntity() instanceof EnderDragon)
distance -= 6.5D;
if (distance > 0) {
// He failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
if (!LagMeasureTask.skipCheck())

View File

@ -0,0 +1,72 @@
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.metrics.MetricsData;
/*
* MM""""""""`M dP MM'""""'YMM dP oo dP
* MM mmmmmmmM 88 M' .mmm. `M 88 88
* M' MMMM .d8888b. .d8888b. d8888P M MMMMMooM 88 dP .d8888b. 88 .dP
* MM MMMMMMMM 88' `88 Y8ooooo. 88 M MMMMMMMM 88 88 88' `"" 88888"
* MM MMMMMMMM 88. .88 88 88 M. `MMM' .M 88 88 88. ... 88 `8b.
* MM MMMMMMMM `88888P8 `88888P' dP MM. .dM dP dP `88888P' dP `YP
* MMMMMMMMMMMM MMMMMMMMMMM
*/
/**
* The FastClick check will prevents players from taking automatically all items from any inventory (chests, etc.).
*/
public class FastClick extends Check {
/**
* Instantiates a new fast click check.
*/
public FastClick() {
super(CheckType.INVENTORY_FASTCLICK);
}
/**
* Checks a player.
*
* @param player
* the player
* @return true, if successful
*/
public boolean check(final Player player) {
// Metrics data.
MetricsData.addChecked(type);
final InventoryData data = InventoryData.getData(player);
boolean cancel = false;
// If the last inventory click has been made within 45 milliseconds.
if (System.currentTimeMillis() - data.fastClickLastTime < 45L) {
if (data.fastClickLastCancelled) {
// Calculate the difference between the limit and the time elapsed.
final double difference = 45L - System.currentTimeMillis() + data.fastClickLastTime;
// Increment the violation level.
data.fastClickVL += difference;
// Find out if we need to cancel the event.
cancel = executeActions(player, data.fastClickVL, difference,
InventoryConfig.getConfig(player).fastClickActions);
} else
data.fastClickLastCancelled = true;
} else {
data.fastClickLastCancelled = false;
// Reduce the violation level.
data.fastClickVL *= 0.98D;
}
// Remember the current time.s
data.fastClickLastTime = System.currentTimeMillis();
return cancel;
}
}

View File

@ -76,6 +76,9 @@ public class InventoryConfig implements CheckConfig {
public final long dropTimeFrame;
public final ActionList dropActions;
public final boolean fastClickCheck;
public final ActionList fastClickActions;
public final boolean instantBowCheck;
public final ActionList instantBowActions;
@ -94,6 +97,9 @@ public class InventoryConfig implements CheckConfig {
dropTimeFrame = data.getLong(ConfPaths.INVENTORY_DROP_TIMEFRAME);
dropActions = data.getActionList(ConfPaths.INVENTORY_DROP_ACTIONS, Permissions.INVENTORY_DROP);
fastClickCheck = data.getBoolean(ConfPaths.INVENTORY_FASTCLICK_CHECK);
fastClickActions = data.getActionList(ConfPaths.INVENTORY_FASTCLICK_ACTIONS, Permissions.INVENTORY_FASTCLICK);
instantBowCheck = data.getBoolean(ConfPaths.INVENTORY_INSTANTBOW_CHECK);
instantBowActions = data
.getActionList(ConfPaths.INVENTORY_INSTANTBOW_ACTIONS, Permissions.INVENTORY_INSTANTBOW);
@ -111,6 +117,8 @@ public class InventoryConfig implements CheckConfig {
switch (checkType) {
case INVENTORY_DROP:
return dropCheck;
case INVENTORY_FASTCLICK:
return fastClickCheck;
case INVENTORY_INSTANTBOW:
return instantBowCheck;
case INVENTORY_INSTANTEAT:

View File

@ -50,6 +50,7 @@ public class InventoryData implements CheckData {
// Violation levels.
public double dropVL;
public double fastClickVL;
public double instantBowVL;
public double instantEatVL;
@ -57,6 +58,10 @@ public class InventoryData implements CheckData {
public int dropCount;
public long dropLastTime;
// Data of the fast click check.
public boolean fastClickLastCancelled;
public long fastClickLastTime;
// Data of the instant bow check.
public long instantBowLastTime;

View File

@ -8,6 +8,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -40,6 +41,9 @@ public class InventoryListener implements Listener {
/** The drop check. */
private final Drop drop = new Drop();
/** The fast click check. */
private final FastClick fastClick = new FastClick();
/** The instant bow check. */
private final InstantBow instantBow = new InstantBow();
@ -100,6 +104,31 @@ public class InventoryListener implements Listener {
}
}
/**
* We listen to InventoryClick events for the FastClick check.
*
* @param event
* the event
*/
@EventHandler(
ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onInventoryClick(final InventoryClickEvent event) {
/*
* ___ _ ____ _ _ _
* |_ _|_ ____ _____ _ __ | |_ ___ _ __ _ _ / ___| (_) ___| | __
* | || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | | | | | |/ __| |/ /
* | || | | \ V / __/ | | | || (_) | | | |_| | | |___| | | (__| <
* |___|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | \____|_|_|\___|_|\_\
* |___/
*/
if (event.getWhoClicked() instanceof Player) {
final Player player = (Player) event.getWhoClicked();
if (fastClick.isEnabled(player) && fastClick.check(player))
// The check requested the event to be cancelled.
event.setCancelled(true);
}
}
/**
* We listen to DropItem events for the Drop check.
*
@ -134,7 +163,7 @@ public class InventoryListener implements Listener {
* the event
*/
@EventHandler(
priority = EventPriority.LOWEST)
ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInteractEvent(final PlayerInteractEvent event) {
/*
* ____ _ ___ _ _

View File

@ -267,7 +267,7 @@ public class MovingListener implements Listener {
* the event
*/
@EventHandler(
ignoreCancelled = true, priority = EventPriority.MONITOR)
priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event) {
/*
* ____ _ _ _
@ -307,10 +307,9 @@ public class MovingListener implements Listener {
*/
final Player player = event.getPlayer();
// Don't care for movements that are very high distance, to another world (such that it is very likely the event
// data was modified by another plugin before we got it) or if the player is inside a vehicle.
if (!event.getFrom().getWorld().equals(event.getTo().getWorld())
|| event.getFrom().distanceSquared(event.getTo()) > 400D || player.isInsideVehicle())
// Don't care for movements to another world (such that it is very likely the event data was modified by another
// plugin before we got it) or if the player is inside a vehicle.
if (!event.getFrom().getWorld().equals(event.getTo().getWorld()) || player.isInsideVehicle())
return;
final MovingData data = MovingData.getData(player);
@ -424,7 +423,7 @@ public class MovingListener implements Listener {
* the event
*/
@EventHandler(
priority = EventPriority.HIGHEST)
ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
/*
* ____ _ _____ _ _
@ -506,8 +505,7 @@ public class MovingListener implements Listener {
// Don't care if a player isn't inside the vehicle, for movements that are very high distance or to another
// world (such that it is very likely the event data was modified by another plugin before we got it).
if (event.getVehicle().getPassenger() == null || !(event.getVehicle().getPassenger() instanceof Player)
|| !event.getFrom().getWorld().equals(event.getTo().getWorld())
|| event.getFrom().distanceSquared(event.getTo()) > 400D)
|| !event.getFrom().getWorld().equals(event.getTo().getWorld()))
return;
final Player player = (Player) event.getVehicle().getPassenger();

View File

@ -196,7 +196,8 @@ public class SurvivalFly extends Check {
double vDistanceAboveLimit = to.getY() - data.setBack.getY() - vAllowedDistance;
// Step can also be blocked.
if (vDistanceAboveLimit <= 0D && from.isOnGround() && to.isOnGround() && to.getY() - from.getY() == 1D)
if (from.isOnGround() && to.isOnGround() && to.getY() - from.getY() == 1D && vDistanceAboveLimit <= 0D
&& !player.hasPermission(Permissions.MOVING_SURVIVALFLY_STEP))
vDistanceAboveLimit = 1D;
if (from.isOnGround() || to.isOnGround())

View File

@ -40,7 +40,7 @@ public abstract class ConfPaths {
*/
private static final String MISCELLANEOUS = "miscellaneous.";
public static final String MISCELLANEOUS_ALLOWCLIENTMODS = MISCELLANEOUS + "allowclientmods";
public static final String MISCELLANEOUS_FIXMOVEDTOOQUICKLY = MISCELLANEOUS + "fixmovedtooquickly";
public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY = MISCELLANEOUS + "nomovedtooquickly";
public static final String MISCELLANEOUS_OPINCONSOLEONLY = MISCELLANEOUS + "opinconsoleonly";
public static final String MISCELLANEOUS_PROTECTPLUGINS = MISCELLANEOUS + "protectplugins";
@ -274,6 +274,10 @@ public abstract class ConfPaths {
public static final String INVENTORY_DROP_TIMEFRAME = INVENTORY_DROP + "timeframe";
public static final String INVENTORY_DROP_ACTIONS = INVENTORY_DROP + "actions";
private static final String INVENTORY_FASTCLICK = INVENTORY + "fastclick.";
public static final String INVENTORY_FASTCLICK_CHECK = INVENTORY_FASTCLICK + "active";
public static final String INVENTORY_FASTCLICK_ACTIONS = INVENTORY_FASTCLICK + "actions";
private static final String INVENTORY_INSTANTBOW = INVENTORY + "instantbow.";
public static final String INVENTORY_INSTANTBOW_CHECK = INVENTORY_INSTANTBOW + "active";
public static final String INVENTORY_INSTANTBOW_ACTIONS = INVENTORY_INSTANTBOW + "actions";

View File

@ -48,7 +48,7 @@ public class DefaultConfig extends ConfigFile {
* d888b Y8b Y8b 888 d,dP "88,e8' "YeeP" 888 888 "88 888 888 888 "YeeP" "88 88" "88 88" d,dP
*/
set(ConfPaths.MISCELLANEOUS_ALLOWCLIENTMODS, false);
set(ConfPaths.MISCELLANEOUS_FIXMOVEDTOOQUICKLY, false);
set(ConfPaths.MISCELLANEOUS_NOMOVEDTOOQUICKLY, false);
set(ConfPaths.MISCELLANEOUS_OPINCONSOLEONLY, false);
set(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS, true);
@ -239,6 +239,9 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.INVENTORY_DROP_TIMEFRAME, 20L);
set(ConfPaths.INVENTORY_DROP_ACTIONS, "log:drop:0:1:cif cmd:kick");
set(ConfPaths.INVENTORY_FASTCLICK_CHECK, true);
set(ConfPaths.INVENTORY_FASTCLICK_ACTIONS, "cancel"); // TODO
set(ConfPaths.INVENTORY_INSTANTBOW_CHECK, true);
set(ConfPaths.INVENTORY_INSTANTBOW_ACTIONS, "log:instantbow:2:5:if cancel");

View File

@ -0,0 +1,49 @@
package fr.neatmonster.nocheatplus.packets;
import net.minecraft.server.NetHandler;
import net.minecraft.server.NetServerHandler;
import net.minecraft.server.Packet11PlayerPosition;
/*
* M"""""""`YM MM'""""'YMM MM"""""""`YM MM"""""""`YM dP dP d88 d88
* M mmmm. M M' .mmm. `M MM mmmmm M MM mmmmm M 88 88 88 88
* M MMMMM M M MMMMMooM M' .M M' .M .d8888b. .d8888b. 88 .dP .d8888b. d8888P 88 88
* M MMMMM M M MMMMMMMM MM MMMMMMMM MM MMMMMMMM 88' `88 88' `"" 88888" 88ooood8 88 88 88
* M MMMMM M M. `MMM' .M MM MMMMMMMM MM MMMMMMMM 88. .88 88. ... 88 `8b. 88. ... 88 88 88
* M MMMMM M MM. .dM MM MMMMMMMM MM MMMMMMMM `88888P8 `88888P' dP `YP `88888P' dP d88P d88P
* MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMM
*
* MM"""""""`YM dP MM"""""""`YM oo dP oo
* MM mmmmm M 88 MM mmmmm M 88
* M' .M 88 .d8888b. dP dP .d8888b. 88d888b. M' .M .d8888b. .d8888b. dP d8888P dP .d8888b. 88d888b.
* MM MMMMMMMM 88 88' `88 88 88 88ooood8 88' `88 MM MMMMMMMM 88' `88 Y8ooooo. 88 88 88 88' `88 88' `88
* MM MMMMMMMM 88 88. .88 88. .88 88. ... 88 MM MMMMMMMM 88. .88 88 88 88 88 88. .88 88 88
* MM MMMMMMMM dP `88888P8 `8888P88 `88888P' dP MM MMMMMMMM `88888P' `88888P' dP dP dP `88888P' dP dP
* MMMMMMMMMMMM .88 MMMMMMMMMMMM
* d8888P
*/
/**
* A custom PlayerPosition packet.
*/
public class NCPPacket11PlayerPosition extends Packet11PlayerPosition {
/* (non-Javadoc)
* @see net.minecraft.server.Packet10Flying#handle(net.minecraft.server.NetHandler)
*/
@Override
public void handle(final NetHandler netHandler) {
if (netHandler instanceof NetServerHandler && hasPos) {
final NetServerHandler nsh = (NetServerHandler) netHandler;
final double deltaX = Math.max(Math.abs(x - nsh.player.locX), Math.abs(nsh.player.motX));
final double deltaY = Math.max(Math.abs(y - nsh.player.locY), Math.abs(nsh.player.motY));
final double deltaZ = Math.max(Math.abs(z - nsh.player.locZ), Math.abs(nsh.player.motZ));
final double delta = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
if (delta > 100D) {
nsh.player.locX = x;
nsh.player.locY = y;
nsh.player.locZ = z;
}
}
super.handle(netHandler);
}
}

View File

@ -0,0 +1,57 @@
package fr.neatmonster.nocheatplus.packets;
import net.minecraft.server.NetHandler;
import net.minecraft.server.NetServerHandler;
import net.minecraft.server.Packet13PlayerLookMove;
/*
* M"""""""`YM MM'""""'YMM MM"""""""`YM MM"""""""`YM dP dP d88 d8888b.
* M mmmm. M M' .mmm. `M MM mmmmm M MM mmmmm M 88 88 88 `88
* M MMMMM M M MMMMMooM M' .M M' .M .d8888b. .d8888b. 88 .dP .d8888b. d8888P 88 aaad8'
* M MMMMM M M MMMMMMMM MM MMMMMMMM MM MMMMMMMM 88' `88 88' `"" 88888" 88ooood8 88 88 `88
* M MMMMM M M. `MMM' .M MM MMMMMMMM MM MMMMMMMM 88. .88 88. ... 88 `8b. 88. ... 88 88 .88
* M MMMMM M MM. .dM MM MMMMMMMM MM MMMMMMMM `88888P8 `88888P' dP `YP `88888P' dP d88P d88888P
* MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMM
*
* MM"""""""`YM dP M""MMMMMMMM dP
* MM mmmmm M 88 M MMMMMMMM 88
* M' .M 88 .d8888b. dP dP .d8888b. 88d888b. M MMMMMMMM .d8888b. .d8888b. 88 .dP
* MM MMMMMMMM 88 88' `88 88 88 88ooood8 88' `88 M MMMMMMMM 88' `88 88' `88 88888"
* MM MMMMMMMM 88 88. .88 88. .88 88. ... 88 M MMMMMMMM 88. .88 88. .88 88 `8b.
* MM MMMMMMMM dP `88888P8 `8888P88 `88888P' dP M M `88888P' `88888P' dP `YP
* MMMMMMMMMMMM .88 MMMMMMMMMMM
* d8888P
*
* M"""""`'"""`YM
* M mm. mm. M
* M MMM MMM M .d8888b. dP .dP .d8888b.
* M MMM MMM M 88' `88 88 d8' 88ooood8
* M MMM MMM M 88. .88 88 .88' 88. ...
* M MMM MMM M `88888P' 8888P' `88888P'
* MMMMMMMMMMMMMM
*/
/**
* A custom PlayerLookMove packet.
*/
public class NCPPacket13PlayerLookMove extends Packet13PlayerLookMove {
/* (non-Javadoc)
* @see net.minecraft.server.Packet10Flying#handle(net.minecraft.server.NetHandler)
*/
@Override
public void handle(final NetHandler netHandler) {
if (netHandler instanceof NetServerHandler && hasPos) {
final NetServerHandler nsh = (NetServerHandler) netHandler;
final double deltaX = Math.max(Math.abs(x - nsh.player.motX), Math.abs(nsh.player.motX));
final double deltaY = Math.max(Math.abs(y - nsh.player.motY), Math.abs(nsh.player.motY));
final double deltaZ = Math.max(Math.abs(z - nsh.player.motZ), Math.abs(nsh.player.motZ));
final double delta = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
if (delta > 100D) {
nsh.player.locX = x;
nsh.player.locY = y;
nsh.player.locZ = z;
}
}
super.handle(netHandler);
}
}

View File

@ -0,0 +1,73 @@
package fr.neatmonster.nocheatplus.packets;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.server.Packet;
/*
* MM"""""""`YM dP dP
* MM mmmmm M 88 88
* M' .M .d8888b. .d8888b. 88 .dP .d8888b. d8888P .d8888b.
* MM MMMMMMMM 88' `88 88' `"" 88888" 88ooood8 88 Y8ooooo.
* MM MMMMMMMM 88. .88 88. ... 88 `8b. 88. ... 88 88
* MM MMMMMMMM `88888P8 `88888P' dP `YP `88888P' dP `88888P'
* MMMMMMMMMMMM
*
* M""MMM""MMM""M dP dP
* M MMM MMM M 88 88
* M MMP MMP M .d8888b. 88d888b. 88 .dP .d8888b. 88d888b. .d8888b. dP dP 88d888b. .d888b88
* M MM' MM' .M 88' `88 88' `88 88888" 88' `88 88' `88 88' `88 88 88 88' `88 88' `88
* M `' . '' .MM 88. .88 88 88 `8b. 88. .88 88 88. .88 88. .88 88 88 88. .88
* M .d .dMMM `88888P' dP dP `YP `88888P8 dP `88888P' `88888P' dP dP `88888P8
* MMMMMMMMMMMMMM
*/
/**
* The packets workaround.
*/
public class PacketsWorkaround {
/** The old classes. */
private static Map<Integer, Class<?>> oldClasses = new HashMap<Integer, Class<?>>();
/**
* Disable the packets workaround.
*/
public static void disable() {
for (final int packetId : oldClasses.keySet())
replace(packetId, oldClasses.get(packetId));
}
/**
* Enable the packets workaround.
*/
public static void enable() {
oldClasses.put(11, replace(11, NCPPacket11PlayerPosition.class));
oldClasses.put(13, replace(13, NCPPacket13PlayerLookMove.class));
}
/**
* Replace a packet class.
*
* @param packetId
* the packet id
* @param newClass
* the new class
* @return the class
*/
@SuppressWarnings({"rawtypes", "unchecked"})
private static Class<?> replace(final int packetId, final Class<?> newClass) {
final Class<?> oldClass = (Class<?>) Packet.l.d(packetId);
Packet.l.a(packetId, newClass);
try {
final Field aField = Packet.class.getDeclaredField("a");
aField.setAccessible(true);
final Map a = (Map) aField.get(null);
a.put(newClass, packetId);
} catch (final Exception e) {
e.printStackTrace();
}
return oldClass;
}
}

View File

@ -110,6 +110,7 @@ public class Permissions {
*/
private static final String INVENTORY = CHECKS + ".inventory";
public static final String INVENTORY_DROP = INVENTORY + ".drop";
public static final String INVENTORY_FASTCLICK = INVENTORY + ".fastclick";
public static final String INVENTORY_INSTANTBOW = INVENTORY + ".instantbow";
public static final String INVENTORY_INSTANTEAT = INVENTORY + ".instanteat";
@ -133,6 +134,7 @@ public class Permissions {
public static final String MOVING_SURVIVALFLY_BLOCKING = MOVING_SURVIVALFLY + ".blocking";
public static final String MOVING_SURVIVALFLY_SNEAKING = MOVING_SURVIVALFLY + ".sneaking";
public static final String MOVING_SURVIVALFLY_SPRINTING = MOVING_SURVIVALFLY + ".sprinting";
public static final String MOVING_SURVIVALFLY_STEP = MOVING_SURVIVALFLY + ".step";
/*
* e e 888 ,e, dP,e, ,e, d8 ,e,