Development Assistance Remove Item from ItemFrame

Discussion in 'Plugin Help/Development/Requests' started by DomTheCon, Dec 22, 2014.

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

    DomTheCon

    Does anyone know how you can properly remove an item from an itemframe to make it empty? I'll post my code below, but I believe that it does not have to do with the below event, but rather with setting an itemframe to empty. It is possible that this problem has to do with the frame not updating, but I have tried chunk reloads with no success. No error messages are sent at all from this. Also (as seen below) it would appear that the itemframe item is not even changing as the type sent in chat is the original item type, so I do not think it is a client update problem. The example below is from my plugin, but I have tried simply setting an itemframe's item to air in other examples only to find the same results. I am using the 1.8 version of spigot. Also in this case the reason I am cancelling the event only to set it to air myself is so that the event can bypass worldguard and prevent the item from dropping. Any help is greatly appreciated.
    Code:
    @EventHandler
       public void itemFrameItemRemoval(EntityDamageEvent event) {
            if(event.getEntity() instanceof ItemFrame) {
                ItemFrame it = (ItemFrame) event.getEntity();
                if(it.getItem().getItemMeta().getDisplayName()!=null)
                if(it.getItem().getItemMeta().getDisplayName().equals(ChatColor.GRAY+"Duster")){
                    event.setCancelled(true);
                    Bukkit.getServer().broadcastMessage("Check");
                    it.setItem(new ItemStack(Material.AIR));
                    Bukkit.getServer().broadcastMessage(it.getItem().getType().toString());
                }
            }
       }
     
  2. Offline

    adam753

  3. Offline

    DomTheCon

    Thank you for the info, hopefully it gets fixed soon.

    As for spawning a new itemframe, I don't think that will work since I am using the itemframe in a runnable.
     
  4. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives.
     
  5. Offline

    DomTheCon

    I have found a fix. In case anyone encounters this problem, simply set the item in the itemframe to a removed technical block such as lava. Since the item for lava (or whichever technical block) no longer exists, then the item will be set to air. This can be used as a pain-free fix until the bug is patched.
     
Thread Status:
Not open for further replies.

Share This Page