NetServerHandler improved. Metrics can now be fully disabled.

Permission for viewing plugins and versions (re-)added.
This commit is contained in:
NeatMonster 2012-08-24 14:52:24 +02:00
parent a97bda6d7f
commit f662f98369
12 changed files with 1043 additions and 440 deletions

View File

@ -114,8 +114,6 @@ permissions:
description: Allow the player to bypass the MorePacketsVehicle check. description: Allow the player to bypass the MorePacketsVehicle check.
nocheatplus.checks.moving.nofall: nocheatplus.checks.moving.nofall:
description: Allow the player to bypass the NoFall check. description: Allow the player to bypass the NoFall check.
nocheatplus.checks.moving.overridebukkit:
description: Allow the overriding of Bukkit to prevent it from blocking fly mods.
nocheatplus.checks.moving.survivalfly: nocheatplus.checks.moving.survivalfly:
description: Allow the player to bypass the SurvivalFly check. description: Allow the player to bypass the SurvivalFly check.
children: children:
@ -125,6 +123,8 @@ permissions:
description: Allow the player to move without speed limits while sneaking. description: Allow the player to move without speed limits while sneaking.
nocheatplus.checks.moving.survivalfly.sprinting: nocheatplus.checks.moving.survivalfly.sprinting:
description: Allow the player to sprint backwards. description: Allow the player to sprint backwards.
nocheatplus.checks.moving.survivalfly.step:
description: Allow the player to use the 'step' functionality of his client.
nocheatplus.mods: nocheatplus.mods:
description: Allow the player to use all the client mods. description: Allow the player to use all the client mods.
children: children:

View File

@ -158,6 +158,13 @@ public class CommandHandler implements CommandExecutor {
@Override @Override
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel,
final String[] args) { final String[] args) {
/*
* ____ _
* / ___|___ _ __ ___ _ __ ___ __ _ _ __ __| |
* | | / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |
* | |__| (_) | | | | | | | | | | | (_| | | | | (_| |
* \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|
*/
// Not our command, how did it get here? // Not our command, how did it get here?
if (!command.getName().equalsIgnoreCase("nocheatplus")) if (!command.getName().equalsIgnoreCase("nocheatplus"))
return false; return false;

View File

@ -0,0 +1,733 @@
package fr.neatmonster.nocheatplus;
import java.lang.reflect.Field;
import java.util.List;
import net.minecraft.server.AxisAlignedBB;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.INetworkManager;
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.ServerConnection;
import net.minecraft.server.WorldServer;
import org.bukkit.Bukkit;
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;
/*
* M"""""""`YM MM'""""'YMM MM"""""""`YM M"""""""`YM dP MP""""""`MM
* M mmmm. M M' .mmm. `M MM mmmmm M M mmmm. M 88 M mmmmm..M
* M MMMMM M M MMMMMooM M' .M M MMMMM M .d8888b. d8888P M. `YM .d8888b. 88d888b. dP .dP .d8888b. 88d888b.
* M MMMMM M M MMMMMMMM MM MMMMMMMM M MMMMM M 88ooood8 88 MMMMMMM. M 88ooood8 88' `88 88 d8' 88ooood8 88' `88
* M MMMMM M M. `MMM' .M MM MMMMMMMM M MMMMM M 88. ... 88 M. .MMM' M 88. ... 88 88 .88' 88. ... 88
* M MMMMM M MM. .dM MM MMMMMMMM M MMMMM M `88888P' dP Mb. .dM `88888P' dP 8888P' `88888P' dP
* MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMM
*
* M""MMMMM""MM dP dP
* M MMMMM MM 88 88
* M `M .d8888b. 88d888b. .d888b88 88 .d8888b. 88d888b.
* M MMMMM MM 88' `88 88' `88 88' `88 88 88ooood8 88' `88
* M MMMMM MM 88. .88 88 88 88. .88 88 88. ... 88
* M MMMMM MM `88888P8 dP dP `88888P8 dP `88888P' dP
* MMMMMMMMMMMM
*/
/**
* A custom NetServerHandler used as a workaround to prevent CraftBukkit from blocking fly mods.
*/
public class NCPNetServerHandler extends NetServerHandler {
/** The default stance of a player. */
private static final double STANCE = 1.6200000047683716D;
/**
* Sets the NetServerHandler of the player.
*
* @param player
* the player
* @param useProxy
* the use proxy
*/
public static void changeNetServerHandler(final Player player, final boolean useProxy) {
final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final NetServerHandler vanillaNSH = entityPlayer.netServerHandler;
final NCPNetServerHandler customNSH = new NCPNetServerHandler(MinecraftServer.getServer(),
vanillaNSH.networkManager, entityPlayer, useProxy ? vanillaNSH : null);
customNSH.a(entityPlayer.locX, entityPlayer.locY, entityPlayer.locZ, entityPlayer.yaw, entityPlayer.pitch);
MinecraftServer.getServer().ac().a(customNSH);
try {
final Field connectionsField = ServerConnection.class.getDeclaredField("d");
connectionsField.setAccessible(true);
((List<?>) connectionsField.get(MinecraftServer.getServer().ac())).remove(vanillaNSH);
} catch (final Exception e) {
e.printStackTrace();
}
vanillaNSH.disconnected = !useProxy;
}
private Field hField = null;
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 flyingPackets;
private boolean justTeleported = false;
private double vanillaX;
private double vanillaY;
private double vanillaZ;
/**
* Instantiates a new nCP net server handler.
*
* @param minecraftServer
* the minecraft server
* @param networkManager
* the network manager
* @param entityPlayer
* the entity player
* @param netServerHandler
* the net server handler
*/
public NCPNetServerHandler(final MinecraftServer minecraftServer, final INetworkManager networkManager,
final EntityPlayer entityPlayer, final NetServerHandler netServerHandler) {
super(minecraftServer, networkManager, entityPlayer);
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() {
if (netServerHandler != null)
return netServerHandler.a();
return super.a();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(double, double, double, float, float)
*/
@Override
public void a(final double d0, final double d1, final double d2, final float f, final float f1) {
if (netServerHandler != null)
netServerHandler.a(d0, d1, d2, f, f1);
else
super.a(d0, d1, d2, f, f1);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet0KeepAlive)
*/
@Override
public void a(final Packet0KeepAlive packet0KeepAlive) {
if (netServerHandler != null)
netServerHandler.a(packet0KeepAlive);
else
super.a(packet0KeepAlive);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet102WindowClick)
*/
@Override
public void a(final Packet102WindowClick packet102WindowClick) {
if (netServerHandler != null)
netServerHandler.a(packet102WindowClick);
else
super.a(packet102WindowClick);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet106Transaction)
*/
@Override
public void a(final Packet106Transaction packet106Transaction) {
if (netServerHandler != null)
netServerHandler.a(packet106Transaction);
else
super.a(packet106Transaction);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet107SetCreativeSlot)
*/
@Override
public void a(final Packet107SetCreativeSlot packet107SetCreativeSlot) {
if (netServerHandler != null)
netServerHandler.a(packet107SetCreativeSlot);
else
super.a(packet107SetCreativeSlot);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet108ButtonClick)
*/
@Override
public void a(final Packet108ButtonClick packet108ButtonClick) {
if (netServerHandler != null)
netServerHandler.a(packet108ButtonClick);
else
super.a(packet108ButtonClick);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet10Flying)
*/
@Override
public void a(final Packet10Flying packet10Flying) {
final WorldServer worldserver = MinecraftServer.getServer().getWorldServer(player.dimension);
try {
hField.set(netServerHandler == null ? this : 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);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
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.getServer().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.getServer().getAllowFlight() && !player.abilities.canFly
&& !worldserver.c(axisalignedbb)) {
if (d12 >= -0.03125D) {
flyingPackets++;
if (flyingPackets > 80) {
logger.warning(player.name + " was kicked for floating too long!");
disconnect("Flying is not enabled on this server");
return;
}
}
} else
flyingPackets = 0;
player.onGround = packet10Flying.g;
MinecraftServer.getServer().getServerConfigurationManager().d(player);
if (player.itemInWorldManager.isCreative())
return;
player.b(player.locY - d0, packet10Flying.g);
}
}
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet130UpdateSign)
*/
@Override
public void a(final Packet130UpdateSign packet130UpdateSign) {
if (netServerHandler != null)
netServerHandler.a(packet130UpdateSign);
else
super.a(packet130UpdateSign);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet14BlockDig)
*/
@Override
public void a(final Packet14BlockDig packet14BlockDig) {
if (netServerHandler != null)
netServerHandler.a(packet14BlockDig);
else
super.a(packet14BlockDig);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet15Place)
*/
@Override
public void a(final Packet15Place packet15Place) {
if (netServerHandler != null)
netServerHandler.a(packet15Place);
else
super.a(packet15Place);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet16BlockItemSwitch)
*/
@Override
public void a(final Packet16BlockItemSwitch packet16BlockItemSwitch) {
if (netServerHandler != null)
netServerHandler.a(packet16BlockItemSwitch);
else
super.a(packet16BlockItemSwitch);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet18ArmAnimation)
*/
@Override
public void a(final Packet18ArmAnimation packet18ArmAnimation) {
if (netServerHandler != null)
netServerHandler.a(packet18ArmAnimation);
else
super.a(packet18ArmAnimation);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet19EntityAction)
*/
@Override
public void a(final Packet19EntityAction packet19EntityAction) {
if (netServerHandler != null)
netServerHandler.a(packet19EntityAction);
else
super.a(packet19EntityAction);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet202Abilities)
*/
@Override
public void a(final Packet202Abilities packet202Abilities) {
if (netServerHandler != null)
netServerHandler.a(packet202Abilities);
else
super.a(packet202Abilities);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet203TabComplete)
*/
@Override
public void a(final Packet203TabComplete packet203TabComplete) {
if (netServerHandler != null)
netServerHandler.a(packet203TabComplete);
else
super.a(packet203TabComplete);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet204LocaleAndViewDistance)
*/
@Override
public void a(final Packet204LocaleAndViewDistance packet204LocaleAndViewDistance) {
if (netServerHandler != null)
netServerHandler.a(packet204LocaleAndViewDistance);
else
super.a(packet204LocaleAndViewDistance);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet205ClientCommand)
*/
@Override
public void a(final Packet205ClientCommand packet205ClientCommand) {
if (netServerHandler != null)
netServerHandler.a(packet205ClientCommand);
else
super.a(packet205ClientCommand);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet250CustomPayload)
*/
@Override
public void a(final Packet250CustomPayload packet250CustomPayload) {
if (netServerHandler != null)
netServerHandler.a(packet250CustomPayload);
else
super.a(packet250CustomPayload);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet255KickDisconnect)
*/
@Override
public void a(final Packet255KickDisconnect packet255KickDisconnect) {
if (netServerHandler != null)
netServerHandler.a(packet255KickDisconnect);
else
super.a(packet255KickDisconnect);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet3Chat)
*/
@Override
public void a(final Packet3Chat packet3Chat) {
if (netServerHandler != null)
netServerHandler.a(packet3Chat);
else
super.a(packet3Chat);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet7UseEntity)
*/
@Override
public void a(final Packet7UseEntity packet7UseEntity) {
if (netServerHandler != null)
netServerHandler.a(packet7UseEntity);
else
super.a(packet7UseEntity);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#a(net.minecraft.server.Packet9Respawn)
*/
@Override
public void a(final Packet9Respawn packet9Respawn) {
if (netServerHandler != null)
netServerHandler.a(packet9Respawn);
else
super.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) {
if (netServerHandler != null)
netServerHandler.a(s, aobject);
else
super.a(s, aobject);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#b()
*/
@Override
public boolean b() {
if (netServerHandler != null)
return netServerHandler.b();
return super.b();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#chat(java.lang.String, boolean)
*/
@Override
public void chat(final String s, final boolean async) {
if (netServerHandler != null)
netServerHandler.chat(s, async);
else
super.chat(s, async);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#d()
*/
@Override
public void d() {
if (netServerHandler != null)
netServerHandler.d();
else
super.d();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#disconnect(java.lang.String)
*/
@Override
public void disconnect(final String s) {
if (netServerHandler != null)
netServerHandler.disconnect(s);
else
super.disconnect(s);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#getPlayer()
*/
@Override
public CraftPlayer getPlayer() {
if (netServerHandler != null)
return netServerHandler.getPlayer();
return super.getPlayer();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#handleContainerClose(net.minecraft.server.Packet101CloseWindow)
*/
@Override
public void handleContainerClose(final Packet101CloseWindow packet101CloseWindow) {
if (netServerHandler != null)
netServerHandler.handleContainerClose(packet101CloseWindow);
else
super.handleContainerClose(packet101CloseWindow);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#lowPriorityCount()
*/
@Override
public int lowPriorityCount() {
if (netServerHandler != null)
return netServerHandler.lowPriorityCount();
return super.lowPriorityCount();
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#onUnhandledPacket(net.minecraft.server.Packet)
*/
@Override
public void onUnhandledPacket(final Packet packet) {
if (netServerHandler != null)
netServerHandler.onUnhandledPacket(packet);
else
super.onUnhandledPacket(packet);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#sendPacket(net.minecraft.server.Packet)
*/
@Override
public void sendPacket(final Packet packet) {
if (netServerHandler != null)
netServerHandler.sendPacket(packet);
else
super.sendPacket(packet);
}
/* (non-Javadoc)
* @see net.minecraft.server.NetServerHandler#teleport(org.bukkit.Location)
*/
@Override
public void teleport(final Location dest) {
final double x = bukkitX = vanillaX = dest.getX();
final double y = bukkitY = vanillaY = dest.getY();
final double z = bukkitZ = vanillaZ = dest.getZ();
final float yaw = bukkitYaw = Float.isNaN(dest.getYaw()) ? 0f : dest.getYaw();
final float pitch = bukkitPitch = Float.isNaN(dest.getPitch()) ? 0f : dest.getPitch();
checkMovement = !(justTeleported = true);
player.setLocation(x, y, z, yaw, pitch);
sendPacket(new Packet13PlayerLookMove(x, y + STANCE, y, z, yaw, pitch, false));
}
}

View File

@ -28,13 +28,13 @@ import fr.neatmonster.nocheatplus.checks.fight.FightListener;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener; import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
import fr.neatmonster.nocheatplus.checks.moving.MovingListener; import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.metrics.Metrics; import fr.neatmonster.nocheatplus.metrics.Metrics;
import fr.neatmonster.nocheatplus.metrics.Metrics.Graph; import fr.neatmonster.nocheatplus.metrics.Metrics.Graph;
import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter; import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter;
import fr.neatmonster.nocheatplus.metrics.MetricsData; import fr.neatmonster.nocheatplus.metrics.MetricsData;
import fr.neatmonster.nocheatplus.metrics.MetricsData.TicksPlotter; import fr.neatmonster.nocheatplus.metrics.MetricsData.TicksPlotter;
import fr.neatmonster.nocheatplus.packets.PacketsWorkaround;
import fr.neatmonster.nocheatplus.players.Permissions; import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask; import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
@ -66,14 +66,18 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
*/ */
@Override @Override
public void onDisable() { public void onDisable() {
/*
* ____ _ _ _
* | _ \(_)___ __ _| |__ | | ___
* | | | | / __|/ _` | '_ \| |/ _ \
* | |_| | \__ \ (_| | |_) | | __/
* |____/|_|___/\__,_|_.__/|_|\___|
*/
final PluginDescriptionFile pdfFile = getDescription(); final PluginDescriptionFile pdfFile = getDescription();
// Stop the lag measuring task. // Stop the lag measuring task.
LagMeasureTask.cancel(); LagMeasureTask.cancel();
// Disable the packets workaround.
PacketsWorkaround.disable();
// Cleanup the configuration manager. // Cleanup the configuration manager.
ConfigManager.cleanup(); ConfigManager.cleanup();
@ -89,6 +93,13 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
*/ */
@Override @Override
public void onEnable() { public void onEnable() {
/*
* _____ _ _
* | ____|_ __ __ _| |__ | | ___
* | _| | '_ \ / _` | '_ \| |/ _ \
* | |___| | | | (_| | |_) | | __/
* |_____|_| |_|\__,_|_.__/|_|\___|
*/
// Read the configuration files. // Read the configuration files.
ConfigManager.init(this); ConfigManager.init(this);
@ -102,10 +113,6 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
listeners.add(new MovingListener()); listeners.add(new MovingListener());
listeners.add(new Workarounds()); 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. // Set up a task to monitor server lag.
LagMeasureTask.start(this); LagMeasureTask.start(this);
@ -118,13 +125,14 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
getCommand("nocheatplus").setExecutor(new CommandHandler(this)); getCommand("nocheatplus").setExecutor(new CommandHandler(this));
// Setup the graphs, plotters and start Metrics. // Setup the graphs, plotters and start Metrics.
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_REPORTTOMETRICS))
try { try {
final Metrics metrics = new Metrics(this); final Metrics metrics = new Metrics(this);
final Graph eventsChecked = metrics.createGraph("Events Checked"); final Graph eventsChecked = metrics.createGraph("Events Checked");
final Graph checksFailed = metrics.createGraph("Checks Failed"); final Graph checksFailed = metrics.createGraph("Checks Failed");
final Graph violationLevels = metrics.createGraph("Violation Levels"); final Graph violationLevels = metrics.createGraph("Violation Levels");
for (final CheckType type : CheckType.values()) for (final CheckType type : CheckType.values())
if (type == CheckType.ALL || type.getParent() != null) { if (type.getParent() != null) {
eventsChecked.addPlotter(new Plotter(type.name()) { eventsChecked.addPlotter(new Plotter(type.name()) {
@Override @Override
@ -195,9 +203,32 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
@EventHandler( @EventHandler(
priority = EventPriority.LOWEST) priority = EventPriority.LOWEST)
final void onExecuteActions(final ExecuteActionsEvent event) { final void onExecuteActions(final ExecuteActionsEvent event) {
/*
* _____ _ _ _ _
* | ____|_ _____ ___ _ _| |_ ___ / \ ___| |_(_) ___ _ __ ___
* | _| \ \/ / _ \/ __| | | | __/ _ \ / _ \ / __| __| |/ _ \| '_ \/ __|
* | |___ > < __/ (__| |_| | || __/ / ___ \ (__| |_| | (_) | | | \__ \
* |_____/_/\_\___|\___|\__,_|\__\___| /_/ \_\___|\__|_|\___/|_| |_|___/
*/
event.executeActions(); event.executeActions();
} }
public void onPlayerJoinLow(final PlayerJoinEvent event) {
/*
* ____ _ _ _
* | _ \| | __ _ _ _ ___ _ __ | | ___ (_)_ __
* | |_) | |/ _` | | | |/ _ \ '__| _ | |/ _ \| | '_ \
* | __/| | (_| | |_| | __/ | | |_| | (_) | | | | |
* |_| |_|\__,_|\__, |\___|_| \___/ \___/|_|_| |_|
* |___/
*/
// Change the NetServerHandler of the player if requested in the configuration.
final ConfigFile configFile = ConfigManager.getConfigFile();
if (configFile.getBoolean(ConfPaths.MISCELLANEOUS_NOMOVEDTOOQUICKLY_ENABLED))
NCPNetServerHandler.changeNetServerHandler(event.getPlayer(),
configFile.getBoolean(ConfPaths.MISCELLANEOUS_NOMOVEDTOOQUICKLY_USEPROXY));
}
/** /**
* This event handler is used to send all the disabling messages to the client. * This event handler is used to send all the disabling messages to the client.
* *
@ -206,7 +237,15 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
*/ */
@EventHandler( @EventHandler(
priority = EventPriority.MONITOR) priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event) { public void onPlayerJoinMonitor(final PlayerJoinEvent event) {
/*
* ____ _ _ _
* | _ \| | __ _ _ _ ___ _ __ | | ___ (_)_ __
* | |_) | |/ _` | | | |/ _ \ '__| _ | |/ _ \| | '_ \
* | __/| | (_| | |_| | __/ | | |_| | (_) | | | | |
* |_| |_|\__,_|\__, |\___|_| \___/ \___/|_|_| |_|
* |___/
*/
final Player player = event.getPlayer(); final Player player = event.getPlayer();
// Send a message to the player if a new update is available. // Send a message to the player if a new update is available.

View File

@ -11,6 +11,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.utilities.CheckUtils; import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/* /*
@ -92,7 +93,7 @@ public class ChatListener implements Listener {
if (ChatConfig.getConfig(player).protectPlugins) if (ChatConfig.getConfig(player).protectPlugins)
if ((command.equalsIgnoreCase("plugins") || command.equalsIgnoreCase("pl") if ((command.equalsIgnoreCase("plugins") || command.equalsIgnoreCase("pl")
|| command.equalsIgnoreCase("version") || command.equalsIgnoreCase("ver")) || command.equalsIgnoreCase("version") || command.equalsIgnoreCase("ver"))
&& !player.isOp()) { && !player.hasPermission(Permissions.ADMINISTRATION_PLUGINS)) {
event.getPlayer().sendMessage( event.getPlayer().sendMessage(
ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. " ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. "
+ "Please contact the server administrators if you believe that this is in error."); + "Please contact the server administrators if you believe that this is in error.");

View File

@ -40,9 +40,13 @@ public abstract class ConfPaths {
*/ */
private static final String MISCELLANEOUS = "miscellaneous."; private static final String MISCELLANEOUS = "miscellaneous.";
public static final String MISCELLANEOUS_ALLOWCLIENTMODS = MISCELLANEOUS + "allowclientmods"; public static final String MISCELLANEOUS_ALLOWCLIENTMODS = MISCELLANEOUS + "allowclientmods";
public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY = MISCELLANEOUS + "nomovedtooquickly";
public static final String MISCELLANEOUS_OPINCONSOLEONLY = MISCELLANEOUS + "opinconsoleonly"; public static final String MISCELLANEOUS_OPINCONSOLEONLY = MISCELLANEOUS + "opinconsoleonly";
public static final String MISCELLANEOUS_PROTECTPLUGINS = MISCELLANEOUS + "protectplugins"; public static final String MISCELLANEOUS_PROTECTPLUGINS = MISCELLANEOUS + "protectplugins";
public static final String MISCELLANEOUS_REPORTTOMETRICS = MISCELLANEOUS + "reporttometrics";
private static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY = MISCELLANEOUS + "nomovedtooquickly.";
public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY_ENABLED = MISCELLANEOUS_NOMOVEDTOOQUICKLY + "enabled";
public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY_USEPROXY = MISCELLANEOUS_NOMOVEDTOOQUICKLY + "useproxy";
private static final String CHECKS = "checks."; private static final String CHECKS = "checks.";

View File

@ -48,9 +48,12 @@ 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 * 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_ALLOWCLIENTMODS, false);
set(ConfPaths.MISCELLANEOUS_NOMOVEDTOOQUICKLY, false);
set(ConfPaths.MISCELLANEOUS_OPINCONSOLEONLY, false); set(ConfPaths.MISCELLANEOUS_OPINCONSOLEONLY, false);
set(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS, true); set(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS, true);
set(ConfPaths.MISCELLANEOUS_REPORTTOMETRICS, true);
set(ConfPaths.MISCELLANEOUS_NOMOVEDTOOQUICKLY_ENABLED, false);
set(ConfPaths.MISCELLANEOUS_NOMOVEDTOOQUICKLY_USEPROXY, false);
/* /*
* 888 88b, 888 888 888 88b, 888 * 888 88b, 888 888 888 88b, 888

View File

@ -5,6 +5,8 @@ import java.util.Map;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter; import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter;
/* /*
@ -51,8 +53,8 @@ public class MetricsData {
} }
} }
/** The violation levels. */ /** Is Metrics enabled? */
private static final Map<CheckType, Double> violationLevels = new HashMap<CheckType, Double>(); private static boolean enabled;
/** The checks failed. */ /** The checks failed. */
private static final Map<CheckType, Integer> checksFailed = new HashMap<CheckType, Integer>(); private static final Map<CheckType, Integer> checksFailed = new HashMap<CheckType, Integer>();
@ -63,6 +65,9 @@ public class MetricsData {
/** The server ticks. */ /** The server ticks. */
private static final Map<Integer, Integer> serverTicks = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> serverTicks = new HashMap<Integer, Integer>();
/** The violation levels. */
private static final Map<CheckType, Double> violationLevels = new HashMap<CheckType, Double>();
/** /**
* Adds the checked. * Adds the checked.
* *
@ -70,7 +75,7 @@ public class MetricsData {
* the type * the type
*/ */
public static void addChecked(final CheckType type) { public static void addChecked(final CheckType type) {
if (type.getParent() != null) if (enabled && type.getParent() != null)
eventsChecked.put(type, getChecked(type) + 1); eventsChecked.put(type, getChecked(type) + 1);
} }
@ -81,6 +86,7 @@ public class MetricsData {
* the ticks * the ticks
*/ */
public static void addTicks(final int ticks) { public static void addTicks(final int ticks) {
if (enabled)
serverTicks.put(ticks, serverTicks.get(ticks) + 1); serverTicks.put(ticks, serverTicks.get(ticks) + 1);
} }
@ -92,7 +98,7 @@ public class MetricsData {
*/ */
public static void addViolation(final ViolationData violationData) { public static void addViolation(final ViolationData violationData) {
final CheckType type = violationData.check.getType(); final CheckType type = violationData.check.getType();
if (type.getParent() != null) { if (enabled && type.getParent() != null) {
checksFailed.put(type, getFailed(type) + 1); checksFailed.put(type, getFailed(type) + 1);
violationLevels.put(type, getViolationLevel(type) + violationData.addedVL); violationLevels.put(type, getViolationLevel(type) + violationData.addedVL);
} }
@ -106,12 +112,6 @@ public class MetricsData {
* @return the checked * @return the checked
*/ */
public static int getChecked(final CheckType type) { public static int getChecked(final CheckType type) {
if (type == CheckType.ALL) {
int eventsChecked = 0;
for (final double value : MetricsData.eventsChecked.values())
eventsChecked += value;
return eventsChecked;
}
if (!eventsChecked.containsKey(type)) if (!eventsChecked.containsKey(type))
resetChecked(type); resetChecked(type);
return eventsChecked.get(type); return eventsChecked.get(type);
@ -125,12 +125,6 @@ public class MetricsData {
* @return the failed * @return the failed
*/ */
public static int getFailed(final CheckType type) { public static int getFailed(final CheckType type) {
if (type == CheckType.ALL) {
int checkFails = 0;
for (final double value : checksFailed.values())
checkFails += value;
return checkFails;
}
if (!checksFailed.containsKey(type)) if (!checksFailed.containsKey(type))
resetFailed(type); resetFailed(type);
return checksFailed.get(type); return checksFailed.get(type);
@ -157,17 +151,18 @@ public class MetricsData {
* @return the violation level * @return the violation level
*/ */
public static double getViolationLevel(final CheckType type) { public static double getViolationLevel(final CheckType type) {
if (type == CheckType.ALL) {
double violationLevel = 0D;
for (final double value : violationLevels.values())
violationLevel += value;
return violationLevel;
}
if (!violationLevels.containsKey(type)) if (!violationLevels.containsKey(type))
resetViolationLevel(type); resetViolationLevel(type);
return violationLevels.get(type); return violationLevels.get(type);
} }
/**
* Initialize the class.
*/
public static void initialize() {
enabled = ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_REPORTTOMETRICS);
}
/** /**
* Reset checked. * Reset checked.
* *

View File

@ -1,49 +0,0 @@
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

@ -1,57 +0,0 @@
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

@ -1,73 +0,0 @@
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

@ -26,6 +26,7 @@ public class Permissions {
public static final String ADMINISTRATION_INFO = ADMINISTRATION + ".info"; public static final String ADMINISTRATION_INFO = ADMINISTRATION + ".info";
public static final String ADMINISTRATION_NOTIFY = ADMINISTRATION + ".notify"; public static final String ADMINISTRATION_NOTIFY = ADMINISTRATION + ".notify";
public static final String ADMINISTRATION_PLUGINS = ADMINISTRATION + ".plugins";
public static final String ADMINISTRATION_RELOAD = ADMINISTRATION + ".reload"; public static final String ADMINISTRATION_RELOAD = ADMINISTRATION + ".reload";
private static final String CHECKS = NOCHEATPLUS + ".checks"; private static final String CHECKS = NOCHEATPLUS + ".checks";
@ -129,7 +130,6 @@ public class Permissions {
public static final String MOVING_MOREPACKETS = MOVING + ".morepackets"; public static final String MOVING_MOREPACKETS = MOVING + ".morepackets";
public static final String MOVING_MOREPACKETSVEHICLE = MOVING + ".morepacketsvehicle"; public static final String MOVING_MOREPACKETSVEHICLE = MOVING + ".morepacketsvehicle";
public static final String MOVING_NOFALL = MOVING + ".nofall"; public static final String MOVING_NOFALL = MOVING + ".nofall";
public static final String MOVING_OVERRIDEBUKKIT = MOVING + ".overridebukkit";
public static final String MOVING_SURVIVALFLY = MOVING + ".survivalfly"; public static final String MOVING_SURVIVALFLY = MOVING + ".survivalfly";
public static final String MOVING_SURVIVALFLY_BLOCKING = MOVING_SURVIVALFLY + ".blocking"; 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_SNEAKING = MOVING_SURVIVALFLY + ".sneaking";