Преглед изворни кода

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
TheBusyBiscuit пре 4 година
родитељ
комит
002887e244
1 измењених фајлова са 37 додато и 0 уклоњено
  1. 37 0
      src/main/java/com/gmail/nossr50/listeners/PlayerListener.java

+ 37 - 0
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) {