Nukkit generator fixes

This commit is contained in:
Jesse Boyd 2016-09-30 14:26:20 +10:00
parent e4d7270c28
commit 6074fc8033
5 changed files with 60 additions and 10 deletions

View File

@ -213,8 +213,6 @@ public class LikePlotMeConverter {
} catch (IOException ignored) {
ignored.printStackTrace();
}
} else {
System.out.println("FILE NOT EXIST " + plotmeDgFile.getAbsolutePath());
}
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
String world = entry.getKey();

View File

@ -52,7 +52,10 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* any reason.
*/
public void save(File file) throws IOException {
file.getParentFile().mkdirs();
File parent = file.getParentFile();
if (parent != null) {
parent.mkdirs();
}
String data = saveToString();

View File

@ -10,9 +10,11 @@ import cn.nukkit.level.generator.Generator;
import cn.nukkit.metadata.MetadataValue;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.plugin.PluginBase;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.IPlotMain;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
@ -24,6 +26,7 @@ import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
@ -278,7 +281,7 @@ public final class NukkitMain extends PluginBase implements Listener, IPlotMain
Class<? extends Generator> gen = Generator.getGenerator(name);
if (gen != null) {
Generator instance = gen.getConstructor(Map.class).newInstance(map);
if (GeneratorWrapper.class.isAssignableFrom(gen.getClass())) {
if (instance instanceof GeneratorWrapper) {
return (GeneratorWrapper<?>) instance;
}
map.put("generator", instance);
@ -346,7 +349,42 @@ public final class NukkitMain extends PluginBase implements Listener, IPlotMain
@Override
public void setGenerator(String worldName) {
throw new UnsupportedOperationException("Not implemented: setGenerator");
Level world = getServer().getLevelByName(worldName);
if (world == null) {
// create world
ConfigurationSection worldConfig = PS.get().worlds.getConfigurationSection("worlds." + worldName);
String manager = worldConfig.getString("generator.plugin", getPluginName());
SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = worldConfig.getString("generator.init", manager);
setup.type = worldConfig.getInt("generator.type");
setup.terrain = worldConfig.getInt("generator.terrain");
setup.step = new ConfigurationNode[0];
setup.world = worldName;
SetupUtils.manager.setupWorld(setup);
world = getServer().getLevelByName(worldName);
} else {
HashMap<String, Object> map = new HashMap<>();
map.put("world", world.getName());
map.put("plot-generator", PS.get().IMP.getDefaultGenerator());
setGenerator(world, new NukkitPlotGenerator(map));
}
if (world != null) {
try {
Field fieldInstance = Level.class.getDeclaredField("generatorInstance");
fieldInstance.setAccessible(true);
Generator gen = (Generator) fieldInstance.get(world);
if (gen instanceof NukkitPlotGenerator) {
PS.get().loadWorld(worldName, (NukkitPlotGenerator) gen);
} else if (gen instanceof GeneratorWrapper) {
PS.get().loadWorld(worldName, (GeneratorWrapper) gen);
} else if (PS.get().worlds.contains("worlds." + worldName)) {
PS.get().loadWorld(worldName, null);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
private void setGenerator(Level level, Generator generator) {

View File

@ -6,7 +6,6 @@ import cn.nukkit.math.NukkitRandom;
import cn.nukkit.math.Vector3;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotArea;
@ -43,10 +42,10 @@ public class NukkitPlotGenerator extends Generator implements GeneratorWrapper<G
if (map.containsKey("generator")) {
final Generator cg = (Generator) map.get("generator");
if (cg instanceof NukkitPlotGenerator) {
throw new IllegalArgumentException("Generator: " + cg.getClass().getName() + " is already a BukkitPlotGenerator!");
throw new IllegalArgumentException("Generator: " + cg.getClass().getName() + " is already a NukkitPlotGenerator!");
}
this.full = false;
PS.debug("BukkitPlotGenerator does not fully support: " + cg);
PS.debug("NukkitPlotGenerator does not fully support: " + cg);
this.platformGenerator = cg;
this.plotGenerator = new IndependentPlotGenerator() {
@Override

View File

@ -119,9 +119,21 @@ public class NukkitSetupUtils extends SetupUtils {
HashMap<String, Object> map = new HashMap<>();
map.put("world", object.world);
map.put("plot-generator", PS.get().IMP.getDefaultGenerator());
plugin.getServer().generateLevel(object.world, object.world.hashCode(), NukkitPlotGenerator.class, map);
if (!plugin.getServer().generateLevel(object.world, object.world.hashCode(), NukkitPlotGenerator.class, map)) {
plugin.getServer().loadLevel(object.world);
}
try {
File nukkitFile = new File("nukkit.yml");
YamlConfiguration nukkitYml = YamlConfiguration.loadConfiguration(nukkitFile);
nukkitYml.set("worlds." + object.world + ".generator", object.setupGenerator);
nukkitYml.save(nukkitFile);
} catch (Throwable e) {
e.printStackTrace();
}
} else {
plugin.getServer().generateLevel(object.world, object.world.hashCode());
if (!plugin.getServer().generateLevel(object.world, object.world.hashCode())) {
plugin.getServer().loadLevel(object.world);
}
}
return object.world;
}