/** called by above methods to clean out original locations list periodically */ protected void pruneOriginalLocations() { long maxTime = SimpleSpleef.getPlugin().getConfig().getInt("keepOriginalLocationsSeconds", 3600); if (maxTime < 0) return; // should not happen... long checkTime = (System.currentTimeMillis() / 1000) - maxTime; // delete entries that are too old for (Entry<String, PlayerOriginalLocation> entry : playerOriginalLocations.entrySet()) { if (entry.getValue().timestamp < checkTime) // remove entries that // are too old playerOriginalLocations.remove(entry.getKey()); } }
/** * save original position of player - possibly, because it is possible that there is an original * position saved already * * @param player */ public void keepPosition(Player player) { long maxTime = SimpleSpleef.getPlugin().getConfig().getInt("keepOriginalLocationsSeconds", 3600); if (maxTime < 0) return; // should not happen... // prune first pruneOriginalLocations(); String playerName = player.getName(); // already in list? => delete old etry if (playerOriginalLocations.containsKey(playerName)) updateOriginalLocationTimestamp(player); // add position else { PlayerOriginalLocation loc = new PlayerOriginalLocation(); loc.timestamp = System.currentTimeMillis() / 1000; loc.location = player.getLocation().clone(); playerOriginalLocations.put(player.getName(), loc); } }