Search in sources :

Example 1 with RegionContainer

use of com.sk89q.worldguard.bukkit.RegionContainer in project Plot-System by AlpsBTE.

the class RawPlotGenerator method createProtection.

@Override
protected void createProtection() {
    RegionContainer container = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
    RegionManager regionManager = container.get(getPlot().getWorld().getBukkitWorld());
    if (regionManager != null) {
        for (String regionID : regionManager.getRegions().keySet()) {
            regionManager.removeRegion(regionID);
        }
    } else {
        throw new RuntimeException("Region Manager is null");
    }
    super.createProtection();
}
Also used : RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager)

Example 2 with RegionContainer

use of com.sk89q.worldguard.bukkit.RegionContainer 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)

Example 3 with RegionContainer

use of com.sk89q.worldguard.bukkit.RegionContainer in project Plot-System by AlpsBTE.

the class EventListener method onPlayerInteractEvent.

@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
        if (event.getItem() != null && event.getItem().equals(CompanionMenu.getMenuItem(event.getPlayer()))) {
            event.getPlayer().performCommand("companion");
        } else if (event.getItem() != null && event.getItem().equals(ReviewMenu.getMenuItem(event.getPlayer()))) {
            event.getPlayer().performCommand("review");
        }
    }
    // Open/Close iron trap door when right-clicking
    if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        if (event.getHand() != EquipmentSlot.OFF_HAND) {
            if (!event.getPlayer().isSneaking()) {
                if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.IRON_TRAPDOOR) {
                    RegionContainer regionContainer = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
                    RegionQuery query = regionContainer.createQuery();
                    if (query.testBuild(event.getPlayer().getLocation(), PlotSystem.DependencyManager.getWorldGuard().wrapPlayer(event.getPlayer()), DefaultFlag.INTERACT)) {
                        BlockState state = event.getClickedBlock().getState();
                        TrapDoor tp = (TrapDoor) state.getData();
                        if (!tp.isOpen()) {
                            tp.setOpen(true);
                            event.getPlayer().playSound(event.getClickedBlock().getLocation(), "block.iron_trapdoor.open", 1f, 1f);
                        } else {
                            tp.setOpen(false);
                            event.getPlayer().playSound(event.getClickedBlock().getLocation(), "block.iron_trapdoor.close", 1f, 1f);
                        }
                        state.update();
                    }
                }
            }
        }
    }
}
Also used : TrapDoor(org.bukkit.material.TrapDoor) BlockState(org.bukkit.block.BlockState) RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) RegionQuery(com.sk89q.worldguard.bukkit.RegionQuery) EventHandler(org.bukkit.event.EventHandler)

Example 4 with RegionContainer

use of com.sk89q.worldguard.bukkit.RegionContainer in project Storage by D-x-Z.

the class BlockBreak method onBreaking.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBreaking(@NotNull BlockBreakEvent e) {
    Player p = e.getPlayer();
    String blocks = e.getBlock().getType().toString();
    String items = null;
    NMSAssistant nms = new NMSAssistant();
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(p);
    Location loc = new Location(p.getWorld(), e.getBlock().getLocation().getBlockX(), e.getBlock().getLocation().getBlockY(), e.getBlock().getLocation().getBlockZ());
    RegionContainer container = WorldGuardPlugin.inst().getRegionContainer();
    RegionQuery query = container.createQuery();
    if (!query.testState(loc, localPlayer, DefaultFlag.BLOCK_BREAK) && !p.hasPermission("Storage.admin")) {
        e.setCancelled(true);
        return;
    }
    e.getBlock().getDrops().clear();
    if (nms.isVersion(12)) {
        e.setDropItems(false);
    }
    List<String> w = getconfigfile().getStringList("Blacklist-World");
    if (!w.contains(p.getWorld().getName())) {
        if (autoPick(p)) {
            for (String getBlockType : Objects.requireNonNull(getconfigfile().getConfigurationSection("Blocks.")).getKeys(false)) {
                if (blocks.equalsIgnoreCase(getBlockType)) {
                    items = getconfigfile().getString("Blocks." + blocks + ".Name");
                    break;
                }
            }
            if (items == null) {
                return;
            }
            if (getMaxStorage(p, blocks) == 0) {
                setMaxStorage(p, blocks, getconfigfile().getInt("Default_Max_Storage"));
            }
            if (p.getItemInHand() != null && p.getItemInHand().getItemMeta().hasEnchant(Enchantment.LOOT_BONUS_BLOCKS)) {
                if (getRandomInt(getconfigfile().getInt("Fortune.Chance.System.Min"), getconfigfile().getInt("Fortune.Chance.System.Max")) <= (p.getItemInHand().getItemMeta().getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS) * getconfigfile().getInt("Fortune.Chance.Player"))) {
                    int fortune = getRandomInt(getconfigfile().getInt("Fortune.Drop.Min"), getconfigfile().getInt("Fortune.Drop.Max"));
                    addStorage(p, blocks, 1 + fortune);
                } else {
                    addStorage(p, blocks, 1);
                }
            } else {
                addStorage(p, blocks, 1);
            }
        }
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) RegionQuery(com.sk89q.worldguard.bukkit.RegionQuery) NMSAssistant(preponderous.ponder.minecraft.bukkit.nms.NMSAssistant) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 5 with RegionContainer

use of com.sk89q.worldguard.bukkit.RegionContainer in project UltraCosmetics by iSach.

the class FlagManager method categoryFlagCheck.

@Override
protected Set<Category> categoryFlagCheck(Player bukkitPlayer) {
    RegionContainer rc = WGBukkit.getPlugin().getRegionContainer();
    RegionQuery query = rc.createQuery();
    return query.queryValue(bukkitPlayer.getLocation(), bukkitPlayer, CATEGORY_FLAG);
}
Also used : RegionContainer(com.sk89q.worldguard.bukkit.RegionContainer) RegionQuery(com.sk89q.worldguard.bukkit.RegionQuery)

Aggregations

RegionContainer (com.sk89q.worldguard.bukkit.RegionContainer)6 RegionQuery (com.sk89q.worldguard.bukkit.RegionQuery)4 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)2 EventHandler (org.bukkit.event.EventHandler)2 BaseCommand (com.alpsbte.plotsystem.commands.BaseCommand)1 BlockVector (com.sk89q.worldedit.BlockVector)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)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 Location (org.bukkit.Location)1 BlockState (org.bukkit.block.BlockState)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1 Player (org.bukkit.entity.Player)1 TrapDoor (org.bukkit.material.TrapDoor)1 NMSAssistant (preponderous.ponder.minecraft.bukkit.nms.NMSAssistant)1