diff --git a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index 69df37eef..682904946 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -17,6 +17,7 @@ import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator; import us.myles.ViaVersion.bukkit.commands.BukkitCommandHandler; import us.myles.ViaVersion.bukkit.commands.BukkitCommandSender; +import us.myles.ViaVersion.bukkit.listeners.ProtocolLibEnableListener; import us.myles.ViaVersion.bukkit.platform.BukkitTaskId; import us.myles.ViaVersion.bukkit.platform.BukkitViaAPI; import us.myles.ViaVersion.bukkit.platform.BukkitViaConfig; @@ -48,13 +49,19 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform // Command handler commandHandler = new BukkitCommandHandler(); + // Init platform + BukkitViaInjector injector = new BukkitViaInjector(); + injector.setProtocolLib(Bukkit.getPluginManager().getPlugin("ProtocolLib") != null); + Bukkit.getPluginManager().registerEvents(new ProtocolLibEnableListener(injector), this); + Via.init(ViaManager.builder() .platform(this) .commandHandler(commandHandler) - .injector(new BukkitViaInjector()) + .injector(injector) .loader(new BukkitViaLoader(this)) .build()); + // Config magic conf = new BukkitViaConfig(); diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/ProtocolLibEnableListener.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/ProtocolLibEnableListener.java new file mode 100644 index 000000000..a818fbd50 --- /dev/null +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/ProtocolLibEnableListener.java @@ -0,0 +1,29 @@ +package us.myles.ViaVersion.bukkit.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; +import us.myles.ViaVersion.bukkit.platform.BukkitViaInjector; + +public class ProtocolLibEnableListener implements Listener { + private final BukkitViaInjector injector; + + public ProtocolLibEnableListener(BukkitViaInjector injector) { + this.injector = injector; + } + + @EventHandler + public void onPluginEnable(PluginEnableEvent e) { + if (e.getPlugin().getName().equals("ProtocolLib")) { + injector.setProtocolLib(true); + } + } + + @EventHandler + public void onPluginDisable(PluginDisableEvent e) { + if (e.getPlugin().getName().equals("ProtocolLib")) { + injector.setProtocolLib(false); + } + } +} diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java index 0960248d5..459abd0af 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java @@ -26,6 +26,8 @@ public class BukkitViaInjector implements ViaInjector { private final List injectedFutures = new ArrayList<>(); private final List> injectedLists = new ArrayList<>(); + private boolean protocolLib; + @Override public void inject() throws Exception { try { @@ -214,7 +216,7 @@ public class BukkitViaInjector implements ViaInjector { @Override public String getDecoderName() { - return "decoder"; + return protocolLib ? "protocol_lib_decoder" : "decoder"; } public static Object getServerConnection() throws Exception { @@ -339,4 +341,8 @@ public class BukkitViaInjector implements ViaInjector { field.set(connection, list); } } + + public void setProtocolLib(boolean protocolLib) { + this.protocolLib = protocolLib; + } } \ No newline at end of file