I need help!

Discussion in 'Spigot Plugin Help' started by cPLAYS, Jun 23, 2021.

  1. I'm trying to create a pet plugin, and when I run my code I get a 2 line error. that makes my pet spawn then instantly despawn. How can I fix this?

    Error:
    Code (Text):
    [18:41:15 WARN]: Entity threw exception at world:0.5023572333254178,211.0,3.896525947393668
    [18:41:15 WARN]: java.lang.NullPointerException
    Sheep Class
    Code (Java):

    public class Sheep extends EntitySheep{
        @SuppressWarnings("rawtypes")
        private final static EntityTypes type = EntityTypes.SHEEP;
        @SuppressWarnings("unchecked")
        public Sheep(Location loc) {
            super(type, ((CraftWorld)loc.getWorld()).getHandle());
            this.setPosition(loc.getX(), loc.getY(), loc.getZ());
        }
       
        public Sheep makeBaby() {
    //        this.setBaby(true);
    //        this.setAge(-25000);
    //        this.ageLocked = true;
            return this;
        }
       
        public Sheep makeInvulnerable() {
            //this.setInvulnerable(true);
            return this;
        }
       
        public Sheep turnOffCollide(EntityLiving el) {
    //        Set<UUID> set = new HashSet<UUID>();
    //        set.add(el.getUniqueID());
    //        this.collidableExemptions = set;
    //        this.collides = false;
            return this;
        }
        public Sheep makeInvisible() {
    //        this.setInvisible(true);
    //        this.persistentInvisibility = true;
            return this;
        }
        public Sheep Color(EnumColor color) {
    //        this.setColor(color);
            return this;
        }
       

        public Sheep setName(String name) {
            this.setCustomName(new ChatComponentText(Main.color(name)));
            return this;
        }
       
       
        @Override
        protected void initPathfinder() {
            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.goalSelector.a(2, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0f));
            this.goalSelector.a(3, new PathfinderGoalRandomLookaround(this));
            this.goalSelector.a(1, new PathfinderGoalPet(this, 1.5, 25));
        }
       
        public void setOwner(Player player) {
            this.setGoalTarget((EntityLiving)((CraftPlayer)player).getHandle(), TargetReason.CUSTOM, false);
        }
       
        public void setItem(EnumItemSlot slot, ItemStack item) {
            this.setSlot(slot,  CraftItemStack.asNMSCopy(item));
        }
        public void show() {
            this.setCustomNameVisible(true);
        }
    }
    Create Pet Class:
    Code (Java):
    public class PetMenu {
        public static HashMap<Player, Entity> owners = new HashMap<Player, Entity>();
        public static void Create(Player owner) {
            owner.sendMessage("hi");
            if(!owners.containsKey(owner)) {
                //owner.setCollidable(false);
                Sheep pet = new Sheep(owner.getLocation()).makeInvulnerable().Color(EnumColor.BLACK);
                //pet.setInvisible(true);
                //pet.persistentInvisibility = true;
                pet.setOwner(owner);
                //pet.canCollideWith(owner);
                pet.setName("&a" + owner.getName() + "'s Pet");
                WorldServer world = ((CraftWorld)owner.getWorld()).getHandle();
                UUID id = pet.getUniqueID();
                world.addEntity(pet);
                Entity e = world.getEntity(id);
                owners.put(owner, e);
            }else {

            }
            return;
        }
       
        private static Entity getPetFromOwner(Player p) {
            return owners.get(p);
        }
        @SuppressWarnings("unused")
        private static Player getOwnerFromPet(Entity o) {
            if(owners.containsValue(o))
                for(int i = 0; i < owners.values().size(); i++) {
                    if(owners.values().toArray()[i].equals(o)) {
                        return ((Player)owners.keySet().toArray()[i]);
                    }
                }
            return null;
        }
       
        public static void deletePet(Player p) {
            p.sendMessage("ASDASD");
            Entity pet = getPetFromOwner(p);
            pet.killEntity();
            owners.remove(p);
        }
       
    }
     
     
  2. You must send full log.