Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7733

sendPluginMessage on Brand channel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • In case it is relevant: I use PacketEvents, but I don't listen to or write to the brand channel with it.

      The error only appears on 1.20.6, on 1.20.5 it works fine.

    • This server is running CraftBukkit version 4184-Spigot-fcd94e2-16c9767 (MC: 1.20.6) (Implementing API version 1.20.6-R0.1-SNAPSHOT)
    • Yes

      When I use player.sendPluginMessage() on the minecraft:brand channel, I get the following error. This also prevents joining when used in an onJoin event:

      io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:custom_payload'
          at net.minecraft.network.codec.IdDispatchCodec.a(SourceFile:55) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.codec.IdDispatchCodec.encode(SourceFile:14) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.PacketEncoder.a(SourceFile:26) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.PacketEncoder.encode(SourceFile:12) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.ChannelOutboundHandlerAdapter.write(ChannelOutboundHandlerAdapter.java:113) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at net.minecraft.network.NetworkManager$2.write(NetworkManager.java:543) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:940) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:966) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:934) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:984) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:306) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at net.minecraft.network.NetworkManager.c(NetworkManager.java:366) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.NetworkManager.lambda$sendPacket$12(NetworkManager.java:359) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
          at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
          at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
      Caused by: java.lang.ClassCastException: class net.minecraft.network.protocol.common.custom.DiscardedPayload cannot be cast to class net.minecraft.network.protocol.common.custom.BrandPayload (net.minecraft.network.protocol.common.custom.DiscardedPayload and net.minecraft.network.protocol.common.custom.BrandPayload are in unnamed module of loader java.net.URLClassLoader @22927a81)
          at net.minecraft.network.codec.StreamCodec$6.encode(SourceFile:42) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.protocol.common.custom.CustomPacketPayload$1.a(SourceFile:52) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.protocol.common.custom.CustomPacketPayload$1.a(SourceFile:57) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.protocol.common.custom.CustomPacketPayload$1.encode(SourceFile:39) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.codec.StreamCodec$8.encode(SourceFile:81) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.codec.StreamCodec$9.a(SourceFile:97) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.codec.StreamCodec$9.encode(SourceFile:87) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          at net.minecraft.network.codec.IdDispatchCodec.a(SourceFile:53) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4184-Spigot-fcd94e2-16c9767]
          ... 31 more
      

      My actual code, in case that my way of doing it is unsupported. If there is a better or new way/API of doing it, please tell me as well:

      public void setBrand(String brand)
      {
          this.brand = ChatColor.translateAlternateColorCodes('&', brand) + ChatColor.RESET;
          this.updateAllBrands();
      }
      
      private void updateAllBrands()
      {
          for (Player onlinePlayer : Bukkit.getOnlinePlayers()) updateBrand(onlinePlayer);
      }
      
      private void updateBrand(final Player player)
      {
          final ByteBuf buf = Unpooled.buffer();
      
          ByteBufUtil.writeString(buf, Placeholders.replacePlaceholders(this.brand, player));
      
          player.sendPluginMessage(AntiCheatAddition.getInstance(), MessageChannel.MC_BRAND_CHANNEL.getChannel().orElseThrow(), ByteBufUtil.toArray(buf));
          buf.release();
      }
      
      @Override
      public void enable()
      {
          Bukkit.getMessenger().registerOutgoingPluginChannel(AntiCheatAddition.getInstance(), MessageChannel.MC_BRAND_CHANNEL.getChannel().orElseThrow());
          this.setBrand(loadString(".brand", "Some Spigot"));
      
          final long refreshRate = loadLong(".refresh_rate", 0);
          if (refreshRate > 0) Bukkit.getScheduler().runTaskTimer(AntiCheatAddition.getInstance(), this::updateAllBrands, 20, refreshRate);
      }
      
      @EventHandler
      public void onJoin(PlayerJoinEvent event)
      {
          // Add the mc brand channel to the player's channels.
          PLAYER_CHANNELS_FIELD.from(event.getPlayer()).asSet(String.class).add(MessageChannel.MC_BRAND_CHANNEL.getChannel().orElseThrow());
          updateBrand(event.getPlayer());
      } 

       

            Unassigned Unassigned
            Photon Photon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: