Search in sources :

Example 1 with ProtectedCuboidRegion

use of com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion in project LandLord by SpatiumPrinceps.

the class WorldGuardHandler method claim.

public void claim(UUID owner, String landname, World world, Location down, Location upper) {
    BlockVector vec1 = OwnedLand.locationToVec(down);
    BlockVector vec2 = OwnedLand.locationToVec(upper);
    ProtectedCuboidRegion pr = new ProtectedCuboidRegion(landname, vec1, vec2);
    DefaultDomain ownerDomain = new DefaultDomain();
    ownerDomain.addPlayer(owner);
    pr.setOwners(ownerDomain);
    // flag management
    pr = setDefaultFlags(pr, down.getChunk());
    RegionManager manager = wg.getRegionContainer().get(world);
    if (manager != null) {
        manager.addRegion(pr);
    }
}
Also used : RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) BlockVector(com.sk89q.worldedit.BlockVector) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain)

Example 2 with ProtectedCuboidRegion

use of com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion in project LandLord by SpatiumPrinceps.

the class WorldGuardHandler method setDefaultFlags.

public ProtectedCuboidRegion setDefaultFlags(ProtectedCuboidRegion region, Chunk chunk) {
    OwnedLand land = new OwnedLand(region, chunk);
    region.setFlag(DefaultFlag.FAREWELL_MESSAGE, Landlord.getInstance().getLangManager().getRawString("Alerts.defaultFarewell").replace("%owner%", land.printOwners()));
    region.setFlag(DefaultFlag.GREET_MESSAGE, Landlord.getInstance().getLangManager().getRawString("Alerts.defaultGreeting").replace("%owner%", land.printOwners()));
    List<String> flaggy = Landlord.getInstance().getConfig().getStringList("Flags");
    Set<String> flags = new HashSet<>();
    flaggy.forEach(s -> flags.add(s.split(" ")[0]));
    // Iterate over all existing flags
    for (Flag<?> flag : DefaultFlag.getFlags()) {
        if (flag instanceof StateFlag) {
            boolean failed = false;
            if (flags.contains(flag.getName())) {
                // Filters the config list for the right line and split that line in the mid at :
                String[] rules = flaggy.stream().filter(s -> s.startsWith(flag.getName())).findFirst().get().split(":");
                if (rules.length == 2) {
                    String[] defSplit = rules[0].split(" ");
                    if (defSplit.length == 3) {
                        StateFlag.State state = StateFlag.State.valueOf(defSplit[1].toUpperCase());
                        if (defSplit[2].equals("nonmembers"))
                            region.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
                        region.setFlag((StateFlag) flag, state);
                    } else {
                        failed = true;
                    }
                } else {
                    failed = true;
                }
            }
            if (failed) {
                Bukkit.getLogger().warning("ERROR: Your flag definition is invalid!");
                break;
            }
        }
    }
    return region;
}
Also used : RegionGroup(com.sk89q.worldguard.protection.flags.RegionGroup) java.util(java.util) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) BukkitUtil.toVector(com.sk89q.worldguard.bukkit.BukkitUtil.toVector) Landlord(biz.princeps.landlord.Landlord) OwnedLand(biz.princeps.landlord.util.OwnedLand) WorldGuardPlugin(com.sk89q.worldguard.bukkit.WorldGuardPlugin) Flag(com.sk89q.worldguard.protection.flags.Flag) Player(org.bukkit.entity.Player) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) org.bukkit(org.bukkit) DefaultFlag(com.sk89q.worldguard.protection.flags.DefaultFlag) BlockVector(com.sk89q.worldedit.BlockVector) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) OwnedLand(biz.princeps.landlord.util.OwnedLand) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag)

Example 3 with ProtectedCuboidRegion

use of com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion in project EliteMobs by MagmaGuy.

the class WorldGuardCompatibility method defineMinidungeon.

/**
 * Automatically creates a worldguard region protected as an EliteMobs minidungeon using two x y z vectors for the
 * locations of the diagonally opposed locations
 *
 * @param corner1
 * @param corner2
 */
public static void defineMinidungeon(Location corner1, Location corner2, Location anchorLocation, String schematicName, Minidungeon minidungeon) {
    try {
        RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(anchorLocation.getWorld()));
        BlockVector3 min = BlockVector3.at(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ());
        BlockVector3 max = BlockVector3.at(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ());
        ProtectedRegion region = new ProtectedCuboidRegion(schematicName.replace(".schem", ""), min, max);
        protectMinidungeonArea(region, minidungeon);
        regionManager.addRegion(region);
    } catch (Exception ex) {
        new WarningMessage("Failed to add Minidungeon WorldGuard zone!");
    }
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) 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) BlockVector3(com.sk89q.worldedit.math.BlockVector3) FlagConflictException(com.sk89q.worldguard.protection.flags.registry.FlagConflictException)

Example 4 with ProtectedCuboidRegion

use of com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion in project AreaShop by NLthijs48.

