Gathering Integers from a Command.

Discussion in 'Plugin Development' started by Havefunpeeps, May 27, 2012.

  1. Offline

    Havefunpeeps

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Basically, I have no idea how to do this> Later in the code, I want to do something like, "If the amount typed in the command is more than the amount in the inventory, then return ("You don't have enough ____ for this!").

    The /mclgive command format will be: /mclgive (iron) (gold) (diamonds) in that order, and I want to assign the values given to Integers, but I'm completely at a loss of how to do so. Sorry for complete java noobiness.
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("mclottery")){
                player.sendMessage("This plugin is a Lottery for minecraft!");
                player.sendMessage("The Pot for the next lottery is: " +IronDeposited+ " Iron, " +GoldDeposited+ " Gold, and " +DiamondsDeposited+ " Diamonds.");
                player.sendMessage("To Deposit into the Lottery for a chance to win it all: /mclgive #Iron #Gold #Diamonds");
            }
            if(commandLabel.equalsIgnoreCase("mclgive")){
                if(args.length == 3){
                    if(player.isOp()){
                        player.sendMessage("Bro, you're too sexy for this.");
                    }
                    PlayerInventory inv = player.getInventory();
                    ItemStack iron = new ItemStack(Material.IRON_INGOT);
                    ItemStack gold = new ItemStack(Material.GOLD_INGOT);
                    ItemStack diamond = new ItemStack(Material.DIAMOND);
                    if(inv.contains(Material.IRON_INGOT)){
                       
                    }
                }else{
                    player.sendMessage("You used an incorrect format for the command! Please review the Command Usage!");
                }
            }
            return false;
        }
  2. Offline

    ddeckys

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    For assigning values to the integers just

    int whatever = args[position];

    make sure you check if the args are integers otherwise you will end up with errors if they're not.
  3. Offline

    Havefunpeeps

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thank you so much! :)

    EDIT: Now i'm lost on how to keep the data of "Player XYZ has deposited X iron, Y gold, and Z diamonds into the lottery". Also, I don't even know how to keep the total iron deposited variable up to date... Sorry once again >_>

    This post has been edited 1 time. It was last edited by Havefunpeeps May 27, 2012.

Share This Page