Added support for external generators

- PlotSquared still handles the Plot IDs and layout, so these external
generators would need to be compatible with PlotSquared
- Server owners would still need to configure the PlotWorld settings in
the settings.yml
- Alternatively, other plugins could add their own PlotWorld class using
the existing API methods. In that case these new methods do not apply.
This commit is contained in:
boy0001 2014-10-04 14:11:31 +10:00
parent 1511db8d12
commit 34f0428d06
4 changed files with 92 additions and 18 deletions

View File

@ -202,7 +202,7 @@ public class PlotMain extends JavaPlugin {
*/
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldname, String id) {
return new WorldGenerator(worldname);
return new PlotSquaredGen(worldname);
}
@SuppressWarnings("deprecation")
@ -1078,16 +1078,57 @@ public class PlotMain extends JavaPlugin {
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.MAX_PLOTS = config.getInt("max_plots");
for (String node : config.getConfigurationSection("worlds").getKeys(false)) {
World world = Bukkit.getWorld(node);
if (world == null) {
Logger.add(LogLevel.WARNING, "World '" + node + "' in settings.yml does not exist (case sensitive)");
} else {
ChunkGenerator gen = world.getGenerator();
if ((gen == null) || !gen.toString().equals("PlotSquared")) {
Logger.add(LogLevel.WARNING, "World '" + node + "' in settings.yml is not using PlotSquared generator");
}
/**
* Adds an external world as a recognized PlotSquared world
* - The PlotWorld class created is based off the configuration in the settings.yml
* - Do not use this method unless the required world is preconfigured in the settings.yml
*
* @param world
*/
public static void loadWorld(World world) {
if (world == null) {
return;
}
Set<String> worlds = config.getConfigurationSection("worlds").getKeys(false);
if (worlds.contains(world.getName())) {
ChunkGenerator gen = world.getGenerator();
if ((gen == null) || !gen.getClass().getSimpleName().equals("PlotSquaredGen")) {
sendConsoleSenderMessage("&cWorld '" + world.getName() + "' in settings.yml is not using PlotSquared generator!");
PlotWorld plotworld = new PlotWorld();
try {
plotworld.AUTO_MERGE = config.getBoolean("worlds." + world + ".plot.auto_merge");
plotworld.PLOT_HEIGHT = config.getInt("worlds." + world + ".plot.height");
plotworld.PLOT_WIDTH = config.getInt("worlds." + world + ".plot.size");
plotworld.PLOT_BIOME = config.getString("worlds." + world + ".plot.biome");
plotworld.MAIN_BLOCK = config.getStringList("worlds." + world + ".plot.filling").toArray(new String[0]);
plotworld.TOP_BLOCK = config.getStringList("worlds." + world + ".plot.floor").toArray(new String[0]);
plotworld.WALL_BLOCK = config.getString("worlds." + world + ".wall.block");
plotworld.ROAD_WIDTH = config.getInt("worlds." + world + ".road.width");
plotworld.ROAD_HEIGHT = config.getInt("worlds." + world + ".road.height");
plotworld.ROAD_STRIPES_ENABLED = config.getBoolean("worlds." + world + ".road.enable_stripes");
plotworld.ROAD_BLOCK = config.getString("worlds." + world + ".road.block");
plotworld.ROAD_STRIPES = config.getString("worlds." + world + ".road.stripes");
plotworld.WALL_FILLING = config.getString("worlds." + world + ".wall.filling");
plotworld.WALL_HEIGHT = config.getInt("worlds." + world + ".wall.height");
plotworld.PLOT_CHAT = config.getBoolean("worlds." + world + ".plot_chat");
plotworld.SCHEMATIC_ON_CLAIM = config.getBoolean("worlds." + world + ".schematic.on_claim");
plotworld.SCHEMATIC_FILE = config.getString("worlds." + world + ".schematic.file");
plotworld.SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("worlds." + world + ".schematic.specify_on_claim");
plotworld.SCHEMATICS = config.getStringList("worlds." + world + ".schematic.schematics");
plotworld.USE_ECONOMY = config.getBoolean("worlds." + world + ".economy.use");
plotworld.PLOT_PRICE = config.getDouble("worlds." + world + ".economy.prices.claim");
plotworld.MERGE_PRICE = config.getDouble("worlds." + world + ".economy.prices.merge");
plotworld.PLOT_CHAT = config.getBoolean("worlds." + world + ".chat.enabled");
}
catch (Exception e) {
sendConsoleSenderMessage("&cThe configuration for '"+world.getName()+"' is not configured incorrectly. Please see the below stacktrace for more information:");
e.printStackTrace();
}
addPlotWorld(world.getName(), plotworld);
}
}
}

View File

@ -42,7 +42,7 @@ import org.bukkit.generator.ChunkGenerator;
*
*/
@SuppressWarnings("deprecation")
public class WorldGenerator extends ChunkGenerator {
public class PlotSquaredGen extends ChunkGenerator {
private long state;
public final long nextLong() {
@ -89,7 +89,7 @@ public class WorldGenerator extends ChunkGenerator {
return Short.parseShort(block);
}
public WorldGenerator(String world) {
public PlotSquaredGen(String world) {
YamlConfiguration config = PlotMain.config;
this.plotworld = new PlotWorld();

View File

@ -1,5 +1,7 @@
package com.intellectualcrafters.plot.database;
import java.io.File;
import java.io.FilenameFilter;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -38,13 +40,38 @@ public class PlotMeConverter {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has started");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has started");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Caching playerdata...");
ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = new ArrayList<com.intellectualcrafters.plot.Plot>();
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
if (!Bukkit.getServer().getOnlineMode()) {
File playersFolder = new File("world" + File.separator + "playerdata");
String[] dat = playersFolder.list(new FilenameFilter() {
public boolean accept(File f, String s) {
return s.endsWith(".dat");
}
});
for (String current : dat) {
UUID uuid = null;
try {
uuid = UUID.fromString(current.replaceAll(".dat$", ""));
}
catch (Exception e) {
}
if (uuid!=null) {
String name = Bukkit.getOfflinePlayer(uuid).getName();
if (name!=null) {
uuidMap.put(name, uuid);
}
}
}
}
for (World world : Bukkit.getWorlds()) {
HashMap<String, Plot> plots = PlotManager.getPlots(world);
if (plots != null) {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Processing '"+plots.size()+"' plots for world '"+world.getName()+"'");
// TODO generate configuration based on PlotMe config
// - Plugin doesn't display a message if database is not
// setup at all
@ -67,7 +94,7 @@ public class PlotMeConverter {
// e.printStackTrace();
// }
PlotMain.sendConsoleSenderMessage("Converting " + plots.size() + " plots for '" + world.toString() + "'...");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting " + plots.size() + " plots for '" + world.toString() + "'...");
for (Plot plot : plots.values()) {
ArrayList<UUID> psAdded = new ArrayList<>();
ArrayList<UUID> psTrusted = new ArrayList<>();
@ -169,12 +196,12 @@ public class PlotMeConverter {
}
}
}
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Creating plot DB");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating plot DB");
DBFunc.createPlots(createdPlots);
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Creating settings/helpers DB");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating settings/helpers DB");
DBFunc.createAllSettingsAndHelpers(createdPlots);
stream.close();
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has finished");
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

View File

@ -60,6 +60,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldLoadEvent;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
@ -120,6 +121,11 @@ public class PlayerEvents implements Listener {
return new Plot(id, null, Biome.FOREST, new ArrayList<UUID>(), new ArrayList<UUID>(), loc.getWorld().getName());
}
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
PlotMain.loadWorld(event.getWorld());
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (!event.getPlayer().hasPlayedBefore()) {