use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class Region method info.
public String info() {
final StringBuilder leaderStringBuilder = new StringBuilder();
final StringBuilder adminStringBuilder = new StringBuilder();
final StringBuilder memberStringBuilder = new StringBuilder();
final StringBuilder today = new StringBuilder();
String leaderString = "None";
String adminString = "None";
String memberString = "None";
String wMsgTemp;
String IsTops = ChatColor.translateAlternateColorCodes('&', RedProtect.get().getLanguageManager().translBool(isOnTop()));
String wName = this.world;
String colorChar = "";
String dynmapInfo = "";
if (RedProtect.get().getConfigManager().configRoot().region_settings.world_colors.containsKey(this.world)) {
colorChar = ChatColor.translateAlternateColorCodes('&', RedProtect.get().getConfigManager().configRoot().region_settings.world_colors.get(this.world));
}
leaders.removeIf(Objects::isNull);
leaders.forEach(leader -> leaderStringBuilder.append(", ").append(leader.getPlayerName()));
admins.removeIf(Objects::isNull);
admins.forEach(admin -> adminStringBuilder.append(", ").append(admin.getPlayerName()));
members.removeIf(Objects::isNull);
members.forEach(member -> memberStringBuilder.append(", ").append(member.getPlayerName()));
if (this.leaders.size() > 0) {
leaderString = leaderStringBuilder.delete(0, 2).toString();
}
if (this.admins.size() > 0) {
adminString = adminStringBuilder.delete(0, 2).toString();
}
if (this.members.size() > 0) {
memberString = memberStringBuilder.delete(0, 2).toString();
}
if (this.wMessage == null || this.wMessage.equals("")) {
wMsgTemp = RedProtect.get().getLanguageManager().get("region.welcome.notset");
} else {
wMsgTemp = wMessage;
}
if (this.date.equals(RedProtect.get().getUtil().dateNow())) {
today.append(RedProtect.get().getLanguageManager().get("region.today"));
} else {
today.append(this.date);
}
for (PlayerRegion pname : this.leaders) {
Player play = RedProtect.get().getServer().getPlayer(pname.getPlayerName());
if (play != null && play.isOnline() && pname.getPlayerName().equalsIgnoreCase(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader)) {
today.append(ChatColor.GREEN).append("Online!");
break;
}
}
for (PlayerRegion pname : this.admins) {
Player play = RedProtect.get().getServer().getPlayer(pname.getPlayerName());
if (play != null && play.isOnline()) {
today.append(ChatColor.GREEN).append("Online!");
break;
}
}
if (RedProtect.get().hooks.checkDyn() && RedProtect.get().getConfigManager().configRoot().hooks.dynmap.enable) {
dynmapInfo = RedProtect.get().getLanguageManager().get("region.dynmap") + " " + (this.getFlagBool("dynmap") ? RedProtect.get().getLanguageManager().get("region.dynmap-showing") : RedProtect.get().getLanguageManager().get("region.dynmap-hiding")) + ", " + RedProtect.get().getLanguageManager().get("region.dynmap-set") + " " + this.getDynmapSet() + "\n";
}
boolean purgeEnabled = RedProtect.get().getConfigManager().configRoot().purge.enabled;
String canPurge = ChatColor.translateAlternateColorCodes('&', RedProtect.get().getLanguageManager().translBool(canPurge()));
String purgeString = "";
if (purgeEnabled) {
purgeString = ChatColor.AQUA + " | " + RedProtect.get().getLanguageManager().get("region.purge") + " " + canPurge;
}
return RedProtect.get().getLanguageManager().get("region.name") + " " + colorChar + this.name + RedProtect.get().getLanguageManager().get("general.color") + " | " + RedProtect.get().getLanguageManager().get("region.priority") + " " + this.prior + "\n" + RedProtect.get().getLanguageManager().get("region.priority.top") + " " + IsTops + RedProtect.get().getLanguageManager().get("general.color") + " | " + RedProtect.get().getLanguageManager().get("region.lastvalue") + " " + EconomyManager.getFormatted(this.value) + "\n" + RedProtect.get().getLanguageManager().get("region.world") + " " + colorChar + wName + RedProtect.get().getLanguageManager().get("general.color") + " | " + RedProtect.get().getLanguageManager().get("region.center") + " " + this.getCenterX() + ", " + this.getCenterZ() + "\n" + RedProtect.get().getLanguageManager().get("region.ysize") + " " + this.minY + " - " + this.maxY + RedProtect.get().getLanguageManager().get("general.color") + " | " + RedProtect.get().getLanguageManager().get("region.area") + " " + this.getArea() + "\n" + RedProtect.get().getLanguageManager().get("region.leaders") + " " + leaderString + "\n" + RedProtect.get().getLanguageManager().get("region.admins") + " " + adminString + RedProtect.get().getLanguageManager().get("general.color") + " | " + RedProtect.get().getLanguageManager().get("region.members") + " " + memberString + "\n" + RedProtect.get().getLanguageManager().get("region.date") + " " + today.toString() + purgeString + "\n" + dynmapInfo + RedProtect.get().getLanguageManager().get("region.welcome.msg") + " " + (wMsgTemp.equals("hide ") ? RedProtect.get().getLanguageManager().get("region.hiding") : ChatColor.translateAlternateColorCodes('&', wMsgTemp));
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class Region method addLeader.
/**
* Add an leader 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 addLeader(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.admins.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
this.leaders.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 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 tppoint = null;
if (rs.getString("tppoint") != null && !rs.getString("tppoint").equalsIgnoreCase("")) {
String[] tpstring = rs.getString("tppoint").split(",");
tppoint = new Location(Bukkit.getWorld(world), Double.parseDouble(tpstring[0]), Double.parseDouble(tpstring[1]), Double.parseDouble(tpstring[2]), Float.parseFloat(tpstring[3]), Float.parseFloat(tpstring[4]));
}
String serverName = RedProtect.get().getConfigManager().configRoot().region_settings.default_leader;
if (!rs.getString("members").isEmpty()) {
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]));
}
}
if (!rs.getString("admins").isEmpty()) {
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]));
}
}
if (!rs.getString("leaders").isEmpty()) {
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);
Bukkit.getScheduler().runTaskLaterAsynchronously(RedProtect.get(), () -> {
if (regions.containsKey(rname)) {
regions.remove(rname);
RedProtect.get().logger.debug(LogLevel.DEFAULT, "Removed cached region: " + rname);
}
}, (20 * 60) * RedProtect.get().getConfigManager().configRoot().mysql.region_cache_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 WorldMySQLRegionManager method load.
@Override
public void load() {
if (this.dbcon == null) {
ConnectDB();
}
try {
PreparedStatement st = this.dbcon.prepareStatement("SELECT * FROM `" + tableName + "` WHERE world = ?");
st.setString(1, this.world);
ResultSet rs = st.executeQuery();
while (rs.next()) {
String finalName = "";
try {
RedProtect.get().logger.debug(LogLevel.DEFAULT, "Load Region: " + rs.getString("name") + ", World: " + this.world);
HashMap<String, Object> flags = new HashMap<>();
String rname = rs.getString("name");
finalName = rname;
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 tppoint = null;
if (rs.getString("tppoint") != null && !rs.getString("tppoint").equalsIgnoreCase("")) {
String[] tpstring = rs.getString("tppoint").split(",");
tppoint = new Location(Bukkit.getWorld(world), Double.parseDouble(tpstring[0]), Double.parseDouble(tpstring[1]), Double.parseDouble(tpstring[2]), Float.parseFloat(tpstring[3]), Float.parseFloat(tpstring[4]));
}
String serverName = RedProtect.get().getConfigManager().configRoot().region_settings.default_leader;
Set<PlayerRegion> leaders;
if (!rs.getString("leaders").isEmpty()) {
leaders = new HashSet<>(Arrays.asList(rs.getString("leaders").split(","))).stream().map(s -> {
String[] pi = s.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
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]);
}
}
return new PlayerRegion(p[0], p[1]);
}).collect(Collectors.toSet());
} else {
leaders = new HashSet<>();
}
Set<PlayerRegion> admins;
if (!rs.getString("admins").isEmpty()) {
admins = new HashSet<>(Arrays.asList(rs.getString("admins").split(","))).stream().map(s -> {
String[] pi = s.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
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]);
}
}
return new PlayerRegion(p[0], p[1]);
}).collect(Collectors.toSet());
} else {
admins = new HashSet<>();
}
Set<PlayerRegion> members;
if (!rs.getString("members").isEmpty()) {
members = new HashSet<>(Arrays.asList(rs.getString("members").split(","))).stream().map(s -> {
String[] pi = s.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
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]);
}
}
return new PlayerRegion(p[0], p[1]);
}).collect(Collectors.toSet());
} else {
members = new HashSet<>();
}
for (String flag : rs.getString("flags").split(",")) {
String key = flag.split(":")[0];
String replace = key + ":";
if (replace.length() <= flag.length()) {
flags.put(key, RedProtect.get().getUtil().parseObject(flag.substring(replace.length())));
}
}
Region newr = new Region(rname, admins, members, leaders, maxMbrX, minMbrX, maxMbrZ, minMbrZ, minY, maxY, flags, wel, prior, world, date, value, tppoint, candel, canPurge);
regions.put(newr.getName(), newr);
} catch (Exception e) {
RedProtect.get().logger.severe("Error on load region " + finalName);
CoreUtil.printJarVersion();
e.printStackTrace();
}
}
st.close();
rs.close();
} catch (SQLException e) {
CoreUtil.printJarVersion();
e.printStackTrace();
}
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class WorldFlatFileRegionManager method loadRegion.
private static Region loadRegion(CommentedConfigurationNode region, String rname, World world) {
Region newr = null;
try {
if (region.getNode(rname, "name").getString() == null) {
region.getNode(rname, "name").setValue(rname);
}
int maxX = region.getNode(rname, "maxX").getInt();
int maxZ = region.getNode(rname, "maxZ").getInt();
int minX = region.getNode(rname, "minX").getInt();
int minZ = region.getNode(rname, "minZ").getInt();
int maxY = region.getNode(rname, "maxY").getInt(world.getBlockMax().getY());
int minY = region.getNode(rname, "minY").getInt(0);
String serverName = RedProtect.get().getConfigManager().configRoot().region_settings.default_leader;
Set<PlayerRegion> leaders = new HashSet<>(region.getNode(rname, "leaders").getList(TypeToken.of(String.class))).stream().filter(s -> s.split("@").length == 1 || (s.split("@").length == 2 && !s.split("@")[1].isEmpty())).map(s -> {
String[] pi = s.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
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]);
}
}
return new PlayerRegion(p[0], p[1]);
}).collect(Collectors.toSet());
Set<PlayerRegion> admins = new HashSet<>(region.getNode(rname, "admins").getList(TypeToken.of(String.class))).stream().filter(s -> s.split("@").length == 1 || (s.split("@").length == 2 && !s.split("@")[1].isEmpty())).map(s -> {
String[] pi = s.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
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]);
}
}
return new PlayerRegion(p[0], p[1]);
}).collect(Collectors.toSet());
Set<PlayerRegion> members = new HashSet<>(region.getNode(rname, "members").getList(TypeToken.of(String.class))).stream().filter(s -> s.split("@").length == 1 || (s.split("@").length == 2 && !s.split("@")[1].isEmpty())).map(s -> {
String[] pi = s.split("@");
String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
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]);
}
}
return new PlayerRegion(p[0], p[1]);
}).collect(Collectors.toSet());
String welcome = region.getNode(rname, "welcome").getString("");
int prior = region.getNode(rname, "priority").getInt(0);
String date = region.getNode(rname, "lastvisit").getString("");
long value = region.getNode(rname, "value").getLong(0);
boolean candel = region.getNode(rname, "candelete").getBoolean(true);
boolean canPurge = region.getNode(rname, "canpurge").getBoolean(true);
Location<World> tppoint = null;
if (!region.getNode(rname, "tppoint").getString("").isEmpty()) {
String[] tpstring = region.getNode(rname, "tppoint").getString().split(",");
tppoint = new Location<>(world, Double.parseDouble(tpstring[0]), Double.parseDouble(tpstring[1]), Double.parseDouble(tpstring[2]));
}
newr = new Region(rname, admins, members, leaders, new int[] { minX, minX, maxX, maxX }, new int[] { minZ, minZ, maxZ, maxZ }, minY, maxY, prior, world.getName(), date, RedProtect.get().getConfigManager().getDefFlagsValues(), welcome, value, tppoint, candel, canPurge);
for (String flag : RedProtect.get().getConfigManager().getDefFlags()) {
if (region.getNode(rname, "flags", flag) != null) {
newr.getFlags().put(flag, region.getNode(rname, "flags", flag).getValue());
} else {
newr.getFlags().put(flag, RedProtect.get().getConfigManager().getDefFlagsValues().get(flag));
}
}
// this prevents admin flags from being erased after server restart
for (Object o : region.getNode(rname, "flags").getChildrenMap().keySet().stream().filter(o -> !RedProtect.get().getConfigManager().getDefFlags().contains(o.toString())).filter(o -> !CoreConfigManager.ADMIN_FLAGS.contains(o.toString())).toArray()) {
RedProtect.get().logger.warning("Admin flag: " + o.toString());
CoreConfigManager.ADMIN_FLAGS.add(o.toString());
}
for (String flag : CoreConfigManager.ADMIN_FLAGS) {
if (region.getNode(rname, "flags", flag).getString() != null) {
newr.getFlags().put(flag, region.getNode(rname, "flags", flag).getValue());
}
}
} catch (Exception e) {
RedProtect.get().logger.severe("Error on load region " + rname);
CoreUtil.printJarVersion();
e.printStackTrace();
}
return newr;
}
Aggregations