@@ -3,8 +3,15 @@ package us.ajg0702.queue.api.commands;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import us.ajg0702.queue.api.util.Handle;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public interface ICommandSender extends Handle, Audience {
|
||||
boolean hasPermission(String permission);
|
||||
boolean isPlayer();
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if the sender is not a player
|
||||
*/
|
||||
UUID getUniqueId() throws IllegalStateException;
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ repositories {
|
||||
}
|
||||
|
||||
allprojects {
|
||||
version = "2.3.0"
|
||||
version = "2.3.1"
|
||||
group = "us.ajg0702"
|
||||
|
||||
plugins.apply("java")
|
||||
|
||||
@@ -3,6 +3,8 @@ package us.ajg0702.queue.commands.commands;
|
||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerSender implements ICommandSender {
|
||||
|
||||
final AdaptedPlayer handle;
|
||||
@@ -21,6 +23,11 @@ public class PlayerSender implements ICommandSender {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() throws IllegalStateException {
|
||||
return handle.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdaptedPlayer getHandle() {
|
||||
return handle;
|
||||
|
||||
@@ -37,6 +37,7 @@ public class ManageCommand extends BaseCommand {
|
||||
addSubCommand(new Update(main));
|
||||
addSubCommand(new Kick(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,9 +11,13 @@ import us.ajg0702.utils.common.Messages;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class QueueCommand extends BaseCommand {
|
||||
|
||||
public static Map<AdaptedPlayer, Long> cooldowns = new ConcurrentHashMap<>();
|
||||
|
||||
private final QueueMain main;
|
||||
|
||||
public QueueCommand(QueueMain main) {
|
||||
@@ -58,6 +62,14 @@ public class QueueCommand extends BaseCommand {
|
||||
}
|
||||
AdaptedPlayer player = main.getPlatformMethods().senderToPlayer(sender);
|
||||
|
||||
long lastUse = cooldowns.getOrDefault(player, 0L);
|
||||
if(System.currentTimeMillis() - lastUse < main.getConfig().getDouble("queue-command-cooldown") * 1000L) {
|
||||
sender.sendMessage(main.getMessages().getComponent("errors.too-fast-queue"));
|
||||
return;
|
||||
}
|
||||
|
||||
cooldowns.put(player, System.currentTimeMillis());
|
||||
|
||||
if(args.length > 0) {
|
||||
if(main.getConfig().getBoolean("require-permission") && !player.hasPermission("ajqueue.queue."+args[0])) {
|
||||
sender.sendMessage(getMessages().getComponent("noperm"));
|
||||
@@ -79,7 +91,11 @@ public class QueueCommand extends BaseCommand {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
if(args.length == 1) {
|
||||
return filterCompletion(main.getQueueManager().getServerNames(), args[0]);
|
||||
List<String> servers = filterCompletion(main.getQueueManager().getServerNames(), args[0]);
|
||||
if(main.getConfig().getBoolean("require-permission")) {
|
||||
servers.removeIf(s -> !sender.hasPermission("ajqueue.queue." + s));
|
||||
}
|
||||
return servers;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||
import us.ajg0702.queue.commands.commands.manage.PauseQueueServer;
|
||||
import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
||||
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||
import us.ajg0702.queue.common.utils.Debug;
|
||||
import us.ajg0702.utils.common.TimeUtils;
|
||||
@@ -144,15 +146,13 @@ public class EventHandlerImpl implements EventHandler {
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(AdaptedPlayer player) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
if (main.getUpdater().isUpdateAvailable() && player.hasPermission("ajqueue.manage.update")) {
|
||||
if(player.hasPermission("ajqueue.manage.update")) {
|
||||
main.getTaskManager().runLater(() -> {
|
||||
if (main.getUpdater().isUpdateAvailable() && !main.getUpdater().isAlreadyDownloaded()) {
|
||||
player.sendMessage(main.getMessages().getComponent("updater.update-available"));
|
||||
}
|
||||
}).start();
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
ImmutableList<QueuePlayer> queues = main.getQueueManager().findPlayerInQueues(player);
|
||||
for(QueuePlayer queuePlayer : queues) {
|
||||
@@ -194,7 +194,12 @@ public class EventHandlerImpl implements EventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if(main.getConfig().getBoolean("include-server-switch-in-cooldown")) {
|
||||
QueueCommand.cooldowns.put(player, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
if(!PauseQueueServer.pausedPlayers.contains(player)) {
|
||||
String serverName = player.getServerName();
|
||||
List<String> svs = main.getConfig().getStringList("queue-servers");
|
||||
for(String s : svs) {
|
||||
@@ -206,6 +211,7 @@ public class EventHandlerImpl implements EventHandler {
|
||||
main.getQueueManager().addToQueue(player, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -212,6 +212,7 @@ public class QueueMain extends AjQueueAPI {
|
||||
d.put("errors.wrong-version.base", "<red>You must be on {VERSIONS} to join this server!");
|
||||
d.put("errors.wrong-version.or", " or ");
|
||||
d.put("errors.wrong-version.comma", ", ");
|
||||
d.put("errors.too-fast-queue", "<red>You're queueing too fast!");
|
||||
|
||||
d.put("commands.leave-queue", "&aYou left the queue for {SERVER}!");
|
||||
d.put("commands.reload", "&aConfig and messages reloaded successfully!");
|
||||
@@ -222,6 +223,9 @@ public class QueueMain extends AjQueueAPI {
|
||||
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.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!");
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.premium.Logic;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
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.queues.QueueServerImpl;
|
||||
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
|
||||
public void sendQueueEvents() {
|
||||
if(main.getConfig().getBoolean("force-queue-server-target")) {
|
||||
@@ -440,6 +443,14 @@ public class QueueManagerImpl implements QueueManager {
|
||||
QueueServer to = findServer(toName);
|
||||
if(from == null || to == null) continue;
|
||||
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)) {
|
||||
addToQueue(player, to);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Dont touch this number please
|
||||
config-version: 34
|
||||
config-version: 35
|
||||
|
||||
|
||||
# This is the main config for ajQueue.
|
||||
@@ -313,6 +313,12 @@ give-fulljoin-players-priority: 0
|
||||
# not in the queue for the target server, it will add them.
|
||||
force-queue-server-target: true
|
||||
|
||||
# How long should the cooldown for queue commands be? (in seconds)
|
||||
queue-command-cooldown: 3
|
||||
|
||||
# Should any server switch (including the initial join) count against the queue command cooldown?
|
||||
include-server-switch-in-cooldown: false
|
||||
|
||||
|
||||
# The minimum time between pinging the server.
|
||||
# If ajQueue is pinging your backend servers too often, raise this number
|
||||
|
||||
+8
@@ -8,6 +8,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
import us.ajg0702.queue.platforms.bungeecord.BungeeQueue;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeeSender implements ICommandSender {
|
||||
|
||||
final CommandSender handle;
|
||||
@@ -27,6 +29,12 @@ public class BungeeSender implements ICommandSender {
|
||||
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
|
||||
public void sendMessage(@NotNull Component message) {
|
||||
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.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeePlayer implements AdaptedPlayer, Audience {
|
||||
@@ -172,4 +173,17 @@ public class BungeePlayer implements AdaptedPlayer, Audience {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -2,6 +2,7 @@ package us.ajg0702.queue.platforms.bungeecord.server;
|
||||
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import us.ajg0702.queue.api.AjQueueAPI;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
@@ -51,8 +52,9 @@ public class BungeeServer implements AdaptedServer {
|
||||
if(debug) logger.info("[pinger] [" + getName() + "] sending ping");
|
||||
|
||||
handle.ping((pp, error) -> {
|
||||
if(error != null) {
|
||||
if(error != null || pp == null) {
|
||||
markOffline(debug, logger, future, sent, error);
|
||||
return;
|
||||
}
|
||||
|
||||
offlineTime = 0;
|
||||
@@ -71,7 +73,7 @@ public class BungeeServer implements AdaptedServer {
|
||||
return future;
|
||||
}
|
||||
|
||||
private void markOffline(boolean debug, QueueLogger logger, CompletableFuture<AdaptedServerPing> future, long sent, Throwable e) {
|
||||
private void markOffline(boolean debug, QueueLogger logger, CompletableFuture<AdaptedServerPing> future, long sent, @Nullable Throwable e) {
|
||||
long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime();
|
||||
offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE);
|
||||
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import us.ajg0702.queue.api.server.AdaptedServerPing;
|
||||
|
||||
public class BungeeServerPing implements AdaptedServerPing {
|
||||
@@ -11,7 +12,7 @@ public class BungeeServerPing implements AdaptedServerPing {
|
||||
final ServerPing handle;
|
||||
private final long sent;
|
||||
|
||||
public BungeeServerPing(ServerPing handle, long sent) {
|
||||
public BungeeServerPing(@NotNull ServerPing handle, long sent) {
|
||||
this.handle = handle;
|
||||
this.sent = sent;
|
||||
}
|
||||
|
||||
+9
@@ -2,11 +2,14 @@ package us.ajg0702.queue.platforms.velocity.commands;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocitySender implements ICommandSender {
|
||||
|
||||
final CommandSource handle;
|
||||
@@ -26,6 +29,12 @@ public class VelocitySender implements ICommandSender {
|
||||
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
|
||||
public void sendMessage(@NotNull Component message) {
|
||||
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 java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -205,4 +206,17 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +53,15 @@ public class Commands implements CommandExecutor {
|
||||
player = tply;
|
||||
srvname = 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);
|
||||
} else {
|
||||
assert player != null;
|
||||
pl.sendMessage(player, "queue", srvname);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user