mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-29 04:04:43 +02:00
Move bukkit specific files
This commit is contained in:
@ -1,117 +0,0 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public abstract class APlotMeConnector {
|
||||
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
|
||||
|
||||
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;
|
||||
|
||||
public abstract boolean accepts(String version);
|
||||
|
||||
public String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public boolean isValidConnection(Connection connection) {
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
public void copyConfig(FileConfiguration plotConfig, String world, String actualWorldName) {
|
||||
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.width", pathwidth);
|
||||
final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotsize);
|
||||
final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallblock);
|
||||
final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Arrays.asList(floor));
|
||||
final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Arrays.asList(filling));
|
||||
final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.block", road);
|
||||
Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
||||
if (height == null) {
|
||||
height = 64;
|
||||
}
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
}
|
||||
|
||||
public Location getPlotTopLocAbs(int path, int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 256, z);
|
||||
}
|
||||
|
||||
public Location getPlotBottomLocAbs(int path, int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 1, z);
|
||||
}
|
||||
|
||||
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
|
||||
HashMap<PlotId, boolean[]> plots = merges.get(world);
|
||||
PlotId id2;
|
||||
switch (direction) {
|
||||
case 0: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean[] merge1;
|
||||
boolean[] merge2;
|
||||
if (plots.containsKey(id)) {
|
||||
merge1 = plots.get(id);
|
||||
}
|
||||
else {
|
||||
merge1 = new boolean[]{false, false, false, false};
|
||||
}
|
||||
if (plots.containsKey(id2)) {
|
||||
merge2 = plots.get(id2);
|
||||
}
|
||||
else {
|
||||
merge2 = new boolean[]{false, false, false, false};
|
||||
}
|
||||
merge1[direction] = true;
|
||||
merge2[(direction + 2) % 4] = true;
|
||||
plots.put(id, merge1);
|
||||
plots.put(id2, merge1);
|
||||
}
|
||||
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class ClassicPlotMeConnector extends APlotMeConnector {
|
||||
|
||||
private String plugin;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
final String user = plotConfig.getString("mySQLuname");
|
||||
final String password = plotConfig.getString("mySQLpass");
|
||||
final String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
// return new MySQL(plotsquared, hostname, port, database, username, password)
|
||||
} else {
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||
ResultSet r;
|
||||
PreparedStatement stmt;
|
||||
final HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
final HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Plots`");
|
||||
r = stmt.executeQuery();
|
||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
|
||||
boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME;
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("owner");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
plots.put(world, new HashMap<PlotId, Plot>());
|
||||
if (merge) {
|
||||
int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId,boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
int tx = r.getInt("topX");
|
||||
int tz = r.getInt("topZ");
|
||||
int bx = r.getInt("bottomX") - 1;
|
||||
int bz = r.getInt("bottomZ") - 1;
|
||||
int path = roadWidth.get(world);
|
||||
int plot = plotWidth.get(world);
|
||||
Location top = getPlotTopLocAbs(path, plot, id);
|
||||
Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
owner = DBFunc.everyone;
|
||||
}
|
||||
else {
|
||||
if (checkUUID){
|
||||
try {
|
||||
byte[] bytes = r.getBytes("ownerid");
|
||||
if (bytes != null) {
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
if (owner != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
final Plot plot = new Plot(world, id, owner);
|
||||
plots.get(world).put(id, plot);
|
||||
}
|
||||
|
||||
for (Entry<String, HashMap<PlotId, boolean[]>> entry : merges.entrySet()) {
|
||||
String world = entry.getKey();
|
||||
for (Entry<PlotId, boolean[]> entry2 : entry.getValue().entrySet()) {
|
||||
HashMap<PlotId, Plot> newplots = plots.get(world);
|
||||
Plot plot = newplots.get(entry2.getKey());
|
||||
if (plot != null) {
|
||||
plot.getSettings().setMerged(entry2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
try {
|
||||
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "Denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID denied = UUIDHandler.getUUID(name);
|
||||
if (denied == null) {
|
||||
if (name.equals("*")) {
|
||||
denied = DBFunc.everyone;
|
||||
} else {
|
||||
MainUtil.sendConsoleMessage("&6Could not identify denied for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).getDenied().add(denied);
|
||||
}
|
||||
}
|
||||
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID helper = UUIDHandler.getUUID(name);
|
||||
if (helper == null) {
|
||||
if (name.equals("*")) {
|
||||
helper = DBFunc.everyone;
|
||||
} else {
|
||||
MainUtil.sendConsoleMessage("&6Could not identify helper for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).getTrusted().add(helper);
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
}
|
||||
catch (Exception e) {}
|
||||
return plots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(String version) {
|
||||
if (version == null) {
|
||||
return true;
|
||||
}
|
||||
return PS.get().canUpdate(version, "0.17.0");
|
||||
}
|
||||
}
|
@ -1,323 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
/**
|
||||
* Created 2014-08-17 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class LikePlotMeConverter {
|
||||
private String plugin;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin Plugin Used to run the converter
|
||||
*/
|
||||
public LikePlotMeConverter(String plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
private void sendMessage(final String message) {
|
||||
PS.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
||||
}
|
||||
|
||||
public String getPlotMePath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public String getAthionPlotsPath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||
if (!plotMeFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(plotMeFile);
|
||||
}
|
||||
|
||||
public Set<String> getPlotMeWorlds(FileConfiguration plotConfig) {
|
||||
return plotConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
}
|
||||
|
||||
public void updateWorldYml(String plugin, String location) {
|
||||
try {
|
||||
Path path = Paths.get(location);
|
||||
File file = new File(location);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
Charset charset = StandardCharsets.UTF_8;
|
||||
String content = new String(Files.readAllBytes(path), charset);
|
||||
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
|
||||
content = content.replaceAll(plugin, "PlotSquared");
|
||||
Files.write(path, content.getBytes(charset));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean run(final APlotMeConnector connector) {
|
||||
try {
|
||||
String dataFolder = getPlotMePath();
|
||||
FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
|
||||
if (plotConfig == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String version = plotConfig.getString("Version");
|
||||
if (version == null) version = plotConfig.getString("version");
|
||||
if (!connector.accepts(version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PS.log("&3Using connector: " + connector.getClass().getCanonicalName());
|
||||
|
||||
Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
||||
|
||||
if (!connector.isValidConnection(connection)) {
|
||||
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
|
||||
sendMessage("Connecting to " + plugin + " DB");
|
||||
|
||||
int plotCount = 0;
|
||||
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
||||
|
||||
sendMessage("Collecting plot data");
|
||||
|
||||
String dbPrefix = plugin.toLowerCase();
|
||||
sendMessage(" - " + dbPrefix + "Plots");
|
||||
final Set<String> worlds = getPlotMeWorlds(plotConfig);
|
||||
|
||||
if (Settings.CONVERT_PLOTME) {
|
||||
sendMessage("Updating bukkit.yml");
|
||||
updateWorldYml(plugin, "bukkit.yml");
|
||||
updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
|
||||
for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
|
||||
sendMessage("Copying config for: " + world);
|
||||
try {
|
||||
String actualWorldName = getWorld(world);
|
||||
connector.copyConfig(plotConfig, world, actualWorldName);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
|
||||
}
|
||||
}
|
||||
}
|
||||
HashMap<String, HashMap<PlotId, Plot>> plots = connector.getPlotMePlots(connection);
|
||||
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||
plotCount += entry.getValue().size();
|
||||
}
|
||||
if (!Settings.CONVERT_PLOTME) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(" - " + dbPrefix + "Allowed");
|
||||
|
||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||
final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
||||
if (PLOTME_DG_FILE.exists()) {
|
||||
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
|
||||
try {
|
||||
for (final String world : plots.keySet()) {
|
||||
String actualWorldName = getWorld(world);
|
||||
final String plotMeWorldName = world.toLowerCase();
|
||||
Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
||||
if (pathwidth == null) {
|
||||
pathwidth = 7;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.width", pathwidth);
|
||||
Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
|
||||
if (plotsize == null) {
|
||||
plotsize = 32;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.size", plotsize);
|
||||
String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
|
||||
if (wallblock == null) {
|
||||
wallblock = "44";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".wall.block", wallblock);
|
||||
String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
|
||||
if (floor == null) {
|
||||
floor = "2";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.floor", Arrays.asList(floor));
|
||||
String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
|
||||
if (filling == null) {
|
||||
filling = "3";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.filling", Arrays.asList(filling));
|
||||
String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
|
||||
if (road == null) {
|
||||
road = "5";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.block", road);
|
||||
Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
||||
if ((height == null) || (height == 0)) {
|
||||
height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
|
||||
if ((height == null) || (height == 0)) {
|
||||
height = 64;
|
||||
}
|
||||
}
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
for (final String world : plots.keySet()) {
|
||||
int duplicate = 0;
|
||||
for (final Plot plot : plots.get(world).values()) {
|
||||
if (!PS.get().getPlots(world).containsKey(plot.id)) {
|
||||
createdPlots.add(plot);
|
||||
} else {
|
||||
duplicate++;
|
||||
}
|
||||
}
|
||||
if (duplicate > 0) {
|
||||
PS.log("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
||||
}
|
||||
}
|
||||
sendMessage("Creating plot DB");
|
||||
Thread.sleep(1000);
|
||||
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendMessage("&aDatabase conversion is now complete!");
|
||||
PS.log("&c - Stop the server");
|
||||
PS.log("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||
PS.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||
PS.log("&c - Start the server");
|
||||
PS.get().setAllPlotsRaw(DBFunc.getPlots());
|
||||
}
|
||||
});
|
||||
sendMessage("Saving configuration...");
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final IOException e) {
|
||||
sendMessage(" - &cFailed to save configuration.");
|
||||
}
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
boolean MV = false;
|
||||
boolean MW = false;
|
||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||
MV = true;
|
||||
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
MW = true;
|
||||
}
|
||||
for (final String worldname : worlds) {
|
||||
final World world = Bukkit.getWorld(getWorld(worldname));
|
||||
if (world == null) {
|
||||
sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
|
||||
}
|
||||
final String actualWorldName = world.getName();
|
||||
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
||||
PS.get().removePlotWorld(actualWorldName);
|
||||
if (MV) {
|
||||
// unload world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
|
||||
} else if (MW) {
|
||||
// unload world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
|
||||
} else {
|
||||
// Load using Bukkit API
|
||||
// - User must set generator manually
|
||||
Bukkit.getServer().unloadWorld(world, true);
|
||||
final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen(actualWorldName)).createWorld();
|
||||
myworld.save();
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
PS.log("&/end/");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
package com.intellectualcrafters.plot.database.plotme;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class PlotMeConnector_017 extends APlotMeConnector {
|
||||
private String plugin;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
String user = plotConfig.getString("mySQLuname");
|
||||
String password = plotConfig.getString("mySQLpass");
|
||||
String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
} else {
|
||||
File file = new File(dataFolder + File.separator + "plotmecore.db");
|
||||
if (file.exists()) {
|
||||
return new SQLite(dataFolder + File.separator + "plotmecore.db").openConnection();
|
||||
}
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||
ResultSet r;
|
||||
PreparedStatement stmt;
|
||||
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<Integer, Plot> plots = new HashMap<>();
|
||||
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_plots`");
|
||||
r = stmt.executeQuery();
|
||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerID");
|
||||
boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME;
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
PlotId id = new PlotId(r.getInt("plotX"), r.getInt("plotZ"));
|
||||
String name = r.getString("owner");
|
||||
String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
if (merge) {
|
||||
int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId,boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
int tx = r.getInt("topX");
|
||||
int tz = r.getInt("topZ");
|
||||
int bx = r.getInt("bottomX") - 1;
|
||||
int bz = r.getInt("bottomZ") - 1;
|
||||
int path = roadWidth.get(world);
|
||||
int plot = plotWidth.get(world);
|
||||
Location top = getPlotTopLocAbs(path, plot, id);
|
||||
Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
owner = DBFunc.everyone;
|
||||
}
|
||||
else {
|
||||
if (checkUUID){
|
||||
try {
|
||||
byte[] bytes = r.getBytes("ownerid");
|
||||
if (bytes != null) {
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
if (owner != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
Plot plot = new Plot(world, id, owner);
|
||||
plots.put(key, plot);
|
||||
}
|
||||
for (Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
Plot plot = entry.getValue();
|
||||
HashMap<PlotId, boolean[]> mergeMap = merges.get(plot.world);
|
||||
if (mergeMap != null) {
|
||||
if (mergeMap.containsKey(plot.id)) {
|
||||
plot.getSettings().setMerged(mergeMap.get(plot.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
try {
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "core_denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
MainUtil.sendConsoleMessage("&6Denied (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
UUID denied = UUID.fromString(r.getString("player"));
|
||||
plot.getDenied().add(denied);
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage(" - " + plugin + "core_allowed");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
int key = r.getInt("plot_id");
|
||||
Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
MainUtil.sendConsoleMessage("&6Allowed (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
UUID allowed = UUID.fromString(r.getString("player"));
|
||||
plot.getTrusted().add(allowed);
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HashMap<String, HashMap<PlotId, Plot>> processed = new HashMap<>();
|
||||
|
||||
for (Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
Plot plot = entry.getValue();
|
||||
HashMap<PlotId, Plot> map = processed.get(plot.world);
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
processed.put(plot.world, map);
|
||||
}
|
||||
map.put(plot.id, plot);
|
||||
}
|
||||
return processed ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(String version) {
|
||||
if (version == null) {
|
||||
return false;
|
||||
}
|
||||
return !PS.get().canUpdate(version, "0.17");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user