Synchronisation des méthodes du gestionnaire de file d'attente /staff + mise à jour automatique de la file d'attente /staff depuis la base de données
This commit is contained in:
parent
b82b4a2e4b
commit
c0dae89dbe
@ -35,28 +35,20 @@ public class StaffQueueManager {
|
|||||||
private Scoreboard scoreboardPlayerQueue = Bukkit.getScoreboardManager().getNewScoreboard();
|
private Scoreboard scoreboardPlayerQueue = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public StaffQueueManager() {
|
public StaffQueueManager() {
|
||||||
|
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||||
try {
|
|
||||||
List<StaffTicketElement> elmts = ORM.getTable(StaffTicketTable.class).getAll(null, "creationTime ASC, id ASC", null, null);
|
|
||||||
|
|
||||||
for (StaffTicketElement el : elmts)
|
@Override
|
||||||
playerQueue.add(new WaitingPlayer(el));
|
public void run() {
|
||||||
|
updateQueueFromDB();
|
||||||
} catch (SQLException e) {
|
}
|
||||||
// TODO Auto-generated catch block
|
}, 1, 30*20);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateScoreBoardWaitingList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// le joueur ajouté doit-être en ligne
|
// 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
|
if (getWaitingPlayer(p) != null) return; // le joueur est déjà dans la file
|
||||||
playerQueue.add(new WaitingPlayer(p.getName(), m, p.getLocation()));
|
playerQueue.add(new WaitingPlayer(p.getName(), m, p.getLocation()));
|
||||||
updateScoreBoardWaitingList();
|
updateScoreBoardWaitingList();
|
||||||
@ -66,7 +58,7 @@ public class StaffQueueManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public WaitingPlayer getWaitingPlayer(String p) {
|
public synchronized WaitingPlayer getWaitingPlayer(String p) {
|
||||||
for (WaitingPlayer wp : playerQueue)
|
for (WaitingPlayer wp : playerQueue)
|
||||||
{
|
{
|
||||||
if (wp != null && wp.getPlayerName().equalsIgnoreCase(p))
|
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());
|
return getWaitingPlayer(p.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int getPlayerPosition(OfflinePlayer p) {
|
public synchronized int getPlayerPosition(OfflinePlayer p) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (WaitingPlayer wp : playerQueue)
|
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);
|
WaitingPlayer wp = getWaitingPlayer(p);
|
||||||
if (wp != null)
|
if (wp != null)
|
||||||
{
|
{
|
||||||
@ -105,7 +97,7 @@ public class StaffQueueManager {
|
|||||||
updateScoreBoardWaitingList();
|
updateScoreBoardWaitingList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void removePlayer(OfflinePlayer p) {
|
public synchronized void removePlayer(OfflinePlayer p) {
|
||||||
removePlayer(p.getName());
|
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();
|
String staffName = staffPlayer.getName();
|
||||||
for (WaitingPlayer wp : playerQueue)
|
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
|
// contient les joueurs qui sont associés à un membre du staff
|
||||||
ArrayList<String> selectedPlayers = new ArrayList<String>();
|
ArrayList<String> selectedPlayers = new ArrayList<String>();
|
||||||
@ -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 ---");
|
sender.sendMessage(ChatColor.BOLD+"--- File d'attente des joueurs pour le staff ---");
|
||||||
@ -198,7 +190,7 @@ public class StaffQueueManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<String> getWaitingPlayerNames() {
|
public synchronized List<String> getWaitingPlayerNames() {
|
||||||
List<String> l = new ArrayList<String>();
|
List<String> l = new ArrayList<String>();
|
||||||
|
|
||||||
for (WaitingPlayer wp : playerQueue) {
|
for (WaitingPlayer wp : playerQueue) {
|
||||||
@ -214,6 +206,22 @@ public class StaffQueueManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public synchronized void updateQueueFromDB() {
|
||||||
|
try {
|
||||||
|
List<StaffTicketElement> 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();
|
Player p = event.getPlayer();
|
||||||
if (OnlinePlayerManager.get(p).isInStaff())
|
if (OnlinePlayerManager.get(p).isInStaff())
|
||||||
p.setScoreboard(scoreboardPlayerQueue);
|
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
|
// on vérifie si un membre du staff se déconnecte
|
||||||
for (WaitingPlayer wp : playerQueue) {
|
for (WaitingPlayer wp : playerQueue) {
|
||||||
|
Loading…
Reference in New Issue
Block a user