Remove NPC from Tab List and Get NPC's Coordinates

Discussion in 'Plugin Development' started by DavidBTPW, Sep 20, 2015.

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

    DavidBTPW

    A Bukkit plugin that I am working on right now adds an NPC to the game, but I have several problems with it:

    1.) The NPC shows up in the Online Players Tab list, and I would like to prevent this from happening.
    2.) I need to add a command to the plugin that will display the NPC's Coordinates to the player.

    How can I do this? Here is the class from my project that creates the NPC's GameProfile.
     
  2. Offline

    Ward1246

    1. 1.
    Code:
    Packet201PlayerInfo packet = new Packet201PlayerInfo("HumanNPC", false, 0); //the packet to hide the given players name from tab
    for(Player online : Bukkit.getOnlinePlayers()) {// get all online players
              ((CraftPlayer)online).getHandle().netServerHandler.sendPacket(packet);// send that packet to all players
    2.
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String []args){
            if (label.equalsIgnoreCase("Coordinates")) { //the command code
    Player player = (Player) sender; // get who sent the command
    player.sendMessage(HumanNPC.getLocation() + "Is where the npc is located."); //send the player a message, containing the npcs coordinates, or do this (seems like a better idea)
    player.sendMessage("X: "+ HumanNPC.getLocation().getX())
            }
            return false;
    }
    
    Untested, but should work. Let me know if you need anything.
     
    Last edited: Sep 21, 2015
  3. Offline

    RoboticPlayer

    Check cmd.getName().equalsIgnoreCase(string) instead of label.equalsIgnoreCase(string), it's a good habit to get into, and it allows for aliases. Secondly, check before casting sender to player!
     
  4. and third, sending a raw Location object looks ugly. :p (It's either Location@hashcocde or CraftWorld{name:world},x=69,y=69,z=69 I don't remember it)
     
  5. Offline

    RoboticPlayer

    You would probably want to do something like this:
    Code:
    player.sendMessage("X: " + HumanNPC.getLocation().getX() + //y and z values as well)
     
  6. Offline

    Ward1246

    Can't believe I forgot to do that check I normally always do.. Also I think your way of getting the location would be better, mine doesn't seem right to me.
     
  7. Offline

    RoboticPlayer

    You also might want to include the world that the NPC is in, especially if the server has several worlds.
     
Thread Status:
Not open for further replies.

Share This Page