Search in sources :

Example 6 with PlayerRegion

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 : Sponge.getServer().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 candelete = 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<>(world, Double.parseDouble(tpstring[0]), Double.parseDouble(tpstring[1]), Double.parseDouble(tpstring[2]));
                }
                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, candelete, canPurge);
                regions.put(rname, newr);
            }
            st.close();
            rs.close();
            File datf = new File(RedProtect.get().configDir + File.separator + "data", "data_" + world.getName() + ".conf");
            ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder().setPath(datf.toPath()).build();
            CommentedConfigurationNode fileDB = regionManager.createEmptyNode();
            Set<CommentedConfigurationNode> dbs = new HashSet<>();
            for (Region r : regions.values()) {
                if (r.getName() == null) {
                    continue;
                }
                if (RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
                    if (!r.toSave()) {
                        continue;
                    }
                    datf = new File(RedProtect.get().configDir + File.separator + "data", world.getName() + File.separator + r.getName() + ".conf");
                    regionManager = HoconConfigurationLoader.builder().setPath(datf.toPath()).build();
                    fileDB = regionManager.createEmptyNode();
                }
                addProps(fileDB, r);
                saved++;
                if (RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
                    dbs.add(fileDB);
                    saveConf(fileDB, regionManager);
                    r.setToSave(false);
                }
            }
            if (!RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
                saveConf(fileDB, regionManager);
            } else {
                // remove deleted regions
                File wfolder = new File(RedProtect.get().configDir + File.separator + "data", world.getName());
                if (wfolder.exists()) {
                    File[] listOfFiles = wfolder.listFiles();
                    if (listOfFiles != null) {
                        for (File region : listOfFiles) {
                            if (region.isFile() && !regions.containsKey(region.getName().replace(".conf", ""))) {
                                region.delete();
                            }
                        }
                    }
                }
            }
        // try backup
        /*if (!RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
                    backupRegions(Collections.singleton(fileDB), world.getName(), "data_" + world + ".conf");
                } else {
                    backupRegions(dbs, world.getName(), null);
                }*/
        }
        backupRegions();
        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;
}
Also used : World(org.spongepowered.api.world.World) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) File(java.io.File)

Example 7 with PlayerRegion

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));
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Example 8 with PlayerRegion

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));
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Example 9 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class Region method info.

public Text info() {
    final StringBuilder leaderStringBuilder = new StringBuilder();
    final StringBuilder adminStringBuilder = new StringBuilder();
    final StringBuilder memberStringBuilder = new StringBuilder();
    String leaderString = "None";
    String adminString = "None";
    String memberString = "None";
    String wMsgTemp;
    String IsTops = RedProtect.get().getLanguageManager().translBool(isOnTop());
    String today;
    String wName = this.world;
    String colorChar = "";
    String dynmapInfo = "";
    if (RedProtect.get().getConfigManager().configRoot().region_settings.world_colors.containsKey(this.world)) {
        colorChar = 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 = RedProtect.get().getLanguageManager().get("region.today");
    } else {
        today = this.date;
    }
    for (PlayerRegion pname : this.leaders) {
        Optional<Player> play = Sponge.getServer().getPlayer(pname.getPlayerName());
        if (play.isPresent() && !pname.getPlayerName().equalsIgnoreCase(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader)) {
            today = "&aOnline!";
            break;
        }
    }
    for (PlayerRegion pname : this.admins) {
        Optional<Player> play = Sponge.getServer().getPlayer(pname.getPlayerName());
        if (play.isPresent() && !pname.getPlayerName().equalsIgnoreCase(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader)) {
            today = "&aOnline!";
            break;
        }
    }
    if (RedProtect.get().hooks.Dyn && 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 = RedProtect.get().getLanguageManager().translBool(canPurge());
    String purgeString = "";
    if (purgeEnabled) {
        purgeString = "&b | " + RedProtect.get().getLanguageManager().get("region.purge") + " " + canPurge;
    }
    return RedProtect.get().getUtil().toText(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 + purgeString + "\n" + dynmapInfo + RedProtect.get().getLanguageManager().get("region.welcome.msg") + " " + wMsgTemp);
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) Player(org.spongepowered.api.entity.living.player.Player)

Example 10 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class RedProtectUtil method convertFromGP.

public int convertFromGP() {
    int claimed = 0;
    Collection<Claim> claims = GriefPrevention.instance.dataStore.getClaims();
    for (Claim claim : claims) {
        if (Bukkit.getWorlds().contains(claim.getGreaterBoundaryCorner().getWorld())) {
            World w = claim.getGreaterBoundaryCorner().getWorld();
            String pname = claim.getOwnerName().replace(" ", "_").toLowerCase();
            if (claim.ownerID != null) {
                pname = claim.ownerID.toString();
            }
            Set<PlayerRegion> leaders = new HashSet<>();
            leaders.add(new PlayerRegion(claim.ownerID != null ? claim.ownerID.toString() : pname, pname));
            Location newmin = claim.getGreaterBoundaryCorner();
            Location newmax = claim.getLesserBoundaryCorner();
            newmin.setY(w.getMinHeight());
            newmax.setY(w.getMaxHeight());
            Region r = new Region(nameGen(claim.getOwnerName().replace(" ", "_").toLowerCase(), w.getName()), new HashSet<>(), new HashSet<>(), leaders, newmin, newmax, RedProtect.get().getConfigManager().getDefFlagsValues(), "GriefPrevention region", 0, w.getName(), dateNow(), 0, null, true, true);
            Region other = RedProtect.get().getRegionManager().getTopRegion(w.getName(), r.getCenterX(), r.getCenterY(), r.getCenterZ());
            if (other == null || !r.getWelcome().equals(other.getWelcome())) {
                RedProtect.get().getRegionManager().add(r, w.getName());
                RedProtect.get().logger.debug(LogLevel.DEFAULT, "Region: " + r.getName());
                claimed++;
            }
        }
    }
    return claimed;
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Claim(me.ryanhamshire.GriefPrevention.Claim)

Aggregations

PlayerRegion (br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)31 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)11 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)6 World (org.spongepowered.api.world.World)6 DefineRegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.actions.DefineRegionBuilder)4 RegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionBuilder)4 File (java.io.File)4 IOException (java.io.IOException)4 Player (org.bukkit.entity.Player)4 CoreUtil (br.net.fabiozumbi12.RedProtect.Core.helpers.CoreUtil)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Location (org.bukkit.Location)3 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)3 RedProtect (br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect)2 LogLevel (br.net.fabiozumbi12.RedProtect.Core.helpers.LogLevel)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)2 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)2 Operation (com.sk89q.worldedit.function.operation.Operation)2