3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Delay registration of protocols until the plugin has loaded to prevent it being done at the wrong time, #323 #316 Fixed

Dieser Commit ist enthalten in:
Myles 2016-04-03 23:30:10 +01:00
Ursprung 4431ca63c2
Commit c7c6ee9fbc
3 geänderte Dateien mit 21 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -94,6 +94,9 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
getCommand("viaversion").setExecutor(commandHandler = new ViaCommandHandler()); getCommand("viaversion").setExecutor(commandHandler = new ViaCommandHandler());
getCommand("viaversion").setTabCompleter(commandHandler); getCommand("viaversion").setTabCompleter(commandHandler);
// Register Protocol Listeners
ProtocolRegistry.registerListeners();
} }
@Override @Override

Datei anzeigen

@ -20,7 +20,6 @@ public abstract class Protocol {
public Protocol() { public Protocol() {
registerPackets(); registerPackets();
registerListeners();
} }
/** /**

Datei anzeigen

@ -1,5 +1,6 @@
package us.myles.ViaVersion.api.protocol; package us.myles.ViaVersion.api.protocol;
import org.bukkit.Bukkit;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9; import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
@ -11,6 +12,7 @@ public class ProtocolRegistry {
// Input Version -> Output Version & Protocol (Allows fast lookup) // Input Version -> Output Version & Protocol (Allows fast lookup)
private static Map<Integer, Map<Integer, Protocol>> registryMap = new HashMap<>(); private static Map<Integer, Map<Integer, Protocol>> registryMap = new HashMap<>();
private static Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new HashMap<>(); private static Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new HashMap<>();
private static List<Protocol> registerList = new ArrayList<>();
static { static {
// Register built in protocols // Register built in protocols
@ -37,6 +39,12 @@ public class ProtocolRegistry {
registryMap.get(version).put(output, protocol); registryMap.get(version).put(output, protocol);
} }
if (Bukkit.getPluginManager().getPlugin("ViaVersion").isEnabled()) {
protocol.registerListeners();
} else {
registerList.add(protocol);
}
} }
/** /**
@ -51,6 +59,16 @@ public class ProtocolRegistry {
return false; // No destination for protocol return false; // No destination for protocol
} }
/**
* Called when the server is enabled, to register any non registered listeners.
*/
public static void registerListeners() {
for (Protocol protocol : registerList) {
protocol.registerListeners();
}
registerList.clear();
}
/** /**
* Calculate a path to get from an input protocol to the servers protocol. * Calculate a path to get from an input protocol to the servers protocol.
* *