From 7e63ffe745cee97699b8869212d3a24be1a29168 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 17 Apr 2019 14:30:05 +1000 Subject: [PATCH] Optimize vanilla world generation* *For single plot worlds Reuse base world data. Instead of taking several seconds, it should now take tens of milliseconds. --- .../bukkit/util/BukkitSetupUtils.java | 17 ++--- .../plot/object/worlds/SinglePlotArea.java | 67 ++++++++++++++++--- 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSetupUtils.java index 5eb2e3fbc..ad3de7cd3 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -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); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java index 749829e9c..c6a9a4c3e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java @@ -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() { @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); } });