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
This commit is contained in:
TheBusyBiscuit 2021-04-03 03:47:43 +02:00 committed by GitHub
parent 48afb81174
commit 002887e244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) // @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
// public void onPlayerStatisticIncrementEvent(PlayerStatisticIncrementEvent event) { // public void onPlayerStatisticIncrementEvent(PlayerStatisticIncrementEvent event) {