diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 7a8262600..b8b9153c2 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -973,6 +973,43 @@ public class PlayerListener implements Listener { } } } + + /** + * When a {@link Player} attempts to place an {@link ItemStack} + * into an {@link ItemFrame}, we want to make sure to remove any + * Ability buffs from that item. + * + * @param event The {@link PlayerInteractEntityEvent} to handle + */ + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + /* + * We can check for an instance instead of EntityType here, so we are + * ready for the infamous "Glow Item Frame" in 1.17 too! + */ + if (event.getRightClicked() instanceof ItemFrame) { + ItemFrame frame = (ItemFrame) event.getRightClicked(); + + // Check for existing items (ignore rotations) + if (frame.getItem().getType() != Material.AIR) { + return; + } + + // Get the item the Player is about to place + ItemStack itemInHand; + + if (event.getHand() == EquipmentSlot.OFF_HAND) { + itemInHand = event.getPlayer().getInventory().getItemInOffHand(); + } + else { + itemInHand = event.getPlayer().getInventory().getItemInMainHand(); + } + + // and remove any skill ability buffs! + SkillUtils.removeAbilityBuff(itemInHand); + } + } + // // @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) // public void onPlayerStatisticIncrementEvent(PlayerStatisticIncrementEvent event) {