From 2901ac3abc97d7001e340e9b83a1c3d1780f7dcb Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 3 Nov 2012 13:15:29 +0100 Subject: [PATCH] Javadoc/comments. --- .../nocheatplus/players/DataManager.java | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/players/DataManager.java b/src/fr/neatmonster/nocheatplus/players/DataManager.java index 1e307e48..a5539dfb 100644 --- a/src/fr/neatmonster/nocheatplus/players/DataManager.java +++ b/src/fr/neatmonster/nocheatplus/players/DataManager.java @@ -40,6 +40,14 @@ import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.hooks.APIUtils; +/** + * Central access point for a lot of functionality for managing data, especially removing data for cleanup.
+ * Originally intended as temporary or intermediate design, this might help reorganizing the API at some point.
+ * However i could not yet find a pleasing way for generic configuration access for a centralized data management (all in one), + * so this might just be a workarounds class for coping with the current design, until somehow resolved in another way. + * @author mc_dev + * + */ public class DataManager implements Listener, INotifyReload, INeedConfig, IComponentRegistry{ protected static DataManager instance = null; @@ -65,15 +73,28 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo */ protected final Map> executionHistories = new HashMap>(); + /** + * Duration in milliseconds for expiration of logged off players data. + * Disabled with 0, in the config minutes are used as unit. + */ protected long durExpireData = 0; + /** Data and execution history. */ protected boolean deleteData = true; + /** Violation history and execution history. */ protected boolean deleteHistory = false; + /** + * Sets the static instance reference. + */ public DataManager(){ instance = this; } + /** + * Check the logged out players for if any data can be removed.
+ * Currently only "dumb" full removal is performed. Later it is thinkable to remove "as much as reasonable". + */ public void checkExpiration(){ if (durExpireData <= 0) return; final long now = System.currentTimeMillis(); @@ -119,6 +140,10 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo onLeave(event.getPlayer()); } + /** + * Quit or kick. + * @param player + */ private final void onLeave(final Player player) { final long now = System.currentTimeMillis(); lastLogout.put(player.getName(), now); @@ -127,10 +152,13 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo @Override public void onReload() { - // future + // present. adjustSettings(); } + /** + * Fetch settings from the current default config. + */ private void adjustSettings() { final ConfigFile config = ConfigManager.getConfigFile(); durExpireData = config.getLong(ConfPaths.DATA_EXPIRATION_DURATION) * 60000L; // in minutes @@ -138,6 +166,12 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo deleteHistory = config.getBoolean(ConfPaths.DATA_EXPIRATION_HISTORY); } + /** + * Used by checks to register the history for external access.
+ * NOTE: This method is not really meant ot be used from outside NCP. + * @param type + * @param histories + */ public static void registerExecutionHistory(CheckType type, Map histories) { instance.executionHistories.put(type, histories); } @@ -154,6 +188,12 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo return null; } + /** + * Remove the execution history for a player for the given check type. + * @param type + * @param playerName + * @return + */ public static boolean removeExecutionHistory(final CheckType type, final String playerName){ boolean removed = false; // TODO: design ... @@ -199,8 +239,8 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo /** * 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 + * @param playerName Exact player name. + * @param checkType Check type to remove data for, null is regarded as ALL. * @return If any data was present. */ public static boolean removeData(final String playerName, CheckType checkType) { @@ -226,7 +266,7 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo /** * 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. + * That should at least go for chat engine data. * @param CheckType * @param PlayerName * @return If something was removed. @@ -276,7 +316,7 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, ICompo } /** - * Cleanup method. + * Cleanup method, removes all data and config, but does not call ConfigManager.cleanup. */ public void onDisable() { clearData(CheckType.ALL);