Search in sources :

Example 1 with WorldConfiguration

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

the class RegionQuery method getApplicableRegions.

/**
 * Query for regions containing the given location.
 *
 * <p>An instance of {@link ApplicableRegionSet} will always be returned,
 * even if regions are disabled or region data failed to load. An
 * appropriate "virtual" set will be returned in such a case (for example,
 * if regions are disabled, the returned set would permit all
 * activities).</p>
 *
 * @param location the location
 * @param option the option
 * @return a region set
 */
public ApplicableRegionSet getApplicableRegions(Location location, QueryOption option) {
    checkNotNull(location);
    checkNotNull(option);
    World world = (World) location.getExtent();
    WorldConfiguration worldConfig = config.get(world);
    if (!worldConfig.useRegions) {
        return PermissiveRegionSet.getInstance();
    }
    RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get((World) location.getExtent());
    if (manager != null) {
        return cache.queryContains(manager, location, option);
    } else {
        return FailedLoadRegionSet.getInstance();
    }
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) World(com.sk89q.worldedit.world.World)

Example 2 with WorldConfiguration

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

the class SpongeUtil method addSpongeWater.

/**
 * Add water around a sponge.
 *
 * @param world The world the sponge is located in
 * @param ox The x coordinate of the 'sponge' block
 * @param oy The y coordinate of the 'sponge' block
 * @param oz The z coordinate of the 'sponge' block
 */
public static void addSpongeWater(World world, int ox, int oy, int oz) {
    WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
    // The negative x edge
    int cx = ox - wcfg.spongeRadius - 1;
    for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
        for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
            BlockVector3 vector = BlockVector3.at(cx, cy, cz);
            if (isReplacable(world.getBlock(vector).getBlockType())) {
                try {
                    setBlockToWater(world, cx + 1, cy, cz);
                } catch (WorldEditException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // The positive x edge
    cx = ox + wcfg.spongeRadius + 1;
    for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
        for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
            BlockVector3 vector = BlockVector3.at(cx, cy, cz);
            if (isReplacable(world.getBlock(vector).getBlockType())) {
                try {
                    setBlockToWater(world, cx - 1, cy, cz);
                } catch (WorldEditException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // The negative y edge
    int cy = oy - wcfg.spongeRadius - 1;
    for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
        for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
            BlockVector3 vector = BlockVector3.at(cx, cy, cz);
            if (isReplacable(world.getBlock(vector).getBlockType())) {
                try {
                    setBlockToWater(world, cx, cy + 1, cz);
                } catch (WorldEditException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // The positive y edge
    cy = oy + wcfg.spongeRadius + 1;
    for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
        for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
            BlockVector3 vector = BlockVector3.at(cx, cy, cz);
            if (isReplacable(world.getBlock(vector).getBlockType())) {
                try {
                    setBlockToWater(world, cx, cy - 1, cz);
                } catch (WorldEditException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // The negative z edge
    int cz = oz - wcfg.spongeRadius - 1;
    for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
        for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
            BlockVector3 vector = BlockVector3.at(cx, cy, cz);
            if (isReplacable(world.getBlock(vector).getBlockType())) {
                try {
                    setBlockToWater(world, cx, cy, cz + 1);
                } catch (WorldEditException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // The positive z edge
    cz = oz + wcfg.spongeRadius + 1;
    for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
        for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
            BlockVector3 vector = BlockVector3.at(cx, cy, cz);
            if (isReplacable(world.getBlock(vector).getBlockType())) {
                try {
                    setBlockToWater(world, cx, cy, cz - 1);
                } catch (WorldEditException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldEditException(com.sk89q.worldedit.WorldEditException)

Example 3 with WorldConfiguration

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

the class RegionProtectionListener method isWhitelisted.

/**
 * Return whether the given cause is whitelist (should be ignored).
 *
 * @param cause the cause
 * @param world the world
 * @param pvp whether the event in question is PvP combat
 * @return true if whitelisted
 */
private boolean isWhitelisted(Cause cause, World world, boolean pvp) {
    Object rootCause = cause.getRootCause();
    if (rootCause instanceof Player) {
        Player player = (Player) rootCause;
        WorldConfiguration config = getWorldConfig(world);
        if (config.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
            return true;
        }
        LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
        return !pvp && WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld());
    } else {
        return false;
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer)

Example 4 with WorldConfiguration

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

the class WorldGuardBlockListener method onBlockExplode.

@EventHandler(ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    if (wcfg.blockOtherExplosions) {
        event.setCancelled(true);
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 5 with WorldConfiguration

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

the class WorldGuardBlockListener method onLeavesDecay.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onLeavesDecay(LeavesDecayEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    if (wcfg.disableLeafDecay) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.useRegions) {
        if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.LEAF_DECAY))) {
            event.setCancelled(true);
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) 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