Teleport npc's when i only want players

Discussion in 'Plugin Development' started by w0lves, Nov 16, 2020.

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

    w0lves

    Hello everyone!

    I'm developing a factions plugin but i have a mistake and i have no idea about how fix it.

    On resume, i need to tp all the players in one world to the spawn:

    Code:
    public static void teleportAllPlayerOutWorld(Location location) {
            for (Player player : Bukkit.getServer().getWorld("customworld").getPlayers()) {
                player.sendMessage(Utils.chat("&bYou have been teleported to the spawn."));
                player.teleport(location);
            }
        }
    The problem, i've another plugin that spawn a npc on this world, and when i tp all the players, the npc is send to the spawn too.

    How can i filter to tp only the real players and not npc?

    Thanks!
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    w0lves

    @timtower it's a sandbot

    It's a NPC from CitizensAPI
     
  4. Online

    timtower Administrator Administrator Moderator

    What plugin is putting it there? What would you define as NPC?
     
  5. Offline

    w0lves

    It's a NPC from CitizensAPI :)
     
  6. Online

    timtower Administrator Administrator Moderator

    @w0lves And if you loop over the players in the server and check the world?
     
  7. Offline

    w0lves

    Okay i fixed it just adding to the path Citizens plugin and


    Code:
    for (Player player : Bukkit.getServer().getWorld("customworld").getPlayers()) {
                if (!CitizensAPI.getNPCRegistry().isNPC(player)) {
                    player.sendMessage(Utils.chat("&bYou have been teleported to spawn"));
                    player.teleport(location);
                }
            }
    I don't know if there is other way of doing it withoud adding Citizens, but at least it works i think, im gonna test it now.
     
Thread Status:
Not open for further replies.

Share This Page