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; break;
} }
case 1: { case 1: {
if (!object.plotManager.endsWith(":single")) {
if (!PlotSquared.get().worlds.contains(worldPath)) { if (!PlotSquared.get().worlds.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath); PlotSquared.get().worlds.createSection(worldPath);
} }
ConfigurationSection worldSection = if (steps.length != 0) {
PlotSquared.get().worlds.getConfigurationSection(worldPath); ConfigurationSection worldSection = PlotSquared.get().worlds.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) { for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue()); worldSection.set(step.getConstant(), step.getValue());
} }
if (!object.plotManager.endsWith(":single")) { }
PlotSquared.get().worlds.set("worlds." + world + ".generator.type", object.type); 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.terrain", object.terrain);
PlotSquared.get().worlds.set("worlds." + world + ".generator.plugin", object.plotManager); PlotSquared.get().worlds.set("worlds." + world + ".generator.plugin", object.plotManager);

View File

@ -1,16 +1,26 @@
package com.github.intellectualsites.plotsquared.plot.object.worlds; package com.github.intellectualsites.plotsquared.plot.object.worlds;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; 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.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
import com.github.intellectualsites.plotsquared.plot.generator.GridPlotWorld; 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.SetupUtils;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class SinglePlotArea extends GridPlotWorld { public class SinglePlotArea extends GridPlotWorld {
@ -26,9 +36,12 @@ public class SinglePlotArea extends GridPlotWorld {
VOID = config.getBoolean("void", false); VOID = config.getBoolean("void", false);
} }
@Override public void saveConfiguration(ConfigurationSection config) {
new Exception().printStackTrace();
super.saveConfiguration(config);
}
public void loadWorld(final PlotId id) { public void loadWorld(final PlotId id) {
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override public void run(Object value) {
String worldName = id.toCommaSeparatedString(); String worldName = id.toCommaSeparatedString();
if (WorldUtil.IMP.isWorld(worldName)) { if (WorldUtil.IMP.isWorld(worldName)) {
return; return;
@ -40,6 +53,44 @@ public class SinglePlotArea extends GridPlotWorld {
setup.terrain = TERRAIN; setup.terrain = TERRAIN;
setup.step = new ConfigurationNode[0]; setup.step = new ConfigurationNode[0];
setup.world = worldName; 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;
}
SetupUtils.manager.setupWorld(setup); SetupUtils.manager.setupWorld(setup);
} }
}); });