allow restricting joining queues to certain protocol versions
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package us.ajg0702.queue.common;
|
||||
|
||||
import us.ajg0702.queue.api.PlatformMethods;
|
||||
import us.ajg0702.queue.api.ProtocolNameManager;
|
||||
import us.ajg0702.utils.common.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ProtocolNameManagerImpl implements ProtocolNameManager {
|
||||
|
||||
private final Config config;
|
||||
private final PlatformMethods platformMethods;
|
||||
public ProtocolNameManagerImpl(Config config, PlatformMethods platformMethods) {
|
||||
this.config = config;
|
||||
this.platformMethods = platformMethods;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName(int protocol) {
|
||||
return getProtocolNames().getOrDefault(protocol, platformMethods.getProtocolName(protocol));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, String> getProtocolNames() {
|
||||
List<String> raw = config.getStringList("protocol-names");
|
||||
HashMap<Integer, String> result = new HashMap<>();
|
||||
for(String protocolRaw : raw) {
|
||||
String[] parts = protocolRaw.split(":");
|
||||
if(parts.length < 2) continue;
|
||||
String versionRaw = parts[0];
|
||||
String versionString = parts[1];
|
||||
int version;
|
||||
try {
|
||||
version = Integer.parseInt(versionRaw);
|
||||
} catch(NumberFormatException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.put(version, versionString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,12 @@ public class QueueMain extends AjQueueAPI {
|
||||
return logicGetter;
|
||||
}
|
||||
|
||||
private ProtocolNameManager protocolNameManager;
|
||||
@Override
|
||||
public ProtocolNameManager getProtocolNameManager() {
|
||||
return protocolNameManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
taskManager.shutdown();
|
||||
@@ -140,6 +146,8 @@ public class QueueMain extends AjQueueAPI {
|
||||
logic = logicGetter.constructLogic();
|
||||
aliasManager = logicGetter.constructAliasManager(config);
|
||||
|
||||
protocolNameManager = new ProtocolNameManagerImpl(config, platformMethods);
|
||||
|
||||
taskManager.rescheduleTasks();
|
||||
|
||||
}
|
||||
@@ -168,6 +176,9 @@ public class QueueMain extends AjQueueAPI {
|
||||
d.put("errors.already-connected", "&cYou are already connected to this server!");
|
||||
d.put("errors.cant-join-paused", "&cYou cannot join the queue for {SERVER} because it is paused.");
|
||||
d.put("errors.deny-joining-from-server", "&cYou are not allowed to join queues from this server!");
|
||||
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("commands.leave-queue", "&aYou left the queue for {SERVER}!");
|
||||
d.put("commands.reload", "&aConfig and messages reloaded successfully!");
|
||||
|
||||
@@ -55,6 +55,35 @@ public class QueueManagerImpl implements QueueManager {
|
||||
result.add(queueServer);
|
||||
}
|
||||
|
||||
List<String> supportedProtocolsRaw = main.getConfig().getStringList("supported-protocols");
|
||||
for(String supportedProtocolsString : supportedProtocolsRaw) {
|
||||
String[] parts = supportedProtocolsString.split(":");
|
||||
if(parts.length < 2) {
|
||||
main.getLogger().warn("Invalid supported protocols entry! Must have a colon to seperate the server(s) and the protocols");
|
||||
continue;
|
||||
}
|
||||
String serversRaw = parts[0];
|
||||
String protocolsRaw = parts[1];
|
||||
|
||||
List<Integer> protocols = new ArrayList<>();
|
||||
for(String protocolString : protocolsRaw.split(",")) {
|
||||
try {
|
||||
protocols.add(Integer.valueOf(protocolString));
|
||||
} catch(NumberFormatException e) {
|
||||
main.getLogger().info("The protocol "+protocolString+" is not a valid number!");
|
||||
}
|
||||
}
|
||||
|
||||
for(String serverName : serversRaw.split(",")) {
|
||||
for(QueueServer server : result) {
|
||||
if(serverName.equalsIgnoreCase(server.getName())) {
|
||||
server.setSupportedProtocols(protocols);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -70,6 +99,22 @@ public class QueueManagerImpl implements QueueManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
int playerVersion = player.getProtocolVersion();
|
||||
List<Integer> supportedProtocols = server.getSupportedProtocols();
|
||||
if(!supportedProtocols.contains(playerVersion) && supportedProtocols.size() > 0) {
|
||||
StringBuilder versions = new StringBuilder();
|
||||
for(int protocol : supportedProtocols) {
|
||||
versions.append(main.getProtocolNameManager().getProtocolName(protocol));
|
||||
if(supportedProtocols.indexOf(protocol) == supportedProtocols.size()-2) {
|
||||
versions.append(msgs.getString("errors.wrong-version.or"));
|
||||
} else if(supportedProtocols.indexOf(protocol) != supportedProtocols.size()-1) {
|
||||
versions.append(msgs.getString("errors.wrong-version.comma"));
|
||||
}
|
||||
}
|
||||
player.sendMessage(msgs.getComponent("errors.wrong-version.base", "VERSIONS:" + versions));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(server.isPaused() && main.getConfig().getBoolean("prevent-joining-paused")) {
|
||||
player.sendMessage(msgs.getComponent("errors.cant-join-paused", "SERVER:"+server.getAlias()));
|
||||
return false;
|
||||
|
||||
@@ -62,6 +62,8 @@ public class QueueServerImpl implements QueueServer {
|
||||
|
||||
private final List<QueuePlayer> queue = new ArrayList<>();
|
||||
|
||||
private List<Integer> supportedProtocols = new ArrayList<>();
|
||||
|
||||
|
||||
private int playerCount;
|
||||
private int maxPlayers;
|
||||
@@ -409,4 +411,14 @@ public class QueueServerImpl implements QueueServer {
|
||||
public HashMap<AdaptedServer, AdaptedServerPing> getLastPings() {
|
||||
return new HashMap<>(pings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getSupportedProtocols() {
|
||||
return new ArrayList<>(supportedProtocols);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSupportedProtocols(List<Integer> list) {
|
||||
supportedProtocols = new ArrayList<>(list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user