Fixed PlotMe converter + Added more debug statements

This commit is contained in:
boy0001 2015-01-30 09:16:31 +11:00
parent d69209364a
commit 0daf83c232
9 changed files with 178 additions and 146 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>PlotSquared</artifactId> <artifactId>PlotSquared</artifactId>
<version>2.5.12</version> <version>2.6.0</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@ -900,7 +900,14 @@ public class PlotMain extends JavaPlugin implements Listener {
public static void worldLoad(WorldLoadEvent event) { public static void worldLoad(WorldLoadEvent event) {
if (!UUIDHandler.CACHED) { if (!UUIDHandler.CACHED) {
UUIDHandler.cacheAll(); 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 { try {
new PlotMeConverter(PlotMain.getMain()).runAsync(); new PlotMeConverter(PlotMain.getMain()).runAsync();
} catch (final Exception e) { } catch (final Exception e) {

View File

@ -83,6 +83,9 @@ public class PlotMeConverter {
final ArrayList<Plot> createdPlots = new ArrayList<>(); final ArrayList<Plot> createdPlots = new ArrayList<>();
final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator; final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
final File plotMeFile = new File(dataFolder + "config.yml"); final File plotMeFile = new File(dataFolder + "config.yml");
if (!plotMeFile.exists()) {
return;
}
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile); final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
int count = 0; int count = 0;
@ -96,6 +99,7 @@ public class PlotMeConverter {
connection = new SQLite(PlotMain.getMain(), dataFolder + File.separator + "plots.db").openConnection(); connection = new SQLite(PlotMain.getMain(), dataFolder + File.separator + "plots.db").openConnection();
} }
sendMessage("Collecting plot data"); sendMessage("Collecting plot data");
sendMessage(" - plotmePlots");
ResultSet r; ResultSet r;
Statement stmt; Statement stmt;
final HashMap<String, Integer> plotSize = new HashMap<>(); final HashMap<String, Integer> plotSize = new HashMap<>();
@ -114,7 +118,6 @@ public class PlotMeConverter {
plotSize.put(world, size); plotSize.put(world, size);
plots.put(world, new HashMap<PlotId, Plot>()); plots.put(world, new HashMap<PlotId, Plot>());
} }
UUID owner = UUIDHandler.getUUID(name); UUID owner = UUIDHandler.getUUID(name);
if (owner == null) { if (owner == null) {
if (name.equals("*")) { if (name.equals("*")) {
@ -128,7 +131,7 @@ public class PlotMeConverter {
final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world); final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
plots.get(world).put(id, plot); plots.get(world).put(id, plot);
} }
sendMessage(" - plotmeAllowed");
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`"); r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
while (r.next()) { while (r.next()) {
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); 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); plots.get(world).get(id).helpers.add(helper);
} }
} }
sendMessage(" - plotmeDenied");
r = stmt.executeQuery("SELECT * FROM `plotmeDenied`"); r = stmt.executeQuery("SELECT * FROM `plotmeDenied`");
while (r.next()) { while (r.next()) {
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
@ -301,7 +304,7 @@ public class PlotMeConverter {
PlotMain.setAllPlotsRaw(DBFunc.getPlots()); PlotMain.setAllPlotsRaw(DBFunc.getPlots());
sendMessage("Conversion has finished"); 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) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -31,11 +31,13 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
@ -151,11 +153,18 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void createAllSettingsAndHelpers(final ArrayList<Plot> plots) { public void createAllSettingsAndHelpers(final ArrayList<Plot> mylist) {
int size = mylist.size();
// TODO SEVERE [ More than 5000 plots will fail in a single SQLite int packet;
// query. if (PlotMain.getMySQL() != null) {
packet = Math.min(size, 50000);
}
else {
packet = Math.min(size, 5000);
}
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<String, HashMap<PlotId, Integer>> stored = new HashMap<>();
final HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<>(); final HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<>();
try { try {
@ -175,9 +184,8 @@ public class SQLManager implements AbstractDB {
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
for (final Plot plot : plots) { for (final Plot plot : plots) {
final String world = Bukkit.getWorld(plot.world).getName(); final String world = plot.world;
if (stored.containsKey(world)) { if (stored.containsKey(world)) {
final Integer id = stored.get(world).get(plot.id); final Integer id = stored.get(world).get(plot.id);
if (id != null) { if (id != null) {
@ -185,7 +193,6 @@ public class SQLManager implements AbstractDB {
} }
} }
} }
if (helpers.size() == 0) { if (helpers.size() == 0) {
return; return;
} }
@ -209,7 +216,6 @@ public class SQLManager implements AbstractDB {
createPlotSettings(ids[i], null); createPlotSettings(ids[i], null);
} }
} }
// add plot helpers // add plot helpers
String prefix = ""; String prefix = "";
statement = new StringBuilder(this.CREATE_HELPERS); statement = new StringBuilder(this.CREATE_HELPERS);
@ -247,6 +253,7 @@ public class SQLManager implements AbstractDB {
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to set all helpers for plots"); PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to set all helpers for plots");
} }
} }
}
/** /**
* Create a plot * Create a plot
@ -254,11 +261,18 @@ public class SQLManager implements AbstractDB {
* @param plots * @param plots
*/ */
@Override @Override
public void createPlots(final ArrayList<Plot> plots) { public void createPlots(final ArrayList<Plot> mylist) {
int size = mylist.size();
// TODO SEVERE [ More than 5000 plots will fail in a single SQLite int packet;
// query. if (PlotMain.getMySQL() != null) {
packet = Math.min(size, 50000);
}
else {
packet = Math.min(size, 5000);
}
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) { if (plots.size() == 0) {
return; return;
} }
@ -287,6 +301,7 @@ public class SQLManager implements AbstractDB {
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace();
PlotMain.sendConsoleSenderMessage("&6[WARN] "+"Could not bulk save. Conversion may be slower..."); PlotMain.sendConsoleSenderMessage("&6[WARN] "+"Could not bulk save. Conversion may be slower...");
try { try {
for (Plot plot : plots) { for (Plot plot : plots) {
@ -304,6 +319,7 @@ public class SQLManager implements AbstractDB {
} }
} }
} }
}
/** /**
* Create a plot * Create a plot
@ -1393,9 +1409,6 @@ public class SQLManager implements AbstractDB {
if (alias != null) { if (alias != null) {
cluster.settings.setAlias(alias); cluster.settings.setAlias(alias);
} }
else {
System.out.print("ALIAS IS NULL!!!");
}
final String pos = r.getString("position"); final String pos = r.getString("position");

View File

@ -38,7 +38,6 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; 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 { 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) { public static void onWorldLoad(final WorldLoadEvent event) {
PlotMain.loadWorld(event.getWorld()); PlotMain.loadWorld(event.getWorld());
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onChunkLoad(final ChunkLoadEvent event) { public static void onChunkLoad(final ChunkLoadEvent event) {
String worldname = event.getWorld().getName(); String worldname = event.getWorld().getName();
Chunk chunk = event.getChunk(); 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) { public static void onJoin(final PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (!player.hasPlayedBefore()) { if (!player.hasPlayedBefore()) {
@ -275,7 +274,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onBigBoom(final EntityExplodeEvent event) { public static void onBigBoom(final EntityExplodeEvent event) {
final World world = event.getLocation().getWorld(); final World world = event.getLocation().getWorld();
if (!isPlotWorld(world)) { 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) { public static void onInteract(final PlayerInteractEvent event) {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if (block == null) { if (block == null) {

View File

@ -188,7 +188,7 @@ public class UUIDHandler {
} }
public static UUID getUUID(final String name) { public static UUID getUUID(final String name) {
if (name == null) { if (name == null || name.length() == 0) {
return null; return null;
} }
// check online // check online
@ -205,11 +205,9 @@ public class UUIDHandler {
if (uuid != null) { if (uuid != null) {
return uuid; return uuid;
} }
// Read from disk OR convert directly to offline UUID // Read from disk OR convert directly to offline UUID
if (Settings.UUID_FROM_DISK || uuidWrapper instanceof OfflineUUIDWrapper) { if (Settings.UUID_FROM_DISK || uuidWrapper instanceof OfflineUUIDWrapper) {
OfflinePlayer op = Bukkit.getOfflinePlayer(name); uuid = UUIDHandler.uuidWrapper.getUUID(name);
uuid = UUIDHandler.uuidWrapper.getUUID(op);
add(new StringWrapper(name), uuid); add(new StringWrapper(name), uuid);
return uuid; return uuid;
} }

View File

@ -28,4 +28,9 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
return Bukkit.getPlayer(uuid); return Bukkit.getPlayer(uuid);
} }
@Override
public UUID getUUID(String name) {
return Bukkit.getOfflinePlayer(name).getUniqueId();
}
} }

View File

@ -56,4 +56,9 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
return null; return null;
} }
@Override
public UUID getUUID(String name) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
}
} }

View File

@ -10,6 +10,8 @@ public abstract class UUIDWrapper {
public abstract UUID getUUID(OfflinePlayer player); public abstract UUID getUUID(OfflinePlayer player);
public abstract UUID getUUID(String name);
public abstract OfflinePlayer getOfflinePlayer(UUID uuid); public abstract OfflinePlayer getOfflinePlayer(UUID uuid);
public abstract Player getPlayer(UUID uuid); public abstract Player getPlayer(UUID uuid);