2015-07-30 19:24:01 +02:00
|
|
|
package com.plotsquared.bukkit.util;
|
2015-02-22 14:12:32 +01:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Map.Entry;
|
2015-07-28 13:38:49 +02:00
|
|
|
|
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-30 16:25:16 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
|
|
|
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
|
|
|
import com.intellectualcrafters.plot.generator.PlotGenerator;
|
2015-08-02 21:25:41 +02:00
|
|
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
|
|
|
import com.intellectualcrafters.plot.object.SetupObject;
|
|
|
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
2015-08-02 21:25:41 +02:00
|
|
|
import com.plotsquared.bukkit.generator.AugmentedPopulator;
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper;
|
|
|
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
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-07-28 13:38:49 +02:00
|
|
|
SetupUtils.generators.put(name, new BukkitGeneratorWrapper("CheckingPlotSquaredGenerator", generator));
|
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-07-28 13:38:49 +02:00
|
|
|
PlotGenerator<ChunkGenerator> gen = (PlotGenerator<ChunkGenerator>) generators.get(object.setupGenerator);
|
2015-07-30 22:09:28 +02:00
|
|
|
if (gen != null && gen.generator instanceof BukkitPlotGenerator) {
|
2015-05-15 18:23:59 +02:00
|
|
|
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();
|
2015-07-26 19:00:09 +02:00
|
|
|
if (!(generator instanceof BukkitPlotGenerator)) {
|
2015-04-02 05:52:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
2015-07-28 13:38:49 +02:00
|
|
|
for (Entry<String, PlotGenerator<?>> entry : generators.entrySet()) {
|
|
|
|
if (entry.getValue().generator.getClass().getName().equals(generator.getClass().getName())) {
|
2015-04-02 05:52:14 +02:00
|
|
|
return entry.getKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-08-02 21:25:41 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removePopulator(String world, PlotCluster cluster) {
|
|
|
|
AugmentedPopulator.removePopulator(world, cluster);
|
|
|
|
}
|
2015-02-22 14:12:32 +01:00
|
|
|
}
|