From 27c011f488abb92d443ca3bb971a90ebe4a5337a Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 20 Oct 2014 19:04:59 -0700 Subject: [PATCH] Working on PlotMeConverter Re-organized some debug messages to display messages in a better format. --- .../intellectualcrafters/plot/PlotMain.java | 10 ++- .../plot/database/DBFunc.java | 16 ++++- .../plot/database/PlotMeConverter.java | 64 ++++++++++++++----- 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 2ba638d83..0d76eda45 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -592,9 +592,13 @@ public class PlotMain extends JavaPlugin { } catch (ClassNotFoundException | SQLException e) { Logger.add(LogLevel.DANGER, "MySQL connection failed."); - System.out.print("\u001B[31m[Plots] MySQL is not setup correctly. The plugin will disable itself.\u001B[0m"); - System.out.print("\u001B[36m==== Here is an ugly stacktrace if you are interested in those things ====\u001B[0m"); - e.printStackTrace(); + sendConsoleSenderMessage("&c[Plots] MySQL is not setup correctly. The plugin will disable itself."); + if (config==null || config.getBoolean("debug")) { + sendConsoleSenderMessage("&d==== Here is an ugly stacktrace if you are interested in those things ===="); + e.printStackTrace(); + sendConsoleSenderMessage("&d==== End of stacktrace ===="); + sendConsoleSenderMessage("&6Please go to the PlotSquared 'storage.yml' and configure MySQL correctly."); + } Bukkit.getPluginManager().disablePlugin(this); return; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 5d32e0588..8d370b8c8 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -163,6 +163,9 @@ public class DBFunc { * @param plots */ public static void createPlots(ArrayList plots) { + + // TODO collect list of plots to check if plot exists. + if (plots.size() == 0) { return; } @@ -422,6 +425,7 @@ public class DBFunc { PlotId plot_id; int id; Plot p; + HashMap noExist = new HashMap(); while (r.next()) { plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z")); id = r.getInt("id"); @@ -485,12 +489,18 @@ public class DBFunc { plots.put(worldname, map); } else { - if (PlotMain.config.getBoolean("debug" )) { - PlotMain.sendConsoleSenderMessage("&cPlot '" + p.id + "' in DB for world '" + p.world + "' does not exist! Please create this world, or remove the plots from the DB!"); - } + if (noExist.containsKey(worldname)) { + noExist.put(worldname,noExist.get(worldname)+1); + } + else { + noExist.put(worldname,1); + } } } } + for (String worldname: noExist.keySet()) { + PlotMain.sendConsoleSenderMessage("&4[WARNING] Found "+noExist.get(worldname)+" plots in DB for non existant world; '"+worldname+"'!!!\n&c - Please create this world, or remove the plots from the DB using the purge command!"); + } stmt.close(); } catch (SQLException e) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java index a0a6b8dbe..84a277fac 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -7,8 +7,10 @@ import com.intellectualcrafters.plot.PlotMain; import com.worldcretornica.plotme.PlayerList; import com.worldcretornica.plotme.Plot; import com.worldcretornica.plotme.PlotManager; + import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; import java.io.PrintStream; import java.lang.reflect.Field; @@ -40,14 +42,32 @@ public class PlotMeConverter { ArrayList createdPlots = new ArrayList(); boolean online = Bukkit.getServer().getOnlineMode(); + + FileConfiguration plotConfig = Bukkit.getPluginManager().getPlugin("PlotMe").getConfig(); + for (World world : Bukkit.getWorlds()) { + int duplicate = 0; HashMap plots = PlotManager.getPlots(world); if (plots != null) { + + + + PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Processing '" + plots.size() + "' plots for world '" + world.getName() + "'"); - PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting " + plots.size() - + " plots for '" + world.toString() + "'..."); + PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting configuration..."); + + int pathwidth = plotConfig.getInt("worlds."+world.getName()+".PathWidth"); + int plotsize = plotConfig.getInt("worlds."+world.getName()+".PlotSize"); + int wallblock = Integer.parseInt(plotConfig.getString("worlds."+world.getName()+".WallBlockId")); + int floor = Integer.parseInt(plotConfig.getString("worlds."+world.getName()+".PlotFloorBlockId")); + int filling = Integer.parseInt(plotConfig.getString("worlds."+world.getName()+".PlotFillingBlockId")); + int road = Integer.parseInt(plotConfig.getString("worlds."+world.getName()+".RoadMainBlockId")); + int road_height = plotConfig.getInt("worlds."+world.getName()+".RoadHeight"); + +// PlotMain.config. + for (Plot plot : plots.values()) { ArrayList psAdded = new ArrayList<>(); ArrayList psTrusted = new ArrayList<>(); @@ -160,32 +180,42 @@ public class PlotMeConverter { new boolean[] { false, false, false, false }); } - // TODO createPlot doesn't add helpers / - // denied - // users if (pl != null) { - createdPlots.add(pl); + if (!PlotMain.getPlots(world).containsKey(pl.id)) { + createdPlots.add(pl); + } + else { + duplicate++; + } } } + if (duplicate>0) { + PlotMain.sendConsoleSenderMessage("&4[WARNING] Found "+duplicate+" duplicate plots already in DB for world: '"+world.getName()+"'. Have you run the converter already?"); + } } } PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating plot DB"); DBFunc.createPlots(createdPlots); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating settings/helpers DB"); + + // TODO createPlot doesn't add denied users DBFunc.createAllSettingsAndHelpers(createdPlots); stream.close(); + PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Copying configuration"); + + // TODO + + // copy over plotme config + + // disable PlotMe + + // unload all plot worlds with MV or MW + + // import those worlds with MV or MW + + // have server owner stop the server and delete PlotMe at some point + PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has finished"); - // TODO disable PlotMe -> Unload all plot worlds, change - // the - // generator, restart the server automatically - // Possibly use multiverse / multiworld if it's to - // difficult - // modifying a world's generator while the server is - // running - // Should really do that? Would seem pretty bad from our - // side + - // bukkit wouldn't approve - Bukkit.getPluginManager().disablePlugin(PlotMeConverter.this.plugin); } });