Maintenance - We're currently working on things and you might experience some issues. Should be wrapped up soon!

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

11
[1.7] Protecting Item Frames With WorldGuard
Author Summary
roastnewt is age 1
Post Body

As many of you that are using Bukkit/Spigot 1.7 may have noticed, Item Frames in WorldGuard protected regions can be emptied by anyone.

As of Spigot build 1173, md_5 added the following workaround: "Call EntityDamageEvent for every damage to a filled item frame."

So I wrote a small listener that checks that a player has edit permissions before allowing them to empty a full item frame. You can download it here or just add the following code to your "catchall" plugin, if you have one:

@EventHandler
public void itemFrameDamage(EntityDamageEvent e)
{
    if(e.getEntityType().equals(EntityType.ITEM_FRAME))
    {
        if (e.getCause().equals(DamageCause.ENTITY_ATTACK))
        {
            EntityDamageByEntityEvent castEvent = (EntityDamageByEntityEvent)e;
            if (!(castEvent.getDamager() instanceof Player)) return;
            if (!getWorldGuard().canBuild((Player)castEvent.getDamager(), e.getEntity().getLocation()))
            {
                e.setCancelled(true);
            }
        }

    }
}

Author
Account Strength
100%
Account Age
15 years
Verified Email
Yes
Verified Flair
No
Total Karma
5,637
Link Karma
196
Comment Karma
5,441
Profile updated: 3 days ago
Posts updated: 7 months ago

Subreddit

Post Details

Age
1
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 years ago