1.16.5 [19:57:07 WARN]: net.minecraft.server.v1_16_R3.CancelledPacketHandleException

Discussion in 'Spigot Plugin Development' started by cPLAYS, Jul 19, 2021.

  1. I am able to right click the villager that pops up an inventory. Everything works fine until I leave the game and rejoin. I get no errors, just a warning of:
    Code (Text):

    [19:57:07 WARN]: net.minecraft.server.v1_16_R3.CancelledPacketHandleException
     
    I have no clue what it's pointing to so I have no clue what to provide.
     
  2. Is it the only single information ?

    Do you have a plugin with a try catch ? Try to debug it manually, maybe you have a log and not a print a stacktrace.
    Else, try to see if you don't have async tasks executing sync methods.
     

  3. I went through all my try-catch statements and added ex.printStackTrace(). I get the same error. If this was an error in the try-catch, why would it work fine before I leave when I rejoin it doesn't work.

    PlayerInteractEntityEvent:
    Code (Java):

    @EventHandler
        public void onInteract(PlayerInteractEntityEvent e) {
            try {
                Entity entity =  ((CraftEntity)e.getRightClicked()).getHandle();
                if(VillagerNPC.getNPC(entity) != null) {
                    VillagerNPC npc = VillagerNPC.getNPC(entity);
                    e.setCancelled(true);
                    npc.getAction().onPlayerInteraceEvent(e, npc);
                }else if(VillagerNPC.alreadyExisting.containsKey(entity)) {
                    e.setCancelled(true);
                    VillagerActions.getAction(VillagerNPC.alreadyExisting.get(entity)).onPlayerInteraceEvent(e, null);;
                }
            }catch(Exception ex) {
                ex.printStackTrace();
                String rval = global.findOurs(ex);
                if(rval != null)
                    global.Log("Error: " + ex.getMessage() + " Line: " + rval, LogTypes.ERROR, Main.getPlugin());
            }
        }
     
    VillagerNPC.java
    Code (Java):

    public class VillagerNPC extends EntityVillager {
        public static List<VillagerNPC> npcs = new ArrayList<>();
        private static EntityTypes<EntityVillager> type = EntityTypes.VILLAGER;
        private static HashMap<Entity, VillagerNPC> entityToVillagerNPC = new HashMap<>();
        public static HashMap<Entity, String> alreadyExisting = new HashMap<>();
        private Entity entity;
        public Location defaultLocation;
        private WorldServer worldServer;
     
        private String action = "test";
     
        public static void init() {
            for(String uuid : DataManager.NPCData.getConfig().getKeys(false)) {
                global.Log(uuid, LogTypes.WARNING, Main.getPlugin());
                try {
                    UUID uid = UUID.fromString(uuid);
                    alreadyCreated(uid.toString());
                }catch(Exception ex) {
                    ex.printStackTrace();
                    String rval = global.findOurs(ex);
                    if(rval != null)
                    global.Log(ex.getMessage() + " Line: " + rval, LogTypes.ERROR, Main.getPlugin());
                }
            }
        }
     
        public VillagerNPC(EntityTypes<? extends EntityVillager> entitytypes, World world, String action) {
            super(entitytypes, world);
            this.action = action;
            SetVariables(world);
        }
        public VillagerNPC(EntityTypes<? extends EntityVillager> entitytypes, World world, VillagerType villagertype, String action) {
            super(entitytypes, world, villagertype);
            this.action = action;
            SetVariables(world);
        }
        private void SetVariables(World w) {
            UUID uid = this.getUniqueID();
            worldServer = ((CraftWorld)w.getWorld()).getHandle();
            worldServer.addEntity(this);
            entity = worldServer.getEntity(uid);
            this.collides = false;
            entityToVillagerNPC.put(entity, this);
        }
     
        public static void alreadyCreated(String uuid) {
            FileConfiguration fc = DataManager.NPCData.getConfig();
            String action = fc.getString(uuid + ".action");
         
            Entity entity = ((CraftWorld)fc.getLocation(uuid + ".location").getWorld()).getHandle().getEntity(UUID.fromString(uuid));
            alreadyExisting.put(entity, action);
            /*Location loc = fc.getLocation(uuid + ".location");
            String name = fc.getString(uuid + ".name");
            boolean noAI = fc.getBoolean(uuid + ".noAI");
            boolean invulnerable = fc.getBoolean(uuid + ".invulnerable");
            VillagerType vType = global.getVillagerType(fc.getString(uuid + ".villagerType"));
            VillagerProfession vProfession = global.getVillagerProfession(fc.getString(uuid + ".villagerProfession"));
            //try {
            Entity entity = ((CraftWorld)fc.getLocation(uuid + ".location").getWorld()).getHandle().getEntity(UUID.fromString(uuid));
            //entity.setPosition(0, -10, 0);
            //entity.noclip = true;
            EntityVillager ev = (EntityVillager)entity;
         
            //}catch(Exception ex) {}
            DataManager.NPCData.writeData(uuid, null);
         
            VillagerNPC npc = VillagerNPC.create(loc, action).setName(name).setVData(vType, vProfession);
            if(noAI)
                npc.setNoAI();
            if(invulnerable)
                npc.setInvulnerable();
            npc.build();
            */

            global.Log("Created already created NPC!", LogTypes.GOOD, Main.getPlugin());
        }

        public static VillagerNPC create(Location loc, String action) {
    //        if(villagerType == null) {
                VillagerNPC npc = new VillagerNPC(type, ((CraftWorld)loc.getWorld()).getHandle(), action);
                npcs.add(npc);
                npc.defaultLocation = loc;
                npc.setLoc(loc);
                npc.setSilent(true);
                Bukkit.getOnlinePlayers().iterator().next().setCollidable(false);
                npc.collides = false;
                global.Log("Created new NPC!", LogTypes.GOOD, Main.getPlugin());
                //npc.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
                return npc;
    //        }else {
    //            VillagerNPC npc = new VillagerNPC(type, ((CraftWorld)loc.getWorld()).getHandle(), villagerType, action);
    //            npcs.add(npc);
    //            npc.setLoc(loc);
    //            //npc.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    //            return npc;
    //        }
         
        }
        public VillagerNPC setVData(VillagerType villagerType, VillagerProfession prof) {
            this.setVillagerData(new VillagerData(villagerType, prof, 5));
            return this;
        }
     
        public VillagerNPC setName(String name) {
            this.setCustomNameVisible(true);
            this.setCustomName(new ChatMessage(global.color(name)));
            return this;
        }
     
        public VillagerNPC setLoc(Location loc) {
            this.setPosition(loc.getX(), loc.getY(), loc.getZ());
            return this;
        }
        public VillagerNPC setNoAI() {
            this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0);
            return this;
        }
        public VillagerNPC setInvulnerable() {
            this.setInvulnerable(true);
            return this;
        }

        public VillagerNPC setAction(String action) {
            this.action = action;
            return this;
        }
        public VillagerAction getAction() {
            return VillagerActions.getAction(this.action);
        }
     
        public VillagerNPC build() {
            String id = this.getUniqueID().toString();
            DataManager.NPCData.writeData(id + ".name", this.getCustomName().getString());
            DataManager.NPCData.writeData(id + ".action", this.action);
            DataManager.NPCData.writeData(id + ".location", this.defaultLocation);
            return this;
        }
     
        public WorldServer getWorldServer() {
            return this.worldServer;
        }
        public Entity getEntity() {
            return this.entity;
        }
     
     
        public static VillagerNPC getNPC(Entity e) {
            return entityToVillagerNPC.get(e);
        }
     
     
     
    #3 cPLAYS, Jul 19, 2021
    Last edited: Jul 19, 2021
  4. Could you send the whole error. What you sent doesn't point to a line (or a plugin even) and is very vague
     
  5. That is the whole error

    https://imgur.com/j64sPye
    [​IMG]

    I just don't understand how it works until I leave and rejoin.
     
  6. That still isn't the whole error

    It should say the plugins name and the line the error occured
     
  7. ->
     
  8. What do you mean that isn't the whole error. That's all I get... It works fine until I rejoin. And if someone else rejoins it doesn't work for them but it works for me until I rejoin. So it's relative to the player.
     
  9. My bad sorry :) Are you sure that it is your plugin causing the warning because it doesn't trace back to it
     
  10. I don't know what is causing it. I put Exception.printStackTrace() in all of my try-catch statements. and It didn't help. I also did Exception.getStackTrace()[0].getLineNumber() to see if there was a line number it could tell me but it didn't return anything. I just find it weird how it works fine after I /reload but then when I exit and join the server again it doesn't work.

    The only plugins on the server are mine and FAWE
     
  11. Try to remove one of this plugin and see if the error still happens. You will be able to know which plugin is causing the error (maybe yours because i have never seen this kind of error with fawe, but we never know.)