int help

Discussion in 'Plugin Development' started by Go Hard, Oct 11, 2013.

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

    Go Hard

    Ok so i have a coins.yml file that keeps track of all my players coins. Now i have a command somthing like

    /coinsadd [playername] [amount]

    it works perfectly fine. Now i have a command like

    /coinstake [playername] [amount]

    And if i do the command and i put the 10 for the ammount it makes the coins negative.
    So say that i had 10010 coins. and i try to take 10 coins away it make the amount -10000

    It takes the 10 coins away but for some reason it makes the coins negitive. here is the command

    Code:
        if (cmd.getName().equalsIgnoreCase("coinstake"))
        {
          if (p.hasPermission("coins.coinsatake")) {
            if (args.length > 2) {
              p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " /coinstake [player] [amount]");
              return true;
            }
     
            if (args.length == 0) {
              p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " /coinstake [player] [amount]");
              return true;
            }
     
            if (args.length == 1) {
              p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " /coinstake [player] [amount]");
              return true;
            }
     
            if (args.length == 2)
            {
              String a = (String)config.get(args[0]);
     
              if (a == null)
                p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " That player does not exist");
              else
                  config.load(configFile);
                  int coinns = Integer.parseInt(args[1]) - Integer.parseInt((String)config.get(args[0]));
                  config.set(args[0], String.valueOf(coinns));
                  config.save(configFile);
                  p.sendMessage(ChatColor.RED + "[Coins]" + "I think you have had coins taken but idk ;)");
                  return true;
            }
          }
    Help?
     
  2. Offline

    Craftiii4

    int coinns = Integer.parseInt(args[1]) - Integer.parseInt((String)config.get(args[0]));

    Should be the other way around.
     
  3. Offline

    Go Hard

    Craftiii4
    Like this?

    int coinns = Integer.parseInt((String)config.get(args[0]) - Integer.parseInt(args[1]));

    If i do that it says its undefinable String, int
     
  4. Offline

    BajanAmerican

    Go Hard
    You have to use an else if statement when you distinguish between the different amount of arguments.
    Code:
    if(args.length == 0){
     
    } else if(args.length == 1){
     
    }
    So on and so on...
     
  5. Offline

    Go Hard

    BajanAmerican
    I have already tried that it didn't do anything.
     
  6. Offline

    Shzylo

    Try what Craftiii4 said, that should fix your troubles.
     
  7. Offline

    Craftiii4

    BajanAmerican

    No you don't? I would never do that as well, just makes it look messy.



    Go Hard

    The reason why it is failing at the moment is because you are getting the amount they want, then taking away the amount in the config.

    For example, say in the config file I ave 50, and you use /coinstake Craftiii4 10

    It will do 10 - 50

    Which will equal -40, instead you want to do 50-10 to get 40.

    So use this:
    Code:java
    1. int coinns = Integer.parseInt((String)config.get(args[0])) - Integer.parseInt(args[1]);
     
  8. Offline

    Go Hard

    Craftiii4
    Thanks it worked. :) Heres a diamond for you! [diamond]
     
Thread Status:
Not open for further replies.

Share This Page