diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java index 6f93541f..d7dfe850 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java @@ -48,6 +48,7 @@ import de.bluecolored.bluemap.core.util.FileHelper; import de.bluecolored.bluemap.core.world.World; import org.apache.commons.io.FileUtils; +import org.jetbrains.annotations.Nullable; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.gson.GsonConfigurationLoader; @@ -82,6 +83,14 @@ public class BlueMapService implements Closeable { private ResourcePack resourcePack; + + public BlueMapService(ServerInterface serverInterface, BlueMapConfigProvider configProvider, @Nullable ResourcePack preloadedResourcePack) { + this(serverInterface, configProvider); + + if (preloadedResourcePack != null) + this.resourcePack = preloadedResourcePack; + } + public BlueMapService(ServerInterface serverInterface, BlueMapConfigProvider configProvider) { this.serverInterface = serverInterface; this.configs = configProvider; @@ -230,6 +239,7 @@ private synchronized void loadMapConfig(String id, MapConfig mapConfig) throws C World world = worlds.get(worldId); if (world == null) { try { + Logger.global.logInfo("Loading world '" + worldId + "' (" + worldFolder.toAbsolutePath().normalize() + ")..."); world = new MCAWorld(worldFolder, mapConfig.getWorldSkyLight(), mapConfig.isIgnoreMissingLightData()); worlds.put(worldId, world); } catch (IOException ex) { @@ -244,6 +254,7 @@ private synchronized void loadMapConfig(String id, MapConfig mapConfig) throws C try { + Logger.global.logInfo("Loading map '" + name + "'..."); BmMap map = new BmMap( id, name, @@ -424,6 +435,10 @@ public synchronized ResourcePack getResourcePack() throws ConfigurationException return resourcePack; } + public Optional getResourcePackIfLoaded() { + return Optional.ofNullable(this.resourcePack); + } + private Collection getWorldFolders() { Set folders = new HashSet<>(); for (MapConfig mapConfig : configs.getMapConfigs().values()) { diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java index fad78080..f6cab23b 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java @@ -45,9 +45,11 @@ import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.map.BmMap; import de.bluecolored.bluemap.core.metrics.Metrics; +import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack; import de.bluecolored.bluemap.core.storage.Storage; import de.bluecolored.bluemap.core.util.FileHelper; import de.bluecolored.bluemap.core.world.World; +import org.jetbrains.annotations.Nullable; import org.spongepowered.configurate.gson.GsonConfigurationLoader; import org.spongepowered.configurate.serialize.SerializationException; @@ -101,15 +103,19 @@ public Plugin(String implementationType, ServerInterface serverInterface) { } public void load() throws IOException { + load(null); + } + + private void load(@Nullable ResourcePack preloadedResourcePack) throws IOException { + loadingLock.lock(); try { - loadingLock.lock(); synchronized (this) { if (loaded) return; unload(); //ensure nothing is left running (from a failed load or something) //load configs - blueMap = new BlueMapService(serverInterface, new BlueMapConfigs(serverInterface)); + blueMap = new BlueMapService(serverInterface, new BlueMapConfigs(serverInterface), preloadedResourcePack); CoreConfig coreConfig = getConfigs().getCoreConfig(); WebserverConfig webserverConfig = getConfigs().getWebserverConfig(); WebappConfig webappConfig = getConfigs().getWebappConfig(); @@ -333,8 +339,8 @@ public void run() { } public void unload() { + loadingLock.interruptAndLock(); try { - loadingLock.interruptAndLock(); synchronized (this) { //save save(); @@ -401,6 +407,31 @@ public void reload() throws IOException { load(); } + /** + * {@link #reload()} but without reloading the resourcepack (if it is loaded). + */ + public void lightReload() throws IOException { + loadingLock.lock(); + try { + synchronized (this) { + + if (!loaded) { + reload(); // reload normally + return; + } + + // hold and reuse loaded resourcepack + ResourcePack preloadedResourcePack = this.blueMap.getResourcePackIfLoaded().orElse(null); + + unload(); + load(preloadedResourcePack); + + } + } finally { + loadingLock.unlock(); + } + } + public synchronized void save() { if (pluginState != null) { try { diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java index 642de5ef..10373ef7 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java @@ -96,9 +96,9 @@ public void init() { LiteralCommandNode versionCommand = literal("version") - .requires(requirementsUnloaded("bluemap.version")) - .executes(this::versionCommand) - .build(); + .requires(requirementsUnloaded("bluemap.version")) + .executes(this::versionCommand) + .build(); LiteralCommandNode helpCommand = literal("help") @@ -109,7 +109,11 @@ public void init() { LiteralCommandNode reloadCommand = literal("reload") .requires(requirementsUnloaded("bluemap.reload")) - .executes(this::reloadCommand) + .executes(context -> this.reloadCommand(context, false)) + + .then(literal("light") + .executes(context -> this.reloadCommand(context, true))) + .build(); LiteralCommandNode debugCommand = @@ -380,14 +384,18 @@ public int helpCommand(CommandContext context) { return 1; } - public int reloadCommand(CommandContext context) { + public int reloadCommand(CommandContext context, boolean light) { CommandSource source = commandSourceInterface.apply(context.getSource()); source.sendMessage(Text.of(TextColor.GOLD, "Reloading BlueMap...")); new Thread(() -> { try { - plugin.reload(); + if (light) { + plugin.lightReload(); + } else { + plugin.reload(); + } if (plugin.isLoaded()) { source.sendMessage(Text.of(TextColor.GREEN, "BlueMap reloaded!"));