Add support for new protocollib builds
This commit is contained in:
1 parent
793ec64aca
commit
d28e709d63
3 files changed
+27
-140
No files matched your search
@@ -397,8 +397,7 @@ public class CommonPlugin extends PluginBase {
|
||||
} else if (!warnedAboutBrokenBundlePacket) {
|
||||
warnedAboutBrokenBundlePacket = true;
|
||||
Logging.LOGGER_NETWORK.log(Level.WARNING, "ProtocolLib cannot be used because it does not support the Bundle packet yet");
|
||||
Logging.LOGGER_NETWORK.log(Level.WARNING, "Please update ProtocolLib to a 1.19.4+ supporting version");
|
||||
Logging.LOGGER_NETWORK.log(Level.WARNING, "For more info, see: https://github.com/dmulloy2/ProtocolLib/issues/2244");
|
||||
Logging.LOGGER_NETWORK.log(Level.WARNING, "Please update ProtocolLib to a 1.19.4+ supporting version (build #620 or newer)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
package com.bergerkiller.bukkit.common.internal.network;
|
||||
|
||||
import com.bergerkiller.bukkit.common.protocol.PacketType;
|
||||
import com.bergerkiller.generated.net.minecraft.network.protocol.PacketHandle;
|
||||
import com.bergerkiller.generated.net.minecraft.network.protocol.game.ClientboundBundlePacketHandle;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.ListeningWhitelist;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Used by the ProtocolLib handler on 1.19.4 and beyond. Listens for bundle packets,
|
||||
* and processes them using all listeners/monitors that have been registered.
|
||||
*/
|
||||
class ProtocolLibBundlePacketHandler extends PacketHandlerRegistration {
|
||||
|
||||
private final ProtocolLibPacketHandler protocolLibHandler;
|
||||
private final Plugin plugin;
|
||||
private final Handler listenerHandler;
|
||||
private final Handler monitorHandler;
|
||||
|
||||
public ProtocolLibBundlePacketHandler(ProtocolLibPacketHandler protocolLibHandler, Plugin plugin) {
|
||||
this.protocolLibHandler = protocolLibHandler;
|
||||
this.plugin = plugin;
|
||||
this.listenerHandler = new Handler(ListenerPriority.LOWEST) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent packetEvent) {
|
||||
// Filter Bundle packets (if not already cancelled. Too complex to solve that.)
|
||||
if (!packetEvent.isPlayerTemporary() && !packetEvent.isCancelled()) {
|
||||
ClientboundBundlePacketHandle bundle = ClientboundBundlePacketHandle.createHandle(packetEvent.getPacket().getHandle());
|
||||
final Player player = packetEvent.getPlayer();
|
||||
if (!bundle.filterSubPackets(packet -> handleSendBundlePacket(packetEvent, player, packet))) {
|
||||
packetEvent.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
this.monitorHandler = new Handler(ListenerPriority.MONITOR) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent packetEvent) {
|
||||
// Notify all packets contained within bundle packets
|
||||
if (!packetEvent.isPlayerTemporary()) {
|
||||
Iterable<Object> subPackets = PacketHandle.tryUnwrapBundlePacket(packetEvent.getPacket().getHandle());
|
||||
for (Object raw_packet : subPackets) {
|
||||
handlePacketSendMonitor(packetEvent.getPlayer(), PacketType.getType(raw_packet), raw_packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void register() {
|
||||
ProtocolLibPacketHandler.getProtocolManager().addPacketListener(listenerHandler);
|
||||
ProtocolLibPacketHandler.getProtocolManager().addPacketListener(monitorHandler);
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
ProtocolLibPacketHandler.getProtocolManager().removePacketListener(listenerHandler);
|
||||
ProtocolLibPacketHandler.getProtocolManager().removePacketListener(monitorHandler);
|
||||
}
|
||||
|
||||
private boolean handleSendBundlePacket(PacketEvent event, Player player, Object raw_packet) {
|
||||
ClientboundBundlePacketHandle bundle = ClientboundBundlePacketHandle.createHandle(raw_packet);
|
||||
PacketType packetType = PacketType.OUT_BUNDLE;
|
||||
|
||||
return bundle.filterSubPackets(p -> protocolLibHandler.handleSendDuring(event, () ->
|
||||
handlePacketSend(player, packetType, p, false, false)));
|
||||
}
|
||||
|
||||
private abstract class Handler implements com.comphenix.protocol.events.PacketListener {
|
||||
private final ListeningWhitelist receiving;
|
||||
private final ListeningWhitelist sending;
|
||||
|
||||
private Handler(ListenerPriority priority) {
|
||||
PacketType[] types = new PacketType[] { PacketType.OUT_BUNDLE };
|
||||
this.receiving = ProtocolLibPacketHandler.getWhiteList(priority, new PacketType[0], true);
|
||||
this.sending = ProtocolLibPacketHandler.getWhiteList(priority, types, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListeningWhitelist getReceivingWhitelist() {
|
||||
return receiving;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListeningWhitelist getSendingWhitelist() {
|
||||
return sending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent packetEvent) {
|
||||
// Client doesn't send bundles
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-37
@@ -48,10 +48,34 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
private Class<?> loggedOutPlayerExceptionType = String.class;
|
||||
private boolean useSilentPacketQueue = false;
|
||||
private boolean isSendSilentPacketBroken = false;
|
||||
private ProtocolLibBundlePacketHandler bundlePacketHandler = null;
|
||||
|
||||
public static boolean isBundlePacketWorking() {
|
||||
return !CommonCapabilities.HAS_BUNDLE_PACKET || getPacketType(PacketType.OUT_BUNDLE) != null;
|
||||
// Unimportant on older MC
|
||||
if (!CommonCapabilities.HAS_BUNDLE_PACKET) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for a >5.0.0 version of protocollib, where for sure it's supported
|
||||
Plugin p = CommonUtil.getPlugin("ProtocolLib");
|
||||
if (p != null) {
|
||||
// 5.0.0-SNAPSHOT-b621
|
||||
String ver = p.getDescription().getVersion();
|
||||
int dashIdx = ver.indexOf('-');
|
||||
if (dashIdx != -1) {
|
||||
ver = ver.substring(0, dashIdx);
|
||||
}
|
||||
if (TextValueSequence.evaluateText(ver, ">", "5.0.0")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Support is unsure - check that the PacketEvent has a getBundle() to indicate its fixed
|
||||
try {
|
||||
PacketEvent.class.getMethod("getBundle");
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,17 +126,6 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
this.isSendSilentPacketBroken = false;
|
||||
}
|
||||
|
||||
// Since 1.19.4 there is a Bundle packet. We listen for this one ourselves and process it with our
|
||||
// own listener system
|
||||
if (CommonCapabilities.HAS_BUNDLE_PACKET) {
|
||||
if (getPacketType(PacketType.OUT_BUNDLE) == null) {
|
||||
Logging.LOGGER_NETWORK.log(Level.SEVERE, "ProtocolLib does not support listening for Bundle packets. Functionality will be broken!");
|
||||
} else {
|
||||
bundlePacketHandler = new ProtocolLibBundlePacketHandler(this, CommonPlugin.getInstance());
|
||||
bundlePacketHandler.register();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -128,10 +141,6 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
this.monitors.clear();
|
||||
this.listeners.clear();
|
||||
this.silentQueueCleanupTask.disable();
|
||||
if (bundlePacketHandler != null) {
|
||||
bundlePacketHandler.unregister();
|
||||
bundlePacketHandler = null;
|
||||
}
|
||||
if (!CommonUtil.isShuttingDown()) {
|
||||
Logging.LOGGER_NETWORK.warning("Reload detected! ProtocolLib does not officially support reloading the server!");
|
||||
if (!Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
@@ -326,10 +335,6 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
mon_iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (bundlePacketHandler != null) {
|
||||
bundlePacketHandler.removePacketListeners(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -342,10 +347,6 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (bundlePacketHandler != null) {
|
||||
bundlePacketHandler.removePacketListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -358,10 +359,6 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (bundlePacketHandler != null) {
|
||||
bundlePacketHandler.removePacketMonitor(monitor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -369,10 +366,6 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
CommonPacketListener commonListener = new CommonPacketListener(plugin, listener, types);
|
||||
getProtocolManager().addPacketListener(commonListener);
|
||||
this.listeners.add(commonListener);
|
||||
|
||||
if (bundlePacketHandler != null) {
|
||||
bundlePacketHandler.addPacketListener(plugin, listener, types);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -380,10 +373,6 @@ public class ProtocolLibPacketHandler implements PacketHandler {
|
||||
CommonPacketMonitor commonMonitor = new CommonPacketMonitor(plugin, monitor, types);
|
||||
getProtocolManager().addPacketListener(commonMonitor);
|
||||
this.monitors.add(commonMonitor);
|
||||
|
||||
if (bundlePacketHandler != null) {
|
||||
bundlePacketHandler.addPacketMonitor(plugin, monitor, types);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user