Search in sources :

Example 6 with ProtectedRegion

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

the class WorldGuardHandler5 method getApplicableRegionsSet.

@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
    Set<ProtectedRegion> result = new HashSet<>();
    Vector vector = new Vector(location.getX(), location.getY(), location.getZ());
    for (ProtectedRegion region : pluginInterface.getWorldGuard().getRegionManager(location.getWorld()).getRegions().values()) {
        if (region.contains(vector)) {
            result.add(region);
        }
    }
    return result;
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Vector(com.sk89q.worldedit.Vector) HashSet(java.util.HashSet)

Example 7 with ProtectedRegion

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

the class WorldGuardHandler6 method getApplicableRegionsSet.

@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
    Set<ProtectedRegion> result = new HashSet<>();
    Vector vector = new Vector(location.getX(), location.getY(), location.getZ());
    for (ProtectedRegion region : pluginInterface.getWorldGuard().getRegionManager(location.getWorld()).getRegions().values()) {
        if (region.contains(vector)) {
            result.add(region);
        }
    }
    return result;
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Vector(com.sk89q.worldedit.Vector) HashSet(java.util.HashSet)

Example 8 with ProtectedRegion

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

the class LLFlag method toggle.

public void toggle() {
    ProtectedRegion pr = land.getWGLand();
    if (flag instanceof StateFlag) {
        if (pr.getFlags().get(flag) == state1) {
            if (g2.equals("nonmembers"))
                pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
            else
                pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.ALL);
            pr.setFlag(flag, state2);
            this.status = state2.name();
        } else {
            if (g1.equals("nonmembers"))
                pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
            else
                pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.ALL);
            pr.setFlag(flag, state1);
            this.status = state1.name();
        }
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag)

Example 9 with ProtectedRegion

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

the class Update method onResetLands.

/**
 * Resets all lands to the default flag state
 */
public void onResetLands(CommandSender sender) {
    sender.sendMessage("Starting to reset lands...");
    for (World w : Bukkit.getWorlds()) {
        for (ProtectedRegion pr : plugin.getWgHandler().getWG().getRegionManager(w).getRegions().values()) {
            if (pr.getId().split("_").length == 3 && Bukkit.getWorld(pr.getId().split("_")[0]) == w) {
                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"))
                                        pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
                                    pr.setFlag((StateFlag) flag, state);
                                } else {
                                    failed = true;
                                }
                            } else {
                                failed = true;
                            }
                        } else {
                            pr.getFlags().remove(flag);
                        }
                        if (failed) {
                            Bukkit.getLogger().warning("ERROR: Your flag definition is invalid!");
                            break;
                        }
                    }
                }
                String name = Bukkit.getOfflinePlayer(pr.getOwners().getUniqueIds().iterator().next()).getName();
                String greeting = lm.getRawString("Alerts.defaultGreeting").replace("%owner%", name);
                String farewell = lm.getRawString("Alerts.defaultFarewell").replace("%owner%", name);
                String actualGreeting = pr.getFlag(DefaultFlag.GREET_MESSAGE);
                String actualFarewell = pr.getFlag(DefaultFlag.FAREWELL_MESSAGE);
                if (!greeting.equals(actualGreeting)) {
                    pr.setFlag(DefaultFlag.GREET_MESSAGE, greeting);
                }
                if (!farewell.equals(actualFarewell)) {
                    pr.setFlag(DefaultFlag.FAREWELL_MESSAGE, farewell);
                }
            }
        }
    }
    sender.sendMessage("Finished resetting lands!");
}
Also used : LandlordCommand(biz.princeps.landlord.commands.LandlordCommand) RegionGroup(com.sk89q.worldguard.protection.flags.RegionGroup) CommandSender(org.bukkit.command.CommandSender) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Landlord(biz.princeps.landlord.Landlord) Set(java.util.Set) Flag(com.sk89q.worldguard.protection.flags.Flag) HashSet(java.util.HashSet) DefaultFlag(com.sk89q.worldguard.protection.flags.DefaultFlag) List(java.util.List) World(org.bukkit.World) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Bukkit(org.bukkit.Bukkit) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) World(org.bukkit.World) HashSet(java.util.HashSet)

