diff --git a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/FastConsume.java b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/FastConsume.java index e7f7e1fb..e052a7f1 100644 --- a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/FastConsume.java +++ b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/FastConsume.java @@ -8,6 +8,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.inventory.ItemStack; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; @@ -17,6 +18,7 @@ import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.logging.LogUtil; import fr.neatmonster.nocheatplus.players.DataManager; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.TickTask; /** @@ -35,6 +37,9 @@ public class FastConsume extends Check implements Listener{ } } + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idCancelDead = counters.registerKey("canceldead"); + public FastConsume() { super(CheckType.INVENTORY_FASTCONSUME); // Overrides the instant-eat check. @@ -48,6 +53,7 @@ public class FastConsume extends Check implements Listener{ if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) { // Eat after death. event.setCancelled(true); + counters.addPrimaryThread(idCancelDead, 1); return; } if (!isEnabled(player)) { diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java index 99c74038..c78f8392 100644 --- a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java @@ -3,14 +3,15 @@ package fr.neatmonster.nocheatplus.net.protocollib; import java.util.Map; import org.bukkit.entity.Player; -import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.components.JoinLeaveListener; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.ActionFrequency; import fr.neatmonster.nocheatplus.utilities.ds.LinkedHashMapCOW; @@ -21,13 +22,16 @@ import fr.neatmonster.nocheatplus.utilities.ds.LinkedHashMapCOW; * @author dev1mc * */ -public class FlyingFrequency extends PacketAdapter implements Listener, JoinLeaveListener { +public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener { + // TODO: Silent cancel count. // TODO: Configuration. // TODO: Optimized options (receive only, other?). - // TODO: Async version ? + // TODO: Forced async version ? private final Map freqMap = new LinkedHashMapCOW(); + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idSilent = counters.registerKey("packet.flying.silentcancel"); public FlyingFrequency(Plugin plugin) { // PacketPlayInFlying[3, legacy: 10] @@ -62,6 +66,7 @@ public class FlyingFrequency extends PacketAdapter implements Listener, JoinLeav freq.add(System.currentTimeMillis(), 1f); if (freq.score(1f) > 300) { event.setCancelled(true); + counters.add(idSilent, 1); // Until it is sure if we can get these async. } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java index f3e03ab0..cae27ebc 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakListener.java @@ -15,12 +15,14 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.inventory.ItemStack; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.checks.CheckListener; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.inventory.Items; import fr.neatmonster.nocheatplus.compat.AlmostBoolean; import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; import fr.neatmonster.nocheatplus.permissions.Permissions; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.BlockProperties; import fr.neatmonster.nocheatplus.utilities.TickTask; @@ -51,6 +53,9 @@ public class BlockBreakListener extends CheckListener { private AlmostBoolean isInstaBreak = AlmostBoolean.NO; + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idCancelDIllegalItem = counters.registerKey("illegalitem"); + public BlockBreakListener(){ super(CheckType.BLOCKBREAK); } @@ -69,6 +74,7 @@ public class BlockBreakListener extends CheckListener { // Illegal enchantments hotfix check. if (Items.checkIllegalEnchantments(player, player.getItemInHand())) { event.setCancelled(true); + counters.addPrimaryThread(idCancelDIllegalItem, 1); } // Cancelled events only leads to resetting insta break. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java index 71f3b420..427da5d1 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractListener.java @@ -12,10 +12,12 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.checks.CheckListener; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.combined.CombinedConfig; import fr.neatmonster.nocheatplus.compat.BridgeHealth; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.BlockProperties; /** @@ -40,6 +42,9 @@ public class BlockInteractListener extends CheckListener { /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */ private final Location useLoc = new Location(null, 0, 0, 0); + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idCancelDead = counters.registerKey("canceldead"); + public BlockInteractListener(){ super(CheckType.BLOCKINTERACT); } @@ -60,6 +65,7 @@ public class BlockInteractListener extends CheckListener { event.setUseInteractedBlock(Result.DENY); event.setUseItemInHand(Result.DENY); event.setCancelled(true); + counters.addPrimaryThread(idCancelDead, 1); return; } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java index 4922ca99..d5372864 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java @@ -16,6 +16,7 @@ import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.checks.CheckListener; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.combined.Combined; @@ -24,6 +25,7 @@ import fr.neatmonster.nocheatplus.checks.combined.Improbable; import fr.neatmonster.nocheatplus.checks.moving.MovingConfig; import fr.neatmonster.nocheatplus.compat.BridgeMisc; import fr.neatmonster.nocheatplus.permissions.Permissions; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.BlockProperties; /** @@ -77,6 +79,10 @@ public class BlockPlaceListener extends CheckListener { /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */ private final Location useLoc = new Location(null, 0, 0, 0); + + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idBoatsAnywhere = counters.registerKey("boatsanywhere"); + private final int idEnderPearl = counters.registerKey("throwenderpearl"); public BlockPlaceListener(){ super(CheckType.BLOCKPLACE); @@ -219,14 +225,16 @@ public class BlockPlaceListener extends CheckListener { if (!player.hasPermission(Permissions.BLOCKPLACE_BOATSANYWHERE)){ event.setCancelled(true); + counters.addPrimaryThread(idBoatsAnywhere, 1); } } else if (type == Material.MONSTER_EGG){ // Check blockplace.speed. - if (speed.isEnabled(player) && speed.check(player)) + if (speed.isEnabled(player) && speed.check(player)) { // If the check was positive, cancel the event. event.setCancelled(true); + } } } @@ -313,6 +321,9 @@ public class BlockPlaceListener extends CheckListener { } } } + if (cancel) { + counters.addPrimaryThread(idEnderPearl, 1); + } } // Cancelled ? diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java index e2dba2b6..40f4d0e9 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java @@ -11,8 +11,10 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.checks.CheckListener; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.TickTask; /** @@ -28,6 +30,9 @@ public class CombinedListener extends CheckListener { protected final Improbable improbable = addCheck(new Improbable()); protected final MunchHausen munchHausen = addCheck(new MunchHausen()); + + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idFakeInvulnerable = counters.registerKey("fakeinvulnerable"); public CombinedListener(){ super(CheckType.COMBINED); @@ -75,6 +80,7 @@ public class CombinedListener extends CheckListener { if (TickTask.getTick() >= data.invulnerableTick + modifier.intValue()) return; // Still invulnerable. event.setCancelled(true); + counters.addPrimaryThread(idFakeInvulnerable, 1); } /** diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java index 1954ab88..64667ed5 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java @@ -22,6 +22,7 @@ import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.checks.CheckListener; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.combined.Combined; @@ -36,6 +37,7 @@ import fr.neatmonster.nocheatplus.checks.moving.MovingListener; import fr.neatmonster.nocheatplus.compat.BridgeHealth; import fr.neatmonster.nocheatplus.components.JoinLeaveListener; import fr.neatmonster.nocheatplus.permissions.Permissions; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.TickTask; import fr.neatmonster.nocheatplus.utilities.TrigUtil; import fr.neatmonster.nocheatplus.utilities.build.BuildParameters; @@ -83,6 +85,9 @@ public class FightListener extends CheckListener implements JoinLeaveListener{ /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */ private final Location useLoc2 = new Location(null, 0, 0, 0); + + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idCancelDead = counters.registerKey("canceldead"); public FightListener(){ super(CheckType.FIGHT); @@ -532,6 +537,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{ if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) { // Heal after death. event.setCancelled(true); + counters.addPrimaryThread(idCancelDead, 1); return; } if (event.getRegainReason() != RegainReason.SATIATED) { diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java index 92fa67f8..814e98fc 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java @@ -25,12 +25,14 @@ import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.checks.CheckListener; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.combined.Combined; import fr.neatmonster.nocheatplus.checks.combined.Improbable; import fr.neatmonster.nocheatplus.compat.BridgeHealth; import fr.neatmonster.nocheatplus.components.JoinLeaveListener; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.InventoryUtil; /** @@ -58,6 +60,11 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */ private final Location useLoc = new Location(null, 0, 0, 0); + + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idCancelDead = counters.registerKey("canceldead"); + private final int idIllegalItem = counters.registerKey("illegalitem"); + private final int idEggOnEntity = counters.registerKey("eggonentity"); public InventoryListener(){ super(CheckType.INVENTORY); @@ -115,6 +122,7 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen else if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) { // Eat after death. event.setCancelled(true); + counters.addPrimaryThread(idCancelDead, 1); } } } @@ -143,14 +151,20 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen final ItemStack cursor = event.getCursor(); final ItemStack clicked = event.getCurrentItem(); - + boolean cancel = false; // Illegal enchantment checks. try{ - if (Items.checkIllegalEnchantments(player, clicked)) event.setCancelled(true); + if (!cancel && Items.checkIllegalEnchantments(player, clicked)) { + cancel = true; + counters.addPrimaryThread(idIllegalItem, 1); + } } catch(final ArrayIndexOutOfBoundsException e){} // Hotfix (CB) try{ - if (Items.checkIllegalEnchantments(player, cursor)) event.setCancelled(true); + if (!cancel && Items.checkIllegalEnchantments(player, cursor)) { + cancel = true; + counters.addPrimaryThread(idIllegalItem, 1); + } } catch(final ArrayIndexOutOfBoundsException e){} // Hotfix (CB) @@ -162,13 +176,16 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen if (player.getGameMode() != GameMode.CREATIVE || !cc.fastClickSpareCreative){ if (fastClick.check(player, now, event.getView(), slot, cursor, clicked, event.isShiftClick(), data, cc)){ // The check requested the event to be cancelled. - event.setCancelled(true); + cancel = true; } // Feed the improbable. Improbable.feed(player, 0.7f, System.currentTimeMillis()); } } data.lastClickTime = now; + if (cancel) { + event.setCancelled(true); + } } } @@ -244,6 +261,7 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen // Illegal enchantments hotfix check. if (Items.checkIllegalEnchantments(player, item)) { event.setCancelled(true); + counters.addPrimaryThread(idIllegalItem, 1); } } else { @@ -267,11 +285,14 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) { // No zombies. event.setCancelled(true); + counters.addPrimaryThread(idCancelDead, 1); return; } final ItemStack stack = player.getItemInHand(); if (stack != null && stack.getType() == Material.MONSTER_EGG && items.isEnabled(player)){ event.setCancelled(true); + counters.addPrimaryThread(idEggOnEntity, 1); + return; } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index ca1cc8e8..4520691b 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -65,6 +65,7 @@ import fr.neatmonster.nocheatplus.logging.DebugUtil; import fr.neatmonster.nocheatplus.logging.LogUtil; import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.players.DataManager; +import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.BlockProperties; import fr.neatmonster.nocheatplus.utilities.CheckUtils; @@ -188,6 +189,14 @@ public class MovingListener extends CheckListener implements TickListener, IRemo /** Location for temporary use with getLocation(useLoc). Always call setWorld(null) after use. Use LocUtil.clone before passing to other API. */ private final Location useLoc = new Location(null, 0, 0, 0); // TODO: Put to use... + /** Statistics / debugging counters. */ + private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); + private final int idMoveHandled = counters.registerKey("event.player.move.handled"); + private final int idMoveHandledPos = counters.registerKey("event.player.move.handled.pos"); + private final int idMoveHandledLook = counters.registerKey("event.player.move.handled.look"); + private final int idMoveHandledPosAndLook = counters.registerKey("event.player.move.handled.pos_look"); + + public MovingListener() { super(CheckType.MOVING); } @@ -356,8 +365,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo * @param event * the event */ - @EventHandler( - ignoreCancelled = true, priority = EventPriority.LOWEST) + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerMove(final PlayerMoveEvent event) { final Player player = event.getPlayer(); @@ -449,10 +457,32 @@ public class MovingListener extends CheckListener implements TickListener, IRemo return; } + { + // Debugging statistics, rather light weight. + final boolean hasPos = !moveInfo.from.isSamePos(moveInfo.to); + final boolean hasLook = from.getYaw() != to.getYaw() || from.getPitch() != to.getPitch(); + counters.addPrimaryThread(idMoveHandled, 1); + final int counterId; + if (hasPos && hasLook) { + counterId = idMoveHandledPosAndLook; + } + else if (hasPos) { + counterId = idMoveHandledPos; + } + else if (hasLook) { + counterId = idMoveHandledLook; + } + else { + counterId = -1; + } + if (counterId != -1) { + counters.addPrimaryThread(counterId, 1); + } + } + // The players location. final Location loc = (cc.noFallCheck || cc.passableCheck) ? player.getLocation(moveInfo.useLoc) : null; - // Check for location consistency. if (cc.enforceLocation && playersEnforce.contains(playerName)) { // NOTE: The setback should not be set before this, even if not yet set.