HELP! balance checking?

Discussion in 'Spigot Help' started by lvo1, Jun 3, 2017.

  1. Hello,

    I am new to programming so all help is good help!

    Here is what I need to do, when someone does /fixall & fixhand it has to take a set amount away, but I am stuck on how I can get it to check that the player has the correct balance and then if they don't it won't fix the item?

    Code (Text):

    package me.crackedDNS.Fixall;

    import java.io.Console;
    import java.util.logging.Logger;

    import net.milkbowl.vault.chat.Chat;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.command.defaults.BukkitCommand;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
    import net.milkbowl.vault.Vault;
    import static sun.audio.AudioPlayer.player;

    public class FixAll extends JavaPlugin {
        public static final String fixall_self_perm = "ognetwork.fixhand";
        public static final String fixall_others_perm = "ognetwork.fixall";

        public void onEnable() {
            System.out.println("[FixAll] This plugin is enabled!");
        }

        public void onDisable() {
        }

        public static String PREFIX2 = ChatColor.RED + "" + ChatColor.BOLD + "Original" + ChatColor.GOLD + "Factions" + ChatColor.GRAY + " » ";
        public static String PREFIX = ChatColor.AQUA + "" + ChatColor.BOLD + "*";

        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {
            if (sender instanceof ConsoleCommandSender) {
                System.out.println("This command can not be sent from console!");
                return true;
            }

            Player p = null;
            if ((sender instanceof Player)) {
                p = (Player) sender;
            }
            if (cmd.getName().equalsIgnoreCase("fixhand")) {
                if (p != null) {
                    if (p.hasPermission("ogNetwork.command.fixhand")) {
                        p.sendMessage(ChatColor.GREEN + "Fixing the item in your hand....");
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take "+ "" + p.getPlayerListName() + "" +" 15000");
                        p.chat("/fix hand");
                        return true;
                    }
                    p.sendMessage("You don't have permision ogNetwork.command.fixhand");
                    return true;
                }
            } else {
                if (cmd.getName().equalsIgnoreCase("fixall")) {
                    if (p != null) {
                        if (p.hasPermission("ogNetwork.command.fixhand")) {
                            p.sendMessage(ChatColor.GREEN + "Fixing the items in your inv....");
                            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take "+ "" + p.getPlayerListName() + "" +" 100000");
                            p.chat("/fix all");
                            return true;
                        }
                        p.sendMessage("You don't have permision ogNetwork.command.fixall");
                        return true;
                    }
                } else {
                    if (cmd.getName().equals("fixhelp")) {
                        if (p != null) {
                            if (p.hasPermission("ogNetwork.command.fix")) {
                                p.sendMessage("§e========[ FixAll Help §e]========");
                                p.sendMessage(PREFIX + ChatColor.GOLD + " /fixall" + ChatColor.GREEN + " - " + ChatColor.GOLD + "Fixes all fixable items in your inv.");
                                p.sendMessage(PREFIX + ChatColor.GOLD + " /fixhand" + ChatColor.GREEN + " - " + ChatColor.GOLD + "Fixes whats is in your hand.");
                                p.sendMessage(PREFIX + ChatColor.DARK_PURPLE + " Fixall - $100k" + ChatColor.GOLD + "(6 Hour cooldown)");
                                p.sendMessage(PREFIX + ChatColor.DARK_PURPLE + " Fixhand - 15k" + ChatColor.GOLD + "(25Min Cooldown)");
                                p.sendMessage("§e========[ FixAll Help §e]========");
                                return true;
                            }
                            p.sendMessage("You don't have permision ogNetwork.command.fix");
                            return true;
                        }
                    }
                    return true;
                }
            }
            return true;
        }
    }
     
    I am not yet done with the fixing as I know away to make it so it does not need to run /fix all or /fix hand, it is there for testing.