use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class Region method removeLeader.
/**
* Remove 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 removeLeader(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 RedProtectUtil method mysqlToFile.
public boolean mysqlToFile() {
HashMap<String, Region> regions = new HashMap<>();
int saved = 1;
try {
Connection dbcon = DriverManager.getConnection("jdbc:mysql://" + RedProtect.get().getConfigManager().configRoot().mysql.host + "/" + RedProtect.get().getConfigManager().configRoot().mysql.db_name + "?autoReconnect=true", RedProtect.get().getConfigManager().configRoot().mysql.user_name, RedProtect.get().getConfigManager().configRoot().mysql.user_pass);
for (World world : Bukkit.getWorlds()) {
String tableName = RedProtect.get().getConfigManager().configRoot().mysql.table_prefix + world.getName();
PreparedStatement st = dbcon.prepareStatement("SELECT * FROM `" + tableName + "` WHERE world=?");
st.setString(1, world.getName());
ResultSet rs = st.executeQuery();
while (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 rname = rs.getString("name");
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(world, Double.parseDouble(tpstring[0]), Double.parseDouble(tpstring[1]), Double.parseDouble(tpstring[2]), Float.parseFloat(tpstring[3]), Float.parseFloat(tpstring[4]));
}
for (String member : rs.getString("members").split(", ")) {
if (member.length() > 0) {
String[] p = member.split("@");
members.add(new PlayerRegion(p[0], p.length == 2 ? p[1] : p[0]));
}
}
for (String admin : rs.getString("admins").split(", ")) {
if (admin.length() > 0) {
String[] p = admin.split("@");
admins.add(new PlayerRegion(p[0], p.length == 2 ? p[1] : p[0]));
}
}
for (String leader : rs.getString("leaders").split(", ")) {
if (leader.length() > 0) {
String[] p = leader.split("@");
leaders.add(new PlayerRegion(p[0], p.length == 2 ? p[1] : p[0]));
}
}
for (String flag : rs.getString("flags").split(",")) {
String key = flag.split(":")[0];
String replace = key + ":";
if (replace.length() <= flag.length()) {
flags.put(key, parseObject(flag.substring(replace.length())));
}
}
Region newr = new Region(rname, admins, members, leaders, maxMbrX, minMbrX, maxMbrZ, minMbrZ, minY, maxY, flags, wel, prior, world.getName(), date, value, tppoint, candel, canPurge);
regions.put(rname, newr);
}
st.close();
rs.close();
// write to yml
YamlConfiguration fileDB = new YamlConfiguration();
File datf = new File(RedProtect.get().getDataFolder() + File.separator + "data", "data_" + world.getName() + ".yml");
for (Region r : regions.values()) {
if (r.getName() == null) {
continue;
}
if (RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
if (!r.toSave()) {
continue;
}
fileDB = new YamlConfiguration();
datf = new File(RedProtect.get().getDataFolder() + File.separator + "data", world.getName() + File.separator + r.getName() + ".yml");
}
addProps(fileDB, r);
saved++;
if (RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
saveYaml(fileDB, datf);
r.setToSave(false);
}
}
if (!RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
saveYaml(fileDB, datf);
} else {
// remove deleted regions
File wfolder = new File(RedProtect.get().getDataFolder() + File.separator + "data", world.getName());
if (wfolder.exists()) {
File[] listOfFiles = new File(RedProtect.get().getDataFolder() + File.separator + "data", world.getName()).listFiles();
if (listOfFiles != null) {
for (File region : listOfFiles) {
if (region.isFile() && !regions.containsKey(region.getName().replace(".yml", ""))) {
region.delete();
}
}
}
}
}
}
dbcon.close();
if (saved > 0) {
RedProtect.get().logger.success((saved - 1) + " regions converted to File with success!");
}
} catch (SQLException e) {
printJarVersion();
e.printStackTrace();
}
return true;
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class WorldFlatFileRegionManager method loadRegion.
private static Region loadRegion(YamlConfiguration fileDB, String rname, String world) {
Region newr = null;
try {
if (fileDB.getString(rname + ".name") == null) {
fileDB.set(rname + ".name", rname);
}
int maxX = fileDB.getInt(rname + ".maxX");
int maxZ = fileDB.getInt(rname + ".maxZ");
int minX = fileDB.getInt(rname + ".minX");
int minZ = fileDB.getInt(rname + ".minZ");
int maxY = fileDB.getInt(rname + ".maxY", Bukkit.getWorld(world).getMaxHeight());
int minY = fileDB.getInt(rname + ".minY", Bukkit.getWorld(world).getMaxHeight());
String name = fileDB.getString(rname + ".name");
String serverName = RedProtect.get().getConfigManager().configRoot().region_settings.default_leader;
Set<PlayerRegion> leaders = new HashSet<>(fileDB.getStringList(rname + ".leaders")).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<>(fileDB.getStringList(rname + ".admins")).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<>(fileDB.getStringList(rname + ".members")).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 = fileDB.getString(rname + ".welcome", "");
int prior = fileDB.getInt(rname + ".priority", 0);
String date = fileDB.getString(rname + ".lastvisit", "");
long value = fileDB.getLong(rname + ".value", 0);
boolean candel = fileDB.getBoolean(rname + ".candelete", true);
boolean canPurge = fileDB.getBoolean(rname + ".canpurge", true);
Location tppoint = null;
if (!fileDB.getString(rname + ".tppoint", "").isEmpty()) {
String[] tpstring = fileDB.getString(rname + ".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]));
}
fixdbFlags(fileDB, rname);
newr = new Region(name, admins, members, leaders, new int[] { minX, minX, maxX, maxX }, new int[] { minZ, minZ, maxZ, maxZ }, minY, maxY, prior, world, date, RedProtect.get().getConfigManager().getDefFlagsValues(), welcome, value, tppoint, candel, canPurge);
Set<String> defaultFlags = RedProtect.get().getConfigManager().getDefFlags();
ConfigurationSection flagsSection = fileDB.getConfigurationSection(rname + ".flags");
for (String flag : defaultFlags) {
Object flagValue = flagsSection.get(flag);
if (flagValue != null) {
newr.getFlags().put(flag, flagValue);
} else {
newr.getFlags().put(flag, RedProtect.get().getConfigManager().getDefFlagsValues().get(flag));
}
}
Set<String> regionFlags = flagsSection.getKeys(false);
for (String flag : regionFlags) {
if (!defaultFlags.contains(flag)) {
newr.getFlags().put(flag, flagsSection.get(flag));
}
}
} catch (Exception e) {
e.printStackTrace();
RedProtect.get().logger.severe("Error on load region " + rname);
CoreUtil.printJarVersion();
}
return newr;
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class ClaimCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
HandleHelpPage(sender, 1);
return true;
}
Player player = (Player) sender;
String claimmode = RedProtect.get().getConfigManager().getWorldClaimType(player.getWorld().getName());
if (!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH") && !RedProtect.get().getPermissionHandler().hasCommandPerm(player, "claim")) {
RedProtect.get().getLanguageManager().sendMessage(player, "blocklistener.region.blockmode");
return true;
}
if (args.length == 0) {
String name = RedProtect.get().getUtil().nameGen(player.getName(), player.getWorld().getName());
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, new PlayerRegion(player.getUniqueId().toString(), player.getName()), new HashSet<>(), false);
if (rb2.ready()) {
Region r2 = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().getRegionManager().add(r2, player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
});
return true;
}
if (args.length == 1) {
String name = args[0];
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, new PlayerRegion(player.getUniqueId().toString(), player.getName()), new HashSet<>(), false);
if (rb2.ready()) {
Region r2 = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().getRegionManager().add(r2, player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
});
return true;
}
if (args.length == 2) {
String name = args[0];
Set<PlayerRegion> addedAdmins = new HashSet<>();
addedAdmins.add(new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(args[1]), args[1]));
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, new PlayerRegion(player.getUniqueId().toString(), player.getName()), addedAdmins, false);
if (rb2.ready()) {
Region r2 = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().getRegionManager().add(r2, player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
});
return true;
}
RedProtect.get().getLanguageManager().sendCommandHelp(sender, "claim", true);
return true;
}
use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.
the class CreatePortalCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
HandleHelpPage(sender, 1);
return true;
}
Player player = (Player) sender;
// rp createportal <regionName> <regionTo> <world>
if (args.length == 3) {
World w = RedProtect.get().getServer().getWorld(args[2]);
if (w == null) {
sender.sendMessage(RedProtect.get().getLanguageManager().get("cmdmanager.region.invalidworld"));
return true;
}
Region r = RedProtect.get().getRegionManager().getRegion(args[1], w.getName());
if (r == null) {
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.createportal.warning").replace("{region}", args[1]));
}
PlayerRegion serverName = new PlayerRegion(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader, RedProtect.get().getConfigManager().configRoot().region_settings.default_leader);
String name = Normalizer.normalize(args[0].replace(" ", "_"), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").replaceAll("[^\\p{L}0-9 ]", "");
final Region[] r2 = { RedProtect.get().getRegionManager().getRegion(name, w.getName()) };
if (r == r2[0]) {
RedProtect.get().getLanguageManager().sendMessage(player, RedProtect.get().getLanguageManager().get("cmdmanager.createportal.equals"));
return true;
}
if (r2[0] != null) {
if ((!r2[0].isLeader(player) || !r2[0].isAdmin(player)) && !r2[0].canBuild(player)) {
RedProtect.get().getLanguageManager().sendMessage(player, "no.permission");
return true;
}
RedProtect.get().getLanguageManager().sendMessage(player, String.format(RedProtect.get().getLanguageManager().get("cmdmanager.region.portalcreated"), name, args[1], w.getName()));
RedProtect.get().getLanguageManager().sendMessage(player, "cmdmanager.region.portalhint");
r2[0].setFlag(sender, "set-portal", args[1] + " " + w.getName());
RedProtect.get().logger.addLog("(World " + r2[0].getWorld() + ") Player " + player.getName() + " CREATED A PORTAL " + r2[0].getName() + " to " + args[1] + " database " + w.getName());
} else {
RedProtect.get().getLanguageManager().sendMessage(player, "regionbuilder.creating");
// Run claim async
Bukkit.getScheduler().runTaskAsynchronously(RedProtect.get(), () -> {
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, serverName, new HashSet<>(), true);
if (rb2.ready()) {
r2[0] = rb2.build();
RedProtect.get().getLanguageManager().sendMessage(player, String.format(RedProtect.get().getLanguageManager().get("cmdmanager.region.portalcreated"), name, args[1], w.getName()));
RedProtect.get().getLanguageManager().sendMessage(player, "cmdmanager.region.portalhint");
r2[0].setFlag(sender, "set-portal", args[1] + " " + w.getName());
RedProtect.get().getRegionManager().add(r2[0], player.getWorld().getName());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2[0].getWorld() + ") Player " + player.getName() + " CREATED A PORTAL " + r2[0].getName() + " to " + args[1] + " database " + w.getName());
}
});
}
return true;
}
RedProtect.get().getLanguageManager().sendCommandHelp(sender, "createportal", true);
return true;
}
Aggregations