Search in sources :

Example 41 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardEntityListener method onEntityChangeBlock.

/**
 * Called when an entity changes a block somehow
 *
 * @param event Relevant event details
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
    Entity ent = event.getEntity();
    WorldConfiguration wcfg = getWorldConfig(ent.getWorld());
    if (ent instanceof FallingBlock) {
        Material id = event.getBlock().getType();
        if (id == Material.GRAVEL && wcfg.noPhysicsGravel) {
            event.setCancelled(true);
            return;
        }
        if ((id == Material.SAND || id == Material.RED_SAND) && wcfg.noPhysicsSand) {
            event.setCancelled(true);
            return;
        }
    } else if (ent instanceof Enderman) {
        if (wcfg.disableEndermanGriefing) {
            event.setCancelled(true);
            return;
        }
    } else if (ent.getType() == EntityType.WITHER) {
        if (wcfg.blockWitherBlockDamage || wcfg.blockWitherExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions) {
            Location location = event.getBlock().getLocation();
            if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(location), (RegionAssociable) null, Flags.WITHER_DAMAGE))) {
                event.setCancelled(true);
                return;
            }
        }
    } else if (/*ent instanceof Zombie && */
    event instanceof EntityBreakDoorEvent) {
        if (wcfg.blockZombieDoorDestruction) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) 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) Enderman(org.bukkit.entity.Enderman) Material(org.bukkit.Material) Location(org.bukkit.Location) EntityBreakDoorEvent(org.bukkit.event.entity.EntityBreakDoorEvent) EventHandler(org.bukkit.event.EventHandler)

Example 42 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardEntityListener method onCreeperPower.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreeperPower(CreeperPowerEvent event) {
    final Entity entity = event.getEntity();
    WorldConfiguration wcfg = getWorldConfig(entity.getWorld());
    if (wcfg.disableCreeperPower) {
        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) EventHandler(org.bukkit.event.EventHandler)

Example 43 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardEntityListener method onEntityDamage.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
    if (event instanceof EntityDamageByEntityEvent) {
        this.onEntityDamageByEntity((EntityDamageByEntityEvent) event);
        return;
    } else if (event instanceof EntityDamageByBlockEvent) {
        this.onEntityDamageByBlock((EntityDamageByBlockEvent) event);
        return;
    }
    Entity defender = event.getEntity();
    DamageCause type = event.getCause();
    WorldConfiguration wcfg = getWorldConfig(defender.getWorld());
    if (defender instanceof Wolf && ((Wolf) defender).isTamed()) {
        if (wcfg.antiWolfDumbness) {
            event.setCancelled(true);
            return;
        }
    } else if (defender instanceof Player) {
        Player player = (Player) defender;
        LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
        if (type == DamageCause.WITHER) {
            // wither boss DoT tick
            if (wcfg.disableMobDamage) {
                event.setCancelled(true);
                return;
            }
            if (wcfg.useRegions) {
                ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
                if (!set.testState(getPlugin().wrapPlayer(player), Flags.MOB_DAMAGE)) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
        if (type == DamageCause.DROWNING && getConfig().hasAmphibiousMode(localPlayer)) {
            player.setRemainingAir(player.getMaximumAir());
            event.setCancelled(true);
            return;
        }
        ItemStack helmet = player.getInventory().getHelmet();
        if (type == DamageCause.DROWNING && wcfg.pumpkinScuba && helmet != null && (helmet.getType() == Material.CARVED_PUMPKIN || helmet.getType() == Material.JACK_O_LANTERN)) {
            player.setRemainingAir(player.getMaximumAir());
            event.setCancelled(true);
            return;
        }
        if (wcfg.disableFallDamage && type == DamageCause.FALL) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.disableFireDamage && (type == DamageCause.FIRE || type == DamageCause.FIRE_TICK)) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.disableDrowningDamage && type == DamageCause.DROWNING) {
            player.setRemainingAir(player.getMaximumAir());
            event.setCancelled(true);
            return;
        }
        if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) {
            localPlayer.findFreePosition();
            event.setCancelled(true);
            return;
        }
        if (wcfg.disableSuffocationDamage && type == DamageCause.SUFFOCATION) {
            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) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityDamageByBlockEvent(org.bukkit.event.entity.EntityDamageByBlockEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) Wolf(org.bukkit.entity.Wolf) ItemStack(org.bukkit.inventory.ItemStack) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 44 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardEntityListener method onFoodChange.

@EventHandler(ignoreCancelled = true)
public void onFoodChange(FoodLevelChangeEvent event) {
    if (event.getItem() != null)
        return;
    HumanEntity ent = event.getEntity();
    if (!(ent instanceof Player))
        return;
    if (event.getFoodLevel() > ent.getFoodLevel())
        return;
    LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer((Player) ent);
    WorldConfiguration wcfg = getWorldConfig(ent.getWorld());
    if (wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testState(player.getLocation(), player, Flags.HUNGER_DRAIN)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) HumanEntity(org.bukkit.entity.HumanEntity) EventHandler(org.bukkit.event.EventHandler)

Example 45 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardHangingListener method onHangingBreak.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    Hanging hanging = event.getEntity();
    World world = hanging.getWorld();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (event instanceof HangingBreakByEntityEvent) {
        HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent) event;
        Entity removerEntity = entityEvent.getRemover();
        if (removerEntity instanceof Projectile) {
            Projectile projectile = (Projectile) removerEntity;
            ProjectileSource remover = projectile.getShooter();
            removerEntity = (remover instanceof LivingEntity ? (LivingEntity) remover : null);
        }
        if (!(removerEntity instanceof Player)) {
            if (removerEntity instanceof Creeper) {
                if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) {
                    event.setCancelled(true);
                    return;
                }
                if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.CREEPER_EXPLOSION))) {
                    event.setCancelled(true);
                    return;
                }
            }
            // due to a non-LivingEntity ProjectileSource
            if (hanging instanceof Painting && (wcfg.blockEntityPaintingDestroy || (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.ENTITY_PAINTING_DESTROY))))) {
                event.setCancelled(true);
            } else if (hanging instanceof ItemFrame && (wcfg.blockEntityItemFrameDestroy || (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(hanging.getLocation()), (RegionAssociable) null, Flags.ENTITY_ITEM_FRAME_DESTROY))))) {
                event.setCancelled(true);
            }
        }
    } else {
        // Explosions from mobs are not covered by HangingBreakByEntity
        if (hanging instanceof Painting && wcfg.blockEntityPaintingDestroy && event.getCause() == RemoveCause.EXPLOSION) {
            event.setCancelled(true);
        } else if (hanging instanceof ItemFrame && wcfg.blockEntityItemFrameDestroy && event.getCause() == RemoveCause.EXPLOSION) {
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Creeper(org.bukkit.entity.Creeper) ItemFrame(org.bukkit.entity.ItemFrame) World(org.bukkit.World) Projectile(org.bukkit.entity.Projectile) Painting(org.bukkit.entity.Painting) LivingEntity(org.bukkit.entity.LivingEntity) RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) Hanging(org.bukkit.entity.Hanging) ProjectileSource(org.bukkit.projectiles.ProjectileSource) 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