Search in sources :

Example 56 with WorldConfiguration

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

the class BlacklistListener method onUseBlock.

@EventHandler(ignoreCancelled = true)
public void onUseBlock(final UseBlockEvent 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);
    event.filter(target -> wcfg.getBlacklist().check(new BlockInteractBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(target), createTarget(target.getBlock(), event.getEffectiveMaterial())), false, false));
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BlockInteractBlacklistEvent(com.sk89q.worldguard.blacklist.event.BlockInteractBlacklistEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 57 with WorldConfiguration

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

the class SpongeUtil method clearSpongeWater.

/**
 * Remove water around a sponge.
 *
 * @param world The world the sponge is 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 clearSpongeWater(World world, int ox, int oy, int oz) {
    WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
    for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
        for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
            for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
                BlockVector3 vector = BlockVector3.at(ox + cx, oy + cy, oz + cz);
                BaseBlock block = world.getFullBlock(vector);
                BlockType blockType = block.getBlockType();
                if (isReplacable(blockType)) {
                    try {
                        world.setBlock(vector, BlockTypes.AIR.getDefaultState());
                    } catch (WorldEditException e) {
                        e.printStackTrace();
                    }
                } else {
                    @SuppressWarnings("unchecked") Property<Object> waterloggedProp = waterloggable.computeIfAbsent(blockType, (bt -> (Property<Object>) bt.getPropertyMap().get("waterlogged")));
                    if (waterloggedProp != null) {
                        try {
                            world.setBlock(vector, block.with(waterloggedProp, false));
                        } catch (WorldEditException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
Also used : Property(com.sk89q.worldedit.registry.state.Property) WorldEditException(com.sk89q.worldedit.WorldEditException) BlockTypes(com.sk89q.worldedit.world.block.BlockTypes) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockType(com.sk89q.worldedit.world.block.BlockType) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) WorldGuard(com.sk89q.worldguard.WorldGuard) Map(java.util.Map) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Maps(com.google.common.collect.Maps) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BlockType(com.sk89q.worldedit.world.block.BlockType) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldEditException(com.sk89q.worldedit.WorldEditException) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Property(com.sk89q.worldedit.registry.state.Property)

Example 58 with WorldConfiguration

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

the class ToggleCommands method allowFire.

@Command(aliases = { "allowfire" }, usage = "[<world>]", desc = "Allows all fire spread temporarily", max = 1)
@CommandPermissions({ "worldguard.fire-toggle.stop" })
public void allowFire(CommandContext args, Actor sender) throws CommandException {
    World world;
    if (args.argsLength() == 0) {
        world = worldGuard.checkPlayer(sender).getWorld();
    } else {
        world = worldGuard.getPlatform().getMatcher().matchWorld(sender, args.getString(0));
    }
    WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
    if (wcfg.fireSpreadDisableToggle) {
        worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("Fire spread has been globally for '" + world.getName() + "' re-enabled by " + sender.getDisplayName() + "."));
    } else {
        sender.print("Fire spread was already globally enabled.");
    }
    wcfg.fireSpreadDisableToggle = false;
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 59 with WorldConfiguration

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

the class RegionCommands method claim.

/**
 * Claiming command for users.
 *
 * <p>This command is a joke and it needs to be rewritten. It was contributed
 * code :(</p>
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "claim" }, usage = "<id>", desc = "Claim a region", min = 1, max = 1)
public void claim(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    LocalPlayer player = worldGuard.checkPlayer(sender);
    RegionPermissionModel permModel = getPermissionModel(player);
    // Check permissions
    if (!permModel.mayClaim()) {
        throw new CommandPermissionsException();
    }
    String id = checkRegionId(args.getString(0), false);
    RegionManager manager = checkRegionManager(player.getWorld());
    checkRegionDoesNotExist(manager, id, false);
    ProtectedRegion region = checkRegionFromSelection(player, id);
    WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(player.getWorld());
    // Check whether the player has created too many regions
    if (!permModel.mayClaimRegionsUnbounded()) {
        int maxRegionCount = wcfg.getMaxRegionCount(player);
        if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(player) >= maxRegionCount) {
            throw new CommandException("You own too many regions, delete one first to claim a new one.");
        }
    }
    ProtectedRegion existing = manager.getRegion(id);
    // Check for an existing region
    if (existing != null) {
        if (!existing.getOwners().contains(player)) {
            throw new CommandException("This region already exists and you don't own it.");
        }
    }
    // We have to check whether this region violates the space of any other region
    ApplicableRegionSet regions = manager.getApplicableRegions(region);
    // Check if this region overlaps any other region
    if (regions.size() > 0) {
        if (!regions.isOwnerOfAll(player)) {
            throw new CommandException("This region overlaps with someone else's region.");
        }
    } else {
        if (wcfg.claimOnlyInsideExistingRegions) {
            throw new CommandException("You may only claim regions inside " + "existing regions that you or your group own.");
        }
    }
    if (wcfg.maxClaimVolume >= Integer.MAX_VALUE) {
        throw new CommandException("The maximum claim volume get in the configuration is higher than is supported. " + "Currently, it must be " + Integer.MAX_VALUE + " or smaller. Please contact a server administrator.");
    }
    // Check claim volume
    if (!permModel.mayClaimRegionsUnbounded()) {
        if (region instanceof ProtectedPolygonalRegion) {
            throw new CommandException("Polygons are currently not supported for /rg claim.");
        }
        if (region.volume() > wcfg.maxClaimVolume) {
            player.printError("This region is too large to claim.");
            player.printError("Max. volume: " + wcfg.maxClaimVolume + ", your volume: " + region.volume());
            return;
        }
    }
    // Inherit from a template region
    if (!Strings.isNullOrEmpty(wcfg.setParentOnClaim)) {
        ProtectedRegion templateRegion = manager.getRegion(wcfg.setParentOnClaim);
        if (templateRegion != null) {
            try {
                region.setParent(templateRegion);
            } catch (CircularInheritanceException e) {
                throw new CommandException(e.getMessage());
            }
        }
    }
    RegionAdder task = new RegionAdder(manager, region);
    task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
    task.setOwnersInput(new String[] { player.getName() });
    final String description = String.format("Claiming region '%s'", id);
    AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), description).sendMessageAfterDelay("(Please wait... " + description + ")").onSuccess(TextComponent.of(String.format("A new region has been claimed named '%s'.", id)), null).onFailure("Failed to claim region", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) CircularInheritanceException(com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException) RegionAdder(com.sk89q.worldguard.commands.task.RegionAdder) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) RegionPermissionModel(com.sk89q.worldguard.internal.permission.RegionPermissionModel) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) Command(com.sk89q.minecraft.util.commands.Command)

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