From e6922eae4677139e4c3c7dce7d931edb6259c915 Mon Sep 17 00:00:00 2001 From: Myles Date: Thu, 1 Nov 2018 22:41:56 +0000 Subject: [PATCH] Don't use -1 if provided by ProtocolDetectorService on Bungee #1064 --- .../service/ProtocolDetectorService.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java index e3aa9defe..252959224 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java @@ -58,19 +58,22 @@ public class ProtocolDetectorService implements Runnable { @Override public void done(ServerPing serverPing, Throwable throwable) { if (throwable == null && serverPing != null && serverPing.getVersion() != null) { - detectedProtocolIds.put(key, serverPing.getVersion().getProtocol()); - if (((BungeeConfigAPI) Via.getConfig()).isBungeePingSave()) { - Map servers = ((BungeeConfigAPI) Via.getConfig()).getBungeeServerProtocols(); - Integer protocol = servers.get(key); - if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { - return; + // Ensure protocol is positive, some services will return -1 + if (serverPing.getVersion().getProtocol() > 0) { + detectedProtocolIds.put(key, serverPing.getVersion().getProtocol()); + if (((BungeeConfigAPI) Via.getConfig()).isBungeePingSave()) { + Map servers = ((BungeeConfigAPI) Via.getConfig()).getBungeeServerProtocols(); + Integer protocol = servers.get(key); + if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { + return; + } + // Ensure we're the only ones writing to the config + synchronized (Via.getPlatform().getConfigurationProvider()) { + servers.put(key, serverPing.getVersion().getProtocol()); + } + // Save + Via.getPlatform().getConfigurationProvider().saveConfig(); } - // Ensure we're the only ones writing to the config - synchronized (Via.getPlatform().getConfigurationProvider()) { - servers.put(key, serverPing.getVersion().getProtocol()); - } - // Save - Via.getPlatform().getConfigurationProvider().saveConfig(); } } }