New Bukkit.getPlayer() methode??

Discussion in 'Plugin Development' started by GamingChrisYT, Sep 22, 2016.

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

    GamingChrisYT

    Hey,
    I want to write a nick plugin and ich have the Problem that the Methode Bukkit.getPlayer too old is. So i want to ask you if it gives an Alternative? I have a second problem. Ich change the Display name and List name. How I can chang the name back with the command /nickoff <Player>

    Thank You ;-)

    PS: Sorry for my bad English I'm from Germany
     
  2. Offline

    Zombie_Striker

    @GamingChrisYT
    No, it is not "too old". It still works and still will return the player with the specified UUID/name. If you are worried about the "Deprecation" warning, don't be. It is only there to let people know they should try to use UUIDs instead of names.
     
    GamingChrisYT likes this.
  3. Offline

    GamingChrisYT

    Thank you but can you help how I can get with the DislplayName the Player
     
  4. Offline

    Zombie_Striker

  5. Offline

    GamingChrisYT

    But than I have the Real Player name I think.
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    GamingChrisYT

    Yes but how I can get the Display name of an other Player?
     
  8. Offline

    JanTuck

    Bukkit.getPlayer(Playername or UUID).getDisplayName()?
     
    timtower likes this.
  9. Offline

    GamingChrisYT

    And wahtt is if I have only an Display Name?

    That I wrote for this methode, but ther is a mistake:

    if (command.getName().equalsIgnoreCase("nickoff")&& sender.hasPermission("adminjoin.cmd.nick")){
    if (args.length == 0){
    p.setDisplayName(p.getName());
    p.setPlayerListName(p.getName());
    p.sendMessage(getConfig().getString("adminjoin.nickoffcmd"));
    }
    if (args.length == 1){

    if (Bukkit.getPlayer().getDisplayName() == args[0]){

    }

    }

    }
     
  10. Offline

    JanTuck

    @GamingChrisYT
    Code:java
    1.  
    2. if (Bukkit.getPlayer().getDisplayName().equals(args[0])){
    3.  
    4. }
    5.  


    Bukkit.getPlayer(String or UUID).getDisplayName()

    Let's say we have Bob and i wanted to print out bobs name to the console.

    I would.
    Code:java
    1.  
    2. TheLogger(Bukkit.getPlayer("Bob").getDisplayName());
    3.  


    so it would look something like if we took and used yours
    First we make the if statement. then we get the player Bob with Bukkit.getPlayer("Bob"), after that we get the displayname by Player#getDisplayName(). Now we check if that equals the variable args[0], and that is pretty much it.

    Code:java
    1.  
    2. if (Bukkit.getPlayer("Bob").getDisplayName().equals(args[0]){
    3.  
    4. }
    5.  


    Do you understand?

    If it is you are trying to get the current player who send the command you have to do something else.

    You would first check if the sender is an instanceof Player, then you would make a variable that has sender cast to Player. Then you can check the differents things. Like this

    Code:java
    1.  
    2.  
    3. if (sender instanceof Player){
    4. Player player = (Player) sender;
    5. if (player.getDisplayName().equals(args[0])){
    6.  
    7. }
    8. }
    9.  
     
    Last edited: Sep 23, 2016
  11. Offline

    GamingChrisYT

    but than I have the Mistake "The method getPlayer(String) in the type Bukkit is not applicable for the arguments ()"

    But I haven't In our example Bob but nur the Display name

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 23, 2016
  12. Offline

    Zombie_Striker

    Strings cannot be compared using ==. Always use .equals for strings.
    This error means you are not actually providing a player name/uuid inside the parameters. Provide either the name or uuid of the player you want to get. The thing is, you do not want this.

    Since you want to get the player whose display name is equal to args[0], you will need to for loop through all the players. Use the following bit of code for this:
    Code:
    for(Player online : Bukkit.getOnlinePlayers()){
     if(online.getDisplayName().equals(args[0])){
      //Do what you want.
     }
    }
     
  13. Offline

    JanTuck

  14. Offline

    GamingChrisYT

    Thank you. Now i have no porblem.
     
  15. Offline

    Zombie_Striker

    @GamingChrisYT
    If your problem has been solved, mark this thread as solved.
     
  16. Offline

    GamingChrisYT

    Yes but how i send the online play with nickname a message an change the nickname. T
     
Thread Status:
Not open for further replies.

Share This Page