This only shoots a fireball when you have exactly 3 bones in your inven. How can I change that? It just has to check if there are bones in the players inven, if yes remove 3, else dont do the spell. Code:java private List<String> cantDoCommand7 = new ArrayList<>();@EventHandlerpublic void onInteract7(final AsyncPlayerChatEvent event){ if(event.getPlayer().getItemInHand().getType()==Material.BOOK){ Player player = event.getPlayer();ItemStack stackToCheckFor = new ItemStack(Material.BONE, 3);if(player.getInventory().contains(stackToCheckFor)) { final String name = player.getName();final String message = event.getMessage();if (message.trim().equalsIgnoreCase("Augue")){if (cantDoCommand7.contains(name)){event.setCancelled(true);return;} if(player.hasPermission("Venificus.Augue") || player.getPlayer().isOp()){event.getPlayer().getWorld().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 1);player.getInventory().remove(stackToCheckFor);player.launchProjectile(Fireball.class);cantDoCommand7.add(name);new BukkitRunnable(){@Overridepublic void run(){cantDoCommand7.remove(name);}}.runTaskLater(plugin, 50); }}}}}
What do you mean? I tried doing what you said but it is still the same 'error'. I guess I do not understand you .
The itemstack you create, set the amount to 1 not 3. Then when you are removing from the inventory make a new itemstack with an amount of 3
Yes that is what you said, I did that (I think). But I am doing it wrong, could you give me the line of the itemstack with an amount of 3? Has anyone else any information? I cannot continue with my plugin now . EDIT by Moderator: merged posts, please use the edit button instead of double posting.
On line 8 try to replace Code: if(player.getInventory().contains(stackToCheckFor)){} with Code: if(player.getInventory().contains(Material.BONE)){}
Now it ignores the 'remove 3 bones' thing. It just checks if there is a bone, if yes, it casts the spell.
klofno1 Voila. http://jd.bukkit.org/rb/doxygen/d3/dad/interfaceorg_1_1bukkit_1_1inventory_1_1Inventory.html boolean containsAtLeast (ItemStack item, int amount) Checks if the inventory contains any ItemStacks matching the given ItemStack and at least the minimum amount specified. That would still bug. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
KillerOrbs Rprrr Now it still does not remove the bones : Code:java private List<String> cantDoCommand7 = new ArrayList<>();@EventHandlerpublic void onInteract7(final AsyncPlayerChatEvent event){ if(event.getPlayer().getItemInHand().getType()==Material.BOOK){ Player player = event.getPlayer();ItemStack stackToCheckFor = new ItemStack(Material.BONE, 10);if(player.getInventory().containsAtLeast(stackToCheckFor, 3)) { final String name = player.getName();final String message = event.getMessage();if (message.trim().equalsIgnoreCase("Augue")){if (cantDoCommand7.contains(name)){event.setCancelled(true);return;} if(player.hasPermission("Venificus.Augue") || player.getPlayer().isOp()){player.getInventory().remove(stackToCheckFor);event.getPlayer().getWorld().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 1);player.launchProjectile(Fireball.class);cantDoCommand7.add(name);new BukkitRunnable(){@Overridepublic void run(){cantDoCommand7.remove(name);}}.runTaskLater(plugin, 50); }}}}}
Rprrr KillerOrbs Thank you everything is working again! Now I can continue with my plugin, tomrrow. To release a new version with some major changes .