diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index fc144eb77..9ee9b79c8 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -94,6 +94,9 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe getCommand("viaversion").setExecutor(commandHandler = new ViaCommandHandler()); getCommand("viaversion").setTabCompleter(commandHandler); + + // Register Protocol Listeners + ProtocolRegistry.registerListeners(); } @Override diff --git a/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index 02ac37ba2..7ad1ff403 100644 --- a/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -20,7 +20,6 @@ public abstract class Protocol { public Protocol() { registerPackets(); - registerListeners(); } /** diff --git a/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index f11e3c84b..40fa1307c 100644 --- a/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.api.protocol; +import org.bukkit.Bukkit; 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_9to1_8.Protocol1_9TO1_8; @@ -11,6 +12,7 @@ public class ProtocolRegistry { // Input Version -> Output Version & Protocol (Allows fast lookup) private static Map> registryMap = new HashMap<>(); private static Map, List>> pathCache = new HashMap<>(); + private static List registerList = new ArrayList<>(); static { // Register built in protocols @@ -37,6 +39,12 @@ public class ProtocolRegistry { 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 } + /** + * 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. *