Added /ajq pausequeueserver command, which will temporarily not queue you when you are in queue-servers
This commit is contained in:
@@ -3,8 +3,15 @@ package us.ajg0702.queue.api.commands;
|
|||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import us.ajg0702.queue.api.util.Handle;
|
import us.ajg0702.queue.api.util.Handle;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
public interface ICommandSender extends Handle, Audience {
|
public interface ICommandSender extends Handle, Audience {
|
||||||
boolean hasPermission(String permission);
|
boolean hasPermission(String permission);
|
||||||
boolean isPlayer();
|
boolean isPlayer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws IllegalStateException if the sender is not a player
|
||||||
|
*/
|
||||||
|
UUID getUniqueId() throws IllegalStateException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package us.ajg0702.queue.commands.commands;
|
|||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerSender implements ICommandSender {
|
public class PlayerSender implements ICommandSender {
|
||||||
|
|
||||||
final AdaptedPlayer handle;
|
final AdaptedPlayer handle;
|
||||||
@@ -21,6 +23,11 @@ public class PlayerSender implements ICommandSender {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() throws IllegalStateException {
|
||||||
|
return handle.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AdaptedPlayer getHandle() {
|
public AdaptedPlayer getHandle() {
|
||||||
return handle;
|
return handle;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ public class ManageCommand extends BaseCommand {
|
|||||||
addSubCommand(new Update(main));
|
addSubCommand(new Update(main));
|
||||||
addSubCommand(new Kick(main));
|
addSubCommand(new Kick(main));
|
||||||
addSubCommand(new KickAll(main));
|
addSubCommand(new KickAll(main));
|
||||||
|
addSubCommand(new PauseQueueServer(main));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package us.ajg0702.queue.commands.commands.manage;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
|
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||||
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
import us.ajg0702.queue.commands.SubCommand;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.queue.common.utils.Debug;
|
||||||
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class PauseQueueServer extends SubCommand {
|
||||||
|
|
||||||
|
public static final List<AdaptedPlayer> pausedPlayers = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
final QueueMain main;
|
||||||
|
public PauseQueueServer(QueueMain main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "pausequeueserver";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<String> getAliases() {
|
||||||
|
return ImmutableList.of("pauseqs");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<ISubCommand> getSubCommands() {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "ajqueue.manage.pausequeueserver";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean showInTabComplete() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Messages getMessages() {
|
||||||
|
return main.getMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
|
if(!checkPermission(sender)) return;
|
||||||
|
|
||||||
|
if(!sender.isPlayer()) {
|
||||||
|
sender.sendMessage(getMessages().getComponent("errors.player-only"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdaptedPlayer player = main.getPlatformMethods().getPlayer(sender.getUniqueId());
|
||||||
|
if(pausedPlayers.contains(player)) {
|
||||||
|
pausedPlayers.remove(player);
|
||||||
|
sender.sendMessage(getMessages().getComponent("commands.pausequeueserver.unpaused"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pausedPlayers.add(player);
|
||||||
|
sender.sendMessage(getMessages().getComponent("commands.pausequeueserver.paused"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import us.ajg0702.queue.api.players.QueuePlayer;
|
|||||||
import us.ajg0702.queue.api.queues.QueueServer;
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||||
|
import us.ajg0702.queue.commands.commands.manage.PauseQueueServer;
|
||||||
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||||
import us.ajg0702.queue.common.utils.Debug;
|
import us.ajg0702.queue.common.utils.Debug;
|
||||||
import us.ajg0702.utils.common.TimeUtils;
|
import us.ajg0702.utils.common.TimeUtils;
|
||||||
@@ -195,15 +196,17 @@ public class EventHandlerImpl implements EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String serverName = player.getServerName();
|
if(!PauseQueueServer.pausedPlayers.contains(player)) {
|
||||||
List<String> svs = main.getConfig().getStringList("queue-servers");
|
String serverName = player.getServerName();
|
||||||
for(String s : svs) {
|
List<String> svs = main.getConfig().getStringList("queue-servers");
|
||||||
if(!s.contains(":")) continue;
|
for(String s : svs) {
|
||||||
String[] parts = s.split(":");
|
if(!s.contains(":")) continue;
|
||||||
String from = parts[0];
|
String[] parts = s.split(":");
|
||||||
QueueServer to = main.getQueueManager().findServer(parts[1]);
|
String from = parts[0];
|
||||||
if(from.equalsIgnoreCase(serverName) && to != null) {
|
QueueServer to = main.getQueueManager().findServer(parts[1]);
|
||||||
main.getQueueManager().addToQueue(player, to);
|
if(from.equalsIgnoreCase(serverName) && to != null) {
|
||||||
|
main.getQueueManager().addToQueue(player, to);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -222,6 +222,9 @@ public class QueueMain extends AjQueueAPI {
|
|||||||
d.put("commands.kick.success", "<green>Kicked <white>{PLAYER} <green>from {NUM} queue{s}!");
|
d.put("commands.kick.success", "<green>Kicked <white>{PLAYER} <green>from {NUM} queue{s}!");
|
||||||
d.put("commands.kickall.usage", "<red>Usage: /ajqueue kickall <queue>");
|
d.put("commands.kickall.usage", "<red>Usage: /ajqueue kickall <queue>");
|
||||||
d.put("commands.kickall.success", "<green>Kicked <white>{NUM} <green>player{s} from <white>{SERVER}<green>!");
|
d.put("commands.kickall.success", "<green>Kicked <white>{NUM} <green>player{s} from <white>{SERVER}<green>!");
|
||||||
|
d.put("commands.pausequeueserver.unpaused", "<green>You are no longer paused! <gray>You can now use queue-servers normally.");
|
||||||
|
d.put("commands.pausequeueserver.paused", "<green>You are now paused! <gray>You will no longer be sent using queue-servers.");
|
||||||
|
d.put("commands.pausequeueserver.reminder", "<gold>Reminder: <yellow>You are currently paused for queue-servers, so you will not be sent using them!<gray> Use <white>/ajQueue pausequeueserver</white> to un-pause and return to normal behaviour");
|
||||||
|
|
||||||
d.put("noperm", "&cYou do not have permission to do this!");
|
d.put("noperm", "&cYou do not have permission to do this!");
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import us.ajg0702.queue.api.players.QueuePlayer;
|
|||||||
import us.ajg0702.queue.api.premium.Logic;
|
import us.ajg0702.queue.api.premium.Logic;
|
||||||
import us.ajg0702.queue.api.queues.QueueServer;
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
|
import us.ajg0702.queue.commands.commands.manage.PauseQueueServer;
|
||||||
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||||
import us.ajg0702.queue.common.queues.QueueServerImpl;
|
import us.ajg0702.queue.common.queues.QueueServerImpl;
|
||||||
import us.ajg0702.queue.common.utils.Debug;
|
import us.ajg0702.queue.common.utils.Debug;
|
||||||
@@ -427,6 +428,8 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final Map<AdaptedPlayer, Long> pausedAntiSpam = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendQueueEvents() {
|
public void sendQueueEvents() {
|
||||||
if(main.getConfig().getBoolean("force-queue-server-target")) {
|
if(main.getConfig().getBoolean("force-queue-server-target")) {
|
||||||
@@ -440,6 +443,14 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
QueueServer to = findServer(toName);
|
QueueServer to = findServer(toName);
|
||||||
if(from == null || to == null) continue;
|
if(from == null || to == null) continue;
|
||||||
from.getPlayers().forEach(player -> {
|
from.getPlayers().forEach(player -> {
|
||||||
|
if(PauseQueueServer.pausedPlayers.contains(player)) {
|
||||||
|
long lastReminder = pausedAntiSpam.getOrDefault(player, 0L);
|
||||||
|
if(System.currentTimeMillis() - lastReminder > 60e3) { // 60 second cooldown on the reminder messages
|
||||||
|
player.sendMessage(main.getMessages().getComponent("commands.pausequeueserver.reminder"));
|
||||||
|
pausedAntiSpam.put(player, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!getPlayerQueues(player).contains(to)) {
|
if(!getPlayerQueues(player).contains(to)) {
|
||||||
addToQueue(player, to);
|
addToQueue(player, to);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -8,6 +8,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
import us.ajg0702.queue.platforms.bungeecord.BungeeQueue;
|
import us.ajg0702.queue.platforms.bungeecord.BungeeQueue;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BungeeSender implements ICommandSender {
|
public class BungeeSender implements ICommandSender {
|
||||||
|
|
||||||
final CommandSender handle;
|
final CommandSender handle;
|
||||||
@@ -27,6 +29,12 @@ public class BungeeSender implements ICommandSender {
|
|||||||
return handle instanceof ProxiedPlayer;
|
return handle instanceof ProxiedPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() throws IllegalStateException {
|
||||||
|
if(!(handle instanceof ProxiedPlayer)) throw new IllegalStateException("Cannot get UUID of non-player!");
|
||||||
|
return ((ProxiedPlayer) handle).getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(@NotNull Component message) {
|
public void sendMessage(@NotNull Component message) {
|
||||||
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
|
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
|
||||||
|
|||||||
+14
@@ -20,6 +20,7 @@ import us.ajg0702.queue.platforms.bungeecord.server.BungeeServer;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BungeePlayer implements AdaptedPlayer, Audience {
|
public class BungeePlayer implements AdaptedPlayer, Audience {
|
||||||
@@ -172,4 +173,17 @@ public class BungeePlayer implements AdaptedPlayer, Audience {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
BungeePlayer that = (BungeePlayer) o;
|
||||||
|
return handle.equals(that.handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -2,11 +2,14 @@ package us.ajg0702.queue.platforms.velocity.commands;
|
|||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class VelocitySender implements ICommandSender {
|
public class VelocitySender implements ICommandSender {
|
||||||
|
|
||||||
final CommandSource handle;
|
final CommandSource handle;
|
||||||
@@ -26,6 +29,12 @@ public class VelocitySender implements ICommandSender {
|
|||||||
return !(handle instanceof ConsoleCommandSource);
|
return !(handle instanceof ConsoleCommandSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() throws IllegalStateException {
|
||||||
|
if(!(handle instanceof Player)) throw new IllegalStateException("Cannot get UUID of non-player!");
|
||||||
|
return ((Player) handle).getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(@NotNull Component message) {
|
public void sendMessage(@NotNull Component message) {
|
||||||
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
|
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
|
||||||
|
|||||||
+14
@@ -18,6 +18,7 @@ import us.ajg0702.queue.common.QueueMain;
|
|||||||
import us.ajg0702.queue.common.utils.Debug;
|
import us.ajg0702.queue.common.utils.Debug;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -205,4 +206,17 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
VelocityPlayer that = (VelocityPlayer) o;
|
||||||
|
return handle.equals(that.handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user