Bug with killing entity

Discussion in 'Plugin Development' started by davidclue, Mar 29, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    davidclue

    In my onDisable method I run a simple line
    Code:
    entity.getBukkitEntity().remove();
    And it does not remove the entity and I've tried the killEntity() method and it doesn't work either. I use NMS and I've called this method many other times in the code and it never fails but I believe it is a bug with Bukkit for calling it in the onDisable() method. Any help or workarounds?
     
  2. Offline

    Kars

    If you put any other code in the onDisable, does that code run?
     
  3. Offline

    davidclue

    Yes, I do run some other code that works fine and does not affect the entity at all so it isn't causing any issues.
     
  4. Offline

    Kars

    @davidclue you are probably missing something that causes entity to be null or something. Please show the full code.
     
  5. Offline

    davidclue

    Main class
    Code:
    public void onDisable() {
            for (ClassSelection cs : Game.handler) {
                cs.clearItems();
                cs.killEntity();
            }
        }
    ClassSelection
    Code:
    public abstract class ClassSelection implements Listener {
       
        protected Main plugin;
        protected Player p;
        protected EntityLiving entity;
       
        public abstract void tick();
        public abstract void function();
        public abstract void sendPacket();
        public abstract void clearItems();
        public abstract void killEntity();
       
        public void unRegister() {
            HandlerList.unregisterAll(this);
        }
        public Player getPlayer() {
            return p;
        }
    }
    Class methods that I am calling
    Code:
    public void clearItems() {
            for (ItemStack item : p.getInventory().getContents()) {
                if (item.equals(ability) || item.equals(compass)) item.setAmount(0);
            }
        }
        public void killEntity() {
            entity.getBukkitEntity().remove();
        }
    If the entity were null then it would throw me a null error but it does not throw any errors. And yes the methods are getting called I have tested that, they are in the list.
     
Thread Status:
Not open for further replies.

Share This Page