Says entity exists and doesn't exist?

Discussion in 'Plugin Development' started by shohouku, Jan 31, 2020.

  1. Offline


    So I'm trying to check if a certain entity exists but it's saying it exists and doesn't exist at the same time.
    Location location = new Location(Bukkit.getWorld("world"), -4.762, 89, -19.306);
    for(Entity goblin1 : location.getWorld().getNearbyEntities(location, 100, 100, 100)) {
    if(goblin1.getName() != null)
    if(goblin1.getName().equals("Goblin")) {
    System.out.println("Goblin exists");
    } else {
    System.out.println("Goblin doesn't exist");
  2. Offline


    @shohouku When you call the for loop for all of the nearby entities to your location it will be getting you, the player entity, and whatever your target entity is. When it finds you, it will say that the "goblin doesn't exist" and then when it finds the goblin it say it will exist. This can be fixed by adding an entity type check before your name checks, something like:
    if(!(goblin1 instanceof YourEntity)) {
  3. Offline


  4. Offline


    In an off topic question, is it possible to check the name of the entity instead?
  5. Offline


    @Xp10d3 Not sure what you mean by the name of the entity. If you want the custom name given to the entity you can use (entity).getCustomName() (make sure to check if it's null beforehand). If you want the type of the entity you can use (entity).getType() and use that to compare with the EntityType enum.
  6. Offline


    Never mind. Just wondering if it's possible to get the name of the entity; probably not thinking straight xD Ignore this...

Share This Page