Skip to content

Commit

Permalink
Prevent potion effects for protected NPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 9, 2018
1 parent e3f339b commit d7237df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions main/src/main/java/net/citizensnpcs/EventListen.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand All @@ -28,6 +29,7 @@
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;
Expand Down Expand Up @@ -473,6 +475,18 @@ public void run() {
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))
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/trait/Gravity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public void run() {
public boolean toggle() {
return enabled = !enabled;
}
}
}

0 comments on commit d7237df

Please sign in to comment.