Fixed PlotMe converter for MultiWorld and vanilla Bukkit

This commit is contained in:
boy0001 2014-10-23 22:55:54 +11:00
parent 356923d3e8
commit 127f876d8e

View File

@ -44,255 +44,256 @@ public class PlotMeConverter {
} }
public void runAsync() throws Exception { public void runAsync() throws Exception {
Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
final PrintStream stream = new PrintStream("converter_log.txt"); @Override
public void run() {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has started"); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has started");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Caching playerdata..."); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Caching playerdata...");
ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = ArrayList<com.intellectualcrafters.plot.Plot> createdPlots =
new ArrayList<com.intellectualcrafters.plot.Plot>(); new ArrayList<com.intellectualcrafters.plot.Plot>();
boolean online = Bukkit.getServer().getOnlineMode(); boolean online = Bukkit.getServer().getOnlineMode();
Plugin plotMePlugin = Bukkit.getPluginManager().getPlugin("PlotMe"); Plugin plotMePlugin = Bukkit.getPluginManager().getPlugin("PlotMe");
FileConfiguration plotConfig = plotMePlugin.getConfig(); FileConfiguration plotConfig = plotMePlugin.getConfig();
Set<String> worlds = new HashSet<String>(); Set<String> worlds = new HashSet<String>();
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
int duplicate = 0; int duplicate = 0;
HashMap<String, Plot> plots = PlotManager.getPlots(world); HashMap<String, Plot> plots = PlotManager.getPlots(world);
if (plots != null) { if (plots != null) {
worlds.add(world.getName()); worlds.add(world.getName());
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting configuration for world '"+world.getName()+"'..."); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting configuration for world '"+world.getName()+"'...");
try { try {
Integer pathwidth = plotConfig.getInt("worlds."+world.getName()+".PathWidth"); // Integer pathwidth = plotConfig.getInt("worlds."+world.getName()+".PathWidth"); //
PlotMain.config.set("worlds."+world.getName()+".road.width", pathwidth); PlotMain.config.set("worlds."+world.getName()+".road.width", pathwidth);
Integer plotsize = plotConfig.getInt("worlds."+world.getName()+".PlotSize"); // Integer plotsize = plotConfig.getInt("worlds."+world.getName()+".PlotSize"); //
PlotMain.config.set("worlds."+world.getName()+".plot.size", plotsize); PlotMain.config.set("worlds."+world.getName()+".plot.size", plotsize);
String wallblock = plotConfig.getString("worlds."+world.getName()+".WallBlockId"); // String wallblock = plotConfig.getString("worlds."+world.getName()+".WallBlockId"); //
PlotMain.config.set("worlds."+world.getName()+".wall.block", wallblock); PlotMain.config.set("worlds."+world.getName()+".wall.block", wallblock);
String floor = plotConfig.getString("worlds."+world.getName()+".PlotFloorBlockId"); // String floor = plotConfig.getString("worlds."+world.getName()+".PlotFloorBlockId"); //
PlotMain.config.set("worlds."+world.getName()+".plot.floor", Arrays.asList(new String[] {floor})); PlotMain.config.set("worlds."+world.getName()+".plot.floor", Arrays.asList(new String[] {floor}));
String filling = plotConfig.getString("worlds."+world.getName()+".PlotFillingBlockId"); // String filling = plotConfig.getString("worlds."+world.getName()+".PlotFillingBlockId"); //
PlotMain.config.set("worlds."+world.getName()+".plot.filling", Arrays.asList(new String[] {filling})); PlotMain.config.set("worlds."+world.getName()+".plot.filling", Arrays.asList(new String[] {filling}));
String road = plotConfig.getString("worlds."+world.getName()+".RoadMainBlockId"); String road = plotConfig.getString("worlds."+world.getName()+".RoadMainBlockId");
PlotMain.config.set("worlds."+world.getName()+".road.block", road); PlotMain.config.set("worlds."+world.getName()+".road.block", road);
String road_stripe = plotConfig.getString("worlds."+world.getName()+".RoadStripeBlockId"); String road_stripe = plotConfig.getString("worlds."+world.getName()+".RoadStripeBlockId");
PlotMain.config.set("worlds."+world.getName()+".road.stripes", road_stripe); PlotMain.config.set("worlds."+world.getName()+".road.stripes", road_stripe);
Integer height = plotConfig.getInt("worlds."+world.getName()+".RoadHeight"); // Integer height = plotConfig.getInt("worlds."+world.getName()+".RoadHeight"); //
PlotMain.config.set("worlds."+world.getName()+".road.height", height); PlotMain.config.set("worlds."+world.getName()+".road.height", height);
Boolean auto_link = plotConfig.getBoolean("worlds."+world.getName()+".AutoLinkPlots"); // Boolean auto_link = plotConfig.getBoolean("worlds."+world.getName()+".AutoLinkPlots"); //
PlotMain.config.set("worlds."+world.getName()+".plot.auto_merge", auto_link); PlotMain.config.set("worlds."+world.getName()+".plot.auto_merge", auto_link);
} }
catch (Exception e) { catch (Exception e) {
PlotMain.sendConsoleSenderMessage(" - Failed to save configuration for world '"+world.getName()+"'. This will need to be done using the setup command or manually."); PlotMain.sendConsoleSenderMessage(" - Failed to save configuration for world '"+world.getName()+"'. This will need to be done using the setup command or manually.");
} }
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Processing '" + plots.size() + "' plots for world '" + world.getName() + "'"); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Processing '" + plots.size() + "' plots for world '" + world.getName() + "'");
for (Plot plot : plots.values()) { for (Plot plot : plots.values()) {
ArrayList<UUID> psAdded = new ArrayList<>(); ArrayList<UUID> psAdded = new ArrayList<>();
ArrayList<UUID> psTrusted = new ArrayList<>(); ArrayList<UUID> psTrusted = new ArrayList<>();
ArrayList<UUID> psDenied = new ArrayList<>(); ArrayList<UUID> psDenied = new ArrayList<>();
if (world == null) { if (world == null) {
world = Bukkit.getWorld("world"); world = Bukkit.getWorld("world");
} }
long eR3040bl230 = 22392948l; long eR3040bl230 = 22392948l;
try { try {
if (online) { if (online) {
PlayerList denied = null; PlayerList denied = null;
PlayerList added = null; PlayerList added = null;
Field fAdded = plot.getClass().getDeclaredField("allowed"); Field fAdded = plot.getClass().getDeclaredField("allowed");
Field fDenied = plot.getClass().getDeclaredField("denied"); Field fDenied = plot.getClass().getDeclaredField("denied");
fAdded.setAccessible(true); fAdded.setAccessible(true);
fDenied.setAccessible(true); fDenied.setAccessible(true);
added = (PlayerList) fAdded.get(plot); added = (PlayerList) fAdded.get(plot);
denied = (PlayerList) fDenied.get(plot); denied = (PlayerList) fDenied.get(plot);
for (Map.Entry<String, UUID> set : added.getAllPlayers().entrySet()) { for (Map.Entry<String, UUID> set : added.getAllPlayers().entrySet()) {
if ((set.getValue() != null) || set.getKey().equals("*")) { if ((set.getValue() != null) || set.getKey().equals("*")) {
if (set.getKey().equalsIgnoreCase("*") if (set.getKey().equalsIgnoreCase("*")
|| set.getValue().toString().equals("*")) { || set.getValue().toString().equals("*")) {
psAdded.add(DBFunc.everyone); psAdded.add(DBFunc.everyone);
continue; continue;
} }
} }
if (set.getValue() != null) { if (set.getValue() != null) {
psAdded.add(set.getValue()); psAdded.add(set.getValue());
} }
} }
for (Map.Entry<String, UUID> set : denied.getAllPlayers().entrySet()) { for (Map.Entry<String, UUID> set : denied.getAllPlayers().entrySet()) {
if ((set.getValue() != null) || set.getKey().equals("*")) { if ((set.getValue() != null) || set.getKey().equals("*")) {
if (set.getKey().equals("*") || set.getValue().toString().equals("*")) { if (set.getKey().equals("*") || set.getValue().toString().equals("*")) {
psDenied.add(DBFunc.everyone); psDenied.add(DBFunc.everyone);
continue; continue;
} }
} }
if (set.getValue() != null) { if (set.getValue() != null) {
psDenied.add(set.getValue()); psDenied.add(set.getValue());
} }
} }
} }
else { else {
for (String user : plot.getAllowed().split(",")) { for (String user : plot.getAllowed().split(",")) {
if (user.equals("*")) { if (user.equals("*")) {
psAdded.add(DBFunc.everyone); psAdded.add(DBFunc.everyone);
} }
else { else {
UUID uuid = UUID uuid =
UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8)); UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
psAdded.add(uuid); psAdded.add(uuid);
} }
} }
try { try {
for (String user : plot.getDenied().split(",")) { for (String user : plot.getDenied().split(",")) {
if (user.equals("*")) { if (user.equals("*")) {
psDenied.add(DBFunc.everyone); psDenied.add(DBFunc.everyone);
} }
else { else {
UUID uuid = UUID uuid =
UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8)); UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
psDenied.add(uuid); psDenied.add(uuid);
} }
} }
} }
catch (Throwable e) { catch (Throwable e) {
} }
} }
} }
catch (Throwable e) { catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
eR3040bl230 = 232000499888388747l; eR3040bl230 = 232000499888388747l;
} }
finally { finally {
eR3040bl230 = 232999304998392004l; eR3040bl230 = 232999304998392004l;
} }
stream.println(eR3040bl230); PlotId id =
PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1])); com.intellectualcrafters.plot.Plot pl = null;
com.intellectualcrafters.plot.Plot pl = null; if (online) {
if (online) { pl = new com.intellectualcrafters.plot.Plot(
pl = new com.intellectualcrafters.plot.Plot( id,
id, plot.getOwnerId(),
plot.getOwnerId(), plot.getBiome(),
plot.getBiome(), psAdded, psTrusted,
psAdded, psTrusted, psDenied,
psDenied,
"",
"", PlotHomePosition.DEFAULT,
PlotHomePosition.DEFAULT, null,
null, world.getName(),
world.getName(), new boolean[] { false, false, false, false });
new boolean[] { false, false, false, false }); }
} else {
else { String owner = plot.getOwner();
String owner = plot.getOwner(); pl = new com.intellectualcrafters.plot.Plot(
pl = new com.intellectualcrafters.plot.Plot( id,
id, UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)),
UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)), plot.getBiome(),
plot.getBiome(), psAdded,
psAdded, psTrusted,
psTrusted, psDenied,
psDenied,
"",
"", PlotHomePosition.DEFAULT,
PlotHomePosition.DEFAULT, null,
null, world.getName(),
world.getName(), new boolean[] { false, false, false, false });
new boolean[] { false, false, false, false }); }
}
if (pl != null) {
if (pl != null) { if (!PlotMain.getPlots(world).containsKey(id)) {
if (!PlotMain.getPlots(world).containsKey(id)) { createdPlots.add(pl);
createdPlots.add(pl); }
} else {
else { duplicate++;
duplicate++; }
} }
} }
} if (duplicate>0) {
if (duplicate>0) { PlotMain.sendConsoleSenderMessage("&c[WARNING] Found "+duplicate+" duplicate plots already in DB for world: '"+world.getName()+"'. Have you run the converter already?");
PlotMain.sendConsoleSenderMessage("&c[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");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating plot DB"); DBFunc.createPlots(createdPlots);
DBFunc.createPlots(createdPlots); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating settings/helpers DB");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating settings/helpers DB");
// TODO createPlot doesn't add denied users
// TODO createPlot doesn't add denied users DBFunc.createAllSettingsAndHelpers(createdPlots);
DBFunc.createAllSettingsAndHelpers(createdPlots); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Saving configuration...");
stream.close(); try {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Saving configuration..."); PlotMain.config.save(PlotMain.configFile);
try { } catch (IOException e) {
PlotMain.config.save(PlotMain.configFile); PlotMain.sendConsoleSenderMessage(" - &cFailed to save configuration.");
} catch (IOException e) { }
PlotMain.sendConsoleSenderMessage(" - &cFailed to save configuration.");
} boolean MV = false;
boolean MW = false;
boolean MV = false;
boolean MW = false; if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
MV = true;
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;
else { }
MW = true;
} for (String worldname : worlds) {
World world = Bukkit.getWorld(worldname);
for (String worldname : worlds) { PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Reloading generator for world: '"+worldname+"'...");
World world = Bukkit.getWorld(worldname);
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Reloading generator for world: '"+worldname+"'..."); PlotMain.removePlotWorld(worldname);
PlotMain.removePlotWorld(worldname); if (MV) {
// unload
if (MV) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname);
// unload try {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname); Thread.sleep(1000);
try { } catch(InterruptedException ex) {
Thread.sleep(1000); Thread.currentThread().interrupt();
} catch(InterruptedException ex) { }
Thread.currentThread().interrupt(); // load
} Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared");
// load }
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared"); else if (MW) {
} // unload
else if (MW) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname);
// unload try {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname); Thread.sleep(1000);
try { } catch(InterruptedException ex) {
Thread.sleep(1000); Thread.currentThread().interrupt();
} catch(InterruptedException ex) { }
Thread.currentThread().interrupt(); // load
} Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname+" plugin:PlotSquared");
// load }
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname+" plugin:PlotSquared"); else {
} System.out.print("LOADED WORLD");
else { Bukkit.getServer().unloadWorld(world, true);
Bukkit.getServer().unloadWorld(world, true); World myworld = WorldCreator.name(worldname).generator(new WorldGenerator(worldname)).createWorld();
World myworld = WorldCreator.name(worldname).generator(new WorldGenerator(worldname)).createWorld(); myworld.save();
myworld.save(); }
} }
}
PlotMain.setAllPlotsRaw(DBFunc.getPlots());
PlotMain.setAllPlotsRaw(DBFunc.getPlots());
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Disabling PlotMe...");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Disabling PlotMe..."); Bukkit.getPluginManager().disablePlugin(plotMePlugin);
Bukkit.getPluginManager().disablePlugin(plotMePlugin); PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Conversion has finished");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 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("&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."); }
}, 20);
} }
} }