From 17395cb7420ac21e4e3275bb585c34174e017997 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 3 Nov 2012 10:22:21 +0100 Subject: [PATCH] Deprecate CheckType.removeData(String, CheckType), move to DataManager. --- .../nocheatplus/checks/CheckType.java | 28 +++------------- .../command/admin/RemovePlayerCommand.java | 2 +- .../nocheatplus/players/DataManager.java | 32 +++++++++++++++++++ 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckType.java b/src/fr/neatmonster/nocheatplus/checks/CheckType.java index 0c938c1a..d67dadcf 100644 --- a/src/fr/neatmonster/nocheatplus/checks/CheckType.java +++ b/src/fr/neatmonster/nocheatplus/checks/CheckType.java @@ -1,8 +1,5 @@ package fr.neatmonster.nocheatplus.checks; -import java.util.HashSet; -import java.util.Set; - import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory; @@ -23,7 +20,7 @@ import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig; import fr.neatmonster.nocheatplus.checks.inventory.InventoryData; import fr.neatmonster.nocheatplus.checks.moving.MovingConfig; import fr.neatmonster.nocheatplus.checks.moving.MovingData; -import fr.neatmonster.nocheatplus.hooks.APIUtils; +import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.Permissions; /* @@ -238,29 +235,12 @@ public enum CheckType { /** * Remove the player data for a given player and a given check type. CheckType.ALL and null will be interpreted as removing all data.
+ * @deprecated Will be removed, use DataManager.removeData instead. * @param playerName * @param checkType * @return If any data was present. */ - public static boolean removeData(final String playerName, CheckType checkType) { - if (checkType == null) checkType = ALL; - - // Attempt for direct removal. - CheckDataFactory dataFactory = checkType.getDataFactory(); - if (dataFactory != null) return dataFactory.removeData(playerName) != null; - - // Remove all for which it seems necessary. - final Set factories = new HashSet(); - for (CheckType otherType : CheckType.values()){ - if (checkType == ALL || APIUtils.isParent(checkType, otherType)){ - final CheckDataFactory otherFactory = otherType.getDataFactory(); - if (otherFactory != null) factories.add(otherFactory); - } - } - boolean had = false; - for (final CheckDataFactory otherFactory : factories){ - if (otherFactory.removeData(playerName) != null) had = true; - } - return had; + public static boolean removeData(final String playerName, final CheckType checkType) { + return DataManager.removeData(playerName, checkType); } } \ No newline at end of file diff --git a/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java b/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java index 9142cdf6..74ddc234 100644 --- a/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java +++ b/src/fr/neatmonster/nocheatplus/command/admin/RemovePlayerCommand.java @@ -61,7 +61,7 @@ public class RemovePlayerCommand extends NCPCommand { if (DataManager.removeExecutionHistory(checkType, playerName)) histRemoved = true; - final boolean dataRemoved = CheckType.removeData(playerName, checkType) || DataManager.clearComponentData(checkType, playerName); + final boolean dataRemoved = DataManager.removeData(playerName, checkType); if (dataRemoved || histRemoved){ String which; diff --git a/src/fr/neatmonster/nocheatplus/players/DataManager.java b/src/fr/neatmonster/nocheatplus/players/DataManager.java index 1011c057..b15d335f 100644 --- a/src/fr/neatmonster/nocheatplus/players/DataManager.java +++ b/src/fr/neatmonster/nocheatplus/players/DataManager.java @@ -197,6 +197,38 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo ViolationHistory.clear(checkType); } + /** + * Remove the player data for a given player and a given check type. CheckType.ALL and null will be interpreted as removing all data.
+ * @param playerName + * @param checkType + * @return If any data was present. + */ + public static boolean removeData(final String playerName, CheckType checkType) { + if (checkType == null) checkType = CheckType.ALL; + + // Attempt for direct removal. + CheckDataFactory dataFactory = checkType.getDataFactory(); + if (dataFactory != null) return dataFactory.removeData(playerName) != null; + + // Remove all for which it seems necessary. + final Set factories = new HashSet(); + for (CheckType otherType : CheckType.values()){ + if (checkType == CheckType.ALL || APIUtils.isParent(checkType, otherType)){ + final CheckDataFactory otherFactory = otherType.getDataFactory(); + if (otherFactory != null) factories.add(otherFactory); + } + } + boolean had = false; + for (final CheckDataFactory otherFactory : factories){ + if (otherFactory.removeData(playerName) != null) had = true; + } + + // Check extended registered components. + if (clearComponentData(checkType, playerName)) had = true; + + return had; + } + /** * Clear player related data, only for registered components (not execution history, violation history, normal check data).
* That should at least go for chat engione data.