Solved Getting player always null?

Discussion in 'Plugin Development' started by sgavster, Nov 23, 2013.

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

    sgavster

    Hi!

    I was working on something, and this isn't working:

    Code:java
    1. String name = e.getItem().getItemMeta().getDisplayName();
    2. Player p = Bukkit.getPlayerExact(name);
    3. pl = name;
    4. if(p == null)
    5. {
    6. e.getPlayer().sendMessage("§4Can't open inventory. The player §2" + name + " §4is not real!");
    7. }
    8. else
    9. {
    10. i = Bukkit.createInventory(e.getPlayer(), 9, name);
    11.  
    12. i.setItem(5, setNameAndLore(Material.BONE, 1, "§4Do you want to kill §2" + name.toLowerCase() + "§4?"));
    13.  
    14. e.getPlayer().openInventory(i);
    15. }


    But it always says that name is null. If anyone knows why please let me know! Thanks!
     
  2. Offline

    L33m4n123

    Are you sure the Displayname of the Item is EXACTLY written like a Player that was at least once on YOUR server already? [by Exactly I meant case sensitive aswell]
     
  3. Offline

    sgavster

    L33m4n123 yep, I do it exactly like my IGN :(
     
  4. Offline

    FinalFred

    Try adding this line to your program, before the whole "Player p = ...";
    Code:
    System.out.println("Item name: '" + name + "'");
    
    Sometimes what happens to me is there's an extra space or weird character floating around. Printing it out with single quotes will usually tell you if that's the case.
     
  5. Offline

    sgavster

    FinalFred actually, it is a space! how can I fix? Because, it says
    Can't open inventory. The player<two_spaces>is not real!
     
  6. Offline

    1Rogue

    Bukkit.getPlayerExact(name.trim());
     
    sgavster likes this.
  7. Offline

    sgavster

Thread Status:
Not open for further replies.

Share This Page