Solved Removing Entities on Command?

Discussion in 'Spigot Plugin Development' started by jamesd5, Jan 18, 2020.

  1. Hello, I have been stuck on this for awhile but I can't seem to get a specific entity and remove it.

    Here is my code...
    Code (Text):
    Player p = (Player) sender;
    final removeEntityClass ec = new removeEntityClass(p);
    ec.removeEntity();
    Code (Text):

    public class removeEntityClass {
        public Player p;
        public removeEntityClass(Player p) {
            this.p = p;
        }
        public void removeEntity() {
            p.sendMessage("A Message, that for some reason does not send...");
            testmethod();
        }
        public void testmethod( ) {
            creatingEntityClass sc = new creatingEntityClass();
            UUID uuid = sc.statue.getUniqueId();
            List<Entity> list = p.getNearbyEntities(5, 5, 5);
            for(Entity thing: list) {
                if(thing.getUniqueId().equals(uuid)) {
                    thing.remove();
                }
            }
        }
    }
    The error in the console is that the method removeEntity and testMethod is null. Is there something I am doing wrong? Thank you:>
     
    #1 jamesd5, Jan 18, 2020
    Last edited: Jan 18, 2020
  2. Well this might just be an arbitrary mistake, but you have send the class removeIceEntityClass; while in your Method you called the class removeEntityClass.
    Also, t is not defined (as far as we can see)
    Also, I‘m not gonna point out the various violation to the Java coding style, unless you want me to
     
  3. My bad, I tried to change some variables to keep it simple online, but I forgot to change, what was said up above

    What violation?

    Sadly however, my methods still have the Null error. Is there anyway I can fix this? (The code is fixed above)
     
  4. sc.statue, I suspect, is probably null
     
  5. 1) Classes are classes, they don't have to end in "class"
    2) Methods are methods, they don't have to end in "method"
    3) Player should not be public, instead be accessed with suitable getters and setters
    4) Classes usually start with a capital letter

    Also, could you post the new code?
     
  6. Oh yeah, I guess you are right. Once again, I just tried to make it easier to be understood online(which I guess did not help). Thank you all though, the issue was solved. :>