ProtocolLib

3M Downloads

PacketPlayOutChat sends null when receiving a TextComponent / IChatBaseComponent

BingoRufus opened this issue · 2 comments

commented

Describe the bug
When doing .getChatComponents() from the packet, it will send a null if it is a TextComponent or IChatBaseComponent

To Reproduce
Steps to reproduce the behavior:

  1. Have a listener for Packet.Play.Server.CHAT
  2. Receive a TextComponent
  3. Get the chat components from the packet

Expected behavior
The Method getChatComponents() should also get the TextComponents / IChatBaseComponents

Other info:
I believe you are getting the JSON from the method "a()" for the PacketPlayOutChat. However, components are received from the Field "components." This is the workaround I had to use to get this.

Object chatPacket = packet.getHandle();
			try {
				Field f = chatPacket.getClass().getDeclaredField("components");
				baseComps = (BaseComponent[]) f.get(chatPacket);
				tc = new TextComponent(baseComps);
				json = ComponentSerializer.toString(tc);

			} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
				ex.printStackTrace();
				return;
Timestamp: 08/15/20 01:03:39

ProtocolLib Version: ProtocolLib v4.5.1
Bukkit Version: 1.16.1-R0.1-SNAPSHOT
Server Version: git-Paper-134 (MC: 1.16.1)
Java Version: 1.8.0_211

ProtocolLib: com.comphenix.protocol.ProtocolLib@10e112a4[
  statistics=com.comphenix.protocol.metrics.Statistics@205f2d17
  backgroundCompiler=com.comphenix.protocol.reflect.compiler.BackgroundCompiler@313c9d55
  packetTask=3
  tickCounter=1369117
  unhookTask=com.comphenix.protocol.injector.DelayedSingleTask@2d3d5a2a
  configExpectedMod=1
  updater=com.comphenix.protocol.updater.SpigotUpdater@5db0eb7c
  redirectHandler=com.comphenix.protocol.ProtocolLib$2@45e5248
  commandProtocol=com.comphenix.protocol.CommandProtocol@515db1a3
  commandPacket=com.comphenix.protocol.CommandPacket@16f64da8
  commandFilter=com.comphenix.protocol.CommandFilter@4c47bf01
  packetLogging=com.comphenix.protocol.PacketLogging@3a7d78d3
  skipDisable=false
  isEnabled=true
  loader=org.bukkit.plugin.java.JavaPluginLoader@6910696
  server=CraftServer{serverName=Paper,serverVersion=git-Paper-134,minecraftVersion=1.16.1}
  file=plugins/ProtocolLib.jar
  description=org.bukkit.plugin.PluginDescriptionFile@53609c12
  dataFolder=plugins/ProtocolLib
  classLoader=PluginClassLoader{plugin=ProtocolLib v4.5.1, pluginEnabled=true, url=plugins/ProtocolLib.jar}
  naggable=true
  newConfig=YamlConfiguration[path='', root='YamlConfiguration']
  configFile=plugins/ProtocolLib/config.yml
  logger=com.destroystokyo.paper.utils.PaperPluginLogger@c21ce2c
]
Manager: com.comphenix.protocol.injector.PacketFilterManager@d897994[
  unhookTask=com.comphenix.protocol.injector.DelayedSingleTask@2d3d5a2a
  packetListeners=[PacketAdapter[plugin=VentureChat, sending=ListeningWhitelist[priority=MONITOR, packets=[CHAT[class=PacketPlayOutChat, id=15]], gamephase=PLAYING, options=[]], receiving=EMPTY_WHITELIST], PacketAdapter[plugin=ChatItemDisplay, sending=ListeningWhitelist[priority=LOWEST, packets=[AUTO_RECIPE[class=PacketPlayInAutoRecipe, id=24], CHAT[class=PacketPlayOutChat, id=15]], gamephase=PLAYING, options=[]], receiving=ListeningWhitelist[priority=LOWEST, packets=[AUTO_RECIPE[class=PacketPlayInAutoRecipe, id=24], CHAT[class=PacketPlayOutChat, id=15]], gamephase=PLAYING, options=[]]]]
  packetInjector=com.comphenix.protocol.injector.netty.ProtocolInjector$5@593d2ddd
  playerInjection=com.comphenix.protocol.injector.netty.ProtocolInjector$4@5befd878
  interceptWritePacket=com.comphenix.protocol.injector.packet.InterceptWritePacket@766a0db2
  inputBufferedPackets=[]
  recievedListeners=com.comphenix.protocol.injector.SortedPacketListenerList@30698f32
  sendingListeners=com.comphenix.protocol.injector.SortedPacketListenerList@8a0f27
  hasClosed=false
  classLoader=PluginClassLoader{plugin=ProtocolLib v4.5.1, pluginEnabled=true, url=plugins/ProtocolLib.jar}
  reporter=com.comphenix.protocol.ProtocolLib$1@25033b56
  server=CraftServer{serverName=Paper,serverVersion=git-Paper-134,minecraftVersion=1.16.1}
  library=ProtocolLib v4.5.1
  asyncFilterManager=com.comphenix.protocol.async.AsyncFilterManager@3a2b5d9
  knowsServerPackets=true
  knowsClientPackets=true
  phaseLoginCount=0
  phasePlayingCount=3
  packetCreation=false
  spigotInjector=<null>
  nettyInjector=com.comphenix.protocol.injector.netty.ProtocolInjector@592558c
  pluginVerifier=com.comphenix.protocol.injector.PluginVerifier@f827504
  hasRecycleDistance=true
  minecraftVersion=(MC: 1.16.1)
  loginPackets=com.comphenix.protocol.injector.LoginPackets@4ba02b24
  debug=false
]

Listeners:
mineverse.Aust1n46.chat.listeners.PacketListener@580d7a18[
  plugin=VentureChat v2.19.1
  connectionSide=SERVER_SIDE
  receivingWhitelist=EMPTY_WHITELIST
  sendingWhitelist=ListeningWhitelist[priority=MONITOR, packets=[CHAT[class=PacketPlayOutChat, id=15]], gamephase=PLAYING, options=[]]
]
me.bingorufus.chatitemdisplay.listeners.ChatPacketListener@68cdf0a0[
  msgs={}
  bell=�
  m=ChatItemDisplay v1.4.5
  w=CraftWorld{name=world}
  plugin=ChatItemDisplay v1.4.5
  connectionSide=BOTH
  receivingWhitelist=ListeningWhitelist[priority=LOWEST, packets=[AUTO_RECIPE[class=PacketPlayInAutoRecipe, id=24], CHAT[class=PacketPlayOutChat, id=15]], gamephase=PLAYING, options=[]]
  sendingWhitelist=ListeningWhitelist[priority=LOWEST, packets=[AUTO_RECIPE[class=PacketPlayInAutoRecipe, id=24], CHAT[class=PacketPlayOutChat, id=15]], gamephase=PLAYING, options=[]]
]

Plugins Using ProtocolLib:
ChatItemDisplay by [BingoRufus]
VentureChat by [Aust1n46]```
commented

Still an issue on 4.7.0. Thank you for the workaround!

commented

I'd actually contend that this is intended behavior. The bungee chat API is open source, so we don't need a wrapper for it