ProtocolLib

3M Downloads

IllegalStateException when creating bundle packet container in 1.19.4

josemmo opened this issue ยท 1 comments

commented
  • This issue is not solved in a development build

Describe the bug
When writing to the packet bundles structure of a PacketContainer of the type PacketType.Play.Server.BUNDLE in a 1.19.4 server, ProtocolLib throws an exception.

The issue appears to be related to a failed cast from net.minecraft.network.protocol.BundleDelimiterPacket to net.minecraft.network.protocol.BundlePacket.

To Reproduce

List<PacketContainer> packets = new ArrayList<>();
for (int i=0; i<10; i++) {
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.SET_ACTION_BAR_TEXT);
    packet.getChatComponents().write(0, WrappedChatComponent.fromText("Example #"+i));
    packets.add(packet);
}

PacketContainer container = new PacketContainer(PacketType.Play.Server.BUNDLE);
container.getPacketBundles().write(0, packets); // <--- This throws exception

// Player player = [...];
ProtocolManager connection = ProtocolLibrary.getProtocolManager();
connection.sendServerPacket(player, container);

Expected behavior
It should instantiate and send the bundled packet. Instead, it throws an exception:

java.lang.IllegalStateException: Unable to set value of field private final java.lang.Iterable net.minecraft.network.protocol.BundlePacket.a
        at com.comphenix.protocol.reflect.accessors.DefaultFieldAccessor.set(DefaultFieldAccessor.java:44) ~[ProtocolLib-5.0.0-SNAPSHOT-b636.jar:?]
        at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:359) ~[ProtocolLib-5.0.0-SNAPSHOT-b636.jar:?]
        at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:322) ~[ProtocolLib-5.0.0-SNAPSHOT-b636.jar:?]
        at io.josemmo.bukkit.plugin.renderer.FakeEntity.tryToSendPackets(FakeEntity.java:122) ~[YamipaPlugin.jar:?]
        at io.josemmo.bukkit.plugin.renderer.FakeImage.nextStep(FakeImage.java:542) ~[YamipaPlugin.jar:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.ClassCastException: Cannot cast net.minecraft.network.protocol.BundleDelimiterPacket to net.minecraft.network.protocol.BundlePacket
        at java.lang.Class.cast(Class.java:3889) ~[?:?]
        at com.comphenix.protocol.reflect.accessors.DefaultFieldAccessor.set(DefaultFieldAccessor.java:41) ~[ProtocolLib-5.0.0-SNAPSHOT-b636.jar:?]
        ... 10 more
Version Info
ProtocolLib Dump
Timestamp: 04/24/23 18:58:39

ProtocolLib Version: ProtocolLib v5.0.0-SNAPSHOT-636
Bukkit Version: 1.19.4-R0.1-SNAPSHOT
Server Version: git-Paper-516 (MC: 1.19.4)
Java Version: 17.0.6

ProtocolLib: com.comphenix.protocol.ProtocolLib@593b8127[
  statistics=com.comphenix.protocol.metrics.Statistics@5a08fad4
  packetTask=8
  tickCounter=3327
  configExpectedMod=1
  updater=com.comphenix.protocol.updater.SpigotUpdater@51cc0be8
  redirectHandler=com.comphenix.protocol.ProtocolLib$2@799decf2
  commandProtocol=com.comphenix.protocol.CommandProtocol@7c2a685f
  commandPacket=com.comphenix.protocol.CommandPacket@6169f354
  commandFilter=com.comphenix.protocol.CommandFilter@504b27da
  packetLogging=com.comphenix.protocol.PacketLogging@4627bb5d
  skipDisable=false
  isEnabled=true
  loader=io.papermc.paper.plugin.manager.DummyBukkitPluginLoader@69e04b56
  server=CraftServer{serverName=Paper,serverVersion=git-Paper-516,minecraftVersion=1.19.4}
  file=plugins\ProtocolLib-5.0.0-SNAPSHOT-b636.jar
  description=org.bukkit.plugin.PluginDescriptionFile@4ec16ca7
  pluginMeta=org.bukkit.plugin.PluginDescriptionFile@4ec16ca7
  dataFolder=plugins\ProtocolLib
  classLoader=PluginClassLoader{plugin=ProtocolLib v5.0.0-SNAPSHOT-636, pluginEnabled=true, url=plugins\ProtocolLib-5.0.0-SNAPSHOT-b636.jar}
  naggable=true
  newConfig=YamlConfiguration[path='', root='YamlConfiguration']
  configFile=plugins\ProtocolLib\config.yml
  logger=com.destroystokyo.paper.utils.PaperPluginLogger@5e168c74
]
Manager: com.comphenix.protocol.injector.PacketFilterManager@76b08745[
  plugin=ProtocolLib v5.0.0-SNAPSHOT-636
  server=CraftServer{serverName=Paper,serverVersion=git-Paper-516,minecraftVersion=1.19.4}
  reporter=com.comphenix.protocol.ProtocolLib$1@33516960
  minecraftVersion=(MC: 1.19.4)
  asyncFilterManager=com.comphenix.protocol.async.AsyncFilterManager@38462038
  pluginVerifier=com.comphenix.protocol.injector.PluginVerifier@52596e68
  inboundListeners=com.comphenix.protocol.injector.SortedPacketListenerList@20a151c9
  outboundListeners=com.comphenix.protocol.injector.SortedPacketListenerList@188336d4
  registeredListeners=[io.josemmo.bukkit.plugin.renderer.ItemService@19214e8]
  packetInjector=com.comphenix.protocol.injector.netty.manager.NetworkManagerPacketInjector@114d821c
  playerInjectionHandler=com.comphenix.protocol.injector.netty.manager.NetworkManagerPlayerInjector@87e8473
  networkManagerInjector=com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector@22fbb3ac
  debug=false
  closed=false
  injected=true
]

Listeners:
io.josemmo.bukkit.plugin.renderer.ItemService@19214e8[
]

Plugins Using ProtocolLib:
YamipaPlugin by []
commented

It fails because PacketType.Play.Server.BUNDLE represents the BundleDelimiterPacket which is used to mark the start and end of a bundle packet. What you need would be the ClientboundBundlePacket which is an BundlePacket but I don't think ProtocolLib is currently exposing this PacketType.

I don't think you could even use PacketType for BundlePacket cause BundlePacket isn't a real packet in that it doesn't have a packet id and it's not registered as a normal packet. Mojang added two new netty handlers which unpack and pack a BundlePacket. The PacketBundleUnpacker simply sends a delimiter packet, the bundle sub-packtes and another delimiter. While the PacketBundlePacker does the exact opposite (waiting for delimiter and then group all following packets till the next delimiter).