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 Code: 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)) { inv.remove(gun); inv.addItem(tnt); }
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.
@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.