Withdraw Money

Discussion in 'Plugin Development' started by KoolzSkillz, Oct 10, 2014.

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

    KoolzSkillz

    Hey, Im coding a plugin where you do /transfer <name> <ammout>
    and it removes your money and gives it to them.
    Only Problem is i cant find a way to remove the money.
    This is WITHOUT vault :)

    here is what im using to add the money to the other player
    settings.getConfig().set(tp.getUniqueId() + ".bank", a+args[1] );
     
  2. Offline

    fireblast709

    KoolzSkillz you are concatenating Strings, that can't be correct. You need to convert the amounts to doubles, so you can use math.
     
  3. Offline

    KoolzSkillz

  4. Offline

    Code0

  5. Offline

    KoolzSkillz

    The s-d has an error, (sorry just started config files and fist time using 'math'
    Code0
    fireblast709


    Code:
    package PlayerMoney;
     
    import java.util.ArrayList;
    import java.util.HashMap;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    import Main.SettingsManger;
     
    public class Transfer
      implements CommandExecutor
    {
          SettingsManger settings = SettingsManger.getInstance();
     
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
         
     
        if(!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "Consoles Cant Use This");
            return true;
        }
        Player p = (Player) sender;
        Player tp = p.getServer().getPlayer(args[0]);
       
       
        double d = Double.parseDouble(args[1]);
        String s = settings.getConfig().getString(p.getUniqueId() + ".bank");
        String s2 = settings.getConfig().getString(tp.getUniqueId() + ".bank");
       
       
       
        if (cmd.getName().equalsIgnoreCase("transfer")) {
            p.sendMessage("ยง2[Balance]: "+ settings.getConfig().getString(p.getUniqueId() + ".bank"));
      //      settings.getConfig().set(p.getUniqueId() + ".bank", s-d );
            settings.getConfig().set(tp.getUniqueId() + ".bank", s+d );
           
             
        }
        return false;
      }
    }
     
  6. Offline

    Code0

    You obviously need to put the double parsing after the "if cmd.getName...." section. KoolzSkillz Silly ;)

    Edit: In fact, you need to put everything (almost) under the if statement... :)
     
  7. Offline

    fireblast709

    KoolzSkillz you cannot substract a double from a String xD. Parse their balance (note: you can use getDouble("path.to.balance")) and add/subtract to/from d and set the balance to that in the config.
     
Thread Status:
Not open for further replies.

Share This Page