From 002887e24421c7bd0d130996d74a8a6a5455bb0a Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 3 Apr 2021 03:47:43 +0200 Subject: [PATCH] Sanitize ability buffs when using Item Frames (#4475) * Remove skill ability buffs from items when placed into Item Frames * Ensure compatibility on versions before 1.16 --- .../nossr50/listeners/PlayerListener.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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) {