Solved How to set a variable for a specific player

Discussion in 'Plugin Development' started by KarimAKL, Mar 20, 2018.

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

    KarimAKL

    @Blackwing_Forged I want a command that has 1 arg and that arg needs to be an online player and i want that online player in arg 1's UUID for this. How would i do that?
    EDIT: To check if arg 1 is an online player i should do this, right?:
    Code:
    for (Player p : Bukkit.getOnlinePlayers()) {
                                if (p.getName().equals(args[0])) {
                                   //Code here
                                }
                            }
    
     
    Last edited by a moderator: Mar 31, 2018
  2. @KarimAKL
    Yes and then you would do p.getUniqueId() where you need the UUID
     
  3. Online

    KarimAKL

    @Blackwing_Forged Okay thanks. :D So that would be like this then?:
    Code:
    for (Player p : Bukkit.getOnlinePlayers()) {
                                if (p.getName().equals(args[0])) {
                                    hackerList.add(p.getUniqueId());
                                }
                            }
    
    That should add the UUID to the list instead of the playername, right? If so i'll change this to solved, thanks for all the help. :D
    Btw one last question: I should use "hackerList.remove(p.getUniqueId());" to remove the UUID if i want to do that, right?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @KarimAKL But now you are abusing static functionality. Or do you know how to properly clean it? Do you know when it gets initialized? Do you know what happens if you have multiple instances of that class?
     
  5. Online

    KarimAKL

    @timtower Sorry no i don't know any of these questions. :/ I didn't know it was that big of a deal to use static. ._.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @KarimAKL You never need it with Bukkit.
    It is the lazy way to do it.
     
    RcExtract likes this.
  7. Online

    KarimAKL

    @timtower Oh, but i currently don't know any other way. :/
     
  8. Offline

    timtower Administrator Administrator Moderator

    @KarimAKL Use 1 class and make it private final.
     
  9. Online

    KarimAKL

    @timtower I could do that but i want it in diffrent classes, any other way?
     
  10. Offline

    timtower Administrator Administrator Moderator

    @KarimAKL In my opinion you are lacking the Java knowledge to do this in a decent way.
    That is why I am suggesting the single class method.
     
  11. Online

    KarimAKL

    @timtower Okay, thanks but i'll just be using the static method for now but i'll still try learning Java.
     
Thread Status:
Not open for further replies.

Share This Page