Solved Player Variable?

Discussion in 'Plugin Development' started by pipo3090, Jun 17, 2016.

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

    pipo3090

    I'm working on a plugin that requires a player variable, but I'm making the code that runs when the command is executed in a different class/file. How can I get the player variable from the sender in the other class?
    I think that I don't have to give code, Because it's a general coding question. But if I'm wrong, I will edit this post to give the code.
     
  2. Offline

    Zombie_Striker

    @pipo3090
    If you mean that you want to access another method from the onCommand class, just get that other classes permission and class the method. If you need to pass the player instance, provide it in the method's parameter.

    If you mean you have another method, but need a player from the onCommand, then you would need to store the sender in a Hashmap or array. When you need to get the player's instance, get the command class's instance and get the hashmap or array instance. From there, loop through all the values until you find the player. (Only use a hashmap if you have to store another value with the player.)
     
  3. Offline

    pipo3090

    @Zombie_Striker
    I don't know what I have to do, because my English is bad... I'm going to try to explain as much as possible;)
    In onCommand, there is a parameter(if I say it right) that is the CommandSender sender. I want to use that variable to access a 'feature' (like giving exp) in my init method in my other class.

    If you can tell me which one I have to use, I would be really happy:p

    EDIT: I actually figured it out myself:D
     
    Last edited: Jun 17, 2016
  4. Offline

    Zombie_Striker

    @pipo3090
    I think you want case #1, so do the following:
    1. Go to the init method.
    2. Inside the method parameter, put "CommandSender sender"
    3. Go to the onCommand
    4. When a player sends the command, call the init method, and provide the sender's instance.
     
Thread Status:
Not open for further replies.

Share This Page