Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project hit check to HurtingListener #2589

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void onEggThrow(PlayerEggThrowEvent e) {
* Handle visitor chicken egg hitting
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEggHit(ProjectileHitEvent e) {
if (e.getEntity() instanceof Egg egg) {
if (egg.getShooter() instanceof Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.LingeringPotionSplashEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
Expand Down Expand Up @@ -234,4 +235,46 @@ public void onPlayerShootEvent(final EntityShootBowEvent e) {
firedFireworks.put(e.getProjectile(), e.getEntity());
}
}

/**
* Handle visitor projectile hitting
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onProjectileHit(ProjectileHitEvent e) {
if (e.getEntity().getShooter() instanceof Player attacker) {
if (e.getHitEntity() instanceof LivingEntity entity) {
// Monsters being hit
if (Util.isHostileEntity(entity)) {
if (!checkIsland(e, attacker, entity.getLocation(), Flags.HURT_MONSTERS)) {
e.setCancelled(true);
return;
}
}
// Tamed animals being hit
if (Util.isTamableEntity(entity)) {
if (!checkIsland(e, attacker, entity.getLocation(), Flags.HURT_TAMED_ANIMALS)) {
e.setCancelled(true);
return;
}
}
// Mobs being hit
if (Util.isPassiveEntity(entity)) {
if (!checkIsland(e, attacker, entity.getLocation(), Flags.HURT_ANIMALS)) {
e.setCancelled(true);
return;
}
}
// Villagers being hit
if (entity instanceof AbstractVillager) {
if (!checkIsland(e, attacker, entity.getLocation(), Flags.HURT_VILLAGERS)) {
e.setCancelled(true);
}
}
}

}

}
}
Loading