the class StackCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    // Check permission
    if (!sender.hasPermission("areashop.stack")) {
        plugin.message(sender, "stack-noPermission");
        return;
    }
    // Only from ingame
    if (!(sender instanceof Player)) {
        plugin.message(sender, "cmd-onlyByPlayer");
        return;
    }
    final Player player = (Player) sender;
    // Specify enough arguments
    if (args.length < 5) {
        plugin.message(sender, "stack-help");
        return;
    }
    // Check amount
    int tempAmount = -1;
    try {
        tempAmount = Integer.parseInt(args[1]);
    } catch (NumberFormatException e) {
    // Incorrect number
    }
    if (tempAmount <= 0) {
        plugin.message(player, "stack-wrongAmount", args[1]);
        return;
    }
    // Check gap
    int gap;
    try {
        gap = Integer.parseInt(args[2]);
    } catch (NumberFormatException e) {
        plugin.message(player, "stack-wrongGap", args[2]);
        return;
    }
    // Check region type
    if (!"rent".equalsIgnoreCase(args[4]) && !"buy".equalsIgnoreCase(args[4])) {
        plugin.message(sender, "stack-help");
        return;
    }
    // Get WorldEdit selection
    final Selection selection = plugin.getWorldEdit().getSelection(player);
    if (selection == null) {
        plugin.message(player, "stack-noSelection");
        return;
    }
    // Get or create group
    RegionGroup group = null;
    if (args.length > 5) {
        group = plugin.getFileManager().getGroup(args[5]);
        if (group == null) {
            group = new RegionGroup(plugin, args[5]);
            plugin.getFileManager().addGroup(group);
        }
    }
    // Get facing of the player (must be clearly one of the four directions to make sure it is no mistake)
    BlockFace facing = Utils.yawToFacing(player.getLocation().getYaw());
    if (player.getLocation().getPitch() > 45) {
        facing = BlockFace.DOWN;
    } else if (player.getLocation().getPitch() < -45) {
        facing = BlockFace.UP;
    }
    if (!(facing == BlockFace.NORTH || facing == BlockFace.EAST || facing == BlockFace.SOUTH || facing == BlockFace.WEST || facing == BlockFace.UP || facing == BlockFace.DOWN)) {
        plugin.message(player, "stack-unclearDirection", facing.toString().toLowerCase().replace('_', '-'));
        return;
    }
    Vector shift = new BlockVector(0, 0, 0);
    if (facing == BlockFace.SOUTH) {
        shift = shift.setZ(-selection.getLength() - gap);
    } else if (facing == BlockFace.WEST) {
        shift = shift.setX(selection.getWidth() + gap);
    } else if (facing == BlockFace.NORTH) {
        shift = shift.setZ(selection.getLength() + gap);
    } else if (facing == BlockFace.EAST) {
        shift = shift.setX(-selection.getWidth() - gap);
    } else if (facing == BlockFace.DOWN) {
        shift = shift.setY(-selection.getHeight() - gap);
    } else if (facing == BlockFace.UP) {
        shift = shift.setY(selection.getHeight() + gap);
    }
    AreaShop.debug("  calculated shift vector: " + shift + ", with facing=" + facing);
    // Create regions and add them to AreaShop
    final String nameTemplate = args[3];
    final int regionsPerTick = plugin.getConfig().getInt("adding.regionsPerTick");
    final boolean rentRegions = "rent".equalsIgnoreCase(args[4]);
    final int amount = tempAmount;
    final RegionGroup finalGroup = group;
    final Vector finalShift = shift;
    String type;
    if (rentRegions) {
        type = "rent";
    } else {
        type = "buy";
    }
    Message groupsMessage = Message.empty();
    if (group != null) {
        groupsMessage = Message.fromKey("stack-addToGroup").replacements(group.getName());
    }
    plugin.message(player, "stack-accepted", amount, type, gap, nameTemplate, groupsMessage);
    plugin.message(player, "stack-addStart", amount, regionsPerTick * 20);
    new BukkitRunnable() {

        private int current = -1;

        private RegionManager manager = AreaShop.getInstance().getWorldGuard().getRegionManager(selection.getWorld());

        private int counter = 1;

        private int tooLow = 0;

        private int tooHigh = 0;

        @Override
        public void run() {
            for (int i = 0; i < regionsPerTick; i++) {
                current++;
                if (current < amount) {
                    // Create the region name
                    String counterName = counter + "";
                    int minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
                    while (counterName.length() < minimumLength) {
                        counterName = "0" + counterName;
                    }
                    String regionName;
                    if (nameTemplate.contains("#")) {
                        regionName = nameTemplate.replace("#", counterName);
                    } else {
                        regionName = nameTemplate + counterName;
                    }
                    while (manager.getRegion(regionName) != null || AreaShop.getInstance().getFileManager().getRegion(regionName) != null) {
                        counter++;
                        counterName = counter + "";
                        minimumLength = plugin.getConfig().getInt("stackRegionNumberLength");
                        while (counterName.length() < minimumLength) {
                            counterName = "0" + counterName;
                        }
                        if (nameTemplate.contains("#")) {
                            regionName = nameTemplate.replace("#", counterName);
                        } else {
                            regionName = nameTemplate + counterName;
                        }
                    }
                    // Add the region to WorldGuard (at startposition shifted by the number of this region times the blocks it should shift)
                    BlockVector minimum = new BlockVector(selection.getNativeMinimumPoint().add(finalShift.multiply(current)));
                    BlockVector maximum = new BlockVector(selection.getNativeMaximumPoint().add(finalShift.multiply(current)));
                    // Check for out of bounds
                    if (minimum.getBlockY() < 0) {
                        tooLow++;
                        continue;
                    } else if (maximum.getBlockY() > 256) {
                        tooHigh++;
                        continue;
                    }
                    ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, minimum, maximum);
                    manager.addRegion(region);
                    // Add the region to AreaShop
                    if (rentRegions) {
                        RentRegion rent = new RentRegion(regionName, selection.getWorld());
                        if (finalGroup != null) {
                            finalGroup.addMember(rent);
                        }
                        rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
                        plugin.getFileManager().addRent(rent);
                        rent.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
                        rent.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
                        rent.update();
                    } else {
                        BuyRegion buy = new BuyRegion(regionName, selection.getWorld());
                        if (finalGroup != null) {
                            finalGroup.addMember(buy);
                        }
                        buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, true);
                        plugin.getFileManager().addBuy(buy);
                        buy.handleSchematicEvent(GeneralRegion.RegionEvent.CREATED);
                        buy.runEventCommands(GeneralRegion.RegionEvent.CREATED, false);
                        buy.update();
                    }
                }
            }
            if (current >= amount) {
                if (player.isOnline()) {
                    int added = amount - tooLow - tooHigh;
                    Message wrong = Message.empty();
                    if (tooHigh > 0) {
                        wrong.append(Message.fromKey("stack-tooHigh").replacements(tooHigh));
                    }
                    if (tooLow > 0) {
                        wrong.append(Message.fromKey("stack-tooLow").replacements(tooLow));
                    }
                    plugin.message(player, "stack-addComplete", added, wrong);
                }
                this.cancel();
            }
        }
    }.runTaskTimer(plugin, 1, 1);
}
Also used : Player(org.bukkit.entity.Player) Message(me.wiefferink.interactivemessenger.processing.Message) Selection(com.sk89q.worldedit.bukkit.selections.Selection) BlockFace(org.bukkit.block.BlockFace) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) RentRegion(me.wiefferink.areashop.regions.RentRegion) RegionGroup(me.wiefferink.areashop.regions.RegionGroup) BuyRegion(me.wiefferink.areashop.regions.BuyRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) BlockVector(com.sk89q.worldedit.BlockVector) Vector(com.sk89q.worldedit.Vector) BlockVector(com.sk89q.worldedit.BlockVector)

