use of br.net.fabiozumbi12.RedProtect.Sponge.region.RegionManager in project RedProtect by FabioZumbi12.
the class CommandHandler method handleWGRegions.
private static boolean handleWGRegions() {
if (!RedProtect.get().hooks.checkWG()) {
return false;
}
WorldGuardHelper helper = RedProtect.get().hooks.worldGuardHelper;
List<RegionManager> loaded = helper.getLoaded();
if (loaded.isEmpty())
return false;
int i = 0;
for (RegionManager rm : loaded) {
if (rm.getRegions().isEmpty())
continue;
String w = rm.getName();
for (Map.Entry<String, ProtectedRegion> pr : rm.getRegions().entrySet()) {
if (!pr.getValue().getType().equals(RegionType.CUBOID))
continue;
if (RedProtect.get().getRegionManager().getRegion(pr.getKey(), w) != null)
continue;
Set<PlayerRegion> leaders;
Set<PlayerRegion> members;
if (!pr.getValue().getOwners().getUniqueIds().isEmpty())
leaders = pr.getValue().getOwners().getUniqueIds().stream().filter(p -> Bukkit.getPlayer(p) != null).map(o -> new PlayerRegion(o.toString(), Bukkit.getPlayer(o).getName())).collect(Collectors.toSet());
else
leaders = pr.getValue().getOwners().getPlayers().stream().map(o -> new PlayerRegion(o, o)).collect(Collectors.toSet());
if (!pr.getValue().getMembers().getUniqueIds().isEmpty())
members = pr.getValue().getMembers().getUniqueIds().stream().filter(p -> Bukkit.getPlayer(p) != null).map(o -> new PlayerRegion(o.toString(), Bukkit.getPlayer(o).getName())).collect(Collectors.toSet());
else
members = pr.getValue().getMembers().getPlayers().stream().map(o -> new PlayerRegion(o, o)).collect(Collectors.toSet());
if (leaders.isEmpty()) {
if (members.isEmpty())
leaders.add(new PlayerRegion(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader, RedProtect.get().getConfigManager().configRoot().region_settings.default_leader));
else
leaders.addAll(members);
}
Location min = helper.getMinimumPoint(pr.getValue(), Bukkit.getWorld(w));
Location max = helper.getMaximumPoint(pr.getValue(), Bukkit.getWorld(w));
Region r = new Region(pr.getKey(), new HashSet<>(), members, leaders, min, max, RedProtect.get().getConfigManager().getDefFlagsValues(), "", pr.getValue().getPriority(), w, RedProtect.get().getUtil().dateNow(), 0, null, true, true);
for (Map.Entry<Flag<?>, Object> flag : pr.getValue().getFlags().entrySet()) {
if (r.flagExists(flag.getKey().getName()) && RedProtect.get().getUtil().parseObject(flag.getValue().toString()) != null) {
r.setFlag(Bukkit.getConsoleSender(), flag.getKey().getName(), RedProtect.get().getUtil().parseObject(flag.getValue().toString()));
}
}
RedProtect.get().getRegionManager().add(r, w);
RedProtect.get().logger.warning("Region converted and named to " + r.getName());
i++;
}
RedProtect.get().logger.success(i + " WorldGuard regions imported for world " + w);
}
return i > 0;
}
Aggregations