mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Nukkit generator fixes
This commit is contained in:
parent
e4d7270c28
commit
6074fc8033
@ -213,8 +213,6 @@ public class LikePlotMeConverter {
|
|||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
ignored.printStackTrace();
|
ignored.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
System.out.println("FILE NOT EXIST " + plotmeDgFile.getAbsolutePath());
|
|
||||||
}
|
}
|
||||||
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||||
String world = entry.getKey();
|
String world = entry.getKey();
|
||||||
|
@ -52,7 +52,10 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
|||||||
* any reason.
|
* any reason.
|
||||||
*/
|
*/
|
||||||
public void save(File file) throws IOException {
|
public void save(File file) throws IOException {
|
||||||
file.getParentFile().mkdirs();
|
File parent = file.getParentFile();
|
||||||
|
if (parent != null) {
|
||||||
|
parent.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
String data = saveToString();
|
String data = saveToString();
|
||||||
|
|
||||||
|
@ -10,9 +10,11 @@ import cn.nukkit.level.generator.Generator;
|
|||||||
import cn.nukkit.metadata.MetadataValue;
|
import cn.nukkit.metadata.MetadataValue;
|
||||||
import cn.nukkit.plugin.Plugin;
|
import cn.nukkit.plugin.Plugin;
|
||||||
import cn.nukkit.plugin.PluginBase;
|
import cn.nukkit.plugin.PluginBase;
|
||||||
|
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||||
import com.intellectualcrafters.plot.IPlotMain;
|
import com.intellectualcrafters.plot.IPlotMain;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
|
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
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.PlotManager;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||||
|
import com.intellectualcrafters.plot.object.SetupObject;
|
||||||
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
|
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
|
||||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
import com.intellectualcrafters.plot.util.AbstractTitle;
|
||||||
import com.intellectualcrafters.plot.util.ChatManager;
|
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);
|
Class<? extends Generator> gen = Generator.getGenerator(name);
|
||||||
if (gen != null) {
|
if (gen != null) {
|
||||||
Generator instance = gen.getConstructor(Map.class).newInstance(map);
|
Generator instance = gen.getConstructor(Map.class).newInstance(map);
|
||||||
if (GeneratorWrapper.class.isAssignableFrom(gen.getClass())) {
|
if (instance instanceof GeneratorWrapper) {
|
||||||
return (GeneratorWrapper<?>) instance;
|
return (GeneratorWrapper<?>) instance;
|
||||||
}
|
}
|
||||||
map.put("generator", instance);
|
map.put("generator", instance);
|
||||||
@ -346,7 +349,42 @@ public final class NukkitMain extends PluginBase implements Listener, IPlotMain
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGenerator(String worldName) {
|
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) {
|
private void setGenerator(Level level, Generator generator) {
|
||||||
|
@ -6,7 +6,6 @@ import cn.nukkit.math.NukkitRandom;
|
|||||||
import cn.nukkit.math.Vector3;
|
import cn.nukkit.math.Vector3;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
|
||||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.intellectualcrafters.plot.object.PlotArea;
|
||||||
@ -43,10 +42,10 @@ public class NukkitPlotGenerator extends Generator implements GeneratorWrapper<G
|
|||||||
if (map.containsKey("generator")) {
|
if (map.containsKey("generator")) {
|
||||||
final Generator cg = (Generator) map.get("generator");
|
final Generator cg = (Generator) map.get("generator");
|
||||||
if (cg instanceof NukkitPlotGenerator) {
|
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;
|
this.full = false;
|
||||||
PS.debug("BukkitPlotGenerator does not fully support: " + cg);
|
PS.debug("NukkitPlotGenerator does not fully support: " + cg);
|
||||||
this.platformGenerator = cg;
|
this.platformGenerator = cg;
|
||||||
this.plotGenerator = new IndependentPlotGenerator() {
|
this.plotGenerator = new IndependentPlotGenerator() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,9 +119,21 @@ public class NukkitSetupUtils extends SetupUtils {
|
|||||||
HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("world", object.world);
|
map.put("world", object.world);
|
||||||
map.put("plot-generator", PS.get().IMP.getDefaultGenerator());
|
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 {
|
} 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;
|
return object.world;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user