Server crashes when teleporting user

Discussion in 'BungeeCord Help' started by MinecraftKnightz, May 29, 2018.

  1. Hey guys, so I wasn't really sure what section to put this in, but in a Spigot plugin I'm developing for someone, upon teleporting a user to the spawnpoint (which is fully accessible, making me wonder if it's another problem), the server completely crashes with this error
    Code (Text):
    [11:46:08 ERROR]: [MutantCreeper70] <-> DownstreamBridge <-> [buildbattle] - encountered exception
    io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(29) + length(1) exceeds writerIndex(29): UnpooledSlicedByteBuf(ridx: 29, widx: 29, cap: 29/29, unwrapped: PooledUnsafeDirectByteBuf(ridx: 31, widx: 31, cap: 2048))
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) [BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
    Caused by: java.lang.IndexOutOfBoundsException: readerIndex(29) + length(1) exceeds writerIndex(29): UnpooledSlicedByteBuf(ridx: 29, widx: 29, cap: 29/29, unwrapped: PooledUnsafeDirectByteBuf(ridx: 31, widx: 31, cap: 2048))
            at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1405) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:707) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at net.md_5.bungee.protocol.DefinedPacket.readVarInt(DefinedPacket.java:108) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at net.md_5.bungee.protocol.DefinedPacket.readVarInt(DefinedPacket.java:98) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at net.md_5.bungee.protocol.DefinedPacket.readString(DefinedPacket.java:29) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at net.md_5.bungee.protocol.packet.PlayerListItem.read(PlayerListItem.java:38) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at net.md_5.bungee.protocol.MinecraftDecoder.decode(MinecraftDecoder.java:33) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at net.md_5.bungee.protocol.MinecraftDecoder.decode(MinecraftDecoder.java:10) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[BungeeCord.jar:git:BungeeCord-Bootstrap:1.12-SNAPSHOT:968916c:1316]
            ... 27 more
    Being a Java developer myself, I know how to read a stack-trace, but it seems to suggest some sort of malformed packet is being sent. At first I thought it was my plugin messaging, but none is used in the startGame method. It also works on my testing server with no problems, so I'm really kinda baffled.

    Here's the contents of my full start method, a lot of it is custom but you should be able to get the gist of it, and hopefully make me realize what's going on.
    Code (Java):

    private void start() {
       final GameUser beast;
       if (players.stream().anyMatch((p) -> p.owns(ShopItem.fromName("beastpass")))) {
          List<GameUser> passes = players.stream().filter((p) -> p.owns(ShopItem.fromName("beastpass"))).collect(Collectors.toList());
          beast = passes.get(ThreadLocalRandom.current().nextInt(0, passes.size()));
          beast.applyBeastPass();
       } else {
          beast = players.toArray(new GameUser[0])[ThreadLocalRandom.current().nextInt(0, players.size())];
       }

       beast.setRole(Role.BEAST);
       beast.getRoot().sendMessage(etb.getLang("game.beast-role"));
       beast.getRoot().teleport(getBeastSpawn());
       beast.setFrozen(true);
       beast.getRoot().sendMessage(etb.getLang("game.beast-be-released.beast"));
       SkinsRestorerAPI.applySkin(beast.getRoot(), beast.getDisguise() == null ? etb.getConfig().getString("default-disguise") : beast.getDisguise());
       new BukkitRunnable() {
          public void run() {
             beast.setFrozen(false);
             beast.getRoot().sendMessage(etb.getLang("game.beast-released.beast"));
             String message = etb.getLang("game.beast-released.runners");
             players.stream().filter((b) -> b != beast).map(GameUser::getRoot).forEach((p) -> p.sendMessage(message));
          }
       }.runTaskLater(etb, 300L);
       players.stream().map(GameUser::getRoot).forEach((p) -> {
          p.getInventory().clear();
          GameUser.valueOf(p).applyEquipped();
       });
       players.stream().filter((p) -> p != beast).forEach((g) -> {
          if (g.getDisguise() != null) {
             SkinsRestorerAPI.applySkin(g.getRoot(), g.getDisguise());
          }

          g.setRole(Role.RUNNERS);
          g.getRoot().sendMessage(etb.getLang("game.runner-role"));
          g.getRoot().teleport(getRunnersSpawn());
          g.getRoot().sendMessage(etb.getLang("game.beast-be-released.runners"));
       });
    }
     
    Also, if this is the wrong section please don't hesitate to move it. I was stuck between this, Bungeecord Development, or Spigot Development.

    Thanks guys.
     
    #1 MinecraftKnightz, May 29, 2018
    Last edited: May 29, 2018
  2. This is because you're accessing data that isn't set in the List/Map you're using
     
  3. To avoid this, add a check to see if the data you're getting is there.
     
  4. Can you elaborate? Surely that would cause some sort of NPE, and on the server side, rather than on BungeeCord?
     
  5. Also, I get this error on the server (rather than BungeeCord)
    Code (Text):
     java.lang.ClassCastException: java.lang.String cannot be cast to com.mojang.authlib.properties.Property
     
    No other stack-trace, nothing
     
  6. Bump, still a present issue that needs fixing ASAP.