diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/commands/BungeeCommandHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/commands/BungeeCommandHandler.java index 4e1cbefd5..4d23174b1 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/commands/BungeeCommandHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/commands/BungeeCommandHandler.java @@ -1,7 +1,15 @@ package us.myles.ViaVersion.bungee.commands; +import us.myles.ViaVersion.bungee.commands.subs.SearchServersSubCmd; import us.myles.ViaVersion.commands.ViaCommandHandler; public class BungeeCommandHandler extends ViaCommandHandler { - + public BungeeCommandHandler() { + try { + registerSubCommand(new SearchServersSubCmd()); + } catch (Exception e) { + System.out.println("Failed to register Bungee subcommands"); + e.printStackTrace(); + } + } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/commands/subs/SearchServersSubCmd.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/commands/subs/SearchServersSubCmd.java new file mode 100644 index 000000000..98aa8531f --- /dev/null +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/commands/subs/SearchServersSubCmd.java @@ -0,0 +1,25 @@ +package us.myles.ViaVersion.bungee.commands.subs; + +import us.myles.ViaVersion.api.command.ViaCommandSender; +import us.myles.ViaVersion.api.command.ViaSubCommand; +import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; + +// TODO better name +public class SearchServersSubCmd extends ViaSubCommand { + @Override + public String name() { + return "searchservers"; + } + + @Override + public String description() { + return "Force ViaVersion to search for servers to update the version list (Also happens every minute)"; + } + + @Override + public boolean execute(ViaCommandSender sender, String[] args) { + ProtocolDetectorService.getInstance().run(); + sendMessage(sender, "&6Started searching for subservers"); + return true; + } +} 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 d8113b12f..0f9e2d189 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 @@ -1,5 +1,6 @@ package us.myles.ViaVersion.bungee.service; +import lombok.Getter; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; @@ -11,9 +12,12 @@ import java.util.concurrent.ConcurrentHashMap; public class ProtocolDetectorService implements Runnable { private static final Map protocolIds = new ConcurrentHashMap<>(); private BungeePlugin plugin; + @Getter + private static ProtocolDetectorService instance; public ProtocolDetectorService(BungeePlugin plugin) { this.plugin = plugin; + instance = this; } public static Integer getProtocolId(String serverName) { @@ -39,8 +43,6 @@ public class ProtocolDetectorService implements Runnable { public void done(ServerPing serverPing, Throwable throwable) { if (throwable == null) protocolIds.put(key, serverPing.getVersion().getProtocol()); - else - throwable.printStackTrace(); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java index cfc9c6de5..675df3a22 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java @@ -10,7 +10,7 @@ public class ViaIdleThread implements Runnable { @Override public void run() { for (UserConnection info : Via.getManager().getPortedPlayers().values()) { - if (info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { + if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); if (nextIdleUpdate <= System.currentTimeMillis()) { if (info.getChannel().isOpen()) {