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