mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 12:06:15 +01:00
Some optimization to PlotMeConverter.
This commit is contained in:
parent
07895be660
commit
38c7edbddd
@ -71,7 +71,7 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* settings.properties
|
||||
*/
|
||||
public static File configFile;
|
||||
public static File configFile;
|
||||
/**
|
||||
* The main configuration file
|
||||
*/
|
||||
@ -84,7 +84,11 @@ public class PlotMain extends JavaPlugin {
|
||||
* Contains storage options
|
||||
*/
|
||||
public static YamlConfiguration storage;
|
||||
public static int storage_ver = 1;
|
||||
/**
|
||||
* Storage version
|
||||
*/
|
||||
public static int storage_ver =
|
||||
1;
|
||||
/**
|
||||
* MySQL Connection
|
||||
*/
|
||||
@ -92,20 +96,42 @@ public class PlotMain extends JavaPlugin {
|
||||
/**
|
||||
* WorldEdit object
|
||||
*/
|
||||
public static WorldEditPlugin worldEdit = null;
|
||||
public static WorldEditPlugin worldEdit =
|
||||
null;
|
||||
/**
|
||||
* BarAPI object
|
||||
*/
|
||||
public static BarAPI barAPI = null;
|
||||
public static BarAPI barAPI =
|
||||
null;
|
||||
/**
|
||||
* World Guard
|
||||
* World Guard Object
|
||||
*/
|
||||
public static WorldGuardPlugin worldGuard = null;
|
||||
public static WorldGuardListener worldGuardListener = null;
|
||||
public static Economy economy;
|
||||
public static boolean useEconomy = false;
|
||||
public static HashMap<Material, String> booleanFlags = new HashMap<>();
|
||||
public static WorldGuardPlugin worldGuard =
|
||||
null;
|
||||
/**
|
||||
* World Guard Listener
|
||||
*/
|
||||
public static WorldGuardListener worldGuardListener =
|
||||
null;
|
||||
/**
|
||||
* Economy Object (vault)
|
||||
*/
|
||||
public static Economy
|
||||
economy;
|
||||
/**
|
||||
* Use Economy?
|
||||
*/
|
||||
public static boolean useEconomy =
|
||||
false;
|
||||
/**
|
||||
* Boolean Flags (material)
|
||||
*/
|
||||
public static HashMap<Material, String> booleanFlags =
|
||||
new HashMap<>();
|
||||
|
||||
/**
|
||||
* Initialize the material flags
|
||||
*/
|
||||
static {
|
||||
booleanFlags.put(Material.WOODEN_DOOR, "wooden_door");
|
||||
booleanFlags.put(Material.IRON_DOOR, "iron_door");
|
||||
@ -120,6 +146,7 @@ public class PlotMain extends JavaPlugin {
|
||||
booleanFlags.put(Material.DISPENSER, "dispenser");
|
||||
booleanFlags.put(Material.DROPPER, "dropper");
|
||||
}
|
||||
|
||||
/**
|
||||
* The UUID Saver
|
||||
*/
|
||||
@ -137,8 +164,14 @@ public class PlotMain extends JavaPlugin {
|
||||
* All loaded plot worlds
|
||||
*/
|
||||
private static HashMap<String, PlotWorld> worlds = new HashMap<>();
|
||||
/**
|
||||
* All world managers
|
||||
*/
|
||||
private static HashMap<String, PlotManager> managers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Check for expired plots
|
||||
*/
|
||||
public static void checkForExpiredPlots() {
|
||||
final JavaPlugin plugin = PlotMain.getMain();
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@ -1252,15 +1285,15 @@ public class PlotMain extends JavaPlugin {
|
||||
return plots;
|
||||
}
|
||||
|
||||
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||
PlotMain.plots = plots;
|
||||
}
|
||||
|
||||
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||
PlotMain.plots = new LinkedHashMap<>(plots);
|
||||
// PlotMain.plots.putAll(plots);
|
||||
}
|
||||
|
||||
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||
PlotMain.plots = plots;
|
||||
}
|
||||
|
||||
/**
|
||||
* !!WorldGeneration!!
|
||||
*/
|
||||
@ -1325,6 +1358,9 @@ public class PlotMain extends JavaPlugin {
|
||||
} catch (final Exception e) {
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
} else {
|
||||
// We should at least make them feel bad.
|
||||
sendConsoleSenderMessage("Using metrics will allow us to improve the plugin\nPlease consider it :)");
|
||||
}
|
||||
|
||||
// Kill mobs on roads?
|
||||
@ -1337,6 +1373,7 @@ public class PlotMain extends JavaPlugin {
|
||||
Broadcast(C.ENABLED);
|
||||
}
|
||||
|
||||
// Add tables to this one, if we create more :D
|
||||
final String[] tables = new String[]{
|
||||
"plot_trusted", "plot_ratings", "plot_comments"
|
||||
};
|
||||
@ -1415,6 +1452,10 @@ public class PlotMain extends JavaPlugin {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
// We should not start the plugin if
|
||||
// plotme is present. Maybe do this
|
||||
// earlier, and no register any commands
|
||||
// nor listeners, just run the converter?
|
||||
if (getServer().getPluginManager().getPlugin("PlotMe") != null) {
|
||||
try {
|
||||
new PlotMeConverter(this).runAsync();
|
||||
|
@ -21,22 +21,6 @@
|
||||
|
||||
package com.intellectualcrafters.plot.database;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.intellectualcrafters.plot.PlotHomePosition;
|
||||
import com.intellectualcrafters.plot.PlotId;
|
||||
@ -45,45 +29,73 @@ import com.intellectualcrafters.plot.generator.WorldGenerator;
|
||||
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.WorldCreator;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created 2014-08-17 for ${PROJECT_NAME}
|
||||
* Created 2014-08-17 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlotMeConverter {
|
||||
|
||||
/**
|
||||
* PlotMain Object
|
||||
*/
|
||||
private final PlotMain plugin;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin Plugin Used to run the converter
|
||||
*/
|
||||
public PlotMeConverter(final PlotMain plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private void sendMessage(String message) {
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: " + message);
|
||||
}
|
||||
|
||||
public void runAsync() throws Exception {
|
||||
// We have to make it wait a couple of seconds
|
||||
Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has started");
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Caching playerdata...");
|
||||
final ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = new ArrayList<com.intellectualcrafters.plot.Plot>();
|
||||
final boolean online = Bukkit.getServer().getOnlineMode();
|
||||
|
||||
final Plugin plotMePlugin = Bukkit.getPluginManager().getPlugin("PlotMe");
|
||||
final FileConfiguration plotConfig = plotMePlugin.getConfig();
|
||||
|
||||
final Set<String> worlds = new HashSet<String>();
|
||||
|
||||
sendMessage("&7Conversion has started");
|
||||
sendMessage("7Caching playerdata...");
|
||||
final ArrayList<com.intellectualcrafters.plot.Plot> createdPlots =
|
||||
new ArrayList<>();
|
||||
// Online Mode
|
||||
final boolean online =
|
||||
Bukkit.getServer().getOnlineMode();
|
||||
// PlotMe Plugin
|
||||
final Plugin plotMePlugin =
|
||||
Bukkit.getPluginManager().getPlugin("PlotMe");
|
||||
// PlotMe Configuration
|
||||
final FileConfiguration plotConfig =
|
||||
plotMePlugin.getConfig();
|
||||
// Plot Worlds
|
||||
final Set<String> worlds = new HashSet<>();
|
||||
// Loop through the worlds
|
||||
int duplicate;
|
||||
HashMap<String, Plot> plots;
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
int duplicate = 0;
|
||||
final HashMap<String, Plot> plots = PlotManager.getPlots(world);
|
||||
duplicate = 0;
|
||||
plots = PlotManager.getPlots(world);
|
||||
if (plots != null) {
|
||||
|
||||
worlds.add(world.getName());
|
||||
|
||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting configuration for world '" + world.getName() + "'...");
|
||||
|
||||
sendMessage("&7Converting configuration for world '" + world.getName() + "'...");
|
||||
try {
|
||||
|
||||
final Integer pathwidth = plotConfig.getInt("worlds." + world.getName() + ".PathWidth"); //
|
||||
PlotMain.config.set("worlds." + world.getName() + ".road.width", pathwidth);
|
||||
|
||||
@ -94,10 +106,10 @@ public class PlotMeConverter {
|
||||
PlotMain.config.set("worlds." + world.getName() + ".wall.block", wallblock);
|
||||
|
||||
final 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(floor));
|
||||
|
||||
final 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(filling));
|
||||
|
||||
final String road = plotConfig.getString("worlds." + world.getName() + ".RoadMainBlockId");
|
||||
PlotMain.config.set("worlds." + world.getName() + ".road.block", road);
|
||||
@ -110,24 +122,23 @@ public class PlotMeConverter {
|
||||
|
||||
final Boolean auto_link = plotConfig.getBoolean("worlds." + world.getName() + ".AutoLinkPlots"); //
|
||||
PlotMain.config.set("worlds." + world.getName() + ".plot.auto_merge", auto_link);
|
||||
|
||||
} catch (final Exception e) {
|
||||
PlotMain.sendConsoleSenderMessage(" - Failed to save configuration for world '" + world.getName() + "'. This will need to be done using the setup command or manually.");
|
||||
sendMessage("&c-- &lFailed to save configuration for world '" + world.getName() + "'\nThis 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() + "'");
|
||||
|
||||
sendMessage("&7Processing '" + plots.size() + "' plots for world '" + world.getName() + "'");
|
||||
ArrayList<UUID> psAdded, psTrusted, psDenied;
|
||||
for (final Plot plot : plots.values()) {
|
||||
final ArrayList<UUID> psAdded = new ArrayList<>();
|
||||
final ArrayList<UUID> psTrusted = new ArrayList<>();
|
||||
final ArrayList<UUID> psDenied = new ArrayList<>();
|
||||
psAdded = new ArrayList<>();
|
||||
psTrusted = new ArrayList<>();
|
||||
psDenied = new ArrayList<>();
|
||||
if (world == null) {
|
||||
world = Bukkit.getWorld("world");
|
||||
}
|
||||
try {
|
||||
if (online) {
|
||||
PlayerList denied = null;
|
||||
PlayerList added = null;
|
||||
PlayerList denied;
|
||||
PlayerList added;
|
||||
final Field fAdded = plot.getClass().getDeclaredField("allowed");
|
||||
final Field fDenied = plot.getClass().getDeclaredField("denied");
|
||||
fAdded.setAccessible(true);
|
||||
@ -175,15 +186,14 @@ public class PlotMeConverter {
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
|
||||
// Okay, this is evil.
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
final PlotId id = 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;
|
||||
if (online) {
|
||||
pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psTrusted, psDenied,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user