Example 10 with ProtectedRegion

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

the class Update method onUpdateLands.

/**
 * Supposed to add missing flags to existing lands, remove non existing flags
 */
public void onUpdateLands(CommandSender issuer) {
    issuer.sendMessage("Starting to update lands...");
    for (World w : Bukkit.getWorlds()) {
        for (ProtectedRegion pr : plugin.getWgHandler().getWG().getRegionManager(w).getRegions().values()) {
            if (pr.getId().split("_").length == 3 && w.getName().equals(pr.getId().split("_")[0])) {
                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) {
                                if (!pr.getFlags().containsKey(flag)) {
                                    String[] defSplit = rules[0].split(" ");
                                    if (defSplit.length == 3) {
                                        StateFlag.State state = StateFlag.State.valueOf(defSplit[1].toUpperCase());
                                        if (defSplit[2].equals("nonmembers"))
                                            pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
                                        pr.setFlag((StateFlag) flag, state);
                                    } else {
                                        failed = true;
                                    }
                                }
                            } else {
                                failed = true;
                            }
                        } else {
                            pr.getFlags().remove(flag);
                        }
                        if (failed) {
                            Bukkit.getLogger().warning("ERROR: Your flag definition is invalid!");
                            break;
                        }
                    }
                }
                String name = Bukkit.getOfflinePlayer(pr.getOwners().getUniqueIds().iterator().next()).getName();
                String greeting = lm.getRawString("Alerts.defaultGreeting").replace("%owner%", name);
                String farewell = lm.getRawString("Alerts.defaultFarewell").replace("%owner%", name);
                if (!pr.getFlags().containsKey(DefaultFlag.GREET_MESSAGE)) {
                    pr.setFlag(DefaultFlag.GREET_MESSAGE, greeting);
                }
                if (!pr.getFlags().containsKey(DefaultFlag.FAREWELL_MESSAGE)) {
                    pr.setFlag(DefaultFlag.FAREWELL_MESSAGE, farewell);
                }
            }
        }
    }
    issuer.sendMessage("Finished updating lands!");
}
Also used : LandlordCommand(biz.princeps.landlord.commands.LandlordCommand) RegionGroup(com.sk89q.worldguard.protection.flags.RegionGroup) CommandSender(org.bukkit.command.CommandSender) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Landlord(biz.princeps.landlord.Landlord) Set(java.util.Set) Flag(com.sk89q.worldguard.protection.flags.Flag) HashSet(java.util.HashSet) DefaultFlag(com.sk89q.worldguard.protection.flags.DefaultFlag) List(java.util.List) World(org.bukkit.World) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Bukkit(org.bukkit.Bukkit) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) World(org.bukkit.World) HashSet(java.util.HashSet)

Aggregations

ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)29 ArrayList (java.util.ArrayList)7 World (org.bukkit.World)7 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)6 OwnedLand (biz.princeps.landlord.util.OwnedLand)5 BuyRegion (me.wiefferink.areashop.regions.BuyRegion)5 GeneralRegion (me.wiefferink.areashop.regions.GeneralRegion)5 RentRegion (me.wiefferink.areashop.regions.RentRegion)5 Vector (com.sk89q.worldedit.Vector)4 HashSet (java.util.HashSet)4 Location (org.bukkit.Location)4 Player (org.bukkit.entity.Player)4 LandlordCommand (biz.princeps.landlord.commands.LandlordCommand)3 BlockVector (com.sk89q.worldedit.BlockVector)3 Flag (com.sk89q.worldguard.protection.flags.Flag)3 StateFlag (com.sk89q.worldguard.protection.flags.StateFlag)3 List (java.util.List)3 Landlord (biz.princeps.landlord.Landlord)2 ManageGUIAll (biz.princeps.landlord.guis.ManageGUIAll)2 EditSession (com.sk89q.worldedit.EditSession)2