From 97c452e3112c728aa1bebc38e5ce5b7bf15b5d87 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 1 Oct 2014 22:11:19 +1000 Subject: [PATCH] The damn reflection doesn't want to work. Why did zachbora think it was a good idea to convert the UUIDs to player names before returning them? Anywho, I added a slower method that now works at okay speeds. (22 seconds for 2549 user checks) --- .../plot/database/DBFunc.java | 73 ++++++++++++++++--- .../plot/database/PlotMeConverter.java | 50 ++++++++++++- 2 files changed, 109 insertions(+), 14 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 415c756ca..7564b912f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.block.Biome; @@ -65,38 +66,90 @@ public class DBFunc { }); } - public static void createAllSettings() { - final ArrayList ids = new ArrayList(); + public static void createAllSettingsAndHelpers(ArrayList plots) { + HashMap> stored = new HashMap< String, HashMap>(); + HashMap> helpers = new HashMap>(); try { - PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `plot`"); + PreparedStatement stmt = connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `plot`"); ResultSet result = stmt.executeQuery(); while (result.next()) { int id = result.getInt("id"); - ids.add(id); + int idx = result.getInt("plot_id_x"); + int idz = result.getInt("plot_id_z"); + String world = result.getString("world"); + + if (!stored.containsKey(world)) { + stored.put(world,new HashMap()); + } + stored.get(world).put(new PlotId(idx,idz), id); } } catch (SQLException e) { e.printStackTrace(); } - if (ids.size()==0) { - System.out.print("ERROR: No plots found"); + + for (Plot plot:plots) { + String world = Bukkit.getWorld(plot.world).getName(); + if (stored.containsKey(world)) { + Integer id = stored.get(world).get(plot.id); + if (id!=null) { + helpers.put(id,plot.helpers); + } + } + } + + if (helpers.size()==0) { return; } - final StringBuilder statement = new StringBuilder("INSERT INTO `plot_settings`(`plot_plot_id`) values "); - for (int i = 0; i createdPlots = new ArrayList(); - ArrayList createdIds = new ArrayList(); + HashMap uuidMap = new HashMap(); for (World world : Bukkit.getWorlds()) { HashMap plots = PlotManager.getPlots(world); if (plots!=null) { @@ -57,7 +59,10 @@ public class PlotMeConverter { } long eR3040bl230 = 22392948l; try { - Field fAdded = plot.getClass().getField("added"); + + // TODO It just comes up with a NoSuchFieldException. Y U NO WORK!!! (I didn't change anything here btw) + + Field fAdded = plot.getClass().getField("allowed"); Field fDenied = plot.getClass().getField("denied"); fAdded.setAccessible(true); fDenied.setAccessible(true); @@ -78,6 +83,41 @@ public class PlotMeConverter { psDenied.add(set.getValue()); } } catch (NoSuchFieldException | IllegalAccessException e) { + // Doing it the slow way like a n00b. + for (String user:plot.getAllowed().split(",")) { + try { + if (user.equals("*")) { + psAdded.add(DBFunc.everyone); + } + else if (uuidMap.containsKey(user)) { + psAdded.add(uuidMap.get(user)); + } + else { + UUID uuid = Bukkit.getOfflinePlayer(user).getUniqueId(); + uuidMap.put(user, uuid); + psAdded.add(uuid); + } + } + catch (Exception e2) { + } + } + for (String user:plot.getDenied().split(",")) { + try { + if (user.equals("*")) { + psDenied.add(DBFunc.everyone); + } + else if (uuidMap.containsKey(user)) { + psDenied.add(uuidMap.get(user)); + } + else { + UUID uuid = Bukkit.getOfflinePlayer(user).getUniqueId(); + uuidMap.put(user, uuid); + psDenied.add(uuid); + } + } + catch (Exception e2) { + } + } eR3040bl230 = 232000499888388747l; } finally { eR3040bl230 = 232999304998392004l; @@ -92,9 +132,11 @@ public class PlotMeConverter { } } } - PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Saving to DB"); + PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Creating plot DB"); DBFunc.createPlots(createdPlots); - DBFunc.createAllSettings(); + PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Creating settings/helpers DB"); + DBFunc.createAllSettingsAndHelpers(createdPlots); + stream.close(); PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has finished");