Skip to content

Commit

Permalink
Seperate sudo-queueing and normal queueing on spigot side. `/queue <p…
Browse files Browse the repository at this point in the history
…layer> <server>` on the spigot side now acts the same as `/ajqueue send`
  • Loading branch information
ajgeiss0702 committed Jun 8, 2023
1 parent 80289de commit 2414c69
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
Expand Up @@ -22,13 +22,20 @@ public static AjQueueSpigotAPI getInstance() {
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
Expand Down
Expand Up @@ -4,7 +4,6 @@
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;
Expand Down Expand Up @@ -33,7 +32,8 @@ public CommunicationManager(QueueMain main) {
"inqueue", new InQueueHandler(main),
"queuedfor", new QueuedForHandler(main),
"status", new StatusHandler(main),
"playerstatus", new PlayerStatusHandler(main)
"playerstatus", new PlayerStatusHandler(main),
"serverqueue", new ServerQueueHandler(main)
);
}

Expand Down
Expand Up @@ -7,6 +7,9 @@
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;

Expand Down
@@ -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));
}
}
36 changes: 25 additions & 11 deletions spigot/src/main/java/us/ajg0702/queue/spigot/Commands.java
Expand Up @@ -7,6 +7,7 @@
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 {

Expand Down Expand Up @@ -42,34 +43,47 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
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) {
sender.sendMessage("I need to know what player to send!");
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;
Expand Down
20 changes: 19 additions & 1 deletion spigot/src/main/java/us/ajg0702/queue/spigot/api/SpigotAPI.java
Expand Up @@ -38,7 +38,25 @@ public Future<Boolean> isInQueue(UUID player) {

@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
Expand Down

0 comments on commit 2414c69

Please sign in to comment.