Won't charege player

Discussion in 'Plugin Development' started by baugh70, Oct 31, 2013.

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

    baugh70

    Hello all!

    I am creating a plugin that ranks up a player, a different way than paid ranks as they can choose the town, but it will not charge the player. If any of you could help, that would be great!


    Code:
    package me.baugh70.RankCitySky;
     
    import net.milkbowl.vault.chat.Chat;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.permission.Permission;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CommandListner extends JavaPlugin{
        Chat chatProvider;
        Economy econProvider;
        Permission permProvider;
       
        public void onEnable(){
            System.out.println("[RankCity] Enabling Rank City!");
            loadConfiguration();
            this.getCommand("rankup").setExecutor(this);
            System.out.println("[RankCity] Rank City is Enabled!");
        }
       
        public void onDisable(){
            System.out.println("[RankCity] Disabling Rank City!");
            saveConfig();
            System.out.println("[RankCity] Rank City is Disabled!");
           
        }
        private void loadConfiguration(){
            this.getConfig().options().header("Rank City Configuration! Created by: Baugh70");
            this.getConfig().addDefault("rank1", "Rank");
            this.getConfig().addDefault("rank1money", 0);
           
            this.getConfig().options().copyDefaults(true);
            getConfig().options().copyHeader(true);
            saveConfig();
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
           
            chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class).getProvider();
            econProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider();
            permProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class).getProvider();
     
           
            String rank1 = getConfig().getString("rank1");
           
            if(cmd.getName().equalsIgnoreCase("rankup")){
                if(args.length == 0){
                    player.sendMessage(ChatColor.AQUA + "Do /rankup <rank>");
                }else if(player.hasPermission("rankcity.rank1")){
                    if (args[0].equalsIgnoreCase(rank1)) {
                        if (econProvider.bankHas("Ranking up to " + rank1, getConfig().getDouble("rank1money")) != null) {
                            chatProvider.setPlayerSuffix(player.getPlayer(), rank1);
                            permProvider.playerRemove(player.getPlayer(), "rankcity.rank1");
                            permProvider.playerAdd(player.getPlayer(), "essentials.warp." + getConfig().getString(rank1));
                            econProvider.bankWithdraw("", getConfig().getDouble("rank1money"));
                            player.sendMessage(ChatColor.DARK_BLUE + "You ranked up!");
                        } else {
                            player.sendMessage(ChatColor.DARK_AQUA + "You do not have enough money!");
                        }
                    }else{
                        player.sendMessage(ChatColor.DARK_BLUE + "Do /rankup <rank>");
                    }
                }
            }
           
            return true;   
        }
     
    }
     
     
     
    
     
  2. Offline

    amhokies

    baugh70
    1) Initialize the Chat, Economy, and Permission classes in your onEnable method instead of doing it everytime a command is executed.

    2) Your method is econProvide.bankWithdraw("", getConfig()...) The first parameter of that method is used to specify the player who's bank account you are withdrawing the money from, but you have it blank.
     
  3. Offline

    baugh70

    amhokies
    I have changed this:
    Code:
    String rank1 = getConfig().getString("rank1");
    to this:
    Code:
    econProvider.bankWithdraw(playerMoney, getConfig().getDouble("rank1money"));
    Yet, it still will not withdraw the money from the player's balance.
     
Thread Status:
Not open for further replies.

Share This Page