Double from args

Discussion in 'Plugin Development' started by stamline, Oct 5, 2015.

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

    stamline

    Hi, i would like to get out a double from a arg.
    this is the command i would like to work, "/money remove ''double" 'player'.
    Here is my code.
    Code:
    if(args.length == 3){
                if(args[1].equalsIgnoreCase("remove")){
                    Double removemoney = Double.parseDouble(args[2].replace(",", "."));
                    Listeners.removemoney(player, removemoney);
                    }
                }
    Here is the Listeners class:
    Code:
    public static void removemoney(Player player, double removemoney){
                UUID uuid = player.getUniqueId();
                double  money = Main.plugin.getConfig().getDouble("Money." + uuid);
                money = money-removemoney;
                Main.plugin.getConfig().set("Money." + uuid, money);
                Main.plugin.saveConfig();
                String message = getMessage("Messages.RemoveMoney", player);
                String money2 = Double.toString(money);
                message = message.replace("@m", money2);
                
     
  2. Offline

    mine-care

    Use Double.parseDouble(String param), That will throw a NumberFormatException if the provided string contains non numeric values.
    I cant understand what the problem with your code is ?
     
  3. Offline

    stamline

    if I´m running the command /money remove 60 name
    nothing will show up in the game. And im sending the message 'message' from the removemoney.
     
  4. Offline

    Zombie_Striker

    @stamline
    Let me get this out ofthe way:

    Arg[1] is the SECOND arg. Arg[0] is the first arg.

    This is what the command line looks like /Command arg[0] arg[1] arg[2]

    So yes, because arg[1] would be the "double", it would never be equal to "remove"
     
    mine-care likes this.
  5. Offline

    stamline

    Thanks man, it was the args, that was wrong. Everything else was fine :D
     
  6. Offline

    boomboompower

    @stamline if your issue has been fixed, please mark this thread as solved. Thx -boom
     
Thread Status:
Not open for further replies.

Share This Page