From 7962962a40e873bbd68cb08a5e35c4d8129d1ac1 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 29 Sep 2012 20:57:44 +0200 Subject: [PATCH] Add: /ncp remove * [] --- .../nocheatplus/checks/ViolationHistory.java | 6 ++++++ .../checks/access/CheckDataFactory.java | 5 +++++ .../checks/blockbreak/BlockBreakData.java | 9 +++++++++ .../blockinteract/BlockInteractData.java | 9 +++++++++ .../checks/blockplace/BlockPlaceData.java | 9 +++++++++ .../nocheatplus/checks/chat/ChatData.java | 13 +++++++++++-- .../checks/combined/CombinedData.java | 9 +++++++++ .../nocheatplus/checks/fight/FightData.java | 9 +++++++++ .../checks/inventory/InventoryData.java | 9 +++++++++ .../nocheatplus/checks/moving/MovingData.java | 9 +++++++++ .../command/admin/RemovePlayerCommand.java | 6 ++++++ .../nocheatplus/players/DataManager.java | 19 +++++++++++++++++++ 12 files changed, 110 insertions(+), 2 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/ViolationHistory.java b/src/fr/neatmonster/nocheatplus/checks/ViolationHistory.java index 47cd3c6e..8b5f8c9b 100644 --- a/src/fr/neatmonster/nocheatplus/checks/ViolationHistory.java +++ b/src/fr/neatmonster/nocheatplus/checks/ViolationHistory.java @@ -165,6 +165,12 @@ public class ViolationHistory { public static ViolationHistory removeHistory(final String playerName){ return violationHistories.remove(playerName); } + + public static void clear(final CheckType checkType){ + for (ViolationHistory hist : violationHistories.values()){ + hist.remove(checkType); + } + } /** The violation levels for every check. */ private final List violationLevels = new ArrayList(); diff --git a/src/fr/neatmonster/nocheatplus/checks/access/CheckDataFactory.java b/src/fr/neatmonster/nocheatplus/checks/access/CheckDataFactory.java index 79d43581..2fefbada 100644 --- a/src/fr/neatmonster/nocheatplus/checks/access/CheckDataFactory.java +++ b/src/fr/neatmonster/nocheatplus/checks/access/CheckDataFactory.java @@ -44,4 +44,9 @@ public interface CheckDataFactory { */ public ICheckData removeData(final String playerName); + /** + * Remove all data for all players. + */ + public void removeAllData(); + } diff --git a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java index 15dd3d31..88a57996 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java @@ -44,6 +44,11 @@ public class BlockBreakData extends ACheckData { public ICheckData removeData(final String playerName) { return BlockBreakData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; /** The map containing the data per players. */ @@ -65,6 +70,10 @@ public class BlockBreakData extends ACheckData { public static ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static void clear(){ + playersMap.clear(); + } // Violation levels. public double directionVL; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java b/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java index 2f41fab3..93f4bad6 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockinteract/BlockInteractData.java @@ -42,6 +42,11 @@ public class BlockInteractData extends ACheckData { public ICheckData removeData(final String playerName) { return BlockInteractData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; /** The map containing the data per players. */ @@ -63,6 +68,10 @@ public class BlockInteractData extends ACheckData { public static ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static void clear(){ + playersMap.clear(); + } // Violation levels. public double directionVL; diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java index e897fc91..a69397ea 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceData.java @@ -42,6 +42,11 @@ public class BlockPlaceData extends ACheckData { public ICheckData removeData(final String playerName) { return BlockPlaceData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; /** The map containing the data per players. */ @@ -63,6 +68,10 @@ public class BlockPlaceData extends ACheckData { public static ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static void clear(){ + playersMap.clear(); + } // Violation levels. public double directionVL; diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java index 2d933ffa..2c05fd5a 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatData.java @@ -35,6 +35,11 @@ public class ChatData extends AsyncCheckData { public ICheckData removeData(final String playerName) { return ChatData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; /** The map containing the data per players. */ @@ -47,15 +52,19 @@ public class ChatData extends AsyncCheckData { * the player * @return the data */ - public synchronized static ChatData getData(final Player player) { + public static synchronized ChatData getData(final Player player) { if (!playersMap.containsKey(player.getName())) playersMap.put(player.getName(), new ChatData()); return playersMap.get(player.getName()); } - public synchronized static ICheckData removeData(final String playerName) { + public static synchronized ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static synchronized void clear(){ + playersMap.clear(); + } // Violation levels. public double captchaVL; diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java index 15ca597a..b6016041 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java @@ -23,6 +23,11 @@ public class CombinedData extends ACheckData { public ICheckData removeData(final String playerName) { return CombinedData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; private static final Map playersMap = new HashMap(); @@ -40,6 +45,10 @@ public class CombinedData extends ACheckData { public static ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static void clear(){ + playersMap.clear(); + } public double improbableVL = 0; public double speedVL = 0; diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java b/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java index 8a90c4e4..d691f8c2 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/FightData.java @@ -38,6 +38,11 @@ public class FightData extends ACheckData { public ICheckData removeData(final String playerName) { return FightData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; /** The map containing the data per players. */ @@ -59,6 +64,10 @@ public class FightData extends ACheckData { public static ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static void clear(){ + playersMap.clear(); + } // Violation levels. public double angleVL; diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java index 59549da8..e9f2aeec 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java @@ -36,6 +36,11 @@ public class InventoryData extends ACheckData { public ICheckData removeData(final String playerName) { return InventoryData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; /** The map containing the data per players. */ @@ -57,6 +62,10 @@ public class InventoryData extends ACheckData { public static ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static void clear(){ + playersMap.clear(); + } // Violation levels. public double dropVL; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 2f73f0c7..d31abdf0 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -37,6 +37,11 @@ public class MovingData extends ACheckData { public ICheckData removeData(final String playerName) { return MovingData.removeData(playerName); } + + @Override + public void removeAllData() { + clear(); + } }; /** The map containing the data per players. */ @@ -58,6 +63,10 @@ public class MovingData extends ACheckData { public static ICheckData removeData(final String playerName) { return playersMap.remove(playerName); } + + public static void clear(){ + playersMap.clear(); + } // Violation levels. public double creativeFlyVL = 0D; diff --git a/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java b/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java index 552990f5..ebf4eee8 100644 --- a/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java +++ b/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java @@ -40,6 +40,12 @@ public class RemovePlayerCommand extends NCPCommand { } else checkType = CheckType.ALL; + if (playerName.equals("*")){ + DataManager.clear(checkType); + sender.sendMessage(TAG + "Removed all data and history: " + checkType); + return true; + } + final Player player = Bukkit.getPlayerExact(playerName); if (player != null) playerName = player.getName(); diff --git a/src/fr/neatmonster/nocheatplus/players/DataManager.java b/src/fr/neatmonster/nocheatplus/players/DataManager.java index ca31bbef..b439604c 100644 --- a/src/fr/neatmonster/nocheatplus/players/DataManager.java +++ b/src/fr/neatmonster/nocheatplus/players/DataManager.java @@ -1,6 +1,7 @@ package fr.neatmonster.nocheatplus.players; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -122,4 +123,22 @@ public class DataManager implements Listener, INotifyReload, INeedConfig{ } return removed; } + + /** + * Remove data and history of all players for the given check type and sub checks. + * @param checkType + */ + public static void clear(final CheckType checkType) { + final Set factories = new HashSet(); + for (final CheckType type : APIUtils.getWithChildren(checkType)){ + final Map map = instance.executionHistories.get(type); + if (map != null) map.clear(); + final CheckDataFactory factory = type.getDataFactory(); + if (factory != null) factories.add(factory); + } + for (final CheckDataFactory factory : factories){ + factory.removeAllData(); + } + ViolationHistory.clear(checkType); + } }