Search in sources :

Example 1 with BaseCommand

use of com.alpsbte.plotsystem.commands.BaseCommand in project Plot-System by AlpsBTE.

the class AbstractPlotGenerator method createProtection.

/**
 * Creates plot protection
 */
protected void createProtection() {
    BlockVector min = BlockVector.toBlockPoint(0, 1, 0);
    BlockVector max = BlockVector.toBlockPoint(PlotManager.PLOT_SIZE, 256, PlotManager.PLOT_SIZE);
    RegionContainer container = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
    RegionManager regionManager = container.get(plot.getWorld().getBukkitWorld());
    // Create protected region for world
    GlobalProtectedRegion globalRegion = new GlobalProtectedRegion("__global__");
    globalRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
    globalRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.ALL);
    // Create protected region for plot
    ProtectedRegion protectedPlotRegion = new ProtectedCuboidRegion(plot.getWorld().getWorldName(), min, max);
    protectedPlotRegion.setPriority(100);
    // Add and save regions
    try {
        if (regionManager != null) {
            regionManager.addRegion(globalRegion);
            regionManager.addRegion(protectedPlotRegion);
            regionManager.saveChanges();
        } else {
            throw new RuntimeException("Region Manager is null");
        }
    } catch (StorageException ex) {
        Bukkit.getLogger().log(Level.SEVERE, "An error occurred while saving plot protection!", ex);
        throw new RuntimeException("Plot protection creation completed exceptionally");
    }
    // Add plot owner
    DefaultDomain owner = protectedPlotRegion.getOwners();
    owner.addPlayer(builder.getUUID());
    protectedPlotRegion.setOwners(owner);
    // Set permissions
    protectedPlotRegion.setFlag(DefaultFlag.PASSTHROUGH, StateFlag.State.ALLOW);
    protectedPlotRegion.setFlag(DefaultFlag.PASSTHROUGH.getRegionGroupFlag(), RegionGroup.OWNERS);
    protectedPlotRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.ALLOW);
    protectedPlotRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.ALL);
    FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getCommandsConfig();
    List<String> allowedCommandsNonBuilder = config.getStringList(ConfigPaths.ALLOWED_COMMANDS_NON_BUILDERS);
    allowedCommandsNonBuilder.removeIf(c -> c.equals("/cmd1"));
    for (BaseCommand baseCommand : PlotSystem.getPlugin().getCommandManager().getBaseCommands()) {
        allowedCommandsNonBuilder.addAll(Arrays.asList(baseCommand.getNames()));
        for (String command : baseCommand.getNames()) {
            allowedCommandsNonBuilder.add("/" + command);
        }
    }
    List<String> blockedCommandsBuilders = config.getStringList(ConfigPaths.BLOCKED_COMMANDS_BUILDERS);
    blockedCommandsBuilders.removeIf(c -> c.equals("/cmd1"));
    protectedPlotRegion.setFlag(DefaultFlag.BLOCKED_CMDS, new HashSet<>(blockedCommandsBuilders));
    protectedPlotRegion.setFlag(DefaultFlag.BLOCKED_CMDS.getRegionGroupFlag(), RegionGroup.OWNERS);
    protectedPlotRegion.setFlag(DefaultFlag.ALLOWED_CMDS, new HashSet<>(allowedCommandsNonBuilder));
    protectedPlotRegion.setFlag(DefaultFlag.ALLOWED_CMDS.getRegionGroupFlag(), RegionGroup.NON_OWNERS);
}
Also used : RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) BaseCommand(com.alpsbte.plotsystem.commands.BaseCommand) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) BlockVector(com.sk89q.worldedit.BlockVector) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Aggregations

BaseCommand (com.alpsbte.plotsystem.commands.BaseCommand)1 BlockVector (com.sk89q.worldedit.BlockVector)1 RegionContainer (com.sk89q.worldguard.bukkit.RegionContainer)1 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)1 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)1 StorageException (com.sk89q.worldguard.protection.managers.storage.StorageException)1 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)1 ProtectedCuboidRegion (com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1