mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Some optimization to PlotMeConverter.
This commit is contained in:
parent
07895be660
commit
38c7edbddd
@ -84,7 +84,11 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* Contains storage options
|
* Contains storage options
|
||||||
*/
|
*/
|
||||||
public static YamlConfiguration storage;
|
public static YamlConfiguration storage;
|
||||||
public static int storage_ver = 1;
|
/**
|
||||||
|
* Storage version
|
||||||
|
*/
|
||||||
|
public static int storage_ver =
|
||||||
|
1;
|
||||||
/**
|
/**
|
||||||
* MySQL Connection
|
* MySQL Connection
|
||||||
*/
|
*/
|
||||||
@ -92,20 +96,42 @@ public class PlotMain extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* WorldEdit object
|
* WorldEdit object
|
||||||
*/
|
*/
|
||||||
public static WorldEditPlugin worldEdit = null;
|
public static WorldEditPlugin worldEdit =
|
||||||
|
null;
|
||||||
/**
|
/**
|
||||||
* BarAPI object
|
* BarAPI object
|
||||||
*/
|
*/
|
||||||
public static BarAPI barAPI = null;
|
public static BarAPI barAPI =
|
||||||
|
null;
|
||||||
/**
|
/**
|
||||||
* World Guard
|
* World Guard Object
|
||||||
*/
|
*/
|
||||||
public static WorldGuardPlugin worldGuard = null;
|
public static WorldGuardPlugin worldGuard =
|
||||||
public static WorldGuardListener worldGuardListener = null;
|
null;
|
||||||
public static Economy economy;
|
/**
|
||||||
public static boolean useEconomy = false;
|
* World Guard Listener
|
||||||
public static HashMap<Material, String> booleanFlags = new HashMap<>();
|
*/
|
||||||
|
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 {
|
static {
|
||||||
booleanFlags.put(Material.WOODEN_DOOR, "wooden_door");
|
booleanFlags.put(Material.WOODEN_DOOR, "wooden_door");
|
||||||
booleanFlags.put(Material.IRON_DOOR, "iron_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.DISPENSER, "dispenser");
|
||||||
booleanFlags.put(Material.DROPPER, "dropper");
|
booleanFlags.put(Material.DROPPER, "dropper");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The UUID Saver
|
* The UUID Saver
|
||||||
*/
|
*/
|
||||||
@ -137,8 +164,14 @@ public class PlotMain extends JavaPlugin {
|
|||||||
* All loaded plot worlds
|
* All loaded plot worlds
|
||||||
*/
|
*/
|
||||||
private static HashMap<String, PlotWorld> worlds = new HashMap<>();
|
private static HashMap<String, PlotWorld> worlds = new HashMap<>();
|
||||||
|
/**
|
||||||
|
* All world managers
|
||||||
|
*/
|
||||||
private static HashMap<String, PlotManager> managers = new HashMap<>();
|
private static HashMap<String, PlotManager> managers = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for expired plots
|
||||||
|
*/
|
||||||
public static void checkForExpiredPlots() {
|
public static void checkForExpiredPlots() {
|
||||||
final JavaPlugin plugin = PlotMain.getMain();
|
final JavaPlugin plugin = PlotMain.getMain();
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||||
@ -1252,15 +1285,15 @@ public class PlotMain extends JavaPlugin {
|
|||||||
return plots;
|
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) {
|
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||||
PlotMain.plots = new LinkedHashMap<>(plots);
|
PlotMain.plots = new LinkedHashMap<>(plots);
|
||||||
// PlotMain.plots.putAll(plots);
|
// PlotMain.plots.putAll(plots);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
|
||||||
|
PlotMain.plots = plots;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* !!WorldGeneration!!
|
* !!WorldGeneration!!
|
||||||
*/
|
*/
|
||||||
@ -1325,6 +1358,9 @@ public class PlotMain extends JavaPlugin {
|
|||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to load up metrics.");
|
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?
|
// Kill mobs on roads?
|
||||||
@ -1337,6 +1373,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
Broadcast(C.ENABLED);
|
Broadcast(C.ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add tables to this one, if we create more :D
|
||||||
final String[] tables = new String[]{
|
final String[] tables = new String[]{
|
||||||
"plot_trusted", "plot_ratings", "plot_comments"
|
"plot_trusted", "plot_ratings", "plot_comments"
|
||||||
};
|
};
|
||||||
@ -1415,6 +1452,10 @@ public class PlotMain extends JavaPlugin {
|
|||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
return;
|
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) {
|
if (getServer().getPluginManager().getPlugin("PlotMe") != null) {
|
||||||
try {
|
try {
|
||||||
new PlotMeConverter(this).runAsync();
|
new PlotMeConverter(this).runAsync();
|
||||||
|
@ -21,22 +21,6 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot.database;
|
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.google.common.base.Charsets;
|
||||||
import com.intellectualcrafters.plot.PlotHomePosition;
|
import com.intellectualcrafters.plot.PlotHomePosition;
|
||||||
import com.intellectualcrafters.plot.PlotId;
|
import com.intellectualcrafters.plot.PlotId;
|
||||||
@ -45,45 +29,73 @@ import com.intellectualcrafters.plot.generator.WorldGenerator;
|
|||||||
import com.worldcretornica.plotme.PlayerList;
|
import com.worldcretornica.plotme.PlayerList;
|
||||||
import com.worldcretornica.plotme.Plot;
|
import com.worldcretornica.plotme.Plot;
|
||||||
import com.worldcretornica.plotme.PlotManager;
|
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 Citymonstret
|
||||||
|
* @author Empire92
|
||||||
*/
|
*/
|
||||||
public class PlotMeConverter {
|
public class PlotMeConverter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PlotMain Object
|
||||||
|
*/
|
||||||
private final PlotMain plugin;
|
private final PlotMain plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param plugin Plugin Used to run the converter
|
||||||
|
*/
|
||||||
public PlotMeConverter(final PlotMain plugin) {
|
public PlotMeConverter(final PlotMain plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendMessage(String message) {
|
||||||
|
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: " + message);
|
||||||
|
}
|
||||||
|
|
||||||
public void runAsync() throws Exception {
|
public void runAsync() throws Exception {
|
||||||
|
// We have to make it wait a couple of seconds
|
||||||
Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has started");
|
sendMessage("&7Conversion has started");
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Caching playerdata...");
|
sendMessage("7Caching playerdata...");
|
||||||
final ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = new ArrayList<com.intellectualcrafters.plot.Plot>();
|
final ArrayList<com.intellectualcrafters.plot.Plot> createdPlots =
|
||||||
final boolean online = Bukkit.getServer().getOnlineMode();
|
new ArrayList<>();
|
||||||
|
// Online Mode
|
||||||
final Plugin plotMePlugin = Bukkit.getPluginManager().getPlugin("PlotMe");
|
final boolean online =
|
||||||
final FileConfiguration plotConfig = plotMePlugin.getConfig();
|
Bukkit.getServer().getOnlineMode();
|
||||||
|
// PlotMe Plugin
|
||||||
final Set<String> worlds = new HashSet<String>();
|
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()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
int duplicate = 0;
|
duplicate = 0;
|
||||||
final HashMap<String, Plot> plots = PlotManager.getPlots(world);
|
plots = PlotManager.getPlots(world);
|
||||||
if (plots != null) {
|
if (plots != null) {
|
||||||
|
|
||||||
worlds.add(world.getName());
|
worlds.add(world.getName());
|
||||||
|
sendMessage("&7Converting configuration for world '" + world.getName() + "'...");
|
||||||
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting configuration for world '" + world.getName() + "'...");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final Integer pathwidth = plotConfig.getInt("worlds." + world.getName() + ".PathWidth"); //
|
final 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);
|
||||||
|
|
||||||
@ -94,10 +106,10 @@ public class PlotMeConverter {
|
|||||||
PlotMain.config.set("worlds." + world.getName() + ".wall.block", wallblock);
|
PlotMain.config.set("worlds." + world.getName() + ".wall.block", wallblock);
|
||||||
|
|
||||||
final String floor = plotConfig.getString("worlds." + world.getName() + ".PlotFloorBlockId"); //
|
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"); //
|
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");
|
final 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);
|
||||||
@ -110,24 +122,23 @@ public class PlotMeConverter {
|
|||||||
|
|
||||||
final Boolean auto_link = plotConfig.getBoolean("worlds." + world.getName() + ".AutoLinkPlots"); //
|
final 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 (final Exception e) {
|
} 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()) {
|
for (final Plot plot : plots.values()) {
|
||||||
final ArrayList<UUID> psAdded = new ArrayList<>();
|
psAdded = new ArrayList<>();
|
||||||
final ArrayList<UUID> psTrusted = new ArrayList<>();
|
psTrusted = new ArrayList<>();
|
||||||
final ArrayList<UUID> psDenied = new ArrayList<>();
|
psDenied = new ArrayList<>();
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
world = Bukkit.getWorld("world");
|
world = Bukkit.getWorld("world");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (online) {
|
if (online) {
|
||||||
PlayerList denied = null;
|
PlayerList denied;
|
||||||
PlayerList added = null;
|
PlayerList added;
|
||||||
final Field fAdded = plot.getClass().getDeclaredField("allowed");
|
final Field fAdded = plot.getClass().getDeclaredField("allowed");
|
||||||
final Field fDenied = plot.getClass().getDeclaredField("denied");
|
final Field fDenied = plot.getClass().getDeclaredField("denied");
|
||||||
fAdded.setAccessible(true);
|
fAdded.setAccessible(true);
|
||||||
@ -175,15 +186,14 @@ public class PlotMeConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
|
// Okay, this is evil.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
}
|
}
|
||||||
final PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
|
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) {
|
if (online) {
|
||||||
pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psTrusted, psDenied,
|
pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psTrusted, psDenied,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user