PlotSquared/Sponge/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java

82 lines
3.3 KiB
Java
Raw Normal View History

2015-08-02 21:25:41 +02:00
package com.plotsquared.sponge;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.ConfigurationNode;
2016-02-21 05:07:04 +01:00
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
2015-08-02 21:25:41 +02:00
import com.intellectualcrafters.plot.generator.PlotGenerator;
2016-02-10 19:59:51 +01:00
import com.intellectualcrafters.plot.object.PlotArea;
2015-08-02 21:25:41 +02:00
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.plotsquared.sponge.generator.SpongePlotGenerator;
import com.plotsquared.sponge.util.SpongeUtil;
2016-02-21 05:07:04 +01:00
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.WorldGenerator;
import java.io.IOException;
import java.util.Map;
2015-08-02 21:25:41 +02:00
2015-09-13 06:04:31 +02:00
public class SpongeSetupUtils extends SetupUtils {
2015-08-02 21:25:41 +02:00
@Override
2015-09-13 06:04:31 +02:00
public void updateGenerators() {
if (!SetupUtils.generators.isEmpty()) {
2015-09-13 06:04:31 +02:00
return;
}
SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen()));
throw new UnsupportedOperationException("TODO FETCH EXTERNAL WorldGenerationModifiers");
2015-08-02 21:25:41 +02:00
}
2015-09-13 06:04:31 +02:00
2015-08-02 21:25:41 +02:00
@Override
2016-06-02 17:38:47 +02:00
public String getGenerator(final PlotArea plotArea) {
if (SetupUtils.generators.isEmpty()) {
2015-08-02 21:25:41 +02:00
updateGenerators();
}
2016-06-02 17:38:47 +02:00
final World world = SpongeUtil.getWorld(plotArea.worldname);
2015-09-13 06:04:31 +02:00
if (world == null) {
return null;
}
2015-09-11 12:09:22 +02:00
final WorldGenerator generator = world.getWorldGenerator();
2016-02-21 05:07:04 +01:00
if (!(generator instanceof SpongePlotGenerator)) {
return null;
}
for (final Map.Entry<String, GeneratorWrapper<?>> entry : generators.entrySet()) {
GeneratorWrapper<?> current = entry.getValue();
if (current.equals(generator)) {
return entry.getKey();
}
}
return null;
2015-08-02 21:25:41 +02:00
}
2015-09-13 06:04:31 +02:00
2015-08-02 21:25:41 +02:00
@Override
2015-09-13 06:04:31 +02:00
public String setupWorld(final SetupObject object) {
2015-08-02 21:25:41 +02:00
SetupUtils.manager.updateGenerators();
final ConfigurationNode[] steps = object.step;
final String world = object.world;
2015-09-13 06:04:31 +02:00
for (final ConfigurationNode step : steps) {
2015-08-02 21:25:41 +02:00
PS.get().config.set("worlds." + world + "." + step.getConstant(), step.getValue());
}
2015-09-13 06:04:31 +02:00
if (object.type != 0) {
2016-04-21 20:02:49 +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-09-13 06:04:31 +02:00
if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) {
2016-04-21 20:02:49 +02:00
PS.get().config.set("worlds." + world + ".generator.init", object.setupGenerator);
2015-08-02 21:25:41 +02:00
}
2015-09-11 12:09:22 +02:00
final PlotGenerator<WorldGenerator> gen = (PlotGenerator<WorldGenerator>) generators.get(object.setupGenerator);
2015-09-13 06:04:31 +02:00
if ((gen != null) && (gen.generator instanceof SpongePlotGenerator)) {
2015-08-02 21:25:41 +02:00
object.setupGenerator = null;
}
}
2015-09-13 06:04:31 +02:00
try {
2015-08-02 21:25:41 +02:00
PS.get().config.save(PS.get().configFile);
2015-09-13 06:04:31 +02:00
} catch (final IOException e) {
2015-08-02 21:25:41 +02:00
e.printStackTrace();
}
// TODO FIXME
throw new UnsupportedOperationException("NOT IMPLEMENTED YET: Create a new world here");
// return object.world;
2015-08-02 21:25:41 +02:00
}
}