From 413548b5885972e580180f1c1de8dbf202d737f5 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sun, 8 Aug 2021 13:50:09 -0700 Subject: [PATCH 1/9] priority-messages --- api/build.gradle.kts | 2 +- common/build.gradle.kts | 2 +- .../ajg0702/queue/common/QueueManagerImpl.java | 11 +++++++++++ common/src/main/resources/config.yml | 17 +++++++++++++++-- free/build.gradle.kts | 2 +- platforms/bungeecord/build.gradle.kts | 2 +- platforms/velocity/build.gradle.kts | 2 +- premium/build.gradle.kts | 2 +- spigot/build.gradle.kts | 2 +- 9 files changed, 33 insertions(+), 9 deletions(-) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index e0874fc..bc5cc11 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -17,7 +17,7 @@ dependencies { implementation("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT") compileOnly("com.google.guava:guava:30.1.1-jre") - compileOnly("us.ajg0702:ajUtils:1.1.7") + compileOnly("us.ajg0702:ajUtils:1.1.8") } publishing { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 4cdefba..84d0606 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -16,7 +16,7 @@ dependencies { compileOnly("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT") compileOnly("com.google.guava:guava:30.1.1-jre") - compileOnly("us.ajg0702:ajUtils:1.1.7") + compileOnly("us.ajg0702:ajUtils:1.1.8") compileOnly("org.slf4j:slf4j-log4j12:1.7.29") 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 d380ad0..3fcf3e4 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -145,6 +145,17 @@ public class QueueManagerImpl implements QueueManager { "SERVERNAME:"+server.getName() ) ); + if(main.getConfig().getBoolean("enable-priority-messages")) { + for(String rawPriorityMessage : main.getConfig().getStringList("priority-messages")) { + String[] parts = rawPriorityMessage.split(":"); + if(parts.length != 2) continue; + String level = parts[0]; + String messageRaw = parts[1]; + if(level.equals("*") || level.equals(queuePlayer.getPriority()+"")) { + player.sendMessage(main.getMessages().toComponent(messageRaw)); + } + } + } } if(!server.isJoinable(player)) { diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 319edb8..ed6edaf 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: 22 +config-version: 23 # The time the server will wait between sending people in the queue # Default: 5 @@ -176,4 +176,17 @@ auto-add-kick-reasons: # Should we enable the server command being a queue command? # This may require extra setup on bungeecord. See the wiki: # https://wiki.ajg0702.us/ajqueue/setup/replacing-server-command -enable-server-command: false \ No newline at end of file +enable-server-command: false + +# Should we enable priority messages? +# Configure the priority messages in the option below. +enable-priority-messages: false + +# Messages we send to players with priority queue when they join the queue +# In the free version, "priority" is 1. +# The * will send when a player joins with any priority. +# The format is : +# Example: 1:You have a priority of 1! +priority-messages: + - "*:Joining the queue with priority!" + - "100:Wow! You have a priority of 100!" \ No newline at end of file diff --git a/free/build.gradle.kts b/free/build.gradle.kts index 289c987..023ba38 100644 --- a/free/build.gradle.kts +++ b/free/build.gradle.kts @@ -18,7 +18,7 @@ dependencies { compileOnly("com.google.guava:guava:30.1.1-jre") compileOnly("org.spongepowered:configurate-yaml:4.0.0") - implementation("us.ajg0702:ajUtils:1.1.7") + implementation("us.ajg0702:ajUtils:1.1.8") implementation(project(":platforms:velocity")) implementation(project(":platforms:bungeecord")) diff --git a/platforms/bungeecord/build.gradle.kts b/platforms/bungeecord/build.gradle.kts index 136f1e8..e710573 100644 --- a/platforms/bungeecord/build.gradle.kts +++ b/platforms/bungeecord/build.gradle.kts @@ -15,7 +15,7 @@ repositories { dependencies { compileOnly("net.kyori:adventure-api:4.8.1") compileOnly("com.google.guava:guava:30.1.1-jre") - compileOnly("us.ajg0702:ajUtils:1.1.7") + compileOnly("us.ajg0702:ajUtils:1.1.8") compileOnly("net.md-5:bungeecord-api:1.16-R0.4") diff --git a/platforms/velocity/build.gradle.kts b/platforms/velocity/build.gradle.kts index 48d296f..7feb6c7 100644 --- a/platforms/velocity/build.gradle.kts +++ b/platforms/velocity/build.gradle.kts @@ -15,7 +15,7 @@ repositories { dependencies { compileOnly("net.kyori:adventure-api:4.8.1") compileOnly("com.google.guava:guava:30.1.1-jre") - compileOnly("us.ajg0702:ajUtils:1.1.7") + compileOnly("us.ajg0702:ajUtils:1.1.8") compileOnly("com.velocitypowered:velocity-api:3.0.0") annotationProcessor("com.velocitypowered:velocity-api:3.0.0") diff --git a/premium/build.gradle.kts b/premium/build.gradle.kts index f6e9ee7..dd1d016 100644 --- a/premium/build.gradle.kts +++ b/premium/build.gradle.kts @@ -22,7 +22,7 @@ dependencies { compileOnly("com.google.guava:guava:30.1.1-jre") - compileOnly("us.ajg0702:ajUtils:1.1.7") + compileOnly("us.ajg0702:ajUtils:1.1.8") compileOnly("net.kyori:adventure-api:4.8.1") diff --git a/spigot/build.gradle.kts b/spigot/build.gradle.kts index aec53f1..53b7364 100644 --- a/spigot/build.gradle.kts +++ b/spigot/build.gradle.kts @@ -20,7 +20,7 @@ dependencies { implementation("net.kyori:adventure-api:4.8.1") compileOnly("com.google.guava:guava:30.1.1-jre") - compileOnly("us.ajg0702:ajUtils:1.1.7") + compileOnly("us.ajg0702:ajUtils:1.1.8") compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.5-R0.1-SNAPSHOT") compileOnly("me.clip:placeholderapi:2.10.4") From 764fe2a0d7ba30ba116709bcad2dfe221aae627d Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sun, 8 Aug 2021 15:35:30 -0700 Subject: [PATCH 2/9] Send message if trying to use listpermissions from the console --- .../commands/commands/manage/PermissionList.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PermissionList.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PermissionList.java index 84c340d..74b08db 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PermissionList.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PermissionList.java @@ -2,6 +2,7 @@ package us.ajg0702.queue.commands.commands.manage; import com.google.common.collect.ImmutableList; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.commands.SubCommand; import us.ajg0702.queue.common.QueueMain; @@ -46,7 +47,15 @@ public class PermissionList extends SubCommand { @Override public void execute(ICommandSender sender, String[] args) { if(!checkPermission(sender)) return; - List permissions = main.getLogicGetter().getPermissions(main.getPlatformMethods().senderToPlayer(sender)); + if(!sender.isPlayer()) { + sender.sendMessage( + Component.text("You need to run this as a player with priority!") + .color(NamedTextColor.RED) + ); + } + + List permissions = main.getLogicGetter() + .getPermissions(main.getPlatformMethods().senderToPlayer(sender)); if(permissions == null) { sender.sendMessage(Component.text("no permission handler")); return; From 8a12c6faf055924402797d854acd5756d8089bc7 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sun, 8 Aug 2021 16:00:42 -0700 Subject: [PATCH 3/9] Fix requiring extra permission --- .../ajg0702/queue/commands/commands/manage/ManageCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java index e97d81f..cc69a57 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java @@ -50,7 +50,7 @@ public class ManageCommand extends BaseCommand { @Override public String getPermission() { - return "ajqueue.manage"; + return null; } @Override From 8e61a3b1e51f4bc3342cf943e736a06b2eb9999c Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sun, 8 Aug 2021 16:01:06 -0700 Subject: [PATCH 4/9] fix * priority message sending even if player doesnt have priority --- .../src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3fcf3e4..0124f4f 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -151,7 +151,7 @@ public class QueueManagerImpl implements QueueManager { if(parts.length != 2) continue; String level = parts[0]; String messageRaw = parts[1]; - if(level.equals("*") || level.equals(queuePlayer.getPriority()+"")) { + if((level.equals("*") && queuePlayer.getPriority() > 0) || level.equals(queuePlayer.getPriority()+"")) { player.sendMessage(main.getMessages().toComponent(messageRaw)); } } From 4353341881a095971a1b45204adaafcbeace4b33 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sun, 8 Aug 2021 16:07:11 -0700 Subject: [PATCH 5/9] allow {PRIORITY} placeholder in priority messages --- .../src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java | 2 +- common/src/main/resources/config.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 0124f4f..6d9310b 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -152,7 +152,7 @@ public class QueueManagerImpl implements QueueManager { String level = parts[0]; String messageRaw = parts[1]; if((level.equals("*") && queuePlayer.getPriority() > 0) || level.equals(queuePlayer.getPriority()+"")) { - player.sendMessage(main.getMessages().toComponent(messageRaw)); + player.sendMessage(main.getMessages().toComponent(messageRaw.replaceAll("\\{PRIORITY}", queuePlayer.getPriority()+""))); } } } diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index ed6edaf..2cedc4e 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -188,5 +188,5 @@ enable-priority-messages: false # The format is : # Example: 1:You have a priority of 1! priority-messages: - - "*:Joining the queue with priority!" + - "*:Joining the queue with a priority of {PRIORITY}!" - "100:Wow! You have a priority of 100!" \ No newline at end of file From c4f06b0d77a5fe02215a8053387d367c33437b08 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sun, 8 Aug 2021 19:50:07 -0700 Subject: [PATCH 6/9] whitelist progress --- .../commands/manage/ManageCommand.java | 2 + .../commands/manage/{ => debug}/ISP.java | 2 +- .../manage/{ => debug}/PermissionList.java | 2 +- .../commands/manage/{ => debug}/Tasks.java | 2 +- .../commands/manage/{ => debug}/Version.java | 2 +- .../commands/manage/debug/Whitelist.java | 65 +++++++++++++++++++ .../us/ajg0702/queue/common/QueueMain.java | 1 + .../queue/common/QueueManagerImpl.java | 2 + .../queue/common/queues/QueueServerImpl.java | 24 ++++++- spigot/build.gradle.kts | 2 + .../java/us/ajg0702/queue/spigot/Config.java | 59 ----------------- .../us/ajg0702/queue/spigot/SpigotMain.java | 39 +++++++++-- spigot/src/main/resources/spigot-config.yml | 18 +++++ 13 files changed, 151 insertions(+), 69 deletions(-) rename common/src/main/java/us/ajg0702/queue/commands/commands/manage/{ => debug}/ISP.java (95%) rename common/src/main/java/us/ajg0702/queue/commands/commands/manage/{ => debug}/PermissionList.java (97%) rename common/src/main/java/us/ajg0702/queue/commands/commands/manage/{ => debug}/Tasks.java (95%) rename common/src/main/java/us/ajg0702/queue/commands/commands/manage/{ => debug}/Version.java (95%) create mode 100644 common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Whitelist.java delete mode 100644 spigot/src/main/java/us/ajg0702/queue/spigot/Config.java create mode 100644 spigot/src/main/resources/spigot-config.yml diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java index cc69a57..1febb34 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java @@ -5,6 +5,7 @@ import net.kyori.adventure.text.Component; import us.ajg0702.queue.api.commands.ICommandSender; import us.ajg0702.queue.api.commands.ISubCommand; import us.ajg0702.queue.commands.BaseCommand; +import us.ajg0702.queue.commands.commands.manage.debug.*; import us.ajg0702.queue.common.QueueMain; import us.ajg0702.utils.common.Messages; @@ -28,6 +29,7 @@ public class ManageCommand extends BaseCommand { addSubCommand(new QueueList(main)); addSubCommand(new Send(main)); addSubCommand(new PermissionList(main)); + addSubCommand(new Whitelist(main)); } diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ISP.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/ISP.java similarity index 95% rename from common/src/main/java/us/ajg0702/queue/commands/commands/manage/ISP.java rename to common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/ISP.java index ad29978..2ac03bf 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ISP.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/ISP.java @@ -1,4 +1,4 @@ -package us.ajg0702.queue.commands.commands.manage; +package us.ajg0702.queue.commands.commands.manage.debug; import com.google.common.collect.ImmutableList; import net.kyori.adventure.text.Component; diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PermissionList.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/PermissionList.java similarity index 97% rename from common/src/main/java/us/ajg0702/queue/commands/commands/manage/PermissionList.java rename to common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/PermissionList.java index 74b08db..a92a229 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/PermissionList.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/PermissionList.java @@ -1,4 +1,4 @@ -package us.ajg0702.queue.commands.commands.manage; +package us.ajg0702.queue.commands.commands.manage.debug; import com.google.common.collect.ImmutableList; import net.kyori.adventure.text.Component; diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Tasks.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Tasks.java similarity index 95% rename from common/src/main/java/us/ajg0702/queue/commands/commands/manage/Tasks.java rename to common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Tasks.java index 6d44014..886d522 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Tasks.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Tasks.java @@ -1,4 +1,4 @@ -package us.ajg0702.queue.commands.commands.manage; +package us.ajg0702.queue.commands.commands.manage.debug; import com.google.common.collect.ImmutableList; import net.kyori.adventure.text.Component; diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Version.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Version.java similarity index 95% rename from common/src/main/java/us/ajg0702/queue/commands/commands/manage/Version.java rename to common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Version.java index f7d019e..9d55c31 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Version.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Version.java @@ -1,4 +1,4 @@ -package us.ajg0702.queue.commands.commands.manage; +package us.ajg0702.queue.commands.commands.manage.debug; import com.google.common.collect.ImmutableList; import net.kyori.adventure.text.Component; diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Whitelist.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Whitelist.java new file mode 100644 index 0000000..0dc6ec7 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/debug/Whitelist.java @@ -0,0 +1,65 @@ +package us.ajg0702.queue.commands.commands.manage.debug; + +import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.queues.QueueServer; +import us.ajg0702.queue.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.List; + +public class Whitelist extends SubCommand { + final QueueMain main; + public Whitelist(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "whitelist"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return null; + } + + @Override + public boolean showInTabComplete() { + return false; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + if(args.length < 1) { + sender.sendMessage(main.getMessages().toComponent("Not enough args!")); + return; + } + QueueServer server = main.getQueueManager().findServer(args[0]); + if(server == null) { + sender.sendMessage(main.getMessages().toComponent("Server not found")); + return; + } + sender.sendMessage(main.getMessages().toComponent("Yours: "+ main.getPlatformMethods().senderToPlayer(sender).getUniqueId().toString())); + server.getWhitelistedPlayers().forEach(uuid -> sender.sendMessage(main.getMessages().toComponent(""+uuid))); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java index 8d27916..77b435f 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java @@ -137,6 +137,7 @@ public class QueueMain { d.put("status.offline.full", "full"); d.put("status.offline.restricted", "restricted"); d.put("status.offline.paused", "paused"); + d.put("status.offline.whitelisted", "whitelisted"); d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}"); d.put("status.left-last-queue", "&aYou left the last queue you were in."); 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 6d9310b..e1fd5a5 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -473,6 +473,8 @@ public class QueueManagerImpl implements QueueManager { if(nextPlayer == null) continue; // None of the players in the queue are online + if(server.isWhitelisted() && !server.getWhitelistedPlayers().contains(nextPlayer.getUniqueId())) continue; + if(!server.canAccess(nextPlayer)) continue; if(server.isFull() && !nextPlayer.hasPermission("ajqueue.joinfull")) continue; 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 2238771..1bcdec5 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 @@ -105,6 +105,10 @@ public class QueueServerImpl implements QueueServer { return msgs.getString("status.offline.paused"); } + if(p != null && isWhitelisted() && !getWhitelistedPlayers().contains(p.getUniqueId())) { + return msgs.getString("status.offline.whitelisted"); + } + if(isFull()) { return msgs.getString("status.offline.full"); } @@ -159,6 +163,20 @@ public class QueueServerImpl implements QueueServer { if(serverPing == null) { continue; } + if(serverPing.getPlainDescription().contains("ajQueue;whitelisted=")) { + if(servers.size() > 1) continue; + + setWhitelisted(true); + List uuids = new ArrayList<>(); + for(String uuid : serverPing.getPlainDescription().substring(20).split(",")) { + if(uuid.isEmpty()) continue; + main.getLogger().info("Adding uuid "+uuid+" to whitelist"); + uuids.add(UUID.fromString(uuid)); + } + setWhitelistedPlayers(uuids); + } else { + setWhitelisted(false); + } onlineCount++; playerCount += serverPing.getPlayerCount(); maxPlayers += serverPing.getMaxPlayers(); @@ -217,8 +235,10 @@ public class QueueServerImpl implements QueueServer { @Override public boolean isJoinable(AdaptedPlayer p) { - return (!whitelisted || whitelistedUUIDs.contains(p.getUniqueId())) && - this.isOnline() && + if(p != null && isWhitelisted() && !whitelistedUUIDs.contains(p.getUniqueId())) { + return false; + } + return this.isOnline() && this.canAccess(p) && !this.isFull() && !this.isPaused(); diff --git a/spigot/build.gradle.kts b/spigot/build.gradle.kts index 53b7364..b6944be 100644 --- a/spigot/build.gradle.kts +++ b/spigot/build.gradle.kts @@ -20,6 +20,8 @@ dependencies { implementation("net.kyori:adventure-api:4.8.1") compileOnly("com.google.guava:guava:30.1.1-jre") + compileOnly("org.spongepowered:configurate-yaml:4.0.0") + compileOnly("us.ajg0702:ajUtils:1.1.8") compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.5-R0.1-SNAPSHOT") diff --git a/spigot/src/main/java/us/ajg0702/queue/spigot/Config.java b/spigot/src/main/java/us/ajg0702/queue/spigot/Config.java deleted file mode 100644 index b1eafb6..0000000 --- a/spigot/src/main/java/us/ajg0702/queue/spigot/Config.java +++ /dev/null @@ -1,59 +0,0 @@ -package us.ajg0702.queue.spigot; - -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.file.Files; - -public class Config { - final File f; - final YamlConfiguration yml; - - final JavaPlugin pl; - - - public boolean getBoolean(String key) { - return yml.getBoolean(key); - } - - public Config(JavaPlugin pl) { - this.pl = pl; - f = new File(pl.getDataFolder(), "config.yml"); - if(!f.exists()) { - if(!Files.exists(pl.getDataFolder().toPath())) { - try { - Files.createDirectory(pl.getDataFolder().toPath()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - try { - PrintWriter writer = new PrintWriter(pl.getDataFolder()+File.separator+"config.yml", "UTF-8"); - String[] lines = getDefaultConfig().split("\n"); - for(String line : lines) { - writer.println(line); - - } - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - yml = YamlConfiguration.loadConfiguration(f); - } - - public String getDefaultConfig() { - return "# This is the config for the spigot side.\n" - + "# You can find more settings in the config of bungee.\n" - + "\n\n" - + "# Should we send queue requests from commands in batches?\n" - + "# Enable this if you have issues with players sometimes not executing commands correctly\n" - + "# Note though that it could delay queue commands by up to 1 second!\n" - + "send-queue-commands-in-batches: false"; - } -} diff --git a/spigot/src/main/java/us/ajg0702/queue/spigot/SpigotMain.java b/spigot/src/main/java/us/ajg0702/queue/spigot/SpigotMain.java index 79366b6..76eb6fb 100644 --- a/spigot/src/main/java/us/ajg0702/queue/spigot/SpigotMain.java +++ b/spigot/src/main/java/us/ajg0702/queue/spigot/SpigotMain.java @@ -4,14 +4,19 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; +import us.ajg0702.utils.common.ConfigFile; +import java.io.File; import java.util.HashMap; @SuppressWarnings("UnstableApiUsage") @@ -20,7 +25,7 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List boolean papi = false; Placeholders placeholders; - Config config; + ConfigFile config; @SuppressWarnings("ConstantConditions") public void onEnable() { @@ -53,9 +58,20 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List queuebatch.clear(); sendMessage("massqueue", msg.toString()); }, 2*20, 20); - - config = new Config(this); - + + File oldConfig = new File(getDataFolder(), "config.yml"); + if(oldConfig.exists()) { + //noinspection ResultOfMethodCallIgnored + oldConfig.renameTo(new File(getDataFolder(), "spigot-config.yml")); + } + + try { + config = new ConfigFile(getDataFolder(), getLogger(), "spigot-config.yml"); + } catch (Exception e) { + getLogger().severe("Unable to read config:"); + e.printStackTrace(); + } + getLogger().info("Spigot side enabled! v"+getDescription().getVersion()); } @@ -163,4 +179,19 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List if(!papi) return; placeholders.cleanCache(); } + + @EventHandler(priority = EventPriority.HIGH) + public void onServerPing(ServerListPingEvent e) { + if(!config.getBoolean("take-over-motd-for-whitelist")) return; + if(!Bukkit.hasWhitelist()) return; + + StringBuilder whitelist = new StringBuilder(); + for(OfflinePlayer player : Bukkit.getWhitelistedPlayers()) { + whitelist.append(player.getUniqueId()).append(","); + } + if(whitelist.length() > 1) { + whitelist.deleteCharAt(whitelist.length()-1); + } + e.setMotd("ajQueue;whitelisted="+whitelist); + } } diff --git a/spigot/src/main/resources/spigot-config.yml b/spigot/src/main/resources/spigot-config.yml new file mode 100644 index 0000000..e74fd04 --- /dev/null +++ b/spigot/src/main/resources/spigot-config.yml @@ -0,0 +1,18 @@ +# This is the config for the spigot side. +# You can find more settings in the config of bungee. + + +# Should we send queue requests from commands in batches? +# Enable this if you have issues with players sometimes not executing commands correctly +# Note though that it could delay queue commands by up to 1 second! +send-queue-commands-in-batches: false + +# Should we take over the server MOTD to tell the proxy if the server is whitelisted? +# If you disable this, ajQueue will not be able to tell if the server is whitelisted! +take-over-motd-for-whitelist: true + + + + +# Dont touch this +config-version: 2 \ No newline at end of file From e08accafae84f763aef58f61faded63ae073aaea Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sun, 8 Aug 2021 20:13:02 -0700 Subject: [PATCH 7/9] fix send instant not working on whitelisted server --- .../src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java | 2 +- .../java/us/ajg0702/queue/common/queues/QueueServerImpl.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 e1fd5a5..dbe2ac5 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -125,7 +125,7 @@ public class QueueManagerImpl implements QueueManager { int len = list.size(); boolean sendInstant = main.getConfig().getStringList("send-instantly").contains(server.getName()) || server.isJoinable(player); - boolean sendInstantp = list.size() <= 1 && server.canAccess(player); + boolean sendInstantp = list.size() <= 1 && server.isJoinable(player); boolean timeGood = !main.getConfig().getBoolean("check-last-player-sent-time") || System.currentTimeMillis() - server.getLastSentTime() > Math.floor(main.getConfig().getDouble("wait-time") * 1000); if((sendInstant && (sendInstantp && timeGood))) { 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 1bcdec5..fd77111 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 @@ -170,7 +170,6 @@ public class QueueServerImpl implements QueueServer { List uuids = new ArrayList<>(); for(String uuid : serverPing.getPlainDescription().substring(20).split(",")) { if(uuid.isEmpty()) continue; - main.getLogger().info("Adding uuid "+uuid+" to whitelist"); uuids.add(UUID.fromString(uuid)); } setWhitelistedPlayers(uuids); From 0d910d391c9d8412e3ebfef15e6de717a3e77cb6 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 9 Aug 2021 09:12:17 -0700 Subject: [PATCH 8/9] fix an error with the kick event --- .../main/java/us/ajg0702/queue/common/EventHandlerImpl.java | 4 ++-- .../us/ajg0702/queue/platforms/bungeecord/BungeeQueue.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 d2cb271..f405d95 100644 --- a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -169,7 +169,7 @@ public class EventHandlerImpl implements EventHandler { } ImmutableList queuedServers = main.getQueueManager().getPlayerQueues(player); - if(!queuedServers.contains(main.getQueueManager().findServer(from.getName())) && main.getConfig().getBoolean("auto-add-to-queue-on-kick")) { + if(from != null && !queuedServers.contains(main.getQueueManager().findServer(from.getName())) && main.getConfig().getBoolean("auto-add-to-queue-on-kick")) { List reasons = main.getConfig().getStringList("auto-add-kick-reasons"); boolean shouldqueue = false; @@ -193,7 +193,7 @@ public class EventHandlerImpl implements EventHandler { } - + assert from != null; for(QueueServer server : queuedServers) { if(!(server.getServerNames().contains(from.getName()))) continue; QueuePlayer queuePlayer = server.findPlayer(player); 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 a55b795..7675a92 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 @@ -124,7 +124,7 @@ public class BungeeQueue extends Plugin implements Listener { Component reason = BungeeComponentSerializer.get().deserialize(e.getKickReasonComponent()); main.getEventHandler().onServerKick( new BungeePlayer(e.getPlayer()), - new BungeeServer(e.getCancelServer()), + new BungeeServer(e.getKickedFrom()), reason, false ); From f984d74d880de50c43bb3785d7e933212ce4dc4d Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 9 Aug 2021 10:43:37 -0700 Subject: [PATCH 9/9] 2.0.2 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index b800ae0..2f77b7c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ repositories { } allprojects { - version = "2.0.1" + version = "2.0.2" group = "us.ajg0702" tasks.withType().configureEach {