2016-03-30 15:42:36 +02:00
|
|
|
package com.gamingmesh.jobs.config;
|
2015-10-13 12:13:22 +02:00
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scoreboard.DisplaySlot;
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
import com.gamingmesh.jobs.Jobs;
|
2015-10-13 12:13:22 +02:00
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
public class ScboardManager {
|
2015-10-13 12:13:22 +02:00
|
|
|
|
2016-01-06 14:40:27 +01:00
|
|
|
private ConcurrentHashMap<String, Long> timerMap = new ConcurrentHashMap<String, Long>();
|
2016-08-08 16:36:56 +02:00
|
|
|
private Jobs plugin;
|
2015-10-13 12:13:22 +02:00
|
|
|
|
2016-08-08 16:36:56 +02:00
|
|
|
public ScboardManager(Jobs plugin) {
|
2016-01-06 14:40:27 +01:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
2015-10-13 12:13:22 +02:00
|
|
|
|
2016-01-06 14:40:27 +01:00
|
|
|
private void RunScheduler() {
|
2015-10-13 12:13:22 +02:00
|
|
|
Iterator<Entry<String, Long>> MeinMapIter = timerMap.entrySet().iterator();
|
|
|
|
while (MeinMapIter.hasNext()) {
|
|
|
|
Entry<String, Long> Map = MeinMapIter.next();
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
if (System.currentTimeMillis() > Map.getValue() + (Jobs.getGCManager().ToplistInScoreboardInterval * 1000)) {
|
2015-10-13 12:13:22 +02:00
|
|
|
Player player = Bukkit.getPlayer(Map.getKey());
|
|
|
|
if (player != null) {
|
|
|
|
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
|
|
|
|
}
|
|
|
|
timerMap.remove(Map.getKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timerMap.size() > 0)
|
2016-01-06 14:40:27 +01:00
|
|
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
2016-06-25 17:56:59 +02:00
|
|
|
@Override
|
2015-10-13 12:13:22 +02:00
|
|
|
public void run() {
|
|
|
|
RunScheduler();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}, 20L);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-06 14:40:27 +01:00
|
|
|
public void addNew(Player player) {
|
2015-10-13 12:13:22 +02:00
|
|
|
timerMap.put(player.getName(), System.currentTimeMillis());
|
|
|
|
RunScheduler();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|