Search in sources :

Example 16 with WorldConfiguration

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;
                    }
                }
            }
        }
    }
}
Also used : ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Tameable(org.bukkit.entity.Tameable) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Creeper(org.bukkit.entity.Creeper) TNTPrimed(org.bukkit.entity.TNTPrimed) ItemFrame(org.bukkit.entity.ItemFrame) EnderCrystal(org.bukkit.entity.EnderCrystal) Projectile(org.bukkit.entity.Projectile) LivingEntity(org.bukkit.entity.LivingEntity) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) ArmorStand(org.bukkit.entity.ArmorStand) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 17 with WorldConfiguration

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;
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) Wolf(org.bukkit.entity.Wolf)

Example 18 with WorldConfiguration

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);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) RegainReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason) EventHandler(org.bukkit.event.EventHandler)

Example 19 with WorldConfiguration

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);
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) BlockState(org.bukkit.block.BlockState) EnderDragon(org.bukkit.entity.EnderDragon) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 20 with WorldConfiguration

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;
    }
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)59 EventHandler (org.bukkit.event.EventHandler)45 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)37 Player (org.bukkit.entity.Player)33 LocalPlayer (com.sk89q.worldguard.LocalPlayer)32 HumanEntity (org.bukkit.entity.HumanEntity)14 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)13 Entity (org.bukkit.entity.Entity)13 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)11 Material (org.bukkit.Material)11 World (org.bukkit.World)11 LivingEntity (org.bukkit.entity.LivingEntity)11 Block (org.bukkit.block.Block)10 ItemStack (org.bukkit.inventory.ItemStack)10 World (com.sk89q.worldedit.world.World)4 ItemAcquireBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent)4 ItemEquipBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent)4 RegionAssociable (com.sk89q.worldguard.protection.association.RegionAssociable)4 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)4 Command (com.sk89q.minecraft.util.commands.Command)3