diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java index 78779093b..ee25d4e08 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHack.java @@ -42,8 +42,6 @@ import mineplex.core.updater.event.UpdateEvent; public class AntiHack extends MiniPlugin { - private static Object _antiHackLock = new Object(); - public static AntiHack Instance; private boolean _enabled = true; @@ -115,10 +113,7 @@ public class AntiHack extends MiniPlugin if (!_enabled) return; - synchronized (_antiHackLock) - { - _lastMoveEvent.put(event.getPlayer(), System.currentTimeMillis()); - } + _lastMoveEvent.put(event.getPlayer(), System.currentTimeMillis()); } @EventHandler @@ -127,10 +122,7 @@ public class AntiHack extends MiniPlugin if (!_enabled) return; - synchronized (_antiHackLock) - { - setIgnore(event.getPlayer(), 2000); - } + setIgnore(event.getPlayer(), 2000); } @EventHandler @@ -139,10 +131,7 @@ public class AntiHack extends MiniPlugin if (!_enabled) return; - synchronized (_antiHackLock) - { - _velocityEvent.add(event.getPlayer()); - } + _velocityEvent.add(event.getPlayer()); } @EventHandler @@ -151,7 +140,7 @@ public class AntiHack extends MiniPlugin if (!_enabled) return; - ResetAll(event.getPlayer()); + resetAll(event.getPlayer()); } @EventHandler @@ -162,22 +151,19 @@ public class AntiHack extends MiniPlugin Player player = event.getPlayer(); - synchronized (_antiHackLock) + if (_velocityEvent.remove(player)) { - if (_velocityEvent.remove(player)) - { - setIgnore(player, 2000); - } + setIgnore(player, 2000); + } - //Initial Move (or Lag) Ignore - if (_lastMoveEvent.containsKey(player)) - { - long timeBetweenPackets = System.currentTimeMillis() - _lastMoveEvent.get(player); + //Initial Move (or Lag) Ignore + if (_lastMoveEvent.containsKey(player)) + { + long timeBetweenPackets = System.currentTimeMillis() - _lastMoveEvent.get(player); - if (timeBetweenPackets > 500) - { - setIgnore(player, Math.min(4000, timeBetweenPackets)); - } + if (timeBetweenPackets > 500) + { + setIgnore(player, Math.min(4000, timeBetweenPackets)); } } } @@ -188,15 +174,12 @@ public class AntiHack extends MiniPlugin for (Detector detector : _movementDetectors) detector.Reset(player); - synchronized (_antiHackLock) - { - //Already ignoring for a longer period - if (_ignore.containsKey(player) && _ignore.get(player) > System.currentTimeMillis() + time) - return; + //Already ignoring for a longer period + if (_ignore.containsKey(player) && _ignore.get(player) > System.currentTimeMillis() + time) + return; - //Add Ignore - _ignore.put(player, System.currentTimeMillis() + time); - } + //Add Ignore + _ignore.put(player, System.currentTimeMillis() + time); } public boolean isValid(Player player, boolean groundValid) @@ -246,44 +229,41 @@ public class AntiHack extends MiniPlugin System.out.println(C.cRed + C.Bold + player.getName() + " suspected for " + type + "."); - synchronized (_antiHackLock) + //Add Offense + if (!_offense.containsKey(player)) + _offense.put(player, new HashMap>()); + + if (!_offense.get(player).containsKey(type)) + _offense.get(player).put(type, new ArrayList()); + + _offense.get(player).get(type).add(System.currentTimeMillis()); + + //Cull & Count + int total = 0; + for (String curType : _offense.get(player).keySet()) { - //Add Offense - if (!_offense.containsKey(player)) - _offense.put(player, new HashMap>()); - - if (!_offense.get(player).containsKey(type)) - _offense.get(player).put(type, new ArrayList()); - - _offense.get(player).get(type).add(System.currentTimeMillis()); - - //Cull & Count - int total = 0; - for (String curType : _offense.get(player).keySet()) + //Remove Old Offenses + Iterator offenseIterator = _offense.get(player).get(curType).iterator(); + while (offenseIterator.hasNext()) { - //Remove Old Offenses - Iterator offenseIterator = _offense.get(player).get(curType).iterator(); - while (offenseIterator.hasNext()) - { - if (UtilTime.elapsed(offenseIterator.next(), KeepOffensesFor)) - offenseIterator.remove(); - } - - //Count - total += _offense.get(player).get(curType).size(); + if (UtilTime.elapsed(offenseIterator.next(), KeepOffensesFor)) + offenseIterator.remove(); } - - //Inform - for (Player admin : UtilServer.getPlayers()) - if (_clientManager.Get(admin).GetRank().Has(Rank.MODERATOR) && _preferences.Get(admin).ShowMacReports) - { - UtilPlayer.message(admin, "#" + total + ": " + C.cRed + C.Bold + player.getName() + " suspected for " + type + "."); - } - - // Print (Debug) - System.out.println("[Offense] #" + total + ": "+ player.getName() + " received suspicion for " + type + "."); + //Count + total += _offense.get(player).get(curType).size(); } + + + //Inform + for (Player admin : UtilServer.getPlayers()) + if (_clientManager.Get(admin).GetRank().Has(Rank.MODERATOR) && _preferences.Get(admin).ShowMacReports) + { + UtilPlayer.message(admin, "#" + total + ": " + C.cRed + C.Bold + player.getName() + " suspected for " + type + "."); + } + + // Print (Debug) + System.out.println("[Offense] #" + total + ": "+ player.getName() + " received suspicion for " + type + "."); } @EventHandler @@ -295,48 +275,52 @@ public class AntiHack extends MiniPlugin if (event.getType() != UpdateType.SEC) return; - synchronized (_antiHackLock) + for (Iterator>>> playerIterator = _offense.entrySet().iterator(); playerIterator.hasNext();) { - for (Iterator playerIterator = _offense.keySet().iterator(); playerIterator.hasNext();) + Entry>> entry = playerIterator.next(); + Player player = entry.getKey(); + + String out = ""; + int total = 0; + + for (String type : entry.getValue().keySet()) { - Player player = playerIterator.next(); - - String out = ""; - int total = 0; - - for (String type : _offense.get(player).keySet()) + //Remove Old Offenses + Iterator offenseIterator = entry.getValue().get(type).iterator(); + while (offenseIterator.hasNext()) { - //Remove Old Offenses - Iterator offenseIterator = _offense.get(player).get(type).iterator(); - while (offenseIterator.hasNext()) - { - long time = offenseIterator.next(); + long time = offenseIterator.next(); - if (UtilTime.elapsed(time, KeepOffensesFor)) - offenseIterator.remove(); - } - - //Count - int count = _offense.get(player).get(type).size(); - total += count; - - out += count + " " + type + ", "; + if (UtilTime.elapsed(time, KeepOffensesFor)) + offenseIterator.remove(); } - if (out.length() > 0) - out = out.substring(0, out.length() - 2); + //Count + int count = entry.getValue().get(type).size(); + total += count; - String severity; - if (total > (_strict ? 6 : 18)) severity = "Extreme"; - else if (total > (_strict ? 4 : 12)) severity = "High"; - else if (total > (_strict ? 2 : 6)) severity = "Medium"; - else severity = "Low"; + out += count + " " + type + ", "; + } - //Send Report - sendReport(player, out, severity); - - if (severity.equalsIgnoreCase("Extreme")) - playerIterator.remove(); + if (out.length() > 0) + out = out.substring(0, out.length() - 2); + + String severity = "Low"; + + if (total > (_strict ? 6 : 18)) + severity = "Extreme"; + else if (total > (_strict ? 4 : 12)) + severity = "High"; + else if (total > (_strict ? 2 : 6)) + severity = "Medium"; + + //Send Report + sendReport(player, out, severity); + + if (severity.equalsIgnoreCase("Extreme")) + { + playerIterator.remove(); + resetAll(player, false); } } } @@ -345,8 +329,6 @@ public class AntiHack extends MiniPlugin { if (severity.equals("Extreme")) { - ResetAll(player, false); - //Staff boolean handled = false; for (Player staff : UtilServer.getPlayers()) @@ -414,34 +396,31 @@ public class AntiHack extends MiniPlugin } } - private void Reset() + private void reset() { for (Player player : UtilServer.getPlayers()) - ResetAll(player); + resetAll(player); } - private void ResetAll(Player player) + private void resetAll(Player player) { - ResetAll(player, true); + resetAll(player, true); } - private void ResetAll(Player player, boolean removeOffenses) + private void resetAll(Player player, boolean removeOffenses) { - synchronized (_antiHackLock) - { - _ignore.remove(player); - _velocityEvent.remove(player); - _lastMoveEvent.remove(player); + _ignore.remove(player); + _velocityEvent.remove(player); + _lastMoveEvent.remove(player); - if (removeOffenses) - _offense.remove(player); + if (removeOffenses) + _offense.remove(player); - for (Detector detector : _movementDetectors) - detector.Reset(player); - - for (Detector detector : _combatDetectors) - detector.Reset(player); - } + for (Detector detector : _movementDetectors) + detector.Reset(player); + + for (Detector detector : _combatDetectors) + detector.Reset(player); } @EventHandler @@ -453,38 +432,35 @@ public class AntiHack extends MiniPlugin if (event.getType() != UpdateType.SLOW) return; - synchronized (_antiHackLock) + for (Iterator> playerIterator = _ignore.entrySet().iterator(); playerIterator.hasNext();) { - for (Iterator> playerIterator = _ignore.entrySet().iterator(); playerIterator.hasNext();) - { - Player player = playerIterator.next().getKey(); + Player player = playerIterator.next().getKey(); - if (!player.isOnline() || player.isDead() || !player.isValid()) - { - playerIterator.remove(); + if (!player.isOnline() || player.isDead() || !player.isValid()) + { + playerIterator.remove(); - _velocityEvent.remove(player); - _lastMoveEvent.remove(player); + _velocityEvent.remove(player); + _lastMoveEvent.remove(player); - _offense.remove(player); + _offense.remove(player); - for (Detector detector : _movementDetectors) - detector.Reset(player); - - for (Detector detector : _combatDetectors) - detector.Reset(player); - } + for (Detector detector : _movementDetectors) + detector.Reset(player); + + for (Detector detector : _combatDetectors) + detector.Reset(player); } } } - public void SetEnabled(boolean b) + public void setEnabled(boolean b) { _enabled = b; System.out.println("MAC Enabled: " + b); } - public boolean IsEnabled() + public boolean isEnabled() { return _enabled; } @@ -493,7 +469,7 @@ public class AntiHack extends MiniPlugin { _strict = strict; - Reset(); + reset(); System.out.println("MAC Strict: " + strict); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Fly.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Fly.java index ccc1c68d1..22577738f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Fly.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Fly.java @@ -37,7 +37,7 @@ public class Fly extends MiniPlugin implements Detector @EventHandler(priority = EventPriority.MONITOR) public void updateFlyhack(PlayerMoveEvent event) { - if (!Host.IsEnabled()) + if (!Host.isEnabled()) return; Player player = event.getPlayer(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Idle.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Idle.java index d2aa34c2e..01ad55ea0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Idle.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Idle.java @@ -32,7 +32,7 @@ public class Idle extends MiniPlugin implements Detector @EventHandler(priority = EventPriority.MONITOR) public void updateFlyhack(PlayerMoveEvent event) { - if (!Host.IsEnabled()) + if (!Host.isEnabled()) return; Player player = event.getPlayer(); @@ -43,7 +43,7 @@ public class Idle extends MiniPlugin implements Detector @EventHandler(priority = EventPriority.MONITOR) public void updateFreeCam(UpdateEvent event) { - if (!Host.IsEnabled()) + if (!Host.isEnabled()) return; if (event.getType() != UpdateType.FAST) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Reach.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Reach.java index 4f19d5352..6b439f649 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Reach.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Reach.java @@ -38,7 +38,7 @@ public class Reach extends MiniPlugin implements Detector @EventHandler(priority = EventPriority.LOWEST) public void recordMove(UpdateEvent event) { - if (!Host.IsEnabled()) + if (!Host.isEnabled()) return; if (event.getType() != UpdateType.TICK) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Speed.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Speed.java index fbe092da9..9777b50b5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Speed.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/types/Speed.java @@ -33,7 +33,7 @@ public class Speed extends MiniPlugin implements Detector @EventHandler(priority = EventPriority.MONITOR) public void updateSpeedhack(PlayerMoveEvent event) { - if (!Host.IsEnabled()) + if (!Host.isEnabled()) return; Player player = event.getPlayer();