Removing an item from an inventory

Discussion in 'Plugin Development' started by C0lA_K1nG, May 9, 2014.

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

    C0lA_K1nG

    My plugins work like they use a diamond (right click) to give them a boost, but i need help making it so that the diamond disappears after they right click it.

    Code:java
    1. public class effects
    2. extends JavaPlugin
    3. implements Listener
    4. {
    5. public final Logger log = Logger.getLogger("Minecraft");
    6. public HashMap<String, Long> cooldowns = new HashMap();
    7. private int cooldownTime = 0;
    8.  
    9. public void onEnable()
    10. {
    11. Bukkit.getPluginManager().registerEvents(this, this);
    12. getConfig().options().copyDefaults(true);
    13. saveConfig();
    14. this.log.info("Effects has been enabled");
    15. this.cooldownTime = getConfig().getInt("Cooldown");
    16. }
    17.  
    18. public void onDisable()
    19. {
    20. this.log.info("Effects has been disabled");
    21. }
    22.  
    23. @EventHandler
    24. public void onPlayerInteract(PlayerInteractEvent e)
    25. {
    26. Player player = null;
    27. if ((player instanceof Player))
    28. {
    29. Player p = e.getPlayer();
    30. if ((p.getItemInHand().getType() == Material.DIAMOND) &&
    31. (e.getAction() != Action.RIGHT_CLICK_AIR)){
    32. if (this.cooldowns.containsKey(player.getName())) {
    33. long secondsLeft = ((Long)this.cooldowns.get(player.getName())).longValue() / 1000L + this.cooldownTime - System.currentTimeMillis() / 1000L;
    34. if (secondsLeft > 0L) {
    35. p.sendMessage(ChatColor.DARK_AQUA + "[" + ChatColor.GOLD + "QuickBoost" + ChatColor.DARK_AQUA + "]:" + ChatColor.GRAY + " You are in a cooldown for another " + secondsLeft + " seconds!");
    36. }
    37. }
    38. this.cooldowns.put(p.getName(), Long.valueOf(System.currentTimeMillis()));
    39. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 180, 2));
    40. p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 180, 2));
    41. p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 100, 2));
    42. p.sendMessage(ChatColor.GOLD + "[" + ChatColor.DARK_AQUA + "QuickBoost" + ChatColor.GOLD + "]" + ChatColor.GRAY + ": Boost Activated!");
    43. p.getInventory().remove(arg0);
    44. } else {
    45. p.sendMessage(ChatColor.RED + "You don't have permission!");
    46. }
    47. }
     
  2. Offline

    LilHambo

    p.getInventory().remove(new ItemStack(Material.DIAMOND, 1))

    p.updateInventory()

    The statement above is to be safe. I dont know if it works without it or now.
     
  3. Offline

    C0lA_K1nG

    p.updateInventory() says: updateInventory() from the type Player is deprecated. should I add a supressor?
     
  4. C0lA_K1nG
    updateInventory() isn't necessary. Also, it's deprecated because "This method should not be relied upon as it is a temporary work-around for a larger, more complicated issue."
     
Thread Status:
Not open for further replies.

Share This Page