Other Player

Discussion in 'Plugin Development' started by ZyamLegend337, Oct 5, 2020.

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

    ZyamLegend337

    Ok I really hope that this does not come across as a stupid question, but I just can't remember what it is, and I can't find it on Bukkit API. How do I define another player for a command?

    For example to define the person that runs the command, or the sender, I do;

    Code:
    Player s = (Player) sender;
    But how do I define another person, to perform an action on someone else by running a command? Similar to the /give or /kill command, after typing /kill you type a username like /kill ZyamLegend337, but to do it on yourself, it is just /kill, or /kill @s

    Is there something like
    Code:
    Player p = (Player) receiver;
    
    or
    
    Player p = (Player) target;

    Any help would be appreciated!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @ZyamLegend337 Get the first argument, Bukkit.getPlayer(argument)
     
  3. Offline

    ZyamLegend337

    @timtower so I want it to be when someone writes a command in chat, like /kill, whatever they write after that like /kill ZyamLegend337, how do I get ZyamLegend337 in my code? I know how to do it like Bukkit.getPlayer("ZyamLegend337"), but then that would only work for ZyamLegend337. I want it to work for whoever is entered in the chat. I am very new to Bukkit and Spigot, though I know a little bit of Java.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @ZyamLegend337 You onCommand has an args variable, first value will be the name in this case
     
  5. Offline

    ZyamLegend337

    Ah ok. I figured it out. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page