diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java index beec9c3..69693c4 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java @@ -35,28 +35,20 @@ public class StaffQueueManager { private Scoreboard scoreboardPlayerQueue = Bukkit.getScoreboardManager().getNewScoreboard(); - public StaffQueueManager() { - - try { - List elmts = ORM.getTable(StaffTicketTable.class).getAll(null, "creationTime ASC, id ASC", null, null); + plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { - for (StaffTicketElement el : elmts) - playerQueue.add(new WaitingPlayer(el)); - - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - updateScoreBoardWaitingList(); + @Override + public void run() { + updateQueueFromDB(); + } + }, 1, 30*20); } - // le joueur ajouté doit-être en ligne - public void addWaitingPlayer(Player p, String m) { + public synchronized void addWaitingPlayer(Player p, String m) { if (getWaitingPlayer(p) != null) return; // le joueur est déjà dans la file playerQueue.add(new WaitingPlayer(p.getName(), m, p.getLocation())); updateScoreBoardWaitingList(); @@ -66,7 +58,7 @@ public class StaffQueueManager { - public WaitingPlayer getWaitingPlayer(String p) { + public synchronized WaitingPlayer getWaitingPlayer(String p) { for (WaitingPlayer wp : playerQueue) { if (wp != null && wp.getPlayerName().equalsIgnoreCase(p)) @@ -76,14 +68,14 @@ public class StaffQueueManager { } - public WaitingPlayer getWaitingPlayer(OfflinePlayer p) { + public synchronized WaitingPlayer getWaitingPlayer(OfflinePlayer p) { return getWaitingPlayer(p.getName()); } - public int getPlayerPosition(OfflinePlayer p) { + public synchronized int getPlayerPosition(OfflinePlayer p) { int i = 0; for (WaitingPlayer wp : playerQueue) { @@ -96,7 +88,7 @@ public class StaffQueueManager { - public void removePlayer(String p) { + public synchronized void removePlayer(String p) { WaitingPlayer wp = getWaitingPlayer(p); if (wp != null) { @@ -105,7 +97,7 @@ public class StaffQueueManager { updateScoreBoardWaitingList(); } } - public void removePlayer(OfflinePlayer p) { + public synchronized void removePlayer(OfflinePlayer p) { removePlayer(p.getName()); } @@ -113,7 +105,7 @@ public class StaffQueueManager { - public WaitingPlayer getSelectedWaitingPlayer(Player staffPlayer) { + public synchronized WaitingPlayer getSelectedWaitingPlayer(Player staffPlayer) { String staffName = staffPlayer.getName(); for (WaitingPlayer wp : playerQueue) { @@ -127,7 +119,7 @@ public class StaffQueueManager { - public void updateScoreBoardWaitingList() { + public synchronized void updateScoreBoardWaitingList() { // contient les joueurs qui sont associés à un membre du staff ArrayList selectedPlayers = new ArrayList(); @@ -171,7 +163,7 @@ public class StaffQueueManager { - public void showWaintingList(CommandSender sender) { + public synchronized void showWaintingList(CommandSender sender) { sender.sendMessage(ChatColor.BOLD+"--- File d'attente des joueurs pour le staff ---"); @@ -198,7 +190,7 @@ public class StaffQueueManager { - public List getWaitingPlayerNames() { + public synchronized List getWaitingPlayerNames() { List l = new ArrayList(); for (WaitingPlayer wp : playerQueue) { @@ -214,6 +206,22 @@ public class StaffQueueManager { + public synchronized void updateQueueFromDB() { + try { + List elmts = ORM.getTable(StaffTicketTable.class).getAll(null, "creationTime ASC, id ASC", null, null); + + playerQueue.clear(); + + for (StaffTicketElement el : elmts) + playerQueue.add(new WaitingPlayer(el)); + + updateScoreBoardWaitingList(); + + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } @@ -221,7 +229,14 @@ public class StaffQueueManager { - public void onPlayerJoin(PlayerJoinEvent event) { + + + + + + + + public synchronized void onPlayerJoin(PlayerJoinEvent event) { Player p = event.getPlayer(); if (OnlinePlayerManager.get(p).isInStaff()) p.setScoreboard(scoreboardPlayerQueue); @@ -232,7 +247,7 @@ public class StaffQueueManager { } - public void onPlayerQuit(PlayerQuitEvent event) { + public synchronized void onPlayerQuit(PlayerQuitEvent event) { // on vérifie si un membre du staff se déconnecte for (WaitingPlayer wp : playerQueue) {