1.15.2 PacketTooLargeException - PacketPlayOutPlayerInfo

Discussion in 'Spigot Plugin Development' started by VivianMusic, Mar 20, 2020.

  1. I am getting this error
    Code (Text):
    20.03 05:22:10 [Disconnect] User Squallz has disconnected, reason: Internal Exception: net.minecraft.server.v1_15_R1.PacketEncoder$PacketTooLargeException: PacketTooLarge - PacketPlayOutPlayerInfo is 18415509. Max is 2097152
    from spawning my custom NPCs and showing them.
    NPC Class:
    Code (Text):
    package com.squallz.nationclasses.objects;


    import com.mojang.authlib.GameProfile;
    import com.mojang.authlib.properties.Property;
    import com.squallz.nationclasses.ClassesMain;
    import com.squallz.nationclasses.enums.ClassType;
    import com.squallz.nationclasses.utils.WrapperPlayServerAnimation;
    import net.minecraft.server.v1_15_R1.*;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
    import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
    import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.NameTagVisibility;
    import org.bukkit.scoreboard.Team;

    import java.util.UUID;

    public class NPC {

        private String npcName;
        private ClassType npcClassType;
        private String npcUUID;
        private String worldName;
        private double x;
        private double y;
        private double z;
        private float yaw;
        private float pitch;
        private transient Location npcLocation;
        private transient EntityPlayer npc;
        private transient GameProfile gameProfile;
        private String texture;
        private String signature;

        public NPC (String npcName, ClassType npcClassType, String npcSkinTexture, String npcSkinSignature, String uuid, Location npcLocation ) {

            this.npcName = npcName;
            this.npcClassType = npcClassType;
            this.npcUUID = uuid;
            this.npcLocation = npcLocation;

            this.worldName = getNPCLocation().getWorld().getName();
            this.x = getNPCLocation().getX();
            this.y = getNPCLocation().getY();
            this.z = getNPCLocation().getZ();
            this.yaw = npcLocation.getYaw();
            this.pitch = npcLocation.getPitch();

            this.texture = npcSkinTexture;
            this.signature = npcSkinSignature;

            MinecraftServer minecraftServer = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer worldServer = ((CraftWorld) getNPCLocation().getWorld()).getHandle();

            this.gameProfile = new GameProfile(UUID.fromString(getUUID()), getName());

            setTextureAndSignature();

            this.npc = new EntityPlayer(minecraftServer, worldServer, gameProfile, new PlayerInteractManager((worldServer)));

            DataWatcher dataWatcher = npc.getDataWatcher();
            dataWatcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);

            npcLocation.add(0.5, 0, 0.5);
            this.npc.setLocation(npcLocation.getX(), npcLocation.getY(), npcLocation.getZ(), npcLocation.getYaw(), npcLocation.getPitch());
        }

        public void setTextureAndSignature() {
            this.gameProfile.getProperties().put("textures", new Property("textures", getTexture(), getSignature()));
        }

        public String getName() {
            return npcName;
        }

        public ClassType getClassType() {
            return npcClassType;
        }

        public String getUUID() {
            return npcUUID;
        }

        public Location getNPCLocation(){
            return npcLocation;
        }

        public EntityPlayer getNPC(){
            return npc;
        }

        public String getTexture() {
            return texture;
        }

        public String getSignature() {
            return signature;
        }

        public void show(final Player player) {
            final PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;

            playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
            playerConnection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
            playerConnection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.yaw * 256 / 360)));
            playerConnection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), npc.getDataWatcher(), true));

            org.bukkit.scoreboard.Scoreboard scoreboard = player.getScoreboard();

            Team npcs = null;

            for(Team team : scoreboard.getTeams()) {
                if(team.getName().equals("npcs")) {
                    npcs = team;
                    break;
                }
            }

            if(npcs == null) {
                npcs = scoreboard.registerNewTeam("npcs");
            }

            npcs.setNameTagVisibility(NameTagVisibility.NEVER);
            npcs.addEntry(npcName);

            WrapperPlayServerAnimation animation = new WrapperPlayServerAnimation();
            animation.setEntityID(getNPC().getId());
            animation.setAnimation(0);

            animation.sendPacket(player);

            Bukkit.getScheduler().scheduleSyncDelayedTask(ClassesMain.getInstance(), new Runnable() {
                public void run(){
                    playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, npc));
                }
            }, 20);
        }

        public void hide(Player player) {
            final PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
            connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, npc));
            connection.sendPacket(new PacketPlayOutEntityDestroy(npc.getId()));
        }

        public String getWorldName() {
            return worldName;
        }

        public Double getX(){
            return x;
        }

        public Double getY(){
            return y;
        }

        public Double getZ(){
            return z;
        }

        public float getYaw(){
            return yaw;
        }

        public float getPitch(){
            return pitch;
        }
    }
     
    When the server starts, I create a new NPC for each texture/signature in my .json file:
    Code (Text):
    [
      {
        "npcName": "Knight",
        "npcClassType": "KNIGHT",
        "npcUUID": "0b3f0f30-24a4-4a06-a787-ff6e36479c2a",
        "worldName": "newnations",
        "x": 20.0,
        "y": 69.0,
        "z": 48.0,
        "yaw": 89.821,
        "pitch": 6.45,
        "texture": "eyJ0aW1lc3RhbXAiOjE1ODM4MjAxODk1OTYsInByb2ZpbGVJZCI6ImU0MmI2MGIwYzM1YTQ2MmZhMmI0YjFhOTk4MGYzOTllIiwicHJvZmlsZU5hbWUiOiJTcXVhbGx6Iiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9jOTdlN2VlNjk4YThmN2U1Mjc0MDViNTMwYzE4ZDBiMjFiY2ZjNjZiZWQzZWMyMDg5ZmJkZjdjMGM3NjQyMTkzIiwibWV0YWRhdGEiOnsibW9kZWwiOiJzbGltIn19fX0\u003d",
        "signature": "bIvRgRZjVAxIZEaSVFtwoWiuu+MQQb6Ygt6NaRc9pFVszfeO8Yes3v0+cGp0uO56IQs2TSqUWI9zCy7h7OuMrbFL3jQ/oiSFdADNsya2iaUneRkV92eoGwaa7rQUrHMwWzFqrlHGMushf6Ph96nFtujBowjowWD+DOxZCK8rgQb4jjirB/Yi1lA+CXJ/Z1XDM+AruBPFcv+8bhPHR5Wv+JfWAEgf7qe9qGVYKj8JNyp5kEDA0yf7a3koVJXchKbwbWXou77Bd0O9mBWQ3d0OhjSeavU5U8t75mWuiZ35UZhPNdhmnomjpqEha15YcRt0+hDeEGO/p92hOThjKqrupmGF0r/UP4ANoZW6nEHXuFXsoaeNebWuCQiclae2bR/ZyrPCh/30AIDh/EfWols/W1YgAue8w/LFQV3h5fbz055bmfFfIut4R2lQrAN8gl0JAVorN2lf4G/UztiLEF6xcPGV33Y2fLdTz9aktv/OW3Y4g9tG6b9xamaPrFxUKaH6yEiXZtKetO9mTh1QM2zkwyftf30TLBftXeNQmtK5bi+GRmsWLgg8d10hd06/lexmklxTBTQw6PHqdaIzNRMy26bhQ6SVXHqgZbMu2weoM2xhmWI3hie7VALicI13wdkneVHygpmfctckTnDmae2H8GhClFy10ifCGeVWa0yNDDc\u003d"
      },
      {
        "npcName": "Thief",
        "npcClassType": "THIEF",
        "npcUUID": "99ab5c1b-8a6e-41f4-9d3c-0be19d9ccf85",
        "worldName": "newnations",
        "x": 20.0,
        "y": 69.0,
        "z": 52.0,
        "yaw": 89.821,
        "pitch": 6.45,
        "texture": "eyJ0aW1lc3RhbXAiOjE1ODM4MjEzMTYxMTMsInByb2ZpbGVJZCI6ImU0MmI2MGIwYzM1YTQ2MmZhMmI0YjFhOTk4MGYzOTllIiwicHJvZmlsZU5hbWUiOiJTcXVhbGx6Iiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yMjYxMGY2MWJjODZhZWU0NzVlOTc5ZTJhZWMwYjE0NDIyZDEzODU1MWIwNWJmYTY3NjViODRlMjRlODFmNWFiIiwibWV0YWRhdGEiOnsibW9kZWwiOiJzbGltIn19fX0\u003d",
        "signature": "pkbHKV2sv73DbV4oOBoq8XH/ygaU3A0H7EY2cC9zbOqfuW1+uObd0jKuU6FlPe7qztO3MW6Z0D0cl+FBtlttJX+8NFxlKrbfqHiJnHYm6Yg18MlKQEcPM/wy2drRCL8CuZcXLaB2PnS97qJ3Sr5J4IemN+0gzv9VWklntgRCVgFkOGCNMhSaMyzXDPF9s6tzlksy64RETs+bdPIp6UnOPb6OAnJUBAmM8u/jm+4GZezVpnP3XyV1bt3zNfvs0caZgOWuUYc9Uo8EykZVUvBPjZEVQO0JNKEo9172/Z1Kha6gHw4iamTUBacKEvzjGwaVwTIwqXTc7xPFWtk339E5XQ0ab/PbjZ3F4vuNzuWL8NHmA9ACS85OFKOye+MM+pLk6H1ApWTTjSXV7IKi8+b4lr1qQbZFYx2mkjArNU7H87qpIhfd8rMDSIlfktAU6NNqironhkZckcIFBjTzqrPMvIeHDOJqdu5ldDzDyMqsFFVgJaJKDkL/d/i+Pu8/n6aECefiTDKqMOMsv7/qXj1RasS5n88hqQeQdJZHot5MbCL55vtzeI6WjvZQ2tvulUhJKppSbQwjX/eS0hx9+p+UVr+li913aJRmPQ8TUuLA4aEQvgGNLomN58lPXhYe6A1ix3pqcxLysOK2GA0/Da8rwYVkpXSSOxD29ll7AStAAjA\u003d"
      },
      {
        "npcName": "Necromancer",
        "npcClassType": "NECROMANCER",
        "npcUUID": "54b6039b-11cb-4df4-b92d-ff5ebaf755e1",
        "worldName": "newnations",
        "x": 20.0,
        "y": 69.0,
        "z": 56.0,
        "yaw": 89.821,
        "pitch": 6.45,
        "texture": "eyJ0aW1lc3RhbXAiOjE1ODM4MjE1Mjc1MzAsInByb2ZpbGVJZCI6ImU0MmI2MGIwYzM1YTQ2MmZhMmI0YjFhOTk4MGYzOTllIiwicHJvZmlsZU5hbWUiOiJTcXVhbGx6Iiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8zOWJhYTU1NjBlZmFlMjVlOWQyYzJlMTAzYjU5NTY2N2JkZmQxYjlmZTNjNTAxMjg4MDc1YTE0MTQwZGJjYmExIiwibWV0YWRhdGEiOnsibW9kZWwiOiJzbGltIn19fX0\u003d",
        "signature": "oYhwy5EGd3yDhoh6HfIBwGsLVFphdf82AQZ4KkPfnsHpYdh6qjNwU3GUfl40wRDS5r0m83vKpFVZYHu+oc7QsBzIZakwA0/hzKGp/a5abetPrmtDZUQSGd9Rrs8wEA+cxzwhPQ6j11gnQeuk7k7UtJsgklg3RleDKevyIK1ROJZWkMm389Whp75E8NN6fegx4LvXuMXY4kKa2e4INmxnFIqpSatmaaRvMeqC0L4ylmVrnaMlZ9iNlgAvKaKp13sqkDtr75kZo+qHNytxTbUVKpp+VmpZMosL+/xuKPDQujSMcwbhsh2FFtYsBKxujJ2KZrJMyobEA4aT8BlXU6m35WxW0/FY7737+/UuOB2N6GwpQtMW4HsBnxICCGzEei6VYo/R2aYliTFIqjU/k0E6Qr1GG0GUv2R9x3Lk1kM8pnDPCxd9KQnTKr5H0+/GhEdwfQCRyR81OKKc8HIWmCbpdxS8ye5Pk4YHbMG/mbBlt9kVkEcBRoddOXb9s6vFr2cULjjG4LjTxM/zgEYoGNl5eSP68nv1MmvL1gyuBBC5156qYFYPWdwM9jRnjOWhzUxdTMBS+RJHJ4sO1YhBLKKO4+2J5rLfVIzl2d9vtgyit5jf7gb/1A+Wwr3KQ8bXlmL6/goP2LYCjtq8GwcSDB/CMTqT7RAimBDp7br0B76qTzU\u003d"
      },
      {
        "npcName": "Wizard",
        "npcClassType": "WIZARD",
        "npcUUID": "ea64f486-47a2-4c71-a1c3-955050f42b3c",
        "worldName": "newnations",
        "x": 10.0,
        "y": 69.0,
        "z": 56.0,
        "yaw": 270.12,
        "pitch": 0.75,
        "texture": "eyJ0aW1lc3RhbXAiOjE1ODM4MjE2OTQ2ODEsInByb2ZpbGVJZCI6ImU0MmI2MGIwYzM1YTQ2MmZhMmI0YjFhOTk4MGYzOTllIiwicHJvZmlsZU5hbWUiOiJTcXVhbGx6Iiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS82NzQzZjIyNDUzYTQ3Mzg1ODQzMWYxNjEyNDk5YjRkYzI2ZGYyYTM3NDFhODNlMzRjYWU5MDQyNWY5YzgxM2RiIiwibWV0YWRhdGEiOnsibW9kZWwiOiJzbGltIn19fX0\u003d",
        "signature": "WhHqvNAPZaxUFVCFBKNTHuPJpkRjjvEtQMcqIX6Nyum75ZrflmeHhz2fVhPOrZAFRA4Lt3z+iOU4PjE7Uvr7aeW/xNeLb4gIGo5qrjzxRLrHo8ANdr44isy3FLJbGCxtiO8k566ynH0pP1xX5V8vcaknI02zYnpc004uw06zR4TpQbqxtHR/fpMk2NWS9GyYu9GuHtw6wRhAkmMZXhgByoyJ2cQ9Jv+7NFPZSxq6nlbAPP64YkBBeKAP6nGZcOk58C7MUHPtu7vTMjVpJ+nIc6PqdYXE+uF4T0Aj8fz4Do3MDHqHQkWOlWceQnEPyZd9sbF9seyltBqHKt0CmYkqrGwJELRg790x+Fsbf1Pnw1m3FQhSDkf6TvfJR3xn0N0h+wOCglQRkQLlK8vQ67pXRVhZCk4SgCMzFz8cxNwtx+KDN+CRoWsXEUiOmsUpHoHiy2ZlBSRCAFc2BSrSLFCHzaG4fB4dGYTHa9pyUYq+JZZ6qT0m1sNrmhybEWeNHbxdg4O7z0wdHAoUMyrzzOiJ4URyVTZZP/qJLWWOHje0Uv1i+ulDTbRNeHjILqPxb2G8QIieN3mCFtMHlQ8kmP3sMqKjZ2yP8cmBCBJgwuGV2g6+vvwQzO9jy3AzKJsesexG+q9cbi7tA2xFAq5sKn1DT+JUqfFSDUBtNDGE2GhGpSE\u003d"
      },
      {
        "npcName": "Cleric",
        "npcClassType": "CLERIC",
        "npcUUID": "557dd9e0-731a-4a5a-a9f7-96c7530d4dec",
        "worldName": "newnations",
        "x": 10.0,
        "y": 69.0,
        "z": 52.0,
        "yaw": 273.577,
        "pitch": 5.85,
        "texture": "eyJ0aW1lc3RhbXAiOjE1ODM4MjE4MTg1NDIsInByb2ZpbGVJZCI6ImU0MmI2MGIwYzM1YTQ2MmZhMmI0YjFhOTk4MGYzOTllIiwicHJvZmlsZU5hbWUiOiJTcXVhbGx6Iiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9lNDk0NjRhZDQxN2MyYzkyYjI4OWMyMzA4YWU2MGU1ZGQ4NzU0OWZlNWVhNzMxYjEwZWRkOTJmNjE2MTcxNSIsIm1ldGFkYXRhIjp7Im1vZGVsIjoic2xpbSJ9fX19",
        "signature": "gMNXBPMPA4W7erAVGnxwo8VRgBv6J3FNVqZ09qWS+Vsov4Q4LQ+Wm+1TSTVL1pxiqooPN5Z8stGKq0EckiuVKlJhuCrwx8MbOqu5bEkZTQIlc6Nd0RJEGs6Zng2zcCZ96ivy67X0XTW7ZlnFM/LAiUggcTbfGindBtLQThEK1+ChpDfm0hF5DomRk+Gm4ss8BRPM8afaX0knVIM6IHvNbGvFfuL8+UhuaK946CDR+n2Ph7d1DRx4ilUXkL2V4kU2E9X6BqiHv19tF37iFC6jMZdoeAhlgnPjOCAiPbFPGeUNBdqvz0DCyF0/3a2c2Ka+z1sF+Qbac+nNaoC/HMP7s/m4F9/j0xao2ettxfIByURxrQQzuv12umVk90eJ+gAFV6nXKymLMYFJT+cE1vYg1PjzYmaTE9k8FBGNhET9/bXP3ec4aPW8ZRCuX5YLGySGVKn63Pi0VIp7kp6UKZqLiH8jamd2+xesKOwJJoIU1vZc35x7N9jdIgRC3QjKliZggru4fhDT+0D2ry359LQuw2w73rCNw+nTD7DhWKfW+wYeVIO15T/0U6K5ntVTC4+Nhu/OpAR4mYJHv+VkOGL/wiv7IVjVtjx8mL53qgm361EiWrylqha2Opc+VeSJdcPgIhaHiqKizRfY7CI+xadN/apy+HQDievL5c4+8w+vxHk\u003d"
      }
    ]
    Then I loop through online players and all NPCs and call #Show() from the NPC class for each one. I also call this when the player joins. For some reason, the NPC's textures will randomly just stop working and a couple NPCs will be the Steve/Alex model, sometimes they are completely gone. I have been trying to figure out this issue for a few weeks and can't figure out what triggers it. Now, after week or so of having the NPCs, people are randomly getting kicked for the above error.

    Please help!!
     
  2. Bump

    Bump

    Bump

    Bump

    Bump in the night...
     
  3. Are you sure your texture and signature are good?
     
  4. Yes.. the skins usually work perfectly fine but sometimes randomly stop for some players
     
  5. Is everything bundled together? If so try spreading it out
     
  6. I tested your NPC class and everything works perfectly for me.
     
  7. "Bundled together"?
     
  8. When do you call the #show()"? I call it on join and on reload. Some players see the skins, others see them as Steve and Alex then it fixes after I reload the plugin with plugman. I'm wondering if the error I get has anything to do with spawning the EntityPlayer so many times or something..? Too many entity players in the world? Idk what's going on.
     
  9. i mean is it all in a single class
     
  10. The npc is in one class, then I have my npc manager which loads them from config, puts them in a list and has getters/setters. Then I call the npc#show() on join and server reload.
     
  11. I tried with 127 NPC and that works. When I interact, join and reload all npc are refresh. And no skin problem or kick.
     
  12. Good luck fixing, sorry i don’t know but could it be because it’s #show() instead of npc#show() or something with your server/server host or another plugin is interfering
     
  13. Try joining and leaving multiple times or try having someone else join and see. Fly far away and come back too see if it does anything.
     
  14. Well I'm calling npc#show
     
  15. would u have to do like knight#show() ? or npc#show(knight)
     
  16. Looping through all online players, then for each player I'm looping through all NPCs and calling npc.show(player)
     
  17. [​IMG]
     
  18. They're all missing skins.
     
  19. why don’t you just do some permanent skin