diff --git a/src/fr/neatmonster/nocheatplus/actions/ParameterName.java b/src/fr/neatmonster/nocheatplus/actions/ParameterName.java index 087bb480..618451ad 100644 --- a/src/fr/neatmonster/nocheatplus/actions/ParameterName.java +++ b/src/fr/neatmonster/nocheatplus/actions/ParameterName.java @@ -21,12 +21,12 @@ package fr.neatmonster.nocheatplus.actions; * Some wildcards that are used in commands and log messages. */ public enum ParameterName { - ATTACKS_LIMIT("attackslimit"), CHECK("check"), DISTANCE("distance"), FALL_DISTANCE("falldistance"), FOOD("food"), IP("ip"), + LIMIT("limit"), LOCATION_FROM("locationfrom"), LOCATION_TO("locationto"), PACKETS("packets"), diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java index 6d873e6b..e21896ad 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceConfig.java @@ -67,6 +67,9 @@ public class BlockPlaceConfig { public final long fastPlaceInterval; public final ActionList fastPlaceActions; + public final boolean noSwingCheck; + public final ActionList noSwingActions; + public final boolean reachCheck; public final ActionList reachActions; @@ -89,6 +92,9 @@ public class BlockPlaceConfig { fastPlaceInterval = data.getLong(ConfPaths.BLOCKPLACE_FASTPLACE_INTERVAL); fastPlaceActions = data.getActionList(ConfPaths.BLOCKPLACE_FASTPLACE_ACTIONS, Permissions.BLOCKPLACE_FASTPLACE); + noSwingCheck = data.getBoolean(ConfPaths.BLOCKPLACE_NOSWING_CHECK); + noSwingActions = data.getActionList(ConfPaths.BLOCKPLACE_NOSWING_ACTIONS, Permissions.BLOCKPLACE_NOSWING); + reachCheck = data.getBoolean(ConfPaths.BLOCKPLACE_REACH_CHECK); reachActions = data.getActionList(ConfPaths.BLOCKPLACE_REACH_ACTIONS, Permissions.BLOCKPLACE_REACH); diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java index 7db2d3bd..b0aed8d9 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java @@ -46,6 +46,7 @@ public class BlockPlaceData { // Violation levels. public double directionVL; public double fastPlaceVL; + public double noSwingVL; public double reachVL; public double speedVL; @@ -53,6 +54,9 @@ public class BlockPlaceData { public long fastPlaceLastTime; public boolean fastPlaceLastRefused; + // Data of the no swing check. + public boolean noSwingArmSwung; + // Data of the reach check. public double reachDistance; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java index adeb7c35..13ad1dde 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java @@ -9,6 +9,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerInteractEvent; /* @@ -36,6 +37,7 @@ import org.bukkit.event.player.PlayerInteractEvent; public class BlockPlaceListener implements Listener { private final Direction direction = new Direction(); private final FastPlace fastPlace = new FastPlace(); + private final NoSwing noSwing = new NoSwing(); private final Reach reach = new Reach(); private final Speed speed = new Speed(); @@ -65,22 +67,49 @@ public class BlockPlaceListener implements Listener { boolean cancelled = false; // First, the fast place check. - if (fastPlace.isEnabled(player)) - cancelled = fastPlace.check(player, block); + if (fastPlace.isEnabled(player) && fastPlace.check(player, block)) + cancelled = true; - // Second, the reach check. - if (!cancelled && reach.isEnabled(player)) - cancelled = reach.check(player, block.getLocation()); + // Second, the no swing check. + if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player)) + cancelled = true; - // Third, the direction check. - if (!cancelled && direction.isEnabled(player)) - cancelled = direction.check(player, block.getLocation(), event.getBlockAgainst().getLocation()); + // Third, the reach check. + if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation())) + cancelled = true; + + // Fourth, the direction check. + if (!cancelled && direction.isEnabled(player) + && direction.check(player, block.getLocation(), event.getBlockAgainst().getLocation())) + cancelled = true; // If one of the checks requested to cancel the event, do so. if (cancelled) event.setCancelled(cancelled); } + /** + * We listen to PlayerAnimation events because it is (currently) equivalent to "player swings arm" and we want to + * check if he did that between block breaks. + * + * @param event + * the event + */ + @EventHandler( + priority = EventPriority.MONITOR) + public void onPlayerAnimation(final PlayerAnimationEvent event) { + /* + * ____ _ _ _ _ _ + * | _ \| | __ _ _ _ ___ _ __ / \ _ __ (_)_ __ ___ __ _| |_(_) ___ _ __ + * | |_) | |/ _` | | | |/ _ \ '__| / _ \ | '_ \| | '_ ` _ \ / _` | __| |/ _ \| '_ \ + * | __/| | (_| | |_| | __/ | / ___ \| | | | | | | | | | (_| | |_| | (_) | | | | + * |_| |_|\__,_|\__, |\___|_| /_/ \_\_| |_|_|_| |_| |_|\__,_|\__|_|\___/|_| |_| + * |___/ + */ + // Just set a flag to true when the arm was swung. + BlockPlaceData.getData(event.getPlayer()).noSwingArmSwung = true; + } + /** * We listener to PlayerInteract events to prevent players from spamming the server with monster eggs. */ diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java b/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java index b5d3c95d..53072968 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Knockback.java @@ -1,6 +1,7 @@ package fr.neatmonster.nocheatplus.checks.fight; import org.bukkit.Bukkit; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ParameterName; @@ -52,6 +53,11 @@ public class Knockback extends Check { boolean cancel = false; + // If the item has the knockback enchantment, do not check. + if (player.getItemInHand().containsEnchantment(Enchantment.KNOCKBACK) + || player.getItemInHand().containsEnchantment(Enchantment.ARROW_KNOCKBACK)) + return false; + // How long ago has the player started sprinting? if (data.knockbackSprintTime > 0L && System.currentTimeMillis() - data.knockbackSprintTime < cc.knockbackInterval) { diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java b/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java index d9cf7128..5a430a62 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/Speed.java @@ -88,7 +88,7 @@ public class Speed extends Check { public String getParameter(final ParameterName wildcard, final Player player) { if (wildcard == ParameterName.VIOLATIONS) return String.valueOf(Math.round(FightData.getData(player).speedVL)); - else if (wildcard == ParameterName.ATTACKS_LIMIT) + else if (wildcard == ParameterName.LIMIT) return String.valueOf(Math.round(FightConfig.getConfig(player).speedLimit)); else return super.getParameter(wildcard, player); diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java index 4d496621..24235f17 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java @@ -3,7 +3,6 @@ package fr.neatmonster.nocheatplus.checks.moving; import java.util.Locale; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -75,8 +74,6 @@ public class NoFall extends Check { if (cc.noFallAggressive && (from.isInLiquid() || from.isOnGround() || from.isOnLadder()) && (to.isInLiquid() || to.isOnGround() || to.isOnLadder()) && from.getY() <= to.getY() && player.getFallDistance() > 3F) { - // Bukkit.broadcastMessage(ChatColor.RED + "Problem with the no fall check!"); // TODO - data.noFallDistance = player.getFallDistance(); // Increment violation level. @@ -105,8 +102,6 @@ public class NoFall extends Check { // We want to know if the fallDistance recorded by the game is smaller than the fall distance recorded by the // plugin. if (difference > 1F && (to.isInWater() || to.isOnGround() || to.isOnLadder()) && data.noFallDistance > 2F) { - Bukkit.broadcastMessage(ChatColor.RED + "Problem with the no fall check!"); // TODO - // Increment violation level. data.noFallVL += difference; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index c49b6859..1087e67d 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -281,9 +281,6 @@ public class SurvivalFly extends Check { // Did the player move in unexpected ways? if (result > 0D) { - // Bukkit.broadcastMessage(ChatColor.RED + player.getName() + ": problem with the survival fly check!"); // - // TODO - // Increment violation counter. data.survivalFlyVL += result; diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index 87f6c76f..ad185d91 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -89,6 +89,10 @@ public abstract class ConfPaths { public static final String BLOCKPLACE_FASTPLACE_INTERVAL = BLOCKPLACE_FASTPLACE + "interval"; public static final String BLOCKPLACE_FASTPLACE_ACTIONS = BLOCKPLACE_FASTPLACE + "actions"; + private static final String BLOCKPLACE_NOSWING = BLOCKPLACE + "noswing."; + public static final String BLOCKPLACE_NOSWING_CHECK = BLOCKPLACE_NOSWING + "active"; + public static final String BLOCKPLACE_NOSWING_ACTIONS = BLOCKPLACE_NOSWING + "actions"; + private static final String BLOCKPLACE_REACH = BLOCKPLACE + "reach."; public static final String BLOCKPLACE_REACH_CHECK = BLOCKPLACE_REACH + "active"; public static final String BLOCKPLACE_REACH_ACTIONS = BLOCKPLACE_REACH + "actions"; diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index d864fb0e..4dfd91ce 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -88,6 +88,9 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.BLOCKPLACE_REACH_CHECK, true); set(ConfPaths.BLOCKPLACE_REACH_ACTIONS, "cancel vl>5 log:breach:0:2:if cancel"); + set(ConfPaths.BLOCKPLACE_NOSWING_CHECK, true); + set(ConfPaths.BLOCKPLACE_NOSWING_ACTIONS, "log:noswing:3:2:if cancel"); + set(ConfPaths.BLOCKPLACE_SPEED_CHECK, true); set(ConfPaths.BLOCKPLACE_SPEED_INTERVAL, 45L); set(ConfPaths.BLOCKPLACE_SPEED_ACTIONS, @@ -302,7 +305,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.STRINGS + ".flylong", start + "tried to move from [locationfrom] to [locationto] over a distance of [distance] block(s)" + end); set(ConfPaths.STRINGS + ".freach", start + "tried to attack entity out of reach" + end); - set(ConfPaths.STRINGS + ".fspeed", start + "tried to attack more than [attackslimit] times per second" + end); + set(ConfPaths.STRINGS + ".fspeed", start + "tried to attack more than [limit] times per second" + end); set(ConfPaths.STRINGS + ".godmode", start + "avoided taking damage or lagging" + end); set(ConfPaths.STRINGS + ".instantbow", start + "fires bow to fast" + end); set(ConfPaths.STRINGS + ".instanteat", start + "eats food [food] too fast" + end); diff --git a/src/fr/neatmonster/nocheatplus/players/Permissions.java b/src/fr/neatmonster/nocheatplus/players/Permissions.java index efb168a1..42572203 100644 --- a/src/fr/neatmonster/nocheatplus/players/Permissions.java +++ b/src/fr/neatmonster/nocheatplus/players/Permissions.java @@ -87,7 +87,8 @@ public class Permissions { */ private static final String BLOCKPLACE = CHECKS + ".blockplace"; public static final String BLOCKPLACE_DIRECTION = BLOCKPLACE + ".direction"; - public static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + "fastplace"; + public static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + ".fastplace"; + public static final String BLOCKPLACE_NOSWING = BLOCKPLACE + ".noswing"; public static final String BLOCKPLACE_REACH = BLOCKPLACE + ".reach"; public static final String BLOCKPLACE_SPEED = BLOCKPLACE + ".speed";