diff --git a/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java b/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java index 5d3ad20..e66789e 100644 --- a/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java +++ b/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java @@ -78,6 +78,12 @@ public interface AdaptedPlayer extends Handle, Audience { */ String getName(); + /** + * Kick a player from the proxy + * @param reason The reason to kick them with + */ + void kick(Component reason); + List getPermissions(); default boolean equals(AdaptedPlayer other) { diff --git a/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java b/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java index d80eb89..dba7633 100644 --- a/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java +++ b/api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java @@ -256,6 +256,14 @@ public interface QueueServer { */ void addPlayer(AdaptedServer server); + /** + * Sets if this server is online. + * Note that this is overrided by the pinger, so if you set + * this, it will most likely be temporary + * @param online whether the server is online or not + */ + void setOnline(boolean online); + /** * elliot is bad diff --git a/build.gradle.kts b/build.gradle.kts index f4c1a25..e67f162 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ repositories { } allprojects { - version = "2.2.1" + version = "2.2.2" group = "us.ajg0702" plugins.apply("java") diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/SlashServer/SlashServerCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/SlashServer/SlashServerCommand.java index c625e80..061e9d6 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/SlashServer/SlashServerCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/SlashServer/SlashServerCommand.java @@ -45,6 +45,10 @@ public class SlashServerCommand extends BaseCommand { sender.sendMessage(getMessages().getComponent("errors.player-only")); return; } + if(main.getConfig().getBoolean("require-permission") && !sender.hasPermission("ajqueue.queue."+args[0])) { + sender.sendMessage(getMessages().getComponent("noperm")); + return; + } main.getQueueManager().addToQueue(main.getPlatformMethods().senderToPlayer(sender), server); } diff --git a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java index 0bdd66e..7787dc8 100644 --- a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -217,10 +217,29 @@ public class EventHandlerImpl implements EventHandler { QueuePlayer queuePlayer = server.findPlayer(player); if(queuePlayer.getPosition() != 1) continue; List kickReasons = main.getConfig().getStringList("kick-reasons"); + boolean kickPlayer = main.getConfig().getBoolean("kick-kicked-players"); + if(kickPlayer) { + List svs = main.getConfig().getStringList("queue-servers"); + boolean found = false; + for(String s : svs) { + if(!s.contains(":")) continue; + String[] parts = s.split(":"); + String fromName = parts[0]; + QueueServer toServer = main.getQueueManager().findServer(parts[1]); + if(fromName.equalsIgnoreCase(server.getName()) && toServer != null && toServer.equals(server)) { + found = true; + } + } + kickPlayer = found; + } for(String kickReason : kickReasons) { if(plainReason.toLowerCase().contains(kickReason.toLowerCase())) { server.removePlayer(queuePlayer); + if(kickPlayer) { + player.kick(reason); + } + break; } } } diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java index f9a7c6a..85afa69 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -49,6 +49,9 @@ public class QueueManagerImpl implements QueueManager { if(previousServer != null) { queueServer.setPaused(previousServer.isPaused()); queueServer.setLastSentTime(previousServer.getLastSentTime()); + queueServer.setOnline(previousServer.isOnline()); + queueServer.setWhitelisted(previousServer.isWhitelisted()); + queueServer.setWhitelistedPlayers(previousServer.getWhitelistedPlayers()); } result.add(queueServer); } diff --git a/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java b/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java index c4d4934..7751f18 100644 --- a/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/queues/QueueServerImpl.java @@ -176,7 +176,7 @@ public class QueueServerImpl implements QueueServer { AdaptedServerPing ping = null; try { ping = futurePing.get(5, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException e) { + } catch (Exception e) { if(pingerDebug) { main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] offline:"); e.printStackTrace(); @@ -243,7 +243,7 @@ public class QueueServerImpl implements QueueServer { } if(pingerDebug) { - main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] Success"); + main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] Finished"); } } } @@ -468,4 +468,9 @@ public class QueueServerImpl implements QueueServer { if(!pings.containsKey(server)) throw new IllegalArgumentException("Server is not in this group!"); pings.get(server).addPlayer(); } + + @Override + public void setOnline(boolean online) { + this.online = online; + } } diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 5ad6b70..10970b5 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Dont touch this number please -config-version: 31 +config-version: 32 # This is the main config for ajQueue. @@ -38,6 +38,12 @@ kick-reasons: - 'banned' - 'blacklisted' +# Should we completly kick the user from the server if they are in a queue-server +# and are kicked from the server with one of the above reasons? +# Note this will do nothing on servers that arent queue-servers +# (as in the config option queue-servers) +# Default: true +kick-kicked-players: true # Should we remove a player from the queue if they move servers? # This will remove the player from if they switch to any other server @@ -224,6 +230,7 @@ supported-protocols: # api will be used to find the name of the protocol. # If you are on bungee, only this list can be used. protocol-names: + - "757:1.18.1" - "756:1.17.1" - "755:1.17" - "754:1.16.5" diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeQueue.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeQueue.java index b37400c..e548178 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeQueue.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/BungeeQueue.java @@ -3,6 +3,7 @@ package us.ajg0702.queue.platforms.bungeecord; import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.*; import net.md_5.bungee.api.plugin.Listener; @@ -30,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +@SuppressWarnings("unused") public class BungeeQueue extends Plugin implements Listener, Implementation { private QueueMain main; @@ -106,7 +108,13 @@ public class BungeeQueue extends Plugin implements Listener, Implementation { if(!(e.getReceiver() instanceof ProxiedPlayer)) return; - main.getEventHandler().handleMessage(new BungeePlayer((ProxiedPlayer) e.getReceiver()), e.getData()); + ProxyServer.getInstance().getScheduler().runAsync(this, () -> + main.getEventHandler() + .handleMessage( + new BungeePlayer((ProxiedPlayer) e.getReceiver()), + e.getData() + ) + ); } @EventHandler diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeCommand.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeCommand.java index e0d949b..10356e2 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeCommand.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/commands/BungeeCommand.java @@ -15,6 +15,9 @@ public class BungeeCommand extends Command implements TabExecutor { @Override public void execute(CommandSender sender, String[] args) { + if(args.length == 1 && args[0].isEmpty()) { + args = new String[]{}; + } command.execute(new BungeeSender(sender), args); } diff --git a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java index 16bec07..d4fb41d 100644 --- a/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java +++ b/platforms/bungeecord/src/main/java/us/ajg0702/queue/platforms/bungeecord/players/BungeePlayer.java @@ -6,6 +6,7 @@ import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.SoundStop; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.title.Title; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -136,6 +137,11 @@ public class BungeePlayer implements AdaptedPlayer, Audience { return handle.getName(); } + @Override + public void kick(Component reason) { + handle.disconnect(BungeeComponentSerializer.get().serialize(reason)); + } + @Override public List getPermissions() { return new ArrayList<>(handle.getPermissions()); diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java index c95021c..2354145 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java @@ -20,7 +20,11 @@ public class VelocityCommand implements RawCommand { @Override public void execute(Invocation invocation) { - command.execute(new VelocitySender(invocation.source()), invocation.arguments().split(" ")); + String[] args = new String[]{}; + if(!invocation.arguments().isEmpty()) { + args = invocation.arguments().split(" "); + } + command.execute(new VelocitySender(invocation.source()), args); } @Override diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java index 206e05e..a742860 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java @@ -174,6 +174,11 @@ public class VelocityPlayer implements AdaptedPlayer, Audience { return handle.getUsername(); } + @Override + public void kick(Component reason) { + handle.disconnect(reason); + } + @Override public List getPermissions() { throw new IllegalStateException("AdaptedPlayer#getPermissions cannot be used on velocity");