mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 10:05:12 +01:00
Fix PacketWrapper#sendToServer bypassing ProtocolLib (#2229)
This commit is contained in:
parent
8de26a0ad3
commit
24c56a239e
@ -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<Player>
|
||||
|
||||
// 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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -26,6 +26,8 @@ public class BukkitViaInjector implements ViaInjector {
|
||||
private final List<ChannelFuture> injectedFutures = new ArrayList<>();
|
||||
private final List<Pair<Field, Object>> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user