use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardEntityListener method onEntityDamageByEntity.
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Projectile) {
onEntityDamageByProjectile(event);
return;
}
Entity attacker = event.getDamager();
Entity defender = event.getEntity();
WorldConfiguration wcfg = getWorldConfig(defender.getWorld());
if (defender instanceof ItemFrame) {
if (checkItemFrameProtection(attacker, (ItemFrame) defender)) {
event.setCancelled(true);
return;
}
} else if (defender instanceof ArmorStand && !(attacker instanceof Player)) {
if (wcfg.blockEntityArmorStandDestroy) {
event.setCancelled(true);
return;
}
}
if (attacker instanceof EnderCrystal) {
// in the same way that creepers or tnt can
if (wcfg.useRegions && wcfg.explosionFlagCancellation) {
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(defender.getLocation())).testState(null, Flags.OTHER_EXPLOSION)) {
event.setCancelled(true);
return;
}
}
}
if (defender instanceof Player) {
Player player = (Player) defender;
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
if (wcfg.disableLightningDamage && event.getCause() == DamageCause.LIGHTNING) {
event.setCancelled(true);
return;
}
if (wcfg.disableExplosionDamage) {
switch(event.getCause()) {
case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
event.setCancelled(true);
return;
}
}
if (attacker != null) {
if (attacker instanceof TNTPrimed || attacker instanceof ExplosiveMinecart) {
// The check for explosion damage should be handled already... But... What ever...
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
}
}
if (attacker instanceof LivingEntity && !(attacker instanceof Player)) {
if (attacker instanceof Creeper && wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.disableMobDamage) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
if (!set.testState(localPlayer, Flags.MOB_DAMAGE) && !(attacker instanceof Tameable)) {
event.setCancelled(true);
return;
}
}
}
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardEntityListener method onEntityDamageByBlock.
private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
Entity defender = event.getEntity();
DamageCause type = event.getCause();
WorldConfiguration wcfg = getWorldConfig(defender.getWorld());
if (defender instanceof Wolf && ((Wolf) defender).isTamed()) {
if (wcfg.antiWolfDumbness && !(type == DamageCause.VOID)) {
event.setCancelled(true);
return;
}
} else if (defender instanceof Player) {
Player player = (Player) defender;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (wcfg.disableLavaDamage && type == DamageCause.LAVA) {
event.setCancelled(true);
player.setFireTicks(0);
return;
}
if (wcfg.disableContactDamage && type == DamageCause.CONTACT) {
event.setCancelled(true);
return;
}
if (wcfg.teleportOnVoid && type == DamageCause.VOID) {
localPlayer.findFreePosition();
if (wcfg.safeFallOnVoid) {
localPlayer.resetFallDistance();
}
event.setCancelled(true);
return;
}
if (wcfg.disableVoidDamage && type == DamageCause.VOID) {
event.setCancelled(true);
return;
}
if (type == DamageCause.BLOCK_EXPLOSION && (wcfg.disableExplosionDamage || wcfg.blockOtherExplosions || (wcfg.explosionFlagCancellation && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(localPlayer.getLocation(), (RegionAssociable) null, Flags.OTHER_EXPLOSION))))) {
event.setCancelled(true);
return;
}
} else {
// handled anywhere else
if (type == DamageCause.BLOCK_EXPLOSION && (wcfg.blockOtherExplosions || ((wcfg.explosionFlagCancellation || Entities.isConsideredBuildingIfUsed(defender)) && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(defender.getLocation()), (RegionAssociable) null, Flags.OTHER_EXPLOSION))))) {
event.setCancelled(true);
return;
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardEntityListener method onEntityRegainHealth.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
RegainReason regainReason = event.getRegainReason();
if (regainReason != RegainReason.REGEN && regainReason != RegainReason.SATIATED) {
return;
}
Entity ent = event.getEntity();
WorldConfiguration wcfg = getWorldConfig(ent.getWorld());
if (wcfg.disableHealthRegain) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions && ent instanceof Player && !WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testState(BukkitAdapter.adapt(ent.getLocation()), WorldGuardPlugin.inst().wrapPlayer((Player) ent), Flags.HEALTH_REGEN)) {
event.setCancelled(true);
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardEntityListener method onCreatePortal.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatePortal(PortalCreateEvent event) {
WorldConfiguration wcfg = getWorldConfig(event.getWorld());
if (wcfg.regionNetherPortalProtection && event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR && !event.getBlocks().isEmpty()) {
final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld());
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(world);
if (regionManager == null)
return;
LocalPlayer associable = null;
if (event.getEntity() instanceof Player) {
associable = getPlugin().wrapPlayer(((Player) event.getEntity()));
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) {
return;
}
}
BlockVector3 min = null;
BlockVector3 max = null;
for (BlockState block : event.getBlocks()) {
BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ());
min = min == null ? loc : loc.getMinimum(min);
max = max == null ? loc : loc.getMaximum(max);
}
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
final ApplicableRegionSet regions = regionManager.getApplicableRegions(target);
if (!regions.testState(associable, Flags.BUILD, Flags.BLOCK_PLACE)) {
if (associable != null) {
// NB there is no way to cancel the teleport without PTA (since PlayerPortal doesn't have block info)
// removing PTA was a mistake
String message = regions.queryValue(associable, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("create portals", associable, message);
}
event.setCancelled(true);
}
}
// maybe one day this code will be useful
if (event.getEntity() instanceof EnderDragon && wcfg.blockEnderDragonPortalCreation) {
event.setCancelled(true);
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardEntityListener method onEntityInteract.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityInteract(EntityInteractEvent event) {
Block block = event.getBlock();
WorldConfiguration wcfg = getWorldConfig(block.getWorld());
if (block.getType() == Material.FARMLAND && wcfg.disableCreatureCropTrampling) {
event.setCancelled(true);
return;
}
if (block.getType() == Material.TURTLE_EGG && wcfg.disableCreatureTurtleEggTrampling) {
event.setCancelled(true);
return;
}
}
Aggregations