Solved /<command> playername | How?

Discussion in 'Plugin Development' started by AdityaTD, Mar 3, 2015.

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

    AdityaTD

    Hey guys I have coded a economy plugin for my network and I want to make it so I can give coins to people with their usernames like : /givecoins playername | But I don't know how to do that, what I know is /givecoins and it executes only for the player, please tell how to do it! Thanks...!! :D
     
  2. Offline

    CraftCreeper6

    @AdityaTD
    Bukkit#getPlayer(UUID uuid); OR Bukkit#getPlayer(String name);
     
  3. Offline

    mine-care

  4. Offline

    AdityaTD

    @mine-care and @CraftCreeper6 will this work!?
    Code:
    Player target = (Bukkit.getServer().getPlayer(args[0]));
            if (target == null) {
               sender.sendMessage(args[0] + " is not online!");
    }else{
    //coins code!
     
  5. Offline

    CraftCreeper6

    @AdityaTD
    If args[0] isn't null, then yes.
     
  6. Offline

    mine-care

    CraftCreeper6 likes this.
  7. Offline

    MajorSkillage

    I think you mean if the getServer().getOnlinePlayers().contains(args[0]) :)
     
  8. Nop that won't work.
    Show Spoiler

    I think
     
  9. Offline

    mine-care

    @MajorSkillage as @MaTaMoR_ said, it wont work. what i am proposing is that craftcreper said "...not null..." and i corrected in the sence that it wont be null but it will throw a ArrayIndexOutOfBoundsException if args[0] does not exist. And to retrieve a player object of of a string you need to Bukkit.getPlayer(String name); that will become null if the player is not online at the moment.
     
  10. Offline

    AdityaTD

    @CraftCreeper6 @mine-care @MajorSkillage I get this on this code below: http://prntscr.com/6cpjra

    Code:
            if (cmd.getName().equalsIgnoreCase("givecoins")) {
                if (sender.hasPermission("coin.give")){
                    Player target = (Bukkit.getServer().getPlayer(args[0]));
                    if (target == null) {
                       sender.sendMessage(args[0] + " is not online!");
            }else{
            getServer().dispatchCommand(getServer().getConsoleSender() , "eco give " + target + " 100");
            player.sendMessage(ChatColor.BLUE + "Coins> " + ChatColor.WHITE + "Gave " + ChatColor.YELLOW + target + ChatColor.WHITE + " 100 Coins!");
                    return true;
                }
            }
            }
     
  11. Offline

    CraftCreeper6

  12. Offline

    mine-care

    @AdityaTD
    Please pay some effort reading the basic bukkit plugin tutorial. It will solve all your questions :) link is provided above ^
     
  13. Following up one what @mine-care said, if you don't know already, you need to at least know that basics of Java to understand what you're doing when you code, especially for an API that is written in it. It's going to be very difficult trying to understand, for example, what an ArrayList does without the basic knowledge of Java.
     
    mine-care likes this.
  14. Offline

    MajorSkillage

    Use Vault's API.
     
  15. Offline

    AdityaTD

    Alright thanks guys I guess it's fixed now! :D
     
  16. @AdityaTD Since the the thread is solved (for now), please set this thread to Solved by going to Thread Tools > Edit Title > Prefix > Solved. :)
     
  17. Offline

    AdityaTD

    @CodePlaysMinecraft Thanks, I never knew how because this is first time my prob got solved! :p
     
Thread Status:
Not open for further replies.

Share This Page