diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckType.java b/src/fr/neatmonster/nocheatplus/checks/CheckType.java index e3fb338b..7b9d030c 100644 --- a/src/fr/neatmonster/nocheatplus/checks/CheckType.java +++ b/src/fr/neatmonster/nocheatplus/checks/CheckType.java @@ -35,72 +35,67 @@ public enum CheckType { ALL, BLOCKBREAK(BlockBreakConfig.factory, BlockBreakData.factory), - BLOCKBREAK_DIRECTION(BLOCKBREAK, "direction", Permissions.BLOCKBREAK_DIRECTION), - BLOCKBREAK_FASTBREAK(BLOCKBREAK, "fastBreak", Permissions.BLOCKBREAK_FASTBREAK), - BLOCKBREAK_NOSWING(BLOCKBREAK, "noSwing", Permissions.BLOCKBREAK_NOSWING), - BLOCKBREAK_REACH(BLOCKBREAK, "reach", Permissions.BLOCKBREAK_REACH), + BLOCKBREAK_DIRECTION(BLOCKBREAK, Permissions.BLOCKBREAK_DIRECTION), + BLOCKBREAK_FASTBREAK(BLOCKBREAK, Permissions.BLOCKBREAK_FASTBREAK), + BLOCKBREAK_NOSWING(BLOCKBREAK, Permissions.BLOCKBREAK_NOSWING), + BLOCKBREAK_REACH(BLOCKBREAK, Permissions.BLOCKBREAK_REACH), BLOCKINTERACT(BlockInteractConfig.factory, BlockInteractData.factory), - BLOCKINTERACT_DIRECTION(BLOCKINTERACT, "direction", Permissions.BLOCKINTERACT_DIRECTION), - BLOCKINTERACT_REACH(BLOCKINTERACT, "reach", Permissions.BLOCKINTERACT_REACH), + BLOCKINTERACT_DIRECTION(BLOCKINTERACT, Permissions.BLOCKINTERACT_DIRECTION), + BLOCKINTERACT_REACH(BLOCKINTERACT, Permissions.BLOCKINTERACT_REACH), BLOCKPLACE(BlockPlaceConfig.factory, BlockPlaceData.factory), - BLOCKPLACE_DIRECTION(BLOCKPLACE, "direction", Permissions.BLOCKPLACE_DIRECTION), - BLOCKPLACE_FASTPLACE(BLOCKPLACE, "fastPlace", Permissions.BLOCKPLACE_FASTPLACE), - BLOCKPLACE_NOSWING(BLOCKPLACE, "noSwing", Permissions.BLOCKPLACE_NOSWING), - BLOCKPLACE_REACH(BLOCKPLACE, "reach", Permissions.BLOCKBREAK_REACH), - BLOCKPLACE_SPEED(BLOCKPLACE, "speed", Permissions.BLOCKPLACE_SPEED), + BLOCKPLACE_DIRECTION(BLOCKPLACE, Permissions.BLOCKPLACE_DIRECTION), + BLOCKPLACE_FASTPLACE(BLOCKPLACE, Permissions.BLOCKPLACE_FASTPLACE), + BLOCKPLACE_NOSWING(BLOCKPLACE, Permissions.BLOCKPLACE_NOSWING), + BLOCKPLACE_REACH(BLOCKPLACE, Permissions.BLOCKBREAK_REACH), + BLOCKPLACE_SPEED(BLOCKPLACE, Permissions.BLOCKPLACE_SPEED), CHAT(ChatConfig.factory, ChatData.factory), - CHAT_COLOR(CHAT, "color", Permissions.CHAT_COLOR), - CHAT_NOPWNAGE(CHAT, "noPwnage", Permissions.CHAT_NOPWNAGE), + CHAT_COLOR(CHAT, Permissions.CHAT_COLOR), + CHAT_NOPWNAGE(CHAT, Permissions.CHAT_NOPWNAGE), FIGHT(FightConfig.factory, FightData.factory), - FIGHT_ANGLE(FIGHT, "angle", Permissions.FIGHT_ANGLE), - FIGHT_CRITICAL(FIGHT, "critical", Permissions.FIGHT_CRITICAL), - FIGHT_DIRECTION(FIGHT, "direction", Permissions.FIGHT_DIRECTION), - FIGHT_GODMODE(FIGHT, "godMode", Permissions.FIGHT_GODMODE), - FIGHT_INSTANTHEAL(FIGHT, "instantHeal", Permissions.FIGHT_INSTANTHEAL), - FIGHT_KNOCKBACK(FIGHT, "knockback", Permissions.FIGHT_KNOCKBACK), - FIGHT_NOSWING(FIGHT, "noSwing", Permissions.FIGHT_NOSWING), - FIGHT_REACH(FIGHT, "reach", Permissions.FIGHT_REACH), - FIGHT_SPEED(FIGHT, "speed", Permissions.FIGHT_SPEED), + FIGHT_ANGLE(FIGHT, Permissions.FIGHT_ANGLE), + FIGHT_CRITICAL(FIGHT, Permissions.FIGHT_CRITICAL), + FIGHT_DIRECTION(FIGHT, Permissions.FIGHT_DIRECTION), + FIGHT_GODMODE(FIGHT, Permissions.FIGHT_GODMODE), + FIGHT_INSTANTHEAL(FIGHT, Permissions.FIGHT_INSTANTHEAL), + FIGHT_KNOCKBACK(FIGHT, Permissions.FIGHT_KNOCKBACK), + FIGHT_NOSWING(FIGHT, Permissions.FIGHT_NOSWING), + FIGHT_REACH(FIGHT, Permissions.FIGHT_REACH), + FIGHT_SPEED(FIGHT, Permissions.FIGHT_SPEED), INVENTORY(InventoryConfig.factory, InventoryData.factory), - INVENTORY_DROP(INVENTORY, "drop", Permissions.INVENTORY_DROP), - INVENTORY_INSTANTBOW(INVENTORY, "instantBow", Permissions.INVENTORY_INSTANTBOW), - INVENTORY_INSTANTEAT(INVENTORY, "instantEat", Permissions.INVENTORY_INSTANTEAT), + INVENTORY_DROP(INVENTORY, Permissions.INVENTORY_DROP), + INVENTORY_INSTANTBOW(INVENTORY, Permissions.INVENTORY_INSTANTBOW), + INVENTORY_INSTANTEAT(INVENTORY, Permissions.INVENTORY_INSTANTEAT), MOVING(MovingConfig.factory, MovingData.factory), - MOVING_CREATIVEFLY(MOVING, "creativeFly", Permissions.MOVING_CREATIVEFLY), - MOVING_MOREPACKETS(MOVING, "morePackets", Permissions.MOVING_MOREPACKETS), - MOVING_MOREPACKETSVEHICLE(MOVING, "morePacketsVehicle", Permissions.MOVING_MOREPACKETSVEHICLE), - MOVING_NOFALL(MOVING, "noFall", Permissions.MOVING_NOFALL), - MOVING_SURVIVALFLY(MOVING, "survivalFly", Permissions.MOVING_SURVIVALFLY), + MOVING_CREATIVEFLY(MOVING, Permissions.MOVING_CREATIVEFLY), + MOVING_MOREPACKETS(MOVING, Permissions.MOVING_MOREPACKETS), + MOVING_MOREPACKETSVEHICLE(MOVING, Permissions.MOVING_MOREPACKETSVEHICLE), + MOVING_NOFALL(MOVING, Permissions.MOVING_NOFALL), + MOVING_SURVIVALFLY(MOVING, Permissions.MOVING_SURVIVALFLY), UNKNOWN; /** The group. */ - public final CheckType group; + private CheckType parent = null; /** The configFactory. */ - public final CheckConfigFactory configFactory; + private CheckConfigFactory configFactory = null; /** The dataFactory. */ - public final CheckDataFactory dataFactory; - - /** The name. */ - public final String name; + private CheckDataFactory dataFactory = null; /** The permission. */ - public final String permission; + private String permission = null; /** * Instantiates a new check type. */ - private CheckType() { - this(null, null, null, null, null); - } + private CheckType() {} /** * Instantiates a new check type. @@ -111,59 +106,38 @@ public enum CheckType { * the dataFactory */ private CheckType(final CheckConfigFactory configFactory, final CheckDataFactory dataFactory) { - this(null, configFactory, dataFactory, null, null); + this.configFactory = configFactory; + this.dataFactory = dataFactory; } /** * Instantiates a new check type. * - * @param group - * the group - * @param configFactory - * the configFactory class - * @param dataFactory - * the dataFactory class - * @param name - * the name + * @param parent + * the parent * @param permission * the permission */ - private CheckType(final CheckType group, final CheckConfigFactory configFactory, - final CheckDataFactory dataFactory, final String name, final String permission) { - this.group = group; - this.configFactory = configFactory; - this.dataFactory = dataFactory; - this.name = name; + private CheckType(final CheckType parent, final String permission) { + this.parent = parent; + configFactory = parent.getConfigFactory(); + dataFactory = parent.getDataFactory(); this.permission = permission; } /** - * Instantiates a new check type. + * Gets the configFactory. * - * @param group - * the group - * @param name - * the name - * @param permission - * the permission - */ - private CheckType(final CheckType group, final String name, final String permission) { - this(group, group.getConfigFactory(), group.getDataFactory(), name, permission); - } - - /** - * Gets the configFactory class. - * - * @return the configFactory class + * @return the configFactory */ public CheckConfigFactory getConfigFactory() { return configFactory; } /** - * Gets the dataFactory class. + * Gets the dataFactory. * - * @return the dataFactory class + * @return the dataFactory */ public CheckDataFactory getDataFactory() { return dataFactory; @@ -175,7 +149,16 @@ public enum CheckType { * @return the name */ public String getName() { - return name; + return toString().toLowerCase().replace("_", "."); + } + + /** + * Gets the parent. + * + * @return the parent + */ + public CheckType getParent() { + return parent; } /** diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 45df07d2..b09a6fb0 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -13,11 +13,10 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -135,31 +134,6 @@ public class MovingListener implements Listener { } } - /** - * We listen to EntityDamage events the reset the fall distance when a damage is dealt. - * - * @param event - * the event - */ - @EventHandler( - priority = EventPriority.MONITOR, ignoreCancelled = false) - public void onEntityDamage(final EntityDamageEvent event) { - /* - * _____ _ _ _ ____ - * | ____|_ __ | |_(_) |_ _ _ | _ \ __ _ _ __ ___ __ _ __ _ ___ - * | _| | '_ \| __| | __| | | | | | | |/ _` | '_ ` _ \ / _` |/ _` |/ _ \ - * | |___| | | | |_| | |_| |_| | | |_| | (_| | | | | | | (_| | (_| | __/ - * |_____|_| |_|\__|_|\__|\__, | |____/ \__,_|_| |_| |_|\__,_|\__, |\___| - * |___/ |___/ - */ - // Workaround fix attempt for NoFall multiple damage. - if (event.getCause() == DamageCause.FALL && event.getEntity() instanceof Player) { - final MovingData data = MovingData.getData((Player) event.getEntity()); - // Simple model: once damage dealt the fall distance is reset. - data.noFallFallDistance = data.noFallNewFallDistance = 0D; - } - } - /** * We listen to this event to prevent player from flying by sending bed leaving packets. * @@ -226,6 +200,36 @@ public class MovingListener implements Listener { data.teleported = null; data.clearFlyData(); data.clearMorePacketsData(); + data.resetNoFallDistances(); + } + + /** + * When a player changes his gamemode, all information related to the moving checks becomes invalid. + * + * @param event + * the event + */ + @EventHandler( + ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerGameModeChange(final PlayerGameModeChangeEvent event) { + /* + * ____ _ ____ __ __ _ + * | _ \| | __ _ _ _ ___ _ __ / ___| __ _ _ __ ___ ___| \/ | ___ __| | ___ + * | |_) | |/ _` | | | |/ _ \ '__| | | _ / _` | '_ ` _ \ / _ \ |\/| |/ _ \ / _` |/ _ \ + * | __/| | (_| | |_| | __/ | | |_| | (_| | | | | | | __/ | | | (_) | (_| | __/ + * |_| |_|\__,_|\__, |\___|_| \____|\__,_|_| |_| |_|\___|_| |_|\___/ \__,_|\___| + * |___/ + * ____ _ + * / ___| |__ __ _ _ __ __ _ ___ + * | | | '_ \ / _` | '_ \ / _` |/ _ \ + * | |___| | | | (_| | | | | (_| | __/ + * \____|_| |_|\__,_|_| |_|\__, |\___| + * |___/ + */ + final MovingData data = MovingData.getData(event.getPlayer()); + data.clearFlyData(); + data.clearMorePacketsData(); + data.resetNoFallDistances(); } /** @@ -350,9 +354,11 @@ public class MovingListener implements Listener { // 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 + } else { // He isn't handled by any fly check, clear his data. data.clearFlyData(); + data.resetNoFallDistances(); + } if (newTo == null && morePackets.isEnabled(player)) // If he hasn't been stopped by any other check and is handled by the more packets check, execute it. @@ -390,6 +396,7 @@ public class MovingListener implements Listener { final MovingData data = MovingData.getData(event.getPlayer()); data.clearFlyData(); data.clearMorePacketsData(); + data.resetNoFallDistances(); } /** @@ -412,6 +419,7 @@ public class MovingListener implements Listener { final MovingData data = MovingData.getData(event.getPlayer()); data.clearFlyData(); data.clearMorePacketsData(); + data.resetNoFallDistances(); } /** @@ -449,6 +457,7 @@ public class MovingListener implements Listener { // Always drop data from fly checks, as it always loses its validity after teleports. Always! data.teleported = null; data.clearFlyData(); + data.resetNoFallDistances(); } /** diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java index 8f12d02a..fbd1bf03 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java @@ -75,8 +75,7 @@ public class NoFall extends Check { else if (!data.noFallWasOnGroundServer && data.noFallOnGroundServer) { // If the difference between the fall distance recorded by Bukkit and NoCheatPlus is too big and the fall // distance bigger than 2. - if (data.noFallFallDistance - player.getFallDistance() > Math.pow(1D, -3D) - && (int) data.noFallFallDistance > 2) { + if (data.noFallFallDistance - player.getFallDistance() > 0.1D && (int) data.noFallFallDistance > 2) { // Add the difference to the violation level. data.noFallVL += data.noFallFallDistance - player.getFallDistance(); diff --git a/src/fr/neatmonster/nocheatplus/hooks/NCPHookManager.java b/src/fr/neatmonster/nocheatplus/hooks/NCPHookManager.java index 3c38e04d..678ff037 100644 --- a/src/fr/neatmonster/nocheatplus/hooks/NCPHookManager.java +++ b/src/fr/neatmonster/nocheatplus/hooks/NCPHookManager.java @@ -132,12 +132,12 @@ public final class NCPHookManager { */ private static boolean addToMappingsRecursively(final CheckType checkType, final CheckType refType, final NCPHook hook) { - if (refType.group == null) + if (refType.getParent() == null) return false; - else if (refType.group == checkType) { + else if (refType.getParent() == checkType) { addToMapping(refType, hook); return true; - } else if (addToMappingsRecursively(checkType, refType.group, hook)) { + } else if (addToMappingsRecursively(checkType, refType.getParent(), hook)) { addToMapping(refType, hook); return true; } else @@ -271,8 +271,8 @@ public final class NCPHookManager { final StringBuilder builder = new StringBuilder(1024); builder.append("[NoCheatPlus] Hook " + getHookDescription(hook) + " encountered an unexpected exception:\n"); builder.append("Processing: "); - if (checkType.group != null) - builder.append("Group " + checkType.group + " "); + if (checkType.getParent() != null) + builder.append("Prent " + checkType.getParent() + " "); builder.append("Check " + checkType); builder.append(" Player " + player.getName()); builder.append("\n");