Need help with plugin

Discussion in 'Plugin Development' started by 327, Jan 21, 2017.

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


    trying to make a tntcraft plugin, im new to this stuff. Trying to find out how to make the amount of gun powder have become the x so I can have the sulphur remove and the tnt added

            Player player = (Player) sender;
            Inventory inv = player.getInventory();
            ItemStack gun = new ItemStack(Material.SULPHUR, x);
            ItemStack tnt = new ItemStack(Material.TNT, x);
            int x = ???
            if(cmd.getName().equalsIgnoreCase("tntcraft")) {
                if(inv.contains(Material.SULPHUR)); {
                    player.sendMessage(ChatColor.RED + "You have no gun powder!");
            if(inv.contains(gun)) { 
  2. Offline

    OTF Catastrophe

    Well this is slightly confusing...

    If you want to get the amount of items the player is holding(For instance, how many gunpowder a player is holding) you could use e.getPlayer().getInventory().getItemInHand().getAmount() (I think).

    Your ItemStack for TNT and Sulphur shouldn't both equal to the amount x. I would say check how much gunpowder a player is holding, divide it by 5, then round down to a whole number and give that player the amount of tnt.

    If I'm misconstruding what you're asking please ignore me.
  3. Offline

    timtower Moderator Moderator

    @327 You need to count it manually.
    Loop through the itemstacks in the inventory.
    If it is not null: check type
    If it is gunpowder: increment x by the amount of that stack.
  4. Offline


    any way i can do to the whole inventory
Thread Status:
Not open for further replies.

Share This Page