ProtocolLib

3M Downloads

Wrong type of structure modifier

Brad1944 opened this issue ยท 7 comments

commented
  • [Yes] This issue is not solved in a development build

Describe the bug
PlayerInfoActions#write() should expect an EnumSet instead of a List, resulting in a ClassCastException

To Reproduce
Steps to reproduce the behavior:

  1. Use the following code to create a fake NPC
val packet = PacketContainer(PacketType.Play.Server.PLAYER_INFO)

val gp = WrappedGameProfile.fromPlayer(target).withId(UUID.randomUUID().toString())

val data = PlayerInfoData(
  gp,
  1,
  EnumWrappers.NativeGameMode.SURVIVAL,
  WrappedChatComponent.fromText(
  target.name
))
packet.playerInfoActions.write(0, Collections.singleton(EnumWrappers.PlayerInfoAction.ADD_PLAYER)) // ClassCastException
packet.playerInfoDataLists.write(0, Collections.singletonList(data))

manager.sendServerPacket(target, packet)
  1. Run the code!

Expected behavior
The write() function should accept EnumSet as an argument instead of ArrayList, because Minecraft's code expect so
image

Screenshots
image

Version Info
ProtocolLib Dump
Timestamp: 04/10/23 09:39:59

ProtocolLib Version: ProtocolLib v5.0.0-SNAPSHOT-b632
Bukkit Version: 1.19.4-R0.1-SNAPSHOT
Server Version: git-Paper-504 (MC: 1.19.4)
Java Version: 17-internal

ProtocolLib: com.comphenix.protocol.ProtocolLib@57d1f43f[
statistics=com.comphenix.protocol.metrics.Statistics@9885bcc
packetTask=2
tickCounter=7541
configExpectedMod=1
updater=com.comphenix.protocol.updater.SpigotUpdater@3f9ad26
redirectHandler=com.comphenix.protocol.ProtocolLib$2@495ea214
commandProtocol=com.comphenix.protocol.CommandProtocol@1176d70c
commandPacket=com.comphenix.protocol.CommandPacket@5a6bb8d5
commandFilter=com.comphenix.protocol.CommandFilter@14b5be23
packetLogging=com.comphenix.protocol.PacketLogging@2847f0a3
skipDisable=false
isEnabled=true
loader=io.papermc.paper.plugin.manager.DummyBukkitPluginLoader@f2e9c10
server=CraftServer{serverName=Paper,serverVersion=git-Paper-504,minecraftVersion=1.19.4}
file=plugins/ProtocolLib(5).jar
description=org.bukkit.plugin.PluginDescriptionFile@3179c3a5
pluginMeta=org.bukkit.plugin.PluginDescriptionFile@3179c3a5
dataFolder=plugins/ProtocolLib
classLoader=PluginClassLoader{plugin=ProtocolLib v5.0.0-SNAPSHOT-b632, pluginEnabled=true, url=plugins/ProtocolLib(5).jar}
naggable=true
newConfig=YamlConfiguration[path='', root='YamlConfiguration']
configFile=plugins/ProtocolLib/config.yml
logger=com.destroystokyo.paper.utils.PaperPluginLogger@5d992908
]
Manager: com.comphenix.protocol.injector.PacketFilterManager@7435072b[
plugin=ProtocolLib v5.0.0-SNAPSHOT-b632
server=CraftServer{serverName=Paper,serverVersion=git-Paper-504,minecraftVersion=1.19.4}
reporter=com.comphenix.protocol.ProtocolLib$1@b2e86e3
minecraftVersion=(MC: 1.19.4)
asyncFilterManager=com.comphenix.protocol.async.AsyncFilterManager@4abda2b0
pluginVerifier=com.comphenix.protocol.injector.PluginVerifier@5ef81386
inboundListeners=com.comphenix.protocol.injector.SortedPacketListenerList@2285b2d
outboundListeners=com.comphenix.protocol.injector.SortedPacketListenerList@7d4edc15
registeredListeners=[]
packetInjector=com.comphenix.protocol.injector.netty.manager.NetworkManagerPacketInjector@5a41592e
playerInjectionHandler=com.comphenix.protocol.injector.netty.manager.NetworkManagerPlayerInjector@443b05c3
networkManagerInjector=com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector@48adf5a
debug=false
closed=false
injected=true
]

No listeners

commented

Your code is wrong, you need to call the write method with an ArrayList not an EnumSet.

commented

Sorry i didn't make my post clear, but i have tried using Collections.singletonList() instead of EnumSet.of() in order to get an arraylist, and it results in ClassCastException

commented

Currently, as of 1.19.4, playerInfoDataLists and 'playerInfoActionsshare the same field indicies for the PLAYER_INFO packet, as the PlayerInfoDataList Serializer just accepts anyCollection`.

Use Index 1 for accessing the PlayerInfoDataList and everything should work fine.

I would consider this as a bug however fixing this bug would break Plugins implementing the current behavior. What do you think about this? @dmulloy2

commented

Currently, as of 1.19.4, playerInfoDataLists and 'playerInfoActionsshare the same field indicies for the PLAYER_INFO packet, as the PlayerInfoDataList Serializer just accepts anyCollection`.

Use Index 1 for accessing the PlayerInfoDataList and everything should work fine.

I would consider this as a bug however fixing this bug would break Plugins implementing the current behavior. What do you think about this? @dmulloy2

yeah that's tricky. realistically for something like player info data, there's only going to be one list so maybe something like having a structure modifier that ignores the index would work

commented

Use Index 1 for accessing the PlayerInfoDataList and everything should work fine.

Thank you so much for the workaround, however should i keep using it this way or should i wait till an update?

commented

I would suggest to use this workaround for now. However, keep an eye on it when you update ProtocolLib in the future @Brad1944

commented

Awesome, thank you!