Solved Can remove one item at a time until in gets to zero

Discussion in 'Plugin Development' started by welsar55, Dec 4, 2013.

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

    welsar55

    So I Have this code
    Code:java
    1. if(event.getAction().equals(Action.RIGHT_CLICK_AIR))
    2. {
    3. if(plugin.dementor.contains(player.getName()))
    4. {
    5. if(player.getItemInHand().getType().equals(Material.MONSTER_EGG))
    6. {
    7. for(int i = 0; i < 25; i++)
    8. {
    9. Random random = new Random();
    10. Integer rx = random.nextInt(3);
    11. Integer ry = random.nextInt(3);
    12. Integer rz = random.nextInt(3);
    13. final Bat bat = (Bat) player.getWorld().spawnEntity(new Location(player.getWorld(), player.getLocation().getX() + rx, player.getLocation().getY() + ry, player.getLocation().getZ() + rz), EntityType.BAT);
    14. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
    15. {
    16. public void run()
    17. {
    18. bat.setHealth(0);
    19. }
    20. }, 60L);
    21. }
    22. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 60, 1));
    23. player.teleport(player.getTargetBlock(null, 20).getLocation());
    24. if(player.getItemInHand().getAmount() > 1)
    25. {
    26. player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
    27. }
    28. else
    29. {
    30. player.getItemInHand().setType(Material.AIR);
    31. }
    32. }
    33. }
    34. }

    and it works fine but when they only have one egg in there hand it does not remove it, Whats the fix
     
  2. Offline

    fireblast709

    welsar55 Try
    Code:
    player.setItemInHand(null);
     
  3. Offline

    welsar55

    XD whenever i need help with something its something as simply as this
     
Thread Status:
Not open for further replies.

Share This Page