Add a command to force search versions @ Bungee

This commit is contained in:
Matsv 2016-10-01 15:38:53 +02:00
parent ba3aa4566e
commit 59620f7f93
No known key found for this signature in database
GPG Key ID: 97CEC2A2EA31350F
4 changed files with 39 additions and 4 deletions

View File

@ -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();
}
}
}

View File

@ -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;
}
}

View File

@ -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<String, Integer> 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();
}
});
}

View File

@ -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()) {