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

Fix PacketWrapper#sendToServer bypassing ProtocolLib (#2229)

Dieser Commit ist enthalten in:
Gerrygames 2020-12-08 19:15:55 +01:00 committet von GitHub
Ursprung 8de26a0ad3
Commit 24c56a239e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 44 neuen und 2 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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