From 0410ddb5224ce936a9e2ea7fce8b53f8e1585408 Mon Sep 17 00:00:00 2001 From: Noogear <123232885+Noogear@users.noreply.github.com> Date: Sat, 16 Nov 2024 16:16:13 +0800 Subject: [PATCH] Add the protection flag for eggHit. --- .../flags/protection/EggListener.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EggListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EggListener.java index 001192553..409c28d59 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EggListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EggListener.java @@ -1,7 +1,10 @@ package world.bentobox.bentobox.listeners.flags.protection; +import org.bukkit.entity.Egg; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.player.PlayerEggThrowEvent; import world.bentobox.bentobox.api.flags.FlagListener; @@ -24,4 +27,19 @@ public class EggListener extends FlagListener { e.setHatching(false); } } + + /** + * Handle visitor chicken egg hitting + * @param e - event + */ + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onEggHit(ProjectileHitEvent e) { + if (e.getEntity() instanceof Egg egg) { + if (egg.getShooter() instanceof Player player) { + if (!checkIsland(e, player, egg.getLocation(), Flags.EGGS)) { + e.setCancelled(true); + } + } + } + } }