mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-01-09 17:57:39 +01:00
Add light-reload command to reload bluemap without reloading all block-resources
This commit is contained in:
parent
3b37be432c
commit
1fa8bb5e4c
@ -48,6 +48,7 @@
|
|||||||
import de.bluecolored.bluemap.core.util.FileHelper;
|
import de.bluecolored.bluemap.core.util.FileHelper;
|
||||||
import de.bluecolored.bluemap.core.world.World;
|
import de.bluecolored.bluemap.core.world.World;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
||||||
@ -82,6 +83,14 @@ public class BlueMapService implements Closeable {
|
|||||||
|
|
||||||
private ResourcePack resourcePack;
|
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) {
|
public BlueMapService(ServerInterface serverInterface, BlueMapConfigProvider configProvider) {
|
||||||
this.serverInterface = serverInterface;
|
this.serverInterface = serverInterface;
|
||||||
this.configs = configProvider;
|
this.configs = configProvider;
|
||||||
@ -230,6 +239,7 @@ private synchronized void loadMapConfig(String id, MapConfig mapConfig) throws C
|
|||||||
World world = worlds.get(worldId);
|
World world = worlds.get(worldId);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
try {
|
try {
|
||||||
|
Logger.global.logInfo("Loading world '" + worldId + "' (" + worldFolder.toAbsolutePath().normalize() + ")...");
|
||||||
world = new MCAWorld(worldFolder, mapConfig.getWorldSkyLight(), mapConfig.isIgnoreMissingLightData());
|
world = new MCAWorld(worldFolder, mapConfig.getWorldSkyLight(), mapConfig.isIgnoreMissingLightData());
|
||||||
worlds.put(worldId, world);
|
worlds.put(worldId, world);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -244,6 +254,7 @@ private synchronized void loadMapConfig(String id, MapConfig mapConfig) throws C
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
Logger.global.logInfo("Loading map '" + name + "'...");
|
||||||
BmMap map = new BmMap(
|
BmMap map = new BmMap(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
@ -424,6 +435,10 @@ public synchronized ResourcePack getResourcePack() throws ConfigurationException
|
|||||||
return resourcePack;
|
return resourcePack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<ResourcePack> getResourcePackIfLoaded() {
|
||||||
|
return Optional.ofNullable(this.resourcePack);
|
||||||
|
}
|
||||||
|
|
||||||
private Collection<Path> getWorldFolders() {
|
private Collection<Path> getWorldFolders() {
|
||||||
Set<Path> folders = new HashSet<>();
|
Set<Path> folders = new HashSet<>();
|
||||||
for (MapConfig mapConfig : configs.getMapConfigs().values()) {
|
for (MapConfig mapConfig : configs.getMapConfigs().values()) {
|
||||||
|
@ -45,9 +45,11 @@
|
|||||||
import de.bluecolored.bluemap.core.logger.Logger;
|
import de.bluecolored.bluemap.core.logger.Logger;
|
||||||
import de.bluecolored.bluemap.core.map.BmMap;
|
import de.bluecolored.bluemap.core.map.BmMap;
|
||||||
import de.bluecolored.bluemap.core.metrics.Metrics;
|
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.storage.Storage;
|
||||||
import de.bluecolored.bluemap.core.util.FileHelper;
|
import de.bluecolored.bluemap.core.util.FileHelper;
|
||||||
import de.bluecolored.bluemap.core.world.World;
|
import de.bluecolored.bluemap.core.world.World;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
@ -101,15 +103,19 @@ public Plugin(String implementationType, ServerInterface serverInterface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void load() throws IOException {
|
public void load() throws IOException {
|
||||||
try {
|
load(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load(@Nullable ResourcePack preloadedResourcePack) throws IOException {
|
||||||
loadingLock.lock();
|
loadingLock.lock();
|
||||||
|
try {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
||||||
if (loaded) return;
|
if (loaded) return;
|
||||||
unload(); //ensure nothing is left running (from a failed load or something)
|
unload(); //ensure nothing is left running (from a failed load or something)
|
||||||
|
|
||||||
//load configs
|
//load configs
|
||||||
blueMap = new BlueMapService(serverInterface, new BlueMapConfigs(serverInterface));
|
blueMap = new BlueMapService(serverInterface, new BlueMapConfigs(serverInterface), preloadedResourcePack);
|
||||||
CoreConfig coreConfig = getConfigs().getCoreConfig();
|
CoreConfig coreConfig = getConfigs().getCoreConfig();
|
||||||
WebserverConfig webserverConfig = getConfigs().getWebserverConfig();
|
WebserverConfig webserverConfig = getConfigs().getWebserverConfig();
|
||||||
WebappConfig webappConfig = getConfigs().getWebappConfig();
|
WebappConfig webappConfig = getConfigs().getWebappConfig();
|
||||||
@ -333,8 +339,8 @@ public void run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void unload() {
|
public void unload() {
|
||||||
try {
|
|
||||||
loadingLock.interruptAndLock();
|
loadingLock.interruptAndLock();
|
||||||
|
try {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
//save
|
//save
|
||||||
save();
|
save();
|
||||||
@ -401,6 +407,31 @@ public void reload() throws IOException {
|
|||||||
load();
|
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() {
|
public synchronized void save() {
|
||||||
if (pluginState != null) {
|
if (pluginState != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -109,7 +109,11 @@ public void init() {
|
|||||||
LiteralCommandNode<S> reloadCommand =
|
LiteralCommandNode<S> reloadCommand =
|
||||||
literal("reload")
|
literal("reload")
|
||||||
.requires(requirementsUnloaded("bluemap.reload"))
|
.requires(requirementsUnloaded("bluemap.reload"))
|
||||||
.executes(this::reloadCommand)
|
.executes(context -> this.reloadCommand(context, false))
|
||||||
|
|
||||||
|
.then(literal("light")
|
||||||
|
.executes(context -> this.reloadCommand(context, true)))
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
LiteralCommandNode<S> debugCommand =
|
LiteralCommandNode<S> debugCommand =
|
||||||
@ -380,14 +384,18 @@ public int helpCommand(CommandContext<S> context) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int reloadCommand(CommandContext<S> context) {
|
public int reloadCommand(CommandContext<S> context, boolean light) {
|
||||||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||||
|
|
||||||
source.sendMessage(Text.of(TextColor.GOLD, "Reloading BlueMap..."));
|
source.sendMessage(Text.of(TextColor.GOLD, "Reloading BlueMap..."));
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
if (light) {
|
||||||
|
plugin.lightReload();
|
||||||
|
} else {
|
||||||
plugin.reload();
|
plugin.reload();
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.isLoaded()) {
|
if (plugin.isLoaded()) {
|
||||||
source.sendMessage(Text.of(TextColor.GREEN, "BlueMap reloaded!"));
|
source.sendMessage(Text.of(TextColor.GREEN, "BlueMap reloaded!"));
|
||||||
|
Loading…
Reference in New Issue
Block a user