use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class WorldMySQLRegionManager method getRegion.
@Override
public Region getRegion(final String rname) {
if (this.dbcon == null) {
ConnectDB();
}
if (!regions.containsKey(rname)) {
if (rname == null) {
return null;
}
try {
PreparedStatement st = this.dbcon.prepareStatement("SELECT * FROM `" + tableName + "` WHERE LOWER(name) = ? AND world=?");
st.setString(1, rname.toLowerCase());
st.setString(2, this.world);
ResultSet rs = st.executeQuery();
if (rs.next()) {
Set<PlayerRegion> leaders = new HashSet<>();
Set<PlayerRegion> admins = new HashSet<>();
Set<PlayerRegion> members = new HashSet<>();
HashMap<String, Object> flags = new HashMap<>();
int maxMbrX = rs.getInt("maxMbrX");
int minMbrX = rs.getInt("minMbrX");
int maxMbrZ = rs.getInt("maxMbrZ");
int minMbrZ = rs.getInt("minMbrZ");
int maxY = rs.getInt("maxY");
int minY = rs.getInt("minY");
int prior = rs.getInt("prior");
String world = rs.getString("world");
String date = rs.getString("date");
String wel = rs.getString("wel");
long value = rs.getLong("value");
boolean candel = rs.getBoolean("candelete");
boolean canPurge = rs.getBoolean("canpurge");
Location<World> tppoint = null;
if (rs.getString("tppoint") != null && !rs.getString("tppoint").equalsIgnoreCase("")) {
String[] tpstring = rs.getString("tppoint").split(",");
tppoint = new Location<>(Sponge.getServer().getWorld(world).get(), Double.parseDouble(tpstring[0]), Double.parseDouble(tpstring[1]), Double.parseDouble(tpstring[2]));
}
String serverName = RedProtect.get().getConfigManager().configRoot().region_settings.default_leader;
for (String member : rs.getString("members").split(", ")) {
String[] pi = member.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
if (p[1].isEmpty())
continue;
if (!p[0].equalsIgnoreCase(serverName) && !p[1].equalsIgnoreCase(serverName)) {
if (RedProtect.get().getUtil().isUUIDs(p[1])) {
String before = p[1];
p[1] = RedProtect.get().getUtil().UUIDtoPlayer(p[1]) == null ? p[1] : RedProtect.get().getUtil().UUIDtoPlayer(p[1]).toLowerCase();
RedProtect.get().logger.success("Updated region " + rname + ", player &6" + before + " &ato &6" + p[1]);
}
}
members.add(new PlayerRegion(p[0], p[1]));
}
for (String admin : rs.getString("admins").split(", ")) {
String[] pi = admin.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
if (p[1].isEmpty())
continue;
if (!p[0].equalsIgnoreCase(serverName) && !p[1].equalsIgnoreCase(serverName)) {
if (RedProtect.get().getUtil().isUUIDs(p[1])) {
String before = p[1];
p[1] = RedProtect.get().getUtil().UUIDtoPlayer(p[1]) == null ? p[1] : RedProtect.get().getUtil().UUIDtoPlayer(p[1]).toLowerCase();
RedProtect.get().logger.success("Updated region " + rname + ", player &6" + before + " &ato &6" + p[1]);
}
}
admins.add(new PlayerRegion(p[0], p[1]));
}
for (String leader : rs.getString("leaders").split(", ")) {
String[] pi = leader.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
if (p[1].isEmpty())
continue;
if (!p[0].equalsIgnoreCase(serverName) && !p[1].equalsIgnoreCase(serverName)) {
if (RedProtect.get().getUtil().isUUIDs(p[1])) {
String before = p[1];
p[1] = RedProtect.get().getUtil().UUIDtoPlayer(p[1]) == null ? p[1] : RedProtect.get().getUtil().UUIDtoPlayer(p[1]).toLowerCase();
RedProtect.get().logger.success("Updated region " + rname + ", player &6" + before + " &ato &6" + p[1]);
}
}
leaders.add(new PlayerRegion(p[0], p[1]));
}
for (String flag : rs.getString("flags").split(",")) {
String key = flag.split(":")[0];
flags.put(key, RedProtect.get().getUtil().parseObject(flag.substring((key + ":").length())));
}
Region reg = new Region(rname, admins, members, leaders, maxMbrX, minMbrX, maxMbrZ, minMbrZ, minY, maxY, flags, wel, prior, world, date, value, tppoint, candel, canPurge);
regions.put(rname, reg);
} else {
return null;
}
st.close();
rs.close();
RedProtect.get().logger.debug(LogLevel.DEFAULT, "Adding region to cache: " + rname);
Sponge.getScheduler().createSyncExecutor(RedProtect.get().container).schedule(() -> {
if (regions.containsKey(rname)) {
regions.remove(rname);
RedProtect.get().logger.debug(LogLevel.DEFAULT, "Removed cached region: " + rname);
}
}, RedProtect.get().getConfigManager().configRoot().mysql.region_cache_minutes, TimeUnit.MINUTES);
} catch (SQLException e) {
CoreUtil.printJarVersion();
e.printStackTrace();
}
}
return regions.get(rname);
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion 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;
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class Region method addAdmin.
/**
* Add an admin to the Region. The string need to be UUID if Online Mode, or Player Name if Offline Mode.
*
* @param uuid - UUID or Player Name.
*/
public void addAdmin(String uuid) {
setToSave(true);
String name = RedProtect.get().getUtil().UUIDtoPlayer(uuid).toLowerCase();
PlayerRegion pInfo = new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(uuid), name);
this.members.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
this.leaders.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
this.admins.add(pInfo);
RedProtect.get().getRegionManager().updateLiveRegion(this, "leaders", serializeMembers(leaders));
RedProtect.get().getRegionManager().updateLiveRegion(this, "admins", serializeMembers(admins));
RedProtect.get().getRegionManager().updateLiveRegion(this, "members", serializeMembers(members));
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class Region method removeAdmin.
/**
* Remove an admin to the Region. The string need to be UUID if Online Mode, or Player Name if Offline Mode.
*
* @param uuid - UUID or Player Name.
*/
public void removeAdmin(String uuid) {
setToSave(true);
String name = RedProtect.get().getUtil().UUIDtoPlayer(uuid).toLowerCase();
PlayerRegion pInfo = new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(uuid), name);
this.leaders.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
this.admins.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
this.members.add(pInfo);
RedProtect.get().getRegionManager().updateLiveRegion(this, "leaders", serializeMembers(leaders));
RedProtect.get().getRegionManager().updateLiveRegion(this, "admins", serializeMembers(admins));
RedProtect.get().getRegionManager().updateLiveRegion(this, "members", serializeMembers(members));
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class Region method addMember.
/**
* Add a member to the Region. The string need to be UUID if Online Mode, or Player Name if Offline Mode.
*
* @param uuid - UUID or Player Name.
*/
public void addMember(String uuid) {
setToSave(true);
String name = RedProtect.get().getUtil().UUIDtoPlayer(uuid).toLowerCase();
PlayerRegion pInfo = new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(uuid), name);
this.admins.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
this.leaders.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
this.members.add(pInfo);
RedProtect.get().getRegionManager().updateLiveRegion(this, "leaders", serializeMembers(leaders));
RedProtect.get().getRegionManager().updateLiveRegion(this, "admins", serializeMembers(admins));
RedProtect.get().getRegionManager().updateLiveRegion(this, "members", serializeMembers(members));
}
Aggregations