Java Code Examples for org.spongepowered.api.world.World#getName()

The following examples show how to use org.spongepowered.api.world.World#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
private void initMysql() throws Exception {
    for (World world : Sponge.getServer().getWorlds()) {

        String url = "jdbc:mysql://" + RedProtect.get().config.configRoot().mysql.host + "/";
        String reconnect = "?autoReconnect=true";
        String tableName = RedProtect.get().config.configRoot().mysql.table_prefix + world.getName();

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e2) {
            RedProtect.get().logger.severe("Couldn't find the driver for MySQL! com.mysql.jdbc.Driver.");
            return;
        }
        PreparedStatement st = null;
        try {
            if (!checkTableExists(tableName)) {
                //create db
                Connection con = DriverManager.getConnection(url + RedProtect.get().config.configRoot().mysql.db_name + reconnect, RedProtect.get().config.configRoot().mysql.user_name, RedProtect.get().config.configRoot().mysql.user_pass);
                st = con.prepareStatement("CREATE TABLE `" + tableName + "` "
                        + "(name varchar(20) PRIMARY KEY NOT NULL, leaders varchar(36), admins longtext, members longtext, maxMbrX int, minMbrX int, maxMbrZ int, minMbrZ int, centerX int, centerZ int, minY int, maxY int, date varchar(10), wel longtext, prior int, world varchar(100), value Long not null, tppoint mediumtext, rent longtext, flags longtext, candelete tinyint(1), canpurge tinyint(1)) CHARACTER SET utf8 COLLATE utf8_general_ci");
                st.executeUpdate();
                st.close();
                st = null;
                RedProtect.get().logger.info("Created table: " + tableName + "!");
            }
            addNewColumns(tableName);
        } catch (SQLException e) {
            printJarVersion();
            e.printStackTrace();
            RedProtect.get().logger.severe("There was an error while parsing SQL, redProtect will still with actual DB setting until you change the connection options or check if a Mysql service is running. Use /rp reload to try again");
        } finally {
            if (st != null) {
                st.close();
            }
        }
    }
}
 
Example 2
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public int SingleToFiles() {
    int saved = 0;
    for (World w : Sponge.getServer().getWorlds()) {
        Set<Region> regions = RedProtect.get().rm.getRegionsByWorld(w.getName());
        for (Region r : regions) {
            File wf = new File(RedProtect.get().configDir + File.separator + "data", w.getName() + File.separator + r.getName() + ".conf");
            ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder().setPath(wf.toPath()).build();
            CommentedConfigurationNode fileDB = regionManager.createEmptyNode();

            File f = new File(RedProtect.get().configDir + File.separator + "data", w.getName());
            if (!f.exists()) {
                f.mkdir();
            }

            saved++;
            addProps(fileDB, r);
            saveConf(fileDB, regionManager);
        }

        File oldf = new File(RedProtect.get().configDir + File.separator + "data", "data_" + w.getName() + ".conf");
        if (oldf.exists()) {
            oldf.delete();
        }
    }

    if (!RedProtect.get().config.configRoot().flat_file.region_per_file) {
        RedProtect.get().config.configRoot().flat_file.region_per_file = true;
    }
    RedProtect.get().config.save();
    return saved;
}
 
Example 3
Source File: GDClaimManager.java    From GriefDefender with MIT License 4 votes vote down vote up
public GDClaimManager(World world) {
    this.worldUniqueId = world.getUniqueId();
    this.worldName = world.getName();
}
 
