Solved Adding Player Names to Command

Discussion in 'Plugin Development' started by CloudVox, Jun 16, 2015.

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

    CloudVox

    Sorry for the noob question but I am curious how to put any argument in a command.

    For Example:
    /msg %playername%
    How would I go about adding the %playername%?
     
  2. Offline

    CoolGamerXD

    Player player = Bukkit.getServer().getPlayer(args[0]);

    Also, always checks length of arguments first!
     
    CloudVox likes this.
  3. Offline

    CloudVox

    Code:
    Player p = (Player) sender;
                if(frozen.contains(p.getName())){
                    frozen.remove(p.getName());
    So this is what I have currently (frozen is an ArrayList that stores names)

    Would I edit "Player p = (Player) sender;"
    to -> "Player p = Bukkit.getServer().getPlayer(args[0]);"
    ???
     
  4. Offline

    CoolGamerXD

    Basically, The one 'p' you have before is casted as a "CommandSender". And the Player p = Bukkit.getServer().getPlayer(args[0]); is for casting the player in args[0]. Like /command <player>.

    It depends on you which you really want to add in the Array list.
     
    CloudVox likes this.
  5. Offline

    CloudVox

    One more question while I have you XD
    How would I only send a message client side? I know of the Bukkit.broadcastMessage(); but that would broadcast it to the server
     
  6. Offline

    CoolGamerXD

    Code:
    player.sendMessage("Your message");
     
    CloudVox likes this.
  7. Offline

    CloudVox

    Thank you so much :)
     
  8. Offline

    CoolGamerXD

    No problem, Mark this thread as solved.
     
  9. Offline

    CloudVox

    Well would "player" be the variable "p"

    Or is it part of the API? Because when I use player.sendMessage(); it says player cannot be resolved so would changing the player to my variable "p" do the job?
     
  10. Offline

    CoolGamerXD

    Please learn java before beginning to start coding with bukkit. Anyways, its that which variable you have used. If you are doing
    Code:
     Player p = Bukkit.getServer().getPlayer(args[0]); 
    'p' is your variable of the player.
     
    Last edited: Jun 16, 2015
Thread Status:
Not open for further replies.

Share This Page