mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Fixed PlotMe converter + Added more debug statements
This commit is contained in:
parent
d69209364a
commit
0daf83c232
@ -8,7 +8,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<artifactId>PlotSquared</artifactId>
|
||||
<version>2.5.12</version>
|
||||
<version>2.6.0</version>
|
||||
<name>PlotSquared</name>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
|
@ -900,7 +900,14 @@ public class PlotMain extends JavaPlugin implements Listener {
|
||||
public static void worldLoad(WorldLoadEvent event) {
|
||||
if (!UUIDHandler.CACHED) {
|
||||
UUIDHandler.cacheAll();
|
||||
if (Settings.CONVERT_PLOTME && Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
|
||||
if (Settings.CONVERT_PLOTME) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
|
||||
sendConsoleSenderMessage("&c[IMPORTANT] THIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU WISH TO CONVERT A PLOTME DATABASE");
|
||||
sendConsoleSenderMessage("&c[IMPORTANT] - Please delete your PlotMe.jar before starting your server!");
|
||||
sendConsoleSenderMessage("&c[IMPORTANT] - This is required as the database may be locked if PlotMe is using it!");
|
||||
sendConsoleSenderMessage("&c[IMPORTANT] - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
new PlotMeConverter(PlotMain.getMain()).runAsync();
|
||||
} catch (final Exception e) {
|
||||
|
@ -83,6 +83,9 @@ public class PlotMeConverter {
|
||||
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
||||
final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
|
||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||
if (!plotMeFile.exists()) {
|
||||
return;
|
||||
}
|
||||
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
|
||||
int count = 0;
|
||||
|
||||
@ -96,6 +99,7 @@ public class PlotMeConverter {
|
||||
connection = new SQLite(PlotMain.getMain(), dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
sendMessage("Collecting plot data");
|
||||
sendMessage(" - plotmePlots");
|
||||
ResultSet r;
|
||||
Statement stmt;
|
||||
final HashMap<String, Integer> plotSize = new HashMap<>();
|
||||
@ -114,7 +118,6 @@ public class PlotMeConverter {
|
||||
plotSize.put(world, size);
|
||||
plots.put(world, new HashMap<PlotId, Plot>());
|
||||
}
|
||||
|
||||
UUID owner = UUIDHandler.getUUID(name);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
@ -128,7 +131,7 @@ public class PlotMeConverter {
|
||||
final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
|
||||
plots.get(world).put(id, plot);
|
||||
}
|
||||
|
||||
sendMessage(" - plotmeAllowed");
|
||||
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
@ -147,7 +150,7 @@ public class PlotMeConverter {
|
||||
plots.get(world).get(id).helpers.add(helper);
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(" - plotmeDenied");
|
||||
r = stmt.executeQuery("SELECT * FROM `plotmeDenied`");
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
@ -301,7 +304,7 @@ public class PlotMeConverter {
|
||||
|
||||
PlotMain.setAllPlotsRaw(DBFunc.getPlots());
|
||||
sendMessage("Conversion has finished");
|
||||
PlotMain.sendConsoleSenderMessage("&cAlthough the server may be functional in it's current state, it is recommended that you restart the server and remove PlotMe to finalize the installation. Please make careful note of any warning messages that may have showed up during conversion.");
|
||||
PlotMain.sendConsoleSenderMessage("&cPlease disable 'plotme-convert.enabled' in the settings.yml to indicate that you conversion is no longer required.");
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -31,11 +31,13 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
@ -151,100 +153,105 @@ public class SQLManager implements AbstractDB {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAllSettingsAndHelpers(final ArrayList<Plot> plots) {
|
||||
|
||||
// TODO SEVERE [ More than 5000 plots will fail in a single SQLite
|
||||
// query.
|
||||
|
||||
final HashMap<String, HashMap<PlotId, Integer>> stored = new HashMap<>();
|
||||
final HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<>();
|
||||
try {
|
||||
final PreparedStatement stmt = this.connection.prepareStatement(this.GET_ALL_PLOTS);
|
||||
final ResultSet result = stmt.executeQuery();
|
||||
while (result.next()) {
|
||||
final int id = result.getInt("id");
|
||||
final int idx = result.getInt("plot_id_x");
|
||||
final int idz = result.getInt("plot_id_z");
|
||||
final String world = result.getString("world");
|
||||
|
||||
if (!stored.containsKey(world)) {
|
||||
stored.put(world, new HashMap<PlotId, Integer>());
|
||||
}
|
||||
stored.get(world).put(new PlotId(idx, idz), id);
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
public void createAllSettingsAndHelpers(final ArrayList<Plot> mylist) {
|
||||
int size = mylist.size();
|
||||
int packet;
|
||||
if (PlotMain.getMySQL() != null) {
|
||||
packet = Math.min(size, 50000);
|
||||
}
|
||||
|
||||
for (final Plot plot : plots) {
|
||||
final String world = Bukkit.getWorld(plot.world).getName();
|
||||
if (stored.containsKey(world)) {
|
||||
final Integer id = stored.get(world).get(plot.id);
|
||||
if (id != null) {
|
||||
helpers.put(id, plot.helpers);
|
||||
}
|
||||
}
|
||||
else {
|
||||
packet = Math.min(size, 5000);
|
||||
}
|
||||
|
||||
if (helpers.size() == 0) {
|
||||
return;
|
||||
}
|
||||
// add plot settings
|
||||
final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]);
|
||||
StringBuilder statement = new StringBuilder(this.CREATE_SETTINGS);
|
||||
for (int i = 0; i < (ids.length - 1); i++) {
|
||||
statement.append("(?),");
|
||||
}
|
||||
statement.append("(?)");
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
stmt = this.connection.prepareStatement(statement.toString());
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
stmt.setInt(i + 1, ids[i]);
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (final SQLException e) {
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
createPlotSettings(ids[i], null);
|
||||
}
|
||||
}
|
||||
|
||||
// add plot helpers
|
||||
String prefix = "";
|
||||
statement = new StringBuilder(this.CREATE_HELPERS);
|
||||
for (final Integer id : helpers.keySet()) {
|
||||
for (final UUID helper : helpers.get(id)) {
|
||||
statement.append(prefix + "(?, ?)");
|
||||
prefix = ",";
|
||||
}
|
||||
}
|
||||
if (prefix.equals("")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
stmt = this.connection.prepareStatement(statement.toString());
|
||||
int counter = 0;
|
||||
for (final Integer id : helpers.keySet()) {
|
||||
for (final UUID helper : helpers.get(id)) {
|
||||
|
||||
stmt.setInt((counter * 2) + 1, id);
|
||||
stmt.setString((counter * 2) + 2, helper.toString());
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (final SQLException e) {
|
||||
int amount = size/packet;
|
||||
for (int j = 0; j <= amount;j++) {
|
||||
List<Plot> plots = mylist.subList(j * packet, Math.min(size, (j + 1) * packet));
|
||||
final HashMap<String, HashMap<PlotId, Integer>> stored = new HashMap<>();
|
||||
final HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<>();
|
||||
try {
|
||||
for (final Integer id : helpers.keySet()) {
|
||||
for (final UUID helper : helpers.get(id)) {
|
||||
setHelper(id, helper);
|
||||
final PreparedStatement stmt = this.connection.prepareStatement(this.GET_ALL_PLOTS);
|
||||
final ResultSet result = stmt.executeQuery();
|
||||
while (result.next()) {
|
||||
final int id = result.getInt("id");
|
||||
final int idx = result.getInt("plot_id_x");
|
||||
final int idz = result.getInt("plot_id_z");
|
||||
final String world = result.getString("world");
|
||||
|
||||
if (!stored.containsKey(world)) {
|
||||
stored.put(world, new HashMap<PlotId, Integer>());
|
||||
}
|
||||
stored.get(world).put(new PlotId(idx, idz), id);
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (final Plot plot : plots) {
|
||||
final String world = plot.world;
|
||||
if (stored.containsKey(world)) {
|
||||
final Integer id = stored.get(world).get(plot.id);
|
||||
if (id != null) {
|
||||
helpers.put(id, plot.helpers);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e2) {}
|
||||
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to set all helpers for plots");
|
||||
if (helpers.size() == 0) {
|
||||
return;
|
||||
}
|
||||
// add plot settings
|
||||
final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]);
|
||||
StringBuilder statement = new StringBuilder(this.CREATE_SETTINGS);
|
||||
for (int i = 0; i < (ids.length - 1); i++) {
|
||||
statement.append("(?),");
|
||||
}
|
||||
statement.append("(?)");
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
stmt = this.connection.prepareStatement(statement.toString());
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
stmt.setInt(i + 1, ids[i]);
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (final SQLException e) {
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
createPlotSettings(ids[i], null);
|
||||
}
|
||||
}
|
||||
// add plot helpers
|
||||
String prefix = "";
|
||||
statement = new StringBuilder(this.CREATE_HELPERS);
|
||||
for (final Integer id : helpers.keySet()) {
|
||||
for (final UUID helper : helpers.get(id)) {
|
||||
statement.append(prefix + "(?, ?)");
|
||||
prefix = ",";
|
||||
}
|
||||
}
|
||||
if (prefix.equals("")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
stmt = this.connection.prepareStatement(statement.toString());
|
||||
int counter = 0;
|
||||
for (final Integer id : helpers.keySet()) {
|
||||
for (final UUID helper : helpers.get(id)) {
|
||||
|
||||
stmt.setInt((counter * 2) + 1, id);
|
||||
stmt.setString((counter * 2) + 2, helper.toString());
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (final SQLException e) {
|
||||
try {
|
||||
for (final Integer id : helpers.keySet()) {
|
||||
for (final UUID helper : helpers.get(id)) {
|
||||
setHelper(id, helper);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e2) {}
|
||||
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to set all helpers for plots");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,53 +261,62 @@ public class SQLManager implements AbstractDB {
|
||||
* @param plots
|
||||
*/
|
||||
@Override
|
||||
public void createPlots(final ArrayList<Plot> plots) {
|
||||
|
||||
// TODO SEVERE [ More than 5000 plots will fail in a single SQLite
|
||||
// query.
|
||||
|
||||
if (plots.size() == 0) {
|
||||
return;
|
||||
public void createPlots(final ArrayList<Plot> mylist) {
|
||||
int size = mylist.size();
|
||||
int packet;
|
||||
if (PlotMain.getMySQL() != null) {
|
||||
packet = Math.min(size, 50000);
|
||||
}
|
||||
final StringBuilder statement = new StringBuilder(this.CREATE_PLOTS);
|
||||
|
||||
for (int i = 0; i < (plots.size() - 1); i++) {
|
||||
statement.append("(?,?,?,?),");
|
||||
else {
|
||||
packet = Math.min(size, 5000);
|
||||
}
|
||||
statement.append("(?,?,?,?)");
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
stmt = this.connection.prepareStatement(statement.toString());
|
||||
for (int i = 0; i < plots.size(); i++) {
|
||||
final Plot plot = plots.get(i);
|
||||
stmt.setInt((i * 4) + 1, plot.id.x);
|
||||
stmt.setInt((i * 4) + 2, plot.id.y);
|
||||
try {
|
||||
stmt.setString((i * 4) + 3, plot.owner.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
stmt.setString((i * 4) + 3, DBFunc.everyone.toString());
|
||||
}
|
||||
stmt.setString((i * 4) + 4, plot.world);
|
||||
int amount = size/packet;
|
||||
for (int j = 0; j <= amount;j++) {
|
||||
List<Plot> plots = mylist.subList(j * packet, Math.min(size, (j + 1) * packet));
|
||||
if (plots.size() == 0) {
|
||||
return;
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (final Exception e) {
|
||||
PlotMain.sendConsoleSenderMessage("&6[WARN] "+"Could not bulk save. Conversion may be slower...");
|
||||
final StringBuilder statement = new StringBuilder(this.CREATE_PLOTS);
|
||||
|
||||
for (int i = 0; i < (plots.size() - 1); i++) {
|
||||
statement.append("(?,?,?,?),");
|
||||
}
|
||||
statement.append("(?,?,?,?)");
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
for (Plot plot : plots) {
|
||||
stmt = this.connection.prepareStatement(statement.toString());
|
||||
for (int i = 0; i < plots.size(); i++) {
|
||||
final Plot plot = plots.get(i);
|
||||
stmt.setInt((i * 4) + 1, plot.id.x);
|
||||
stmt.setInt((i * 4) + 2, plot.id.y);
|
||||
try {
|
||||
createPlot(plot);
|
||||
stmt.setString((i * 4) + 3, plot.owner.toString());
|
||||
}
|
||||
catch (Exception e3) {
|
||||
PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to save plot: "+plot.id);
|
||||
catch (Exception e) {
|
||||
stmt.setString((i * 4) + 3, DBFunc.everyone.toString());
|
||||
}
|
||||
stmt.setString((i * 4) + 4, plot.world);
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
PlotMain.sendConsoleSenderMessage("&6[WARN] "+"Could not bulk save. Conversion may be slower...");
|
||||
try {
|
||||
for (Plot plot : plots) {
|
||||
try {
|
||||
createPlot(plot);
|
||||
}
|
||||
catch (Exception e3) {
|
||||
PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to save plot: "+plot.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to save plots!");
|
||||
catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to save plots!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1393,9 +1409,6 @@ public class SQLManager implements AbstractDB {
|
||||
if (alias != null) {
|
||||
cluster.settings.setAlias(alias);
|
||||
}
|
||||
else {
|
||||
System.out.print("ALIAS IS NULL!!!");
|
||||
}
|
||||
|
||||
final String pos = r.getString("position");
|
||||
|
||||
|
@ -38,7 +38,6 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -106,12 +105,12 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
*/
|
||||
public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public static void onWorldLoad(final WorldLoadEvent event) {
|
||||
PlotMain.loadWorld(event.getWorld());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public static void onChunkLoad(final ChunkLoadEvent event) {
|
||||
String worldname = event.getWorld().getName();
|
||||
Chunk chunk = event.getChunk();
|
||||
@ -125,7 +124,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public static void onJoin(final PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.hasPlayedBefore()) {
|
||||
@ -275,7 +274,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public static void onBigBoom(final EntityExplodeEvent event) {
|
||||
final World world = event.getLocation().getWorld();
|
||||
if (!isPlotWorld(world)) {
|
||||
@ -482,7 +481,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public static void onInteract(final PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) {
|
||||
|
@ -188,7 +188,7 @@ public class UUIDHandler {
|
||||
}
|
||||
|
||||
public static UUID getUUID(final String name) {
|
||||
if (name == null) {
|
||||
if (name == null || name.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
// check online
|
||||
@ -205,11 +205,9 @@ public class UUIDHandler {
|
||||
if (uuid != null) {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
// Read from disk OR convert directly to offline UUID
|
||||
if (Settings.UUID_FROM_DISK || uuidWrapper instanceof OfflineUUIDWrapper) {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(name);
|
||||
uuid = UUIDHandler.uuidWrapper.getUUID(op);
|
||||
uuid = UUIDHandler.uuidWrapper.getUUID(name);
|
||||
add(new StringWrapper(name), uuid);
|
||||
return uuid;
|
||||
}
|
||||
|
@ -28,4 +28,9 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||
return Bukkit.getPlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name) {
|
||||
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,4 +56,9 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ public abstract class UUIDWrapper {
|
||||
public abstract UUID getUUID(Player player);
|
||||
|
||||
public abstract UUID getUUID(OfflinePlayer player);
|
||||
|
||||
public abstract UUID getUUID(String name);
|
||||
|
||||
public abstract OfflinePlayer getOfflinePlayer(UUID uuid);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user