Example 4
Source File: DynmapProvider.java    From GriefDefender with MIT License 4 votes vote down vote up
private void updateClaimMarker(Claim claim, Map<String, AreaMarker> markerMap) {
    final World world = Sponge.getServer().getWorld(claim.getWorldUniqueId()).orElse(null);
    if (world == null) {
        return;
    }
    final String worldName = world.getName();
    final String owner = ((GDClaim) claim).getOwnerName();
    if (isVisible((GDClaim) claim, owner, worldName)) {
        final Vector3i lesserPos = claim.getLesserBoundaryCorner();
        final Vector3i greaterPos = claim.getGreaterBoundaryCorner();
        final double[] x = new double[4];
        final double[] z = new double[4];
        x[0] = lesserPos.getX();
        z[0] = lesserPos.getZ();
        x[1] = lesserPos.getX();
        z[1] = greaterPos.getZ() + 1.0;
        x[2] = greaterPos.getX() + 1.0;
        z[2] = greaterPos.getZ() + 1.0;
        x[3] = greaterPos.getX() + 1.0;
        z[3] = lesserPos.getZ();
        final UUID id = claim.getUniqueId();
        final String markerid = "GD_" + id;
        AreaMarker marker = this.areaMarkers.remove(markerid);
        if (marker == null) {
            marker = this.set.createAreaMarker(markerid, owner, false, worldName, x, z, false);
            if (marker == null) {
                return;
            }
        } else {
            marker.setCornerLocations(x, z);
            marker.setLabel(owner);
        }
        if (this.cfg.use3dRegions) {
            marker.setRangeY(greaterPos.getY() + 1.0, lesserPos.getY());
        }

        addOwnerStyle(owner, worldName, marker, claim);
        String desc = getWindowInfo(claim, marker);
        marker.setDescription(desc);
        markerMap.put(markerid, marker);
    }
}
 
Example 5
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean fileToMysql() throws Exception {
    if (!RedProtect.get().config.configRoot().file_type.equalsIgnoreCase("file")) {
        return false;
    }
    RedProtect.get().rm.saveAll(false);

    initMysql();//Create tables
    int counter = 1;

    for (World world : Sponge.getServer().getWorlds()) {

        String dbname = RedProtect.get().config.configRoot().mysql.db_name;
        String url = "jdbc:mysql://" + RedProtect.get().config.configRoot().mysql.host + "/";
        String tableName = RedProtect.get().config.configRoot().mysql.table_prefix + world.getName();

        Connection dbcon = DriverManager.getConnection(url + dbname, RedProtect.get().config.configRoot().mysql.user_name, RedProtect.get().config.configRoot().mysql.user_pass);

        for (Region r : RedProtect.get().rm.getRegionsByWorld(world.getName())) {
            if (!regionExists(dbcon, r.getName(), tableName)) {
                try {
                    PreparedStatement st = dbcon.prepareStatement("INSERT INTO `" + tableName + "` (name,leaders,admins,members,maxMbrX,minMbrX,maxMbrZ,minMbrZ,minY,maxY,centerX,centerZ,date,wel,prior,world,value,tppoint,candelete,flags,canpurge) "
                            + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
                    st.setString(1, r.getName());
                    st.setString(2, r.getLeaders().toString().replace("[", "").replace("]", ""));
                    st.setString(3, r.getAdmins().toString().replace("[", "").replace("]", ""));
                    st.setString(4, r.getMembers().toString().replace("[", "").replace("]", ""));
                    st.setInt(5, r.getMaxMbrX());
                    st.setInt(6, r.getMinMbrX());
                    st.setInt(7, r.getMaxMbrZ());
                    st.setInt(8, r.getMinMbrZ());
                    st.setInt(9, r.getMinY());
                    st.setInt(10, r.getMaxY());
                    st.setInt(11, r.getCenterX());
                    st.setInt(12, r.getCenterZ());
                    st.setString(13, r.getDate());
                    st.setString(14, r.getWelcome());
                    st.setInt(15, r.getPrior());
                    st.setString(16, r.getWorld());
                    st.setLong(17, r.getValue());
                    st.setString(18, r.getTPPointString());
                    st.setInt(19, r.canDelete() ? 1 : 0);
                    st.setString(20, r.getFlagStrings());
                    st.setInt(21, r.canPurge() ? 1 : 0);

                    st.executeUpdate();
                    st.close();
                    counter++;
                } catch (SQLException e) {
                    printJarVersion();
                    e.printStackTrace();
                }
            }
        }
        dbcon.close();
    }
    if (counter > 0) {
        RedProtect.get().logger.success((counter - 1) + " regions converted to Mysql with success!");
    }
    return true;
}