mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
Redesign
This commit is contained in:
parent
b700a99c52
commit
d59954d0f1
@ -123,16 +123,15 @@ public class McrankCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void sqlDisplay(CommandSender sender, String playerName) {
|
||||
//TODO: Localize messages
|
||||
// TODO: Localize messages
|
||||
if (mcMMO.queueManager.contains(sender.getName())) {
|
||||
sender.sendMessage(ChatColor.RED + "Please wait for your previous command to process");
|
||||
}
|
||||
|
||||
if (!mcMMO.queueManager.queue(new McRankAsync(playerName, sender))) {
|
||||
// This will only run if for some reason it is unable to add to the queue
|
||||
sender.sendMessage(ChatColor.RED + "Unable to add to queue.");
|
||||
sender.sendMessage(ChatColor.RED + "Queue is full");
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW + "Calculating mcMMO rankings...");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Calculating rankings...");
|
||||
}
|
||||
}
|
||||
|
@ -123,17 +123,15 @@ public class MctopCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void sqlDisplay(int page, String query, CommandSender sender) {
|
||||
//TODO: Localize messages
|
||||
// TODO: Localize messages
|
||||
if (mcMMO.queueManager.contains(sender.getName())) {
|
||||
sender.sendMessage(ChatColor.RED + "Please wait for your previous command to process");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mcMMO.queueManager.queue(new McTopAsync(page, query, sender))) {
|
||||
// This will only run if for some reason it is unable to add to the queue
|
||||
sender.sendMessage(ChatColor.RED + "Unable to add to queue.");
|
||||
sender.sendMessage(ChatColor.RED + "Queue is full");
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW + "Calculating mcMMO rankings...");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Calculating leaderboards...");
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,28 @@
|
||||
package com.gmail.nossr50.database.queuemanager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class AsyncQueueManager implements Runnable {
|
||||
private LinkedBlockingQueue<Queueable> queue;
|
||||
private boolean running;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
|
||||
public class AsyncQueueManager {
|
||||
|
||||
private List<Queue> queues;
|
||||
protected LinkedBlockingQueue<Queueable> queue;;
|
||||
|
||||
public AsyncQueueManager(BukkitScheduler scheduler, int number) {
|
||||
this.queues = new ArrayList<Queue>();
|
||||
|
||||
for (int i = 1; i <= number; i++) {
|
||||
Queue queue = new Queue();
|
||||
scheduler.runTaskAsynchronously(mcMMO.p, queue);
|
||||
this.queues.add(queue);
|
||||
}
|
||||
|
||||
public AsyncQueueManager() {
|
||||
this.queue = new LinkedBlockingQueue<Queueable>();
|
||||
this.running = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(running) {
|
||||
try {
|
||||
queue.take().run();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean queue(Queueable task) {
|
||||
@ -30,12 +33,6 @@ public class AsyncQueueManager implements Runnable {
|
||||
return queue.contains(new EqualString(player));
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
running = false;
|
||||
// Throw one more Queueable into queue to unblock take()
|
||||
queue.add(new EndThread());
|
||||
}
|
||||
|
||||
private class EqualString {
|
||||
private String player;
|
||||
|
||||
@ -46,18 +43,30 @@ public class AsyncQueueManager implements Runnable {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Queueable) {
|
||||
return ((Queueable)obj).getPlayer().equalsIgnoreCase(player);
|
||||
return ((Queueable) obj).getPlayer().equalsIgnoreCase(player);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class EndThread implements Queueable {
|
||||
public void disable() {
|
||||
for (Queue queueThread : queues) {
|
||||
queueThread.kill();
|
||||
}
|
||||
|
||||
for (int i = 0; i < queues.size(); i++) {
|
||||
queue.offer(new KillQueue());
|
||||
}
|
||||
}
|
||||
|
||||
public class KillQueue implements Queueable {
|
||||
@Override
|
||||
public void run() { }
|
||||
public void run() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayer() { return null; }
|
||||
public String getPlayer() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.gmail.nossr50.database.queuemanager;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
|
||||
public class Queue implements Runnable {
|
||||
private boolean running;
|
||||
|
||||
public Queue() {
|
||||
this.running = true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (running) {
|
||||
try {
|
||||
mcMMO.queueManager.queue.take().run();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
this.running = false;
|
||||
}
|
||||
}
|
@ -464,8 +464,7 @@ public class mcMMO extends JavaPlugin {
|
||||
scheduler.scheduleSyncRepeatingTask(this, new BleedTimerTask(), 40, 40);
|
||||
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
queueManager = new AsyncQueueManager();
|
||||
scheduler.runTaskAsynchronously(this, queueManager);
|
||||
queueManager = new AsyncQueueManager(scheduler, Config.getInstance().getQueueNumber());
|
||||
}
|
||||
|
||||
// Old & Powerless User remover
|
||||
|
Loading…
Reference in New Issue
Block a user