Factions3/src/main/java/net/knarcraft/factions/engine/EngineFlagZombiegrief.java

49 lines
1.5 KiB
Java

package net.knarcraft.factions.engine;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MFlag;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityBreakDoorEvent;
public class EngineFlagZombiegrief extends Engine {
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineFlagZombiegrief i = new EngineFlagZombiegrief();
public static EngineFlagZombiegrief get() {
return i;
}
// -------------------------------------------- //
// FLAG: ZOMBIEGRIEF
// -------------------------------------------- //
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void denyZombieGrief(EntityBreakDoorEvent event) {
// If a zombie is breaking a door ...
Entity entity = event.getEntity();
if (!(entity instanceof Zombie)) {
return;
}
// ... and the faction there has zombiegrief disabled ...
PS ps = PS.valueOf(event.getBlock());
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(MFlag.getFlagZombiegrief())) {
return;
}
// ... stop the door breakage.
event.setCancelled(true);
}
}