2015-02-22 14:12:32 +01:00
|
|
|
package com.intellectualcrafters.plot.util.bukkit;
|
|
|
|
|
2015-07-05 17:44:10 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
2015-02-22 14:12:32 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.World.Environment;
|
|
|
|
import org.bukkit.WorldCreator;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
|
|
|
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotGenerator;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
|
|
|
import com.intellectualcrafters.plot.object.SetupObject;
|
|
|
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
2015-02-22 14:12:32 +01:00
|
|
|
|
|
|
|
public class BukkitSetupUtils extends SetupUtils {
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-02-22 14:12:32 +01:00
|
|
|
@Override
|
|
|
|
public void updateGenerators() {
|
|
|
|
if (SetupUtils.generators.size() > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final String testWorld = "CheckingPlotSquaredGenerator";
|
|
|
|
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
|
|
|
if (plugin.isEnabled()) {
|
|
|
|
final ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
|
|
|
if (generator != null) {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().removePlotWorld(testWorld);
|
2015-02-22 14:12:32 +01:00
|
|
|
final String name = plugin.getDescription().getName();
|
2015-04-21 14:48:18 +02:00
|
|
|
// final PlotGenerator pgen = (PlotGenerator) generator;
|
2015-04-02 02:56:34 +02:00
|
|
|
// if (pgen.getPlotManager() instanceof SquarePlotManager) {
|
2015-04-21 14:48:18 +02:00
|
|
|
SetupUtils.generators.put(name, generator);
|
2015-04-02 02:56:34 +02:00
|
|
|
// }
|
2015-04-21 14:48:18 +02:00
|
|
|
// }
|
2015-02-22 14:12:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-02-22 14:12:32 +01:00
|
|
|
@Override
|
|
|
|
public String setupWorld(final SetupObject object) {
|
2015-04-21 16:03:27 +02:00
|
|
|
SetupUtils.manager.updateGenerators();
|
2015-02-22 14:12:32 +01:00
|
|
|
final ConfigurationNode[] steps = object.step;
|
|
|
|
final String world = object.world;
|
|
|
|
for (final ConfigurationNode step : steps) {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().config.set("worlds." + world + "." + step.getConstant(), step.getValue());
|
2015-02-22 14:12:32 +01:00
|
|
|
}
|
|
|
|
if (object.type != 0) {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
|
|
|
|
PS.get().config.set("worlds." + world + "." + "generator.terrain", object.terrain);
|
|
|
|
PS.get().config.set("worlds." + world + "." + "generator.plugin", object.plotManager);
|
2015-04-21 14:48:18 +02:00
|
|
|
if (object.setupGenerator != null && !object.setupGenerator.equals(object.plotManager)) {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator);
|
2015-04-21 14:48:18 +02:00
|
|
|
}
|
2015-05-15 18:23:59 +02:00
|
|
|
ChunkGenerator gen = generators.get(object.setupGenerator);
|
|
|
|
if (gen instanceof PlotGenerator) {
|
|
|
|
object.setupGenerator = null;
|
|
|
|
}
|
2015-02-22 14:12:32 +01:00
|
|
|
}
|
|
|
|
try {
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().config.save(PS.get().configFile);
|
2015-02-22 14:12:32 +01:00
|
|
|
} catch (final IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2015-04-21 14:48:18 +02:00
|
|
|
if (object.setupGenerator != null) {
|
2015-02-22 14:12:32 +01:00
|
|
|
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
2015-04-21 14:48:18 +02:00
|
|
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.setupGenerator);
|
2015-02-22 14:12:32 +01:00
|
|
|
} else {
|
|
|
|
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
2015-04-21 14:48:18 +02:00
|
|
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator);
|
2015-02-22 14:12:32 +01:00
|
|
|
} else {
|
|
|
|
final WorldCreator wc = new WorldCreator(object.world);
|
2015-04-21 14:48:18 +02:00
|
|
|
wc.generator(object.setupGenerator);
|
2015-02-22 14:12:32 +01:00
|
|
|
wc.environment(Environment.NORMAL);
|
|
|
|
Bukkit.createWorld(wc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
|
|
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal");
|
|
|
|
} else {
|
|
|
|
if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
|
|
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
|
|
|
|
} else {
|
|
|
|
Bukkit.createWorld(new WorldCreator(object.world).environment(World.Environment.NORMAL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return object.world;
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-04-02 05:52:14 +02:00
|
|
|
@Override
|
|
|
|
public String getGenerator(PlotWorld plotworld) {
|
|
|
|
if (SetupUtils.generators.size() == 0) {
|
|
|
|
updateGenerators();
|
|
|
|
}
|
|
|
|
World world = Bukkit.getWorld(plotworld.worldname);
|
|
|
|
if (world == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
ChunkGenerator generator = world.getGenerator();
|
|
|
|
if (!(generator instanceof PlotGenerator)) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-04-21 14:48:18 +02:00
|
|
|
for (Entry<String, ChunkGenerator> entry : generators.entrySet()) {
|
2015-04-02 05:52:14 +02:00
|
|
|
if (entry.getValue().getClass().getName().equals(generator.getClass().getName())) {
|
|
|
|
return entry.getKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-02-22 14:12:32 +01:00
|
|
|
}
|