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();
}
}
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();
}
}
}
}
}
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;
}
}
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);
}
}
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);
}
}
}
Aggregations