Seperate sudo-queueing and normal queueing on spigot side. /queue <player> <server> on the spigot side now acts the same as /ajqueue send
This commit is contained in:
@@ -22,13 +22,20 @@ public abstract class AjQueueSpigotAPI {
|
||||
public abstract Future<Boolean> isInQueue(UUID player);
|
||||
|
||||
/**
|
||||
* Adds a player to a queue
|
||||
* Adds a player to a queue (bypassing any permission checks that would prevent it)
|
||||
* @param player The player to be added
|
||||
* @param queueName The server or group to add the player to
|
||||
* @return True if adding was successful, false if not.
|
||||
*/
|
||||
public abstract Future<Boolean> addToQueue(UUID player, String queueName);
|
||||
|
||||
/**
|
||||
* Emulate the player running the queue command for a certain server, including any permission checks
|
||||
* @param player The player to sudo the command for
|
||||
* @param queueName The queue to send the player to
|
||||
*/
|
||||
public abstract void sudoQueue(UUID player, String queueName);
|
||||
|
||||
/**
|
||||
* Gets the name of the queue that the player is in
|
||||
* @param player the player
|
||||
|
||||
+2
-2
@@ -4,7 +4,6 @@ import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.common.communication.handlers.*;
|
||||
import us.ajg0702.queue.common.utils.Debug;
|
||||
import us.ajg0702.queue.common.utils.MapBuilder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -33,7 +32,8 @@ public class CommunicationManager {
|
||||
"inqueue", new InQueueHandler(main),
|
||||
"queuedfor", new QueuedForHandler(main),
|
||||
"status", new StatusHandler(main),
|
||||
"playerstatus", new PlayerStatusHandler(main)
|
||||
"playerstatus", new PlayerStatusHandler(main),
|
||||
"serverqueue", new ServerQueueHandler(main)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
/**
|
||||
* Actually SudoQueue. Confusing naming is due to legacy support and will be removed next major revision.
|
||||
*/
|
||||
public class QueueHandler extends MessageHandler {
|
||||
private final IBaseCommand moveCommand;
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class ServerQueueHandler extends MessageHandler {
|
||||
public ServerQueueHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().findServer(data);
|
||||
if(server == null) {
|
||||
return ComResponse
|
||||
.from("serverqueue")
|
||||
.id(player.getUniqueId())
|
||||
.with("invalid_server");
|
||||
}
|
||||
return ComResponse
|
||||
.from("serverqueue")
|
||||
.id(player.getUniqueId())
|
||||
.with(main.getQueueManager().addToQueue(player, server));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import us.ajg0702.queue.api.spigot.AjQueueSpigotAPI;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
@@ -42,23 +43,32 @@ public class Commands implements CommandExecutor {
|
||||
pl.sendMessage(player, "leavequeue", arg.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Queue command
|
||||
|
||||
|
||||
if(args.length < 1) return false;
|
||||
|
||||
String srvname = args[0];
|
||||
|
||||
|
||||
String serverName = args[0];
|
||||
|
||||
boolean sudo = true;
|
||||
|
||||
// /queue <player> <server>
|
||||
if(args.length > 1) {
|
||||
pl.getLogger().info("Sending "+args[0]+" to queue '" + args[1] + "'");
|
||||
sudo = false;
|
||||
if(!sender.hasPermission("ajqueue.send")) {
|
||||
sender.sendMessage(color("&cYou do not have permission to do this!"));
|
||||
return true;
|
||||
}
|
||||
Player tply = Bukkit.getPlayer(args[0]);
|
||||
if(tply == null) {
|
||||
pl.getLogger().info("Sending "+args[0]+" to queue '" + args[1] + "'");
|
||||
Player playerToSend = Bukkit.getPlayer(args[0]);
|
||||
if(playerToSend == null) {
|
||||
sender.sendMessage(color("&cCannot find that player!"));
|
||||
return true;
|
||||
}
|
||||
player = tply;
|
||||
srvname = args[1];
|
||||
player = playerToSend;
|
||||
serverName = args[1];
|
||||
}
|
||||
|
||||
if(player == null) {
|
||||
@@ -66,10 +76,14 @@ public class Commands implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(pl.getAConfig().getBoolean("send-queue-commands-in-batches")) {
|
||||
pl.queuebatch.put(player, srvname);
|
||||
if(sudo) {
|
||||
if(pl.getAConfig().getBoolean("send-queue-commands-in-batches")) {
|
||||
pl.queuebatch.put(player, serverName);
|
||||
} else {
|
||||
AjQueueSpigotAPI.getInstance().sudoQueue(player.getUniqueId(), serverName);
|
||||
}
|
||||
} else {
|
||||
pl.sendMessage(player, "queue", srvname);
|
||||
AjQueueSpigotAPI.getInstance().addToQueue(player.getUniqueId(), serverName);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -38,7 +38,25 @@ public class SpigotAPI extends AjQueueSpigotAPI {
|
||||
|
||||
@Override
|
||||
public Future<Boolean> addToQueue(UUID player, String queueName) {
|
||||
throw new UnsupportedOperationException("Not yet implemented!");
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if(p == null) throw new IllegalArgumentException("Player must be online!");
|
||||
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
|
||||
responseManager.awaitResponse(player.toString(), "serverqueue", response -> {
|
||||
future.complete(Boolean.valueOf(response.getResponse()));
|
||||
});
|
||||
|
||||
main.sendMessage(p, "serverqueue", queueName);
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sudoQueue(UUID player, String queueName) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if(p == null) throw new IllegalArgumentException("Player must be online!");
|
||||
main.sendMessage(p, "queue", queueName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user