NOFALL Y U NO WORK?! *hum* NoFall should be fixed now, also fixed a

little mistake with the configuration file (right @asofold? :D).
This commit is contained in:
NeatMonster 2012-08-11 16:43:27 +02:00
parent 7791a13e2c
commit 65fa26d66d
7 changed files with 95 additions and 99 deletions

View File

@ -1,11 +1,11 @@
package fr.neatmonster.nocheatplus;
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.Packet10Flying;
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
/*
* MM'""""'YMM dP M"""""""`YM dP
@ -29,6 +29,21 @@ import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
*/
public class CustomNetServerHandler extends NetServerHandler {
/** The distance the player has falled. */
public double fallDistance;
/** Is the player on the ground? Client-side value. */
public boolean onGroundClient;
/** Is the player on the ground? Server-side value. */
public boolean onGroundServer;
/** Was the player on the ground? Client-side value. */
public boolean wasOnGroundClient;
/** Was the player on the ground? Server-side value. */
public boolean wasOnGroundServer;
/**
* Instantiates a new custom net server handler.
*
@ -49,8 +64,16 @@ public class CustomNetServerHandler extends NetServerHandler {
*/
@Override
public void a(final Packet10Flying packet) {
if (MovingListener.noFall.isEnabled(player.getBukkitEntity()))
MovingListener.noFall.check(player, packet);
wasOnGroundClient = onGroundClient;
wasOnGroundServer = onGroundServer;
onGroundClient = packet.g;
final AxisAlignedBB boundingBoxGround = player.boundingBox.clone().d(packet.x - player.locX,
packet.y - player.locY - 0.001D, packet.z - player.locZ);
onGroundServer = player.world.getCubes(player, boundingBoxGround).size() > 0;
if (packet.hasPos && wasOnGroundServer && !onGroundServer)
fallDistance = 0D;
else if (packet.hasPos && player.locY - packet.y > 0D)
fallDistance += player.locY - packet.y;
super.a(packet);
}
}

View File