Example 5 with ProtectedCuboidRegion

use of com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion in project LandLord by SpatiumPrinceps.

the class WorldGuardHandler method canClaim.

public boolean canClaim(Player player, Chunk currChunk) {
    RegionManager regionManager = wg.getRegionManager(player.getWorld());
    if (regionManager != null) {
        ProtectedRegion check = new ProtectedCuboidRegion("check", toVector(currChunk.getBlock(0, 0, 0)), toVector(currChunk.getBlock(15, 127, 15)));
        List<ProtectedRegion> intersects = check.getIntersectingRegions(new ArrayList<>(regionManager.getRegions().values()));
        for (ProtectedRegion intersect : intersects) {
            if (!regionManager.getApplicableRegions(intersect).canBuild(wg.wrapPlayer(player))) {
                return false;
            }
        }
    }
    return true;
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion)

Aggregations

RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)5 ProtectedCuboidRegion (com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion)5 BlockVector (com.sk89q.worldedit.BlockVector)3 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)3 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)2 Player (org.bukkit.entity.Player)2 Landlord (biz.princeps.landlord.Landlord)1 OwnedLand (biz.princeps.landlord.util.OwnedLand)1 WarningMessage (com.magmaguy.elitemobs.utils.WarningMessage)1 Vector (com.sk89q.worldedit.Vector)1 Selection (com.sk89q.worldedit.bukkit.selections.Selection)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 BukkitUtil.toVector (com.sk89q.worldguard.bukkit.BukkitUtil.toVector)1 WorldGuardPlugin (com.sk89q.worldguard.bukkit.WorldGuardPlugin)1 DefaultFlag (com.sk89q.worldguard.protection.flags.DefaultFlag)1 Flag (com.sk89q.worldguard.protection.flags.Flag)1 RegionGroup (com.sk89q.worldguard.protection.flags.RegionGroup)1 StateFlag (com.sk89q.worldguard.protection.flags.StateFlag)1 FlagConflictException (com.sk89q.worldguard.protection.flags.registry.FlagConflictException)1 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)1