Solved Itemstack

Discussion in 'Plugin Development' started by klofno1, Jul 21, 2013.

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

    klofno1

    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
    1. private List<String> cantDoCommand7 = new ArrayList<>();
    2. @EventHandler
    3. public void onInteract7(final AsyncPlayerChatEvent event){
    4.  
    5. if(event.getPlayer().getItemInHand().getType()==Material.BOOK){
    6. Player player = event.getPlayer();
    7. ItemStack stackToCheckFor = new ItemStack(Material.BONE, 3);
    8. if(player.getInventory().contains(stackToCheckFor)) {
    9.  
    10. final String name = player.getName();
    11. final String message = event.getMessage();
    12. if (message.trim().equalsIgnoreCase("Augue")){
    13. if (cantDoCommand7.contains(name)){
    14. event.setCancelled(true);
    15. return;
    16. }
    17.  
    18. if(player.hasPermission("Venificus.Augue") || player.getPlayer().isOp()){
    19. event.getPlayer().getWorld().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 1);
    20. player.getInventory().remove(stackToCheckFor);
    21. player.launchProjectile(Fireball.class);
    22. cantDoCommand7.add(name);
    23. new BukkitRunnable(){
    24. @Override
    25. public void run(){
    26. cantDoCommand7.remove(name);
    27. }
    28. }.runTaskLater(plugin, 50);
    29. }
    30. }
    31. }
    32. }
    33. }
     
  2. Offline

    Firefly

    Change the amount on stackToCheckFor to 1 and then remove 3 when the spell has been cast.
     
  3. Offline

    klofno1

    What do you mean? I tried doing what you said but it is still the same 'error'. I guess I do not understand you :).
     
  4. Offline

    Firefly

    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
     
  5. Offline

    klofno1


    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.
     
    Last edited by a moderator: Jun 3, 2016
  6. Offline

    KillerOrbs

    On line 8 try to replace
    Code:
    if(player.getInventory().contains(stackToCheckFor)){}
    with
    Code:
    if(player.getInventory().contains(Material.BONE)){}
     
  7. Offline

    klofno1


    Now it ignores the 'remove 3 bones' thing. It just checks if there is a bone, if yes, it casts the spell.
     
  8. Offline

    KillerOrbs

    Code:
    if(player.getInventory().contains(Material.BONE, 3)){}
     
  9. Offline

    Rprrr

    Last edited by a moderator: Jun 3, 2016
  10. Offline

    klofno1

    KillerOrbs Rprrr
    Now it still does not remove the bones :

    Code:java
    1. private List<String> cantDoCommand7 = new ArrayList<>();
    2. @EventHandler
    3. public void onInteract7(final AsyncPlayerChatEvent event){
    4.  
    5. if(event.getPlayer().getItemInHand().getType()==Material.BOOK){
    6. Player player = event.getPlayer();
    7. ItemStack stackToCheckFor = new ItemStack(Material.BONE, 10);
    8. if(player.getInventory().containsAtLeast(stackToCheckFor, 3)) {
    9.  
    10. final String name = player.getName();
    11. final String message = event.getMessage();
    12. if (message.trim().equalsIgnoreCase("Augue")){
    13. if (cantDoCommand7.contains(name)){
    14. event.setCancelled(true);
    15. return;
    16. }
    17.  
    18. if(player.hasPermission("Venificus.Augue") || player.getPlayer().isOp()){
    19. player.getInventory().remove(stackToCheckFor);
    20. event.getPlayer().getWorld().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 1);
    21. player.launchProjectile(Fireball.class);
    22. cantDoCommand7.add(name);
    23. new BukkitRunnable(){
    24. @Override
    25. public void run(){
    26. cantDoCommand7.remove(name);
    27. }
    28. }.runTaskLater(plugin, 50);
    29. }
    30. }
    31. }
    32. }
    33. }
     
  11. Offline

    KillerOrbs

    Add this
    Code:java
    1. player.getInventory().removeItem(stackToCheckFor);
     
  12. Offline

    klofno1

    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 :).
     
  13. Offline

    KillerOrbs

Thread Status:
Not open for further replies.

Share This Page