Optimize vanilla world generation*

*For single plot worlds

Reuse base world data. Instead of taking several seconds, it should now take tens of milliseconds.
This commit is contained in:
Jesse Boyd 2019-04-17 14:30:05 +10:00
parent 27eda9eb7c
commit 7e63ffe745
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 68 additions and 16 deletions

View File

@ -123,15 +123,16 @@ public class BukkitSetupUtils extends SetupUtils {
break;
}
case 1: {
if (!PlotSquared.get().worlds.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath);
}
ConfigurationSection worldSection =
PlotSquared.get().worlds.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue());
}
if (!object.plotManager.endsWith(":single")) {
if (!PlotSquared.get().worlds.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath);
}
if (steps.length != 0) {
ConfigurationSection worldSection = PlotSquared.get().worlds.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue());
}
}
PlotSquared.get().worlds.set("worlds." + world + ".generator.type", object.type);
PlotSquared.get().worlds.set("worlds." + world + ".generator.terrain", object.terrain);
PlotSquared.get().worlds.set("worlds." + world + ".generator.plugin", object.plotManager);

View File

@ -1,16 +1,26 @@
package com.github.intellectualsites.plotsquared.plot.object.worlds;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
import com.github.intellectualsites.plotsquared.plot.generator.GridPlotWorld;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotLoc;
import com.github.intellectualsites.plotsquared.plot.object.PlotSettings;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class SinglePlotArea extends GridPlotWorld {
@ -26,20 +36,61 @@ public class SinglePlotArea extends GridPlotWorld {
VOID = config.getBoolean("void", false);
}
@Override public void saveConfiguration(ConfigurationSection config) {
new Exception().printStackTrace();
super.saveConfiguration(config);
}
public void loadWorld(final PlotId id) {
String worldName = id.toCommaSeparatedString();
if (WorldUtil.IMP.isWorld(worldName)) {
return;
}
SetupObject setup = new SetupObject();
setup.plotManager = "PlotSquared:single";
setup.setupGenerator = "PlotSquared:single";
setup.type = TYPE;
setup.terrain = TERRAIN;
setup.step = new ConfigurationNode[0];
setup.world = worldName;
// Duplicate 0;0
if (setup.type != 0) {
File container = PlotSquared.imp().getWorldContainer();
File dest = new File(container, worldName);
if (!dest.exists()) {
File src = new File(container, "0,0");
if (src.exists()) {
if (!dest.exists()) {
dest.mkdirs();
}
File levelDat = new File(src, "level.dat");
if (levelDat.exists()) {
try {
Files.copy(levelDat.toPath(), new File(dest, levelDat.getName()).toPath());
File data = new File(src, "data");
if (data.exists()) {
File dataDest = new File(dest, "data");
dataDest.mkdirs();
for (File file : data.listFiles()) {
Files.copy(file.toPath(), new File(dataDest, file.getName()).toPath());
}
}
} catch (IOException ignore) {
ignore.printStackTrace();
}
}
}
}
}
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override public void run(Object value) {
String worldName = id.toCommaSeparatedString();
if (WorldUtil.IMP.isWorld(worldName)) {
return;
}
SetupObject setup = new SetupObject();
setup.plotManager = "PlotSquared:single";
setup.setupGenerator = "PlotSquared:single";
setup.type = TYPE;
setup.terrain = TERRAIN;
setup.step = new ConfigurationNode[0];
setup.world = worldName;
SetupUtils.manager.setupWorld(setup);
}
});