Search in sources :

Example 11 with WorldConfiguration

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

the class BlacklistListener method onInventoryCreative.

@EventHandler(ignoreCancelled = true)
public void onInventoryCreative(InventoryCreativeEvent event) {
    HumanEntity entity = event.getWhoClicked();
    ItemStack item = event.getCursor();
    if (item.getType() != Material.AIR && entity instanceof Player) {
        Player player = (Player) entity;
        WorldConfiguration wcfg = getWorldConfig(player.getWorld());
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(entity.getLocation()), createTarget(item)), false, false)) {
            event.setCancelled(true);
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 12 with WorldConfiguration

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

the class BlacklistListener method onPlayerItemHeld.

@EventHandler(ignoreCancelled = true)
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
    Player player = event.getPlayer();
    Inventory inventory = player.getInventory();
    ItemStack item = inventory.getItem(event.getNewSlot());
    if (item != null) {
        WorldConfiguration wcfg = getWorldConfig(player.getWorld());
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(item)), false, false)) {
            inventory.setItem(event.getNewSlot(), null);
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Example 13 with WorldConfiguration

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

the class BlacklistListener method onDestroyEntity.

@EventHandler(ignoreCancelled = true)
public void onDestroyEntity(DestroyEntityEvent event) {
    final WorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Blacklist guard
    if (wcfg.getBlacklist() == null) {
        return;
    }
    Player player = event.getCause().getFirstPlayer();
    if (player == null) {
        return;
    }
    final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    Entity target = event.getEntity();
    if (target instanceof Item) {
        Item item = (Item) target;
        if (!wcfg.getBlacklist().check(new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target.getLocation()), createTarget(item.getItemStack())), false, true)) {
            event.setCancelled(true);
            return;
        }
    }
    Material material = Materials.getRelatedMaterial(target.getType());
    if (material != null) {
        // Not really a block but we only have one on-break blacklist event
        if (!wcfg.getBlacklist().check(new BlockBreakBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(event.getTarget()), createTarget(material)), false, false)) {
            event.setCancelled(true);
        }
    }
}
Also used : ItemAcquireBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent) HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Material(org.bukkit.Material) BlockBreakBlacklistEvent(com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent) EventHandler(org.bukkit.event.EventHandler)

Example 14 with WorldConfiguration

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

the class BlacklistListener method onUseItem.

@EventHandler(ignoreCancelled = true)
public void onUseItem(UseItemEvent event) {
    final WorldConfiguration wcfg = getWorldConfig(event.getWorld());
    // Blacklist guard
    if (wcfg.getBlacklist() == null) {
        return;
    }
    Player player = event.getCause().getFirstPlayer();
    if (player == null) {
        return;
    }
    final LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    ItemStack target = event.getItemStack();
    if (!wcfg.getBlacklist().check(new ItemUseBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(target)), false, false)) {
        event.setCancelled(true);
        return;
    }
    if (Materials.isArmor(target.getType()) && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(target)), false, false)) {
        event.setCancelled(true);
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ItemEquipBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ItemUseBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 15 with WorldConfiguration

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

the class WorldGuardEntityListener method onEntityDamageByProjectile.

private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
    Entity defender = event.getEntity();
    Entity attacker;
    ProjectileSource source = ((Projectile) event.getDamager()).getShooter();
    if (source instanceof LivingEntity) {
        attacker = (LivingEntity) source;
    } else {
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(defender.getWorld());
    if (defender instanceof Player) {
        Player player = (Player) defender;
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        // Check Mob
        if (!(attacker instanceof Player)) {
            if (wcfg.disableMobDamage) {
                event.setCancelled(true);
                return;
            }
            if (wcfg.useRegions) {
                if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation()).testState(localPlayer, Flags.MOB_DAMAGE)) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (event.getDamager() instanceof Fireball) {
                Fireball fireball = (Fireball) event.getDamager();
                if (fireball instanceof WitherSkull) {
                    if (wcfg.blockWitherSkullExplosions) {
                        event.setCancelled(true);
                        return;
                    }
                } else {
                    if (wcfg.blockFireballExplosions) {
                        event.setCancelled(true);
                        return;
                    }
                }
                if (wcfg.useRegions) {
                    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
                    if (!query.testState(localPlayer.getLocation(), localPlayer, Flags.GHAST_FIREBALL) && wcfg.explosionFlagCancellation) {
                        event.setCancelled(true);
                        return;
                    }
                }
            }
        }
    } else if (defender instanceof ItemFrame) {
        if (checkItemFrameProtection(attacker, (ItemFrame) defender)) {
            event.setCancelled(true);
            return;
        }
    } else if (defender instanceof ArmorStand && Entities.isNonPlayerCreature(attacker)) {
        if (wcfg.blockEntityArmorStandDestroy) {
            event.setCancelled(true);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) 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) Fireball(org.bukkit.entity.Fireball) ArmorStand(org.bukkit.entity.ArmorStand) LocalPlayer(com.sk89q.worldguard.LocalPlayer) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) ProjectileSource(org.bukkit.projectiles.ProjectileSource) ItemFrame(org.bukkit.entity.ItemFrame) WitherSkull(org.bukkit.entity.WitherSkull) Projectile(org.bukkit.entity.Projectile)

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