Giving Money

Discussion in 'Spigot Plugin Help' started by MaxNatural, May 15, 2016.

  1. I am trying to give money to players... I'm able to see the pixels they have but I don't know how to add pixels to someone. Here is the code

    Code (Text):
        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
            Player player = (Player) sender;
            if (alias.equalsIgnoreCase("givepixel") || alias.equalsIgnoreCase("givep")) {
            if (args.length == 0) {
            //Player only typed '/heal' so lets heal them back!
            player.sendMessage(Hub.pixel + "Please give a player");
            } else {
            //Player typed something more
            Player target = Bukkit.getPlayerExact(args[0]);
            if (target == null) {
            //Target is not online
            player.sendMessage(Hub.pixel + "The player " + args[0] + " is not online!");
            } else {
            //Targets online
            player.sendMessage(Hub.pixel + args[0] + "'s Pixels: " + PixelsAPI.get(target));
            }  
            }
            if (args.length == 1) {
                Player target2 = Bukkit.getPlayerExact(args[0]);
                if (target2 == null) {
                    player.sendMessage(Hub.pixel + "The player " + args[0] + " is not online!");
                } else {
                    String pixel;
                   
                    player.sendMessage(Hub.pixel + PixelsAPI.add(player, pixel));
                }

                }
            }
            return true;
            }
    }
     
  2. Are you getting any errors if so please post, and before setting type as player make sure it is an actual player
     
  3. No errors, I just need to know how to be able to do /pixel give MaxNatural 1000. I will make sure it's a real player.
     
  4. What currency are you using? and do you have the javac or whatever?
     
  5. I'm using a custom API i used which are pixels.
     
  6. You have to add a method to add pixels?
     
  7. Code (Text):
      public static void add(Player p, int number)
      {
        set(p, get(p) + number);
      }
     
  8. I think that would wok, not 100% sure, but yea
     
  9. But how would I make the command /pixel give <player> <number of pixels> Like I know you use arguments but I'm not totally sure how to.
     
  10. Have to check if args 0 == "give", args 1 == a player that has played on the server, possibly one online and if args 2 == an int
     
  11. How would I do so? I just need the if statements and the checks and I can do the rest of it.
     
  12. Basically said it to you, I think you can figure out the rest it with the help of google
    If(args[0] == "give") {
    //code
    }
     
  13. Is there a way to get the player in args[1] or the name. I tried PixelsAPI.add(args[1], ammount);
    But the add statement is this
    Code (Text):
      public static void add(Player p, int number)
      {
        set(p, get(p) + number);
      }
    and it doesn't work
     
  14. Thats a bad way of checking case and strings

    if(args[0].equalsIgnoreCase("gives")) { //Do code } Should be how its checked.
     
  15. Code (Text):
    getServer().getPlayer(String name);
    Googling "how to get player from string spigot" would have probably been a fair bit quicker. Make sure you know how to use documentation and how to use the basics of Java before trying to develop with Spigot, it is very frustrating if you don't.
     
  16. Fixed! Thank you :)
     
    • Friendly Friendly x 1
  17. Awesome. :)
     
  18. Code (Text):
            if (args[0].equalsIgnoreCase("add"))
            {
               
                double amount = 0;
                try
                {
                    amount = Double.parseDouble(args[2]);
                } catch (Exception e)
                {
                    sender.sendMessage(Hub.pixel + "Please enter a value");
                    return true;
                }

                PixelsAPI.add(args[1], amount);
               
    it won't add the pixels...

    Code (Text):
      public static void add(Player p, int number)
      {
        set(p, get(p) + number);
      }
     
  19. I'm sorry, but did you actually read what I said?
     
  20. I'm sorry I'm learning...?