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