Need help with economy plugin

Discussion in 'Plugin Development' started by abmenzel, Mar 23, 2013.

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

    abmenzel

    Hello!

    I am trying to make this seperate coin plugin.

    every command is working so far, but when it gets to the /ft buff list it does nothing same thing with /ft buff price <potion>

    here is my code:
    Code:
    package me.abmenzel.faithtokens;
     
    import org.bukkit.Bukkit;
    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 main extends JavaPlugin {
        public static main instance;
     
        @Override
        public void onEnable() {
            System.out.println("FaithTokens is now enabled!");
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
     
        @Override
        public void onDisable() {
            System.out.println("FaithTokens is now disabled!");
            saveConfig();
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("ft")){
                if(args.length == 0){
                    if(player.hasPermission("faithtokens.admin")){
                        player.sendMessage(ChatColor.YELLOW + "-" + ChatColor.BLUE + " Faith Tokens " + ChatColor.YELLOW + "-");
                        player.sendMessage(ChatColor.YELLOW + "/ft add <Player> <Amount>" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Add tokens to a player");
                        player.sendMessage(ChatColor.YELLOW + "/ft take <Player> <Amount>" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Take tokens from a player");
                        player.sendMessage(ChatColor.YELLOW + "/ft buff" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Help with token buffs");
                        player.sendMessage(ChatColor.YELLOW + "/ft enchant" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Help with token enchanting");
                        player.sendMessage(ChatColor.YELLOW + "/ft bal" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Token balance");
                        return true;
                    }else{
                        player.sendMessage(ChatColor.YELLOW + "-" + ChatColor.BLUE + " Faith Tokens " + ChatColor.YELLOW + "-");
                        player.sendMessage(ChatColor.YELLOW + "/ft buff" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Help with token buffs");
                        player.sendMessage(ChatColor.YELLOW + "/ft enchant" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Help with token enchanting");
                        player.sendMessage(ChatColor.YELLOW + "/ft bal" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Token balance");
                        return true;
                    }
                }else if(args.length == 1){
                    if(args[0].equalsIgnoreCase("add")){ //if it's /ft add
                        if(args.length <= 2) {
                            player.sendMessage(ChatColor.RED + "Too little arguments!");
                        }else if(args.length == 3) {
                            Player target = (Bukkit.getServer().getPlayer(args[1]));
                            if(target == null) {
                                player.sendMessage(ChatColor.YELLOW + args[1] + ChatColor.RED + "is not online or does not exist!");
                                return true;
                            } else {
                                String targetPlayer = target.getName();
                                String targetName = getConfig().getString(targetPlayer);
                                try {
                                    Integer.parseInt(args[2]);
                                }
                                catch(NumberFormatException ex) {
                                    player.sendMessage(ChatColor.RED + "The amount of tokens must be a number!");
                                    return true;
                                }
                                int amount = Integer.parseInt( args[2] );
                                if(amount <= 0) {
                                    player.sendMessage(ChatColor.RED + "The amount must be a positive number!");
                                    return true;
                                }
                                if(targetName != null) {
                                    int oldAmount = getConfig().getInt(targetPlayer + ".tokens");
                                    int newAmount = oldAmount+amount;
                                    getConfig().set(targetPlayer + ".tokens", newAmount);
                                    saveConfig();
                                    player.sendMessage(ChatColor.DARK_AQUA + "You have given " + ChatColor.YELLOW + targetPlayer + ", " + amount + ChatColor.GRAY + " Faith Token(s).");
                                    target.sendMessage(ChatColor.DARK_AQUA + "You have just received " + ChatColor.YELLOW + amount + ChatColor.GRAY + " Faith Token(s).");
                                    target.sendMessage(ChatColor.DARK_AQUA + "Do " + ChatColor.YELLOW + "/ft" + ChatColor.GRAY + " to spend them.");
                                    return true;
                                } else {
                                    getConfig().set(targetPlayer + ".tokens", amount);
                                    saveConfig();
                                    sender.sendMessage(ChatColor.DARK_AQUA + "You have given " + ChatColor.YELLOW + targetPlayer + ", " + amount + ChatColor.GRAY + " Faith Token(s).");
                                    target.sendMessage(ChatColor.DARK_AQUA + "You have just received " + ChatColor.YELLOW + amount + ChatColor.GRAY + " Faith Token(s).");
                                    target.sendMessage(ChatColor.DARK_AQUA + "Do " + ChatColor.YELLOW + "/ft" + ChatColor.GRAY + " to spend them.");
                                    return true;
                                }
                            }
                        } else {
                            player.sendMessage(ChatColor.RED + "Too many arguments!");
                           
                    }}else if(args[0].equalsIgnoreCase("take")){ //if it's /ft take
                        if(args.length <= 2) {
                            player.sendMessage(ChatColor.RED + "Too little arguments!");
                        }else if(args.length == 3) {
                            Player target = (Bukkit.getServer().getPlayer(args[1]));
                            if(target == null) {
                                player.sendMessage(ChatColor.YELLOW + args[1] + ChatColor.RED + "is not online or does not exist!");
                                return true;
                            } else {
                                String targetPlayer = target.getName();
                                String targetName = getConfig().getString(targetPlayer);
                                try {
                                    Integer.parseInt(args[2]);
                                }
                                catch(NumberFormatException ex) {
                                    player.sendMessage(ChatColor.RED + "The amount of tokens must be a number!");
                                    return true;
                                }
                                int amount = Integer.parseInt( args[2] );
                                if(amount <= 0) {
                                    player.sendMessage(ChatColor.RED + "The amount must be a positive number!");
                                    return true;
                                }
                                if(targetName != null) {
                                    int oldAmount = getConfig().getInt(targetPlayer + ".tokens");
                                    if(amount <= oldAmount) {
                                        int newAmount = oldAmount-amount;
                                        getConfig().set(targetPlayer + ".tokens", newAmount);
                                        saveConfig();
                                        player.sendMessage(ChatColor.DARK_AQUA + "You have taken " + ChatColor.YELLOW + amount + ChatColor.GRAY + " Faith Token(s) off " + ChatColor.YELLOW + args[1]);
                                        return true;
                                    } else {
                                        int tokens = getConfig().getInt(args[1] + ".tokens");
                                        player.sendMessage(ChatColor.YELLOW + args[1] + ChatColor.RED + " only have " + ChatColor.YELLOW + tokens + " Faith Tokens!");
                                        return true;
                                    }
                                } else {
                                    int tokens = getConfig().getInt(args[1] + ".tokens");
                                    player.sendMessage(ChatColor.YELLOW + args[1] + ChatColor.RED + " only have " + ChatColor.YELLOW + tokens + " Faith Tokens!");
                                    return true;
                        }}} else {
                            sender.sendMessage(ChatColor.RED + "Too many arguments!");
                    }}else if(args[0].equalsIgnoreCase("bal")){ //if it's /ft bal
                        if(sender instanceof Player) {
                            if(args.length == 1) {
                                String name = player.getName();
                                String playerName = getConfig().getString(name);
                                if(playerName != null) {
                                    int tokens = getConfig().getInt(name + ".tokens");
                                    player.sendMessage(ChatColor.DARK_AQUA + "You have " + ChatColor.YELLOW + tokens + ChatColor.GRAY + " Faith Token(s) remaining.");
                                    return true;
                                } else {
                                    player.sendMessage(ChatColor.DARK_AQUA + "You have " + ChatColor.YELLOW + "0" + ChatColor.GRAY + " Faith Tokens remaining.");
                                    return true;
                                }
                            } else if(args.length == 2) {
                                String targetName = getConfig().getString(args[1]);
                                if(targetName != null) {
                                    int tokens = getConfig().getInt(args[1] + ".tokens");
                                    player.sendMessage(ChatColor.YELLOW + args[1] + ChatColor.DARK_AQUA + " has " + ChatColor.YELLOW + tokens + ChatColor.GRAY+ " Faith Token(s) remaining.");
                                    return true;
                                } else {
                                    player.sendMessage(ChatColor.YELLOW + args[1] + ChatColor.DARK_AQUA + " has " + ChatColor.YELLOW + "0 " + ChatColor.GRAY + "Faith Tokens remaining.");
                                    return true;
                                }
                            } else {
                                player.sendMessage(ChatColor.RED + "Too many arguments!");
                            }
                        } else {
                            sender.sendMessage(ChatColor.RED + "This command can only be run by a player!");
                            return true;
                        }
                    }else if(args[0].equalsIgnoreCase("buff")){ //if it's /ft buff
                        if(args.length == 1) {
                            player.sendMessage(ChatColor.YELLOW + "-" + ChatColor.BLUE + " FT Buff's " + ChatColor.YELLOW + "-");
                            player.sendMessage(ChatColor.YELLOW + "/ft buff list" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "List all buff names");
                            player.sendMessage(ChatColor.YELLOW + "/ft buff price <buff name>" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Price of a specific buff");
                            player.sendMessage(ChatColor.YELLOW + "/ft buff buy <buff name> <lvl>" + ChatColor.GRAY + " | " + ChatColor.DARK_AQUA + "Buy a buff");
                            return true;
                        }else if(args.length == 2) {
                            if(args[1].equalsIgnoreCase("list")){
                                player.sendMessage(ChatColor.GRAY + "----- " + ChatColor.BLUE + "Buff List" + ChatColor.GRAY + " -----");
                                player.sendMessage(ChatColor.DARK_AQUA + "SPEED");
                                player.sendMessage(ChatColor.DARK_AQUA + "HASTE");
                                player.sendMessage(ChatColor.DARK_AQUA + "REGENERATION");
                                player.sendMessage(ChatColor.DARK_AQUA + "FIRERESISTANCE");
                                player.sendMessage(ChatColor.DARK_AQUA + "WATERBREATHING");
                        }else if(args.length == 3) {
                            if(args[1].equalsIgnoreCase("price")){
                                if(args.length <= 2) {
                                    player.sendMessage(ChatColor.RED + "Too little arguments!");
                                } else if(args.length == 3) {
                                    if(args[2].equalsIgnoreCase("SPEED")) {
                                        player.sendMessage(ChatColor.GRAY + "Speed prices:");
                                        player.sendMessage(ChatColor.DARK_AQUA + "SPEED" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 1" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "3 Tokens");
                                        player.sendMessage(ChatColor.DARK_AQUA + "SPEED" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 2" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "6 Tokens");
                                        return true;
                                    } if(args[2].equalsIgnoreCase("HASTE")) {
                                        player.sendMessage(ChatColor.GRAY + "Haste prices:");
                                        player.sendMessage(ChatColor.DARK_AQUA + "HASTE" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 1" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "3 Tokens");
                                        player.sendMessage(ChatColor.DARK_AQUA + "HASTE" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 2" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "6 Tokens");
                                        return true;
                                    } if(args[2].equalsIgnoreCase("REGENERATION")) {
                                        player.sendMessage(ChatColor.GRAY + "Regeneration prices:");
                                        player.sendMessage(ChatColor.DARK_AQUA + "REGENERATION" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 1" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "3 Tokens");
                                        player.sendMessage(ChatColor.DARK_AQUA + "SPEED" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 2" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "6 Tokens");
                                        return true;
                                    } if(args[2].equalsIgnoreCase("FIRERESISTANCE")) {
                                        player.sendMessage(ChatColor.GRAY + "Fireresistance prices:");
                                        player.sendMessage(ChatColor.DARK_AQUA + "FIRERESISTANCE" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 1" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "3 Tokens");
                                        return true;
                                    } if(args[2].equalsIgnoreCase("WATERBREATHING")) {
                                        player.sendMessage(ChatColor.GRAY + "Waterbreathing prices:");
                                        player.sendMessage(ChatColor.DARK_AQUA + "WATERBREATHING" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "1:30 Mins" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "lvl 1" + ChatColor.YELLOW + " | " + ChatColor.DARK_AQUA + "3 Tokens");
                                        return true;
                                    } else {
                                        player.sendMessage(ChatColor.YELLOW + args[2] + ChatColor.RED + "is not a valid buff!");
                                        player.sendMessage(ChatColor.RED + "Type /ft buff list to see a list of valid buff types");
                                    }
                                }
                            }
                        }
                        }
                    }
                }
            }
            return false;
        }
    }
     
     
     
     
     
     
    
    If you see what my mistakes are please reply to me :) I appreciate any help I can get.

    Thanks in advance!

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    ztowne13

    Is the Saving to config files working?
     
  3. Offline

    cMan_

    So messy. Divide up the args commands into separate classes and then we'll talk.
    You'll probably fix your plugin at the same time.
     
Thread Status:
Not open for further replies.

Share This Page