Search in sources :

Example 6 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project MyPet by xXKeyleXx.

the class WorldGuardHook method fixMissingEntityType.

public void fixMissingEntityType(World world, boolean apply) {
    if (is7) {
        try {
            ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
            com.sk89q.worldedit.world.World w = BukkitAdapter.adapt(world);
            BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(w);
            if (apply) {
                if (missingEntityTypeFixValue.containsKey(world.getName())) {
                    fixMissingEntityType(world, false);
                }
                missingEntityTypeFixValue.put(world.getName(), wcfg.blockPluginSpawning);
                wcfg.blockPluginSpawning = false;
            } else if (missingEntityTypeFixValue.containsKey(world.getName())) {
                wcfg.blockPluginSpawning = missingEntityTypeFixValue.get(world.getName());
                missingEntityTypeFixValue.remove(world.getName());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager)

Example 7 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardBlockListener method onBlockBurn.

/*
     * Called when a block is destroyed from burning.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    BukkitWorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    if (wcfg.disableFireSpread) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.fireSpreadDisableToggle) {
        Block block = event.getBlock();
        event.setCancelled(true);
        checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
        return;
    }
    if (!wcfg.disableFireSpreadBlocks.isEmpty()) {
        Block block = event.getBlock();
        if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(block.getType()).getId())) {
            event.setCancelled(true);
            checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
            return;
        }
    }
    if (wcfg.isChestProtected(BukkitAdapter.adapt(event.getBlock().getLocation()))) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.useRegions) {
        Block block = event.getBlock();
        int x = block.getX();
        int y = block.getY();
        int z = block.getZ();
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
        if (!set.testState(null, Flags.FIRE_SPREAD)) {
            checkAndDestroyFireAround(block.getWorld(), x, y, z);
            event.setCancelled(true);
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Block(org.bukkit.block.Block) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 8 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardEntityListener method onEntityExplode.

/*
     * Called on entity explode.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
    ConfigurationManager cfg = getConfig();
    Entity ent = event.getEntity();
    if (cfg.activityHaltToggle) {
        ent.remove();
        event.setCancelled(true);
        return;
    }
    BukkitWorldConfiguration wcfg = getWorldConfig(event.getLocation().getWorld());
    if (ent instanceof Creeper) {
        if (wcfg.blockCreeperExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.blockCreeperBlockDamage) {
            event.blockList().clear();
            return;
        }
    } else if (ent instanceof EnderDragon) {
        if (wcfg.blockEnderDragonBlockDamage) {
            event.blockList().clear();
            return;
        }
    } else if (ent instanceof TNTPrimed || ent instanceof ExplosiveMinecart) {
        if (wcfg.blockTNTExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.blockTNTBlockDamage) {
            event.blockList().clear();
            return;
        }
    } else if (ent instanceof Fireball) {
        if (ent instanceof WitherSkull) {
            if (wcfg.blockWitherSkullExplosions) {
                event.setCancelled(true);
                return;
            }
            if (wcfg.blockWitherSkullBlockDamage) {
                event.blockList().clear();
                return;
            }
        } else {
            if (wcfg.blockFireballExplosions) {
                event.setCancelled(true);
                return;
            }
            if (wcfg.blockFireballBlockDamage) {
                event.blockList().clear();
                return;
            }
        }
        // allow wither skull blocking since there is no dedicated flag atm
        if (wcfg.useRegions) {
            for (Block block : event.blockList()) {
                if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.GHAST_FIREBALL)) {
                    event.blockList().clear();
                    if (wcfg.explosionFlagCancellation)
                        event.setCancelled(true);
                    return;
                }
            }
        }
    } else if (ent instanceof Wither) {
        if (wcfg.blockWitherExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.blockWitherBlockDamage) {
            event.blockList().clear();
            return;
        }
        if (wcfg.useRegions) {
            for (Block block : event.blockList()) {
                if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(block.getLocation()), (RegionAssociable) null, Flags.WITHER_DAMAGE))) {
                    event.blockList().clear();
                    event.setCancelled(true);
                    return;
                }
            }
        }
    } else {
        // unhandled entity
        if (wcfg.blockOtherExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions) {
            for (Block block : event.blockList()) {
                if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.OTHER_EXPLOSION)) {
                    event.blockList().clear();
                    if (wcfg.explosionFlagCancellation)
                        event.setCancelled(true);
                    return;
                }
            }
        }
    }
    if (wcfg.signChestProtection) {
        for (Block block : event.blockList()) {
            if (wcfg.isChestProtected(BukkitAdapter.adapt(block.getLocation()))) {
                event.blockList().clear();
                return;
            }
        }
    }
}
Also used : ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) Wither(org.bukkit.entity.Wither) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) EnderDragon(org.bukkit.entity.EnderDragon) Fireball(org.bukkit.entity.Fireball) Creeper(org.bukkit.entity.Creeper) TNTPrimed(org.bukkit.entity.TNTPrimed) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) WitherSkull(org.bukkit.entity.WitherSkull) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 9 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class BlockedPotionsListener method onProjectile.

@EventHandler
public void onProjectile(DamageEntityEvent event) {
    if (event.getOriginalEvent() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent originalEvent = (EntityDamageByEntityEvent) event.getOriginalEvent();
        if (Entities.isPotionArrow(originalEvent.getDamager())) {
            // should take care of backcompat
            BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
            PotionEffectType blockedEffect = null;
            if (originalEvent.getDamager() instanceof SpectralArrow) {
                if (wcfg.blockPotions.contains(PotionEffectType.GLOWING)) {
                    blockedEffect = PotionEffectType.GLOWING;
                }
            } else if (originalEvent.getDamager() instanceof Arrow) {
                Arrow tippedArrow = (Arrow) originalEvent.getDamager();
                PotionEffectType baseEffect = tippedArrow.getBasePotionData().getType().getEffectType();
                if (wcfg.blockPotions.contains(baseEffect)) {
                    blockedEffect = baseEffect;
                } else {
                    for (PotionEffect potionEffect : tippedArrow.getCustomEffects()) {
                        if (wcfg.blockPotions.contains(potionEffect.getType())) {
                            blockedEffect = potionEffect.getType();
                            break;
                        }
                    }
                }
            }
            if (blockedEffect != null) {
                Player player = event.getCause().getFirstPlayer();
                if (player != null) {
                    if (getPlugin().hasPermission(player, "worldguard.override.potions")) {
                        return;
                    }
                    player.sendMessage(ChatColor.RED + "Sorry, arrows with " + blockedEffect.getName() + " are presently disabled.");
                }
                event.setCancelled(true);
            }
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) SpectralArrow(org.bukkit.entity.SpectralArrow) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) SpectralArrow(org.bukkit.entity.SpectralArrow) EventHandler(org.bukkit.event.EventHandler)

Example 10 with BukkitWorldConfiguration

use of com.sk89q.worldguard.bukkit.BukkitWorldConfiguration in project WorldGuard by EngineHub.

the class ChestProtectionListener method onPlaceBlock.

@EventHandler(ignoreCancelled = true)
public void onPlaceBlock(final PlaceBlockEvent event) {
    final Player player = event.getCause().getFirstPlayer();
    if (player != null) {
        final BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
        // Early guard
        if (!wcfg.signChestProtection) {
            return;
        }
        event.filter(target -> {
            if (wcfg.getChestProtection().isChest(BukkitAdapter.asBlockType(event.getEffectiveMaterial())) && wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()), WorldGuardPlugin.inst().wrapPlayer(player))) {
                sendMessage(event, player, ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
                return false;
            }
            return true;
        }, true);
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)12 EventHandler (org.bukkit.event.EventHandler)9 Player (org.bukkit.entity.Player)7 LocalPlayer (com.sk89q.worldguard.LocalPlayer)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)4 Entity (org.bukkit.entity.Entity)4 Block (org.bukkit.block.Block)3 HumanEntity (org.bukkit.entity.HumanEntity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 TNTPrimed (org.bukkit.entity.TNTPrimed)2 PotionEffect (org.bukkit.potion.PotionEffect)2 PotionEffectType (org.bukkit.potion.PotionEffectType)2 BukkitPlayer (com.sk89q.worldguard.bukkit.BukkitPlayer)1 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)1 DelayedRegionOverlapAssociation (com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation)1 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Arrow (org.bukkit.entity.Arrow)1