Skip to content

Commit

Permalink
Fixed skip-queue-server-if-possible not working with multiple queue s…
Browse files Browse the repository at this point in the history
…erver targets
  • Loading branch information
ajgeiss0702 committed Dec 21, 2023
1 parent ad1fc00 commit 76d9b39
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
3 changes: 2 additions & 1 deletion api/src/main/java/us/ajg0702/queue/api/AjQueueAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import us.ajg0702.utils.common.Config;
import us.ajg0702.utils.common.Messages;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

Expand Down Expand Up @@ -123,7 +124,7 @@ public static AjQueueSpigotAPI getSpigotInstance() {
*/
public abstract ProtocolNameManager getProtocolNameManager();

public abstract Map<String, String> getQueueServers();
public abstract Map<String, List<String>> getQueueServers();

/**
* Tells ajQueue to shut down.
Expand Down
30 changes: 17 additions & 13 deletions common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,31 @@ public void onServerKick(AdaptedPlayer player, @NotNull AdaptedServer from, Comp

if(!main.getConfig().getBoolean("skip-queue-server-if-possible")) return null;

Map<String, String> queueServers = main.getQueueServers();
Map<String, List<String>> queueServers = main.getQueueServers();

String toName = queueServers.get(initialChoice.getName());
List<String> toNames = queueServers.get(initialChoice.getName());

// don't change if initial target server isn't a queue-server
if(toName == null) return null;
if(toNames == null || toNames.isEmpty()) return null;

QueueServer to = main.getQueueManager().findServer(toName);
for (String toName : toNames) {
QueueServer to = main.getQueueManager().findServer(toName);

if(!main.getQueueManager().canSendInstantly(player, to)) return null;
if(!main.getQueueManager().canSendInstantly(player, to)) continue;

AdaptedServer ideal = to.getIdealServer(player);
AdaptedServer ideal = to.getIdealServer(player);

if(ideal == null) return null;
if(!to.isJoinable(player)) return null;
if(!ideal.isJoinable(player)) return null;
if(!(!main.getConfig().getBoolean("require-queueserver-permission") || player.hasPermission("ajqueue.queueserver." + to.getName()))) return null;
if(ideal == null) continue;
if(!to.isJoinable(player)) continue;
if(!ideal.isJoinable(player)) continue;
if(!(!main.getConfig().getBoolean("require-queueserver-permission") || player.hasPermission("ajqueue.queueserver." + to.getName()))) continue;

Debug.info("Skipping queue-server " + initialChoice.getName() + " for " + player.getName() + " because they would be sent instantly! (skip-queue-server-if-possible)");
Debug.info("Skipping queue-server " + initialChoice.getName() + " for " + player.getName() + " because they would be sent instantly! (skip-queue-server-if-possible)");

ideal.addPlayer();
return ideal;
ideal.addPlayer();
return ideal;
}

return null;
}
}
9 changes: 5 additions & 4 deletions common/src/main/java/us/ajg0702/queue/common/QueueMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import us.ajg0702.queue.api.premium.LogicGetter;
import us.ajg0702.queue.api.queues.QueueServer;
import us.ajg0702.queue.api.util.QueueLogger;
import us.ajg0702.queue.common.utils.Debug;
import us.ajg0702.queue.common.utils.LogConverter;
import us.ajg0702.queue.logic.LogicGetterImpl;
import us.ajg0702.utils.common.Config;
Expand Down Expand Up @@ -117,9 +116,9 @@ public ProtocolNameManager getProtocolNameManager() {
}

@Override
public Map<String, String> getQueueServers() {
public Map<String, List<String>> getQueueServers() {
List<String> rawQueueServers = getConfig().getStringList("queue-servers");
Map<String, String> r = new HashMap<>();
Map<String, List<String>> r = new HashMap<>();
for(String rawQueueServer : rawQueueServers) {
if(!rawQueueServer.contains(":")) continue;
String[] parts = rawQueueServer.split(":");
Expand All @@ -128,7 +127,9 @@ public Map<String, String> getQueueServers() {
QueueServer toServer = getQueueManager().findServer(toName);
if(toServer == null) continue;

r.put(fromName, toName);
List<String> existing = r.computeIfAbsent(fromName, key -> new ArrayList<>());
existing.add(toName);
r.put(fromName, existing);
}
return r;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ public synchronized void sendPlayers(QueueServer queueServer) {
for(QueuePlayer queuePlayer : server.getQueue()) {
if(queuePlayer.getPlayer() != null) continue;
if(main.getLogic().playerDisconnectedTooLong(queuePlayer)) {
Debug.info("Removing " + queuePlayer.getName() + " due to them being disconnected too long");
server.removePlayer(queuePlayer);
}
}
Expand Down

0 comments on commit 76d9b39

Please sign in to comment.