summaryrefslogtreecommitdiffstats
path: root/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java')
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java
new file mode 100644
index 000000000..7a13628c6
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java
@@ -0,0 +1,80 @@
+package com.earth2me.essentials.anticheat.data;
+
+import com.earth2me.essentials.anticheat.NoCheat;
+import com.earth2me.essentials.anticheat.NoCheatPlayer;
+import com.earth2me.essentials.anticheat.player.NoCheatPlayerImpl;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.bukkit.entity.Player;
+
+
+/**
+ * Provide secure access to player-specific data objects for various checks or check groups.
+ */
+public class PlayerManager
+{
+ // Store data between Events
+ private final Map<String, NoCheatPlayerImpl> players;
+ private final NoCheat plugin;
+
+ public PlayerManager(NoCheat plugin)
+ {
+ this.players = new HashMap<String, NoCheatPlayerImpl>();
+ this.plugin = plugin;
+ }
+
+ /**
+ * Get a data object of the specified class. If none is stored yet, create one.
+ */
+ public NoCheatPlayer getPlayer(Player player)
+ {
+
+ NoCheatPlayerImpl p = this.players.get(player.getName().toLowerCase());
+
+ if (p == null)
+ {
+ p = new NoCheatPlayerImpl(player, plugin);
+ this.players.put(player.getName().toLowerCase(), p);
+ }
+
+ p.setLastUsedTime(System.currentTimeMillis());
+ p.refresh(player);
+
+ return p;
+ }
+
+ public void cleanDataMap()
+ {
+ long time = System.currentTimeMillis();
+ List<String> removals = new ArrayList<String>(5);
+
+ for (Entry<String, NoCheatPlayerImpl> e : this.players.entrySet())
+ {
+ if (e.getValue().shouldBeRemoved(time))
+ {
+ removals.add(e.getKey());
+ }
+ }
+
+ for (String key : removals)
+ {
+ this.players.remove(key);
+ }
+ }
+
+ public Map<String, Object> getPlayerData(String playerName)
+ {
+
+ NoCheatPlayer player = this.players.get(playerName.toLowerCase());
+
+ if (player != null)
+ {
+ return player.getDataStore().collectData();
+ }
+
+ return new HashMap<String, Object>();
+ }
+}