Help I can't remove items from a players inventory

Discussion in 'Plugin Development' started by MonkeyPlays, Feb 19, 2014.

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

    MonkeyPlays

    Hello there Bukkit, my problem is that even if I try it wont remove the golden apple from the players inventory once picked up, heres my code can someone help?
    Code:
    package me.BuissnessMonkey.CustomGapples;
     
    import java.io.IOException;
     
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class ItemListener implements Listener {
       
        @EventHandler
        public void onGapplePickup(PlayerPickupItemEvent e) throws IOException{
            Player p = (Player) e.getPlayer();
            if(e.getItem().equals(Material.GOLDEN_APPLE));
            p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100 , 2));
            p.getInventory().remove(Material.GOLDEN_APPLE);
    
     
  2. Offline

    tomudding

    Just do
    Code:
    p.updateInventory();
    after the remove line
     
  3. Offline

    MonkeyPlays

    Dosen't work tomudding, do I have to remove suppress warnings?
     
  4. Offline

    EnderTroll68

    Well one of your problems is that there are no brackets surrounding your stuff... You have a completely useless if statement, what are you doing with that?
     
  5. Offline

    tomudding

    MonkeyPlays, Add SuppresWarning deprecation (or how it is named) And as EnderTroll68 said. Close your event with "}"
     
  6. Offline

    EnderTroll68

    The inventory should be automatically updated when they open it, that is why it is marked as deprecated, as it is no longer needed. If that fixes it, then there is something wrong with your code
     
  7. Offline

    MonkeyPlays

    tomudding Supress warning deprecation doesn't work

    tomudding and EnderTroll68, pls help it's not working

    Hello?

    tomudding Any idea why it's not working?

    HEEEEEEELLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLO

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  8. Offline

    Garris0n

    Please bump once every 24 hours.
    Not...every...minute...

    Anyway, they haven't picked it up when you're removing it. Just cancel it and delete the item entity.
     
  9. Offline

    tomudding

    MonkeyPlays, don't do that. I have school and work. And I coded and debugged about ± 30 minutes for you and got it working. Here is the code.
    Code:java
    1. @EventHandler
    2. public void PickupItem(PlayerPickupItemEvent event) {
    3. Player player = event.getPlayer();
    4. if (event.getItem().getItemStack().getType() == Material.GOLDEN_APPLE) {
    5. player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100 , 2));
    6. event.getItem().remove();
    7. event.setCancelled(true);
    8. }
    9.  
    10. }

    And don't forget to register the event.
     
Thread Status:
Not open for further replies.

Share This Page