@ -4,12 +4,12 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.INetworkManager;
import net.minecraft.server.DedicatedServer;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.NetServerHandler;
import net.minecraft.server.NetworkManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
@ -102,6 +102,10 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
// Register the commands handler.
getCommand("nocheatplus").setExecutor(new CommandHandler(this));
// Set the NetServerHandler of every player.
for (final Player player : Bukkit.getOnlinePlayers())
setCustomNetServerHandler(player);
// Tell the server administrator that we finished loading NoCheatPlus now.
System.out.println("[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled.");
}
@ -129,6 +133,9 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
public void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
// Set the NetServerHandler of the player.
setCustomNetServerHandler(player);
// Check if we allow all the client mods.
final boolean allowAll = ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_ALLOWCLIENTMODS);
String message = "";
@ -208,34 +215,25 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
player.sendMessage(message);
}
/**
* This event handler is used to replace the NetServerHandler of the player by our CustomNetServerHandler.
*
* @param event
* the event handled
*/
@EventHandler(
priority = EventPriority.LOWEST)
public void onPlayerJoin_(final PlayerJoinEvent event) {
final CraftPlayer player = (CraftPlayer) event.getPlayer();
final CraftServer server = (CraftServer) Bukkit.getServer();
final NetServerHandler nSH = player.getHandle().netServerHandler;
if (!(nSH instanceof CustomNetServerHandler)) {
final Location location = event.getPlayer().getLocation();
final CustomNetServerHandler customNSH = new CustomNetServerHandler(server.getHandle().getServer(),
player.getHandle().netServerHandler.networkManager, player.getHandle());
customNSH.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
player.getHandle().netServerHandler = customNSH;
final INetworkManager iNM = player.getHandle().netServerHandler.networkManager;
try {
final Field field = NetworkManager.class.getDeclaredField("packetListener");
field.setAccessible(true);
field.set(iNM, customNSH);
} catch (final Exception e) {
e.printStackTrace();
}
nSH.disconnected = true;
server.getHandle().getServer().ac().a(customNSH);
private boolean setCustomNetServerHandler(final Player player) {
final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final NetServerHandler oldNSH = entityPlayer.netServerHandler;
if (oldNSH instanceof CustomNetServerHandler)
return false;
final DedicatedServer server = ((CraftServer) Bukkit.getServer()).getHandle().getServer();
final NetServerHandler newNSH = new CustomNetServerHandler(server, oldNSH.networkManager, entityPlayer);
newNSH.a(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player
.getLocation().getYaw(), player.getLocation().getPitch());
entityPlayer.netServerHandler = newNSH;
try {
final Field field = NetworkManager.class.getDeclaredField("packetListener");
field.setAccessible(true);
field.set(oldNSH.networkManager, newNSH);
} catch (final Exception e) {
e.printStackTrace();
}
oldNSH.disconnected = true;
server.ac().a(newNSH);
return true;
}
}

View File

@ -134,13 +134,6 @@ public abstract class Check {
if (player.hasPermission(violationData.bypassPermission))
return false;
// final Object configFactory = type.getConfig().getDeclaredMethod("getConfig", Player.class).invoke(null,
// player);
// final Object dataFactory = type.getData().getDeclaredMethod("getData", Player.class).invoke(null,
// player);
// final ActionList actionList = (ActionList) type.getConfig().getDeclaredField(type.getName() + "Actions")
// .get(configFactory);
final ActionList actionList = violationData.actions;
final double violationLevel = violationData.VL;

View File

@ -84,8 +84,6 @@ public class MovingData implements CheckData {
// Data of the no fall check.
public double noFallFallDistance;
public boolean noFallWasOnGroundClient = true;
public boolean noFallWasOnGroundServer = true;
// Data of the survival fly check.
public long survivalFlyInLavaSince;
@ -108,9 +106,6 @@ public class MovingData implements CheckData {
public void clearFlyData() {
bunnyhopDelay = 0;
setBack = null;
noFallFallDistance = 0D;
noFallWasOnGroundClient = true;
noFallWasOnGroundServer = true;
survivalFlyJumpPhase = 0;
}

View File

@ -55,9 +55,6 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
*/
public class MovingListener implements Listener {
/** The no fall check. **/
public static NoFall noFall = new NoFall();
/** The instance of NoCheatPlus. */
private final NoCheatPlus plugin = (NoCheatPlus) Bukkit.getPluginManager().getPlugin(
"NoCheatPlus");
@ -70,6 +67,9 @@ public class MovingListener implements Listener {
/** The more packets vehicle check. */
private final MorePacketsVehicle morePacketsVehicle = new MorePacketsVehicle();
/** The no fall check. **/
private final NoFall noFall = new NoFall();
/** The survival fly check. */
private final SurvivalFly survivalFly = new SurvivalFly();
@ -316,10 +316,13 @@ public class MovingListener implements Listener {
if ((player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight()) && creativeFly.isEnabled(player))
// If the player is handled by the creative fly check, execute it.
newTo = creativeFly.check(player, from, to);
else if (survivalFly.isEnabled(player))
else if (survivalFly.isEnabled(player)) {
// If he is handled by the survival fly check, execute it.
newTo = survivalFly.check(player, from, to);
else
// If don't have a new location and if he is handled by the no fall check, execute it.
if (newTo == null && noFall.isEnabled(player))
noFall.check(player, from, to);
} else
// He isn't handled by any fly check, clear his dataFactory.
data.clearFlyData();

View File

@ -2,16 +2,15 @@ package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import net.minecraft.server.AxisAlignedBB;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.Packet10Flying;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.CustomNetServerHandler;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
/*
* M"""""""`YM MM""""""""`M dP dP
@ -44,71 +43,56 @@ public class NoFall extends Check {
* @param to
* the to
*/
public void check(final EntityPlayer player, final Packet10Flying packet) {
final Player bukkitPlayer = player.getBukkitEntity();
final MovingConfig cc = MovingConfig.getConfig(bukkitPlayer);
final MovingData data = MovingData.getData(bukkitPlayer);
public void check(final Player player, final PlayerLocation from, final PlayerLocation to) {
final MovingConfig cc = MovingConfig.getConfig(player);
final MovingData data = MovingData.getData(player);
// Check the player is now on the ground (for the client and for the server).
final boolean onGroundClient = packet.g;
final AxisAlignedBB boundingBoxGround = player.boundingBox.clone().d(packet.x - player.locX,
packet.y - player.locY - 0.001D, packet.z - player.locZ);
final boolean onGroundServer = player.world.getCubes(player, boundingBoxGround).size() > 0;
// Get the CustomNetServerHandler of the player.
final CustomNetServerHandler customNSH = (CustomNetServerHandler) ((CraftPlayer) player).getHandle().netServerHandler;
// If the packet has position information.
if (packet.hasPos)
// If the player has just started falling.
if (data.noFallWasOnGroundServer && !onGroundServer)
// Reset his fall distance.
data.noFallFallDistance = 0D;
else {
final int id = player.world.getTypeId((int) Math.ceil(packet.x), (int) Math.ceil(packet.y),
(int) Math.ceil(packet.z));
// If the player has just started falling, is falling into a liquid, in web or is on a ladder.
if (to.isInLiquid() || to.isInWeb() || to.isOnLadder())
// Reset his fall distance.
customNSH.fallDistance = 0D;
// If the player is falling into water.
if (id > 7 && id < 12)
// Reset his fall distance.
data.noFallFallDistance = 0D;
else if (player.locY - packet.y > 0D)
// Add the distance to the fall distance.
data.noFallFallDistance += player.locY - packet.y;
}
data.noFallFallDistance = customNSH.fallDistance;
// If the player just touched the ground for the server, but no for the client.
if (!data.noFallWasOnGroundServer && onGroundServer && (data.noFallWasOnGroundClient || !onGroundClient)) {
if (!customNSH.wasOnGroundServer && customNSH.onGroundServer
&& (customNSH.wasOnGroundClient || !customNSH.onGroundClient)) {
// Calculate the fall damages to be dealt.
final int fallDamage = (int) data.noFallFallDistance - 2;
if (fallDamage > 1) {
final int fallDamage = (int) customNSH.fallDistance - 2;
if (fallDamage > 0) {
// Add the fall distance to the violation level.
data.noFallVL += data.noFallFallDistance;
data.noFallVL += customNSH.fallDistance;
// Execute the actions to find out if we need to cancel the event or not.
if (executeActions(bukkitPlayer, data.noFallVL, cc.noFallActions))
if (executeActions(player, data.noFallVL, cc.noFallActions))
// Deal the fall damages to the player.
bukkitPlayer.damage(fallDamage);
player.damage(fallDamage);
}
}
// If the player just touched the ground for the server.
else if (!data.noFallWasOnGroundServer && onGroundServer) {
else if (!customNSH.wasOnGroundServer && customNSH.onGroundServer) {
// Calculate the difference between the fall distance calculated by the server and by the plugin.
final int difference = (int) data.noFallFallDistance - (int) bukkitPlayer.getFallDistance();
final double difference = (customNSH.fallDistance - player.getFallDistance()) / customNSH.fallDistance;
// If the difference is too big and the fall distance calculated by the plugin should hurt the player.
if (difference > 1 && (int) data.noFallFallDistance - 3 > 0) {
if (difference > 0.15D && (int) customNSH.fallDistance > 2) {
// Add the difference to the violation level.
data.noFallVL += data.noFallFallDistance - bukkitPlayer.getFallDistance();
data.noFallVL += customNSH.fallDistance - player.getFallDistance();
// Execute the actions to find out if we need to cancel the event or not.
if (executeActions(bukkitPlayer, data.noFallVL, cc.noFallActions))
if (executeActions(player, data.noFallVL, cc.noFallActions))
// Set the fall distance to its right value.
bukkitPlayer.setFallDistance((float) data.noFallFallDistance);
}
}
// Remember if the player was on ground for the client and for the server.
data.noFallWasOnGroundClient = onGroundClient;
data.noFallWasOnGroundServer = onGroundServer;
player.setFallDistance((float) customNSH.fallDistance);
} else
// Reward the player by lowering his violation level.
data.noFallVL *= 0.95D;
} else
// Reward the player by lowering his violation level.
data.noFallVL *= 0.95D;
}
/* (non-Javadoc)

View File

@ -129,7 +129,7 @@ public class ConfigManager {
public static void init(final NoCheatPlus plugin) {
// First try to obtain and parse the global configuration file.
final File folder = plugin.getDataFolder();
final File globalFile = new File(folder, "configFactory.yml");
final File globalFile = new File(folder, "config.yml");
final ConfigFile global = new ConfigFile();
global.setDefaults(new DefaultConfig());