Prevent potion effects for protected NPCs

This commit is contained in:
fullwall 2018-03-09 20:54:20 +08:00
parent e3f339b80d
commit d7237dff4e
2 changed files with 15 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import org.bukkit.Material;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -28,6 +29,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.PlayerLeashEntityEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerFishEvent;
@ -473,6 +475,18 @@ public class EventListen implements Listener {
skinUpdateTracker.updatePlayer(event.getPlayer(), 15, true);
}
@EventHandler(ignoreCancelled = true)
public void onPotionSplashEvent(PotionSplashEvent event) {
for (LivingEntity entity : event.getAffectedEntities()) {
NPC npc = npcRegistry.getNPC(entity);
if (npc == null)
continue;
if (npc.isProtected()) {
event.setIntensity(entity, 0);
}
}
}
@EventHandler(ignoreCancelled = true)
public void onProjectileHit(final ProjectileHitEvent event) {
if (!(event.getEntity() instanceof FishHook))

View File

@ -38,4 +38,4 @@ public class Gravity extends Trait implements Toggleable {
public boolean toggle() {
return enabled = !enabled;
}
}
}