forked from mirror/BlueMap
Reorganize configs: split config classes and update the plugin accordingliy
This commit is contained in:
parent
406c01d715
commit
b9763a0963
@ -62,8 +62,8 @@
|
||||
import de.bluecolored.bluemap.common.RenderManager;
|
||||
import de.bluecolored.bluemap.common.RenderTask;
|
||||
import de.bluecolored.bluemap.core.config.ConfigManager;
|
||||
import de.bluecolored.bluemap.core.config.MainConfig;
|
||||
import de.bluecolored.bluemap.core.config.MainConfig.MapConfig;
|
||||
import de.bluecolored.bluemap.core.config.CoreConfig;
|
||||
import de.bluecolored.bluemap.core.config.CoreConfig.MapConfig;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.mca.MCAWorld;
|
||||
import de.bluecolored.bluemap.core.metrics.Metrics;
|
||||
@ -95,7 +95,7 @@ public BlueMapCLI(ConfigManager configManager, File configFolder, boolean forceR
|
||||
public void renderMaps() throws IOException {
|
||||
Preconditions.checkNotNull(resourcePack);
|
||||
|
||||
MainConfig config = configManager.getMainConfig();
|
||||
CoreConfig config = configManager.getCoreConfig();
|
||||
configManager.loadResourceConfigs(resourcePack);
|
||||
|
||||
config.getWebDataPath().toFile().mkdirs();
|
||||
@ -287,14 +287,14 @@ public void renderMaps() throws IOException {
|
||||
public void startWebserver() throws IOException {
|
||||
Logger.global.logInfo("Starting webserver ...");
|
||||
|
||||
BlueMapWebServer webserver = new BlueMapWebServer(configManager.getMainConfig());
|
||||
BlueMapWebServer webserver = new BlueMapWebServer(configManager.getCoreConfig());
|
||||
webserver.start();
|
||||
}
|
||||
|
||||
private boolean loadResources() throws IOException, ParseResourceException {
|
||||
Logger.global.logInfo("Loading resources ...");
|
||||
|
||||
MainConfig config = configManager.getMainConfig();
|
||||
CoreConfig config = configManager.getCoreConfig();
|
||||
|
||||
File defaultResourceFile = config.getDataPath().resolve("minecraft-client-" + ResourcePack.MINECRAFT_CLIENT_VERSION + ".jar").toFile();
|
||||
File resourceExtensionsFile = config.getDataPath().resolve("resourceExtensions.zip").toFile();
|
||||
@ -327,7 +327,7 @@ private boolean loadResources() throws IOException, ParseResourceException {
|
||||
}
|
||||
|
||||
private boolean handleMissingResources(File resourceFile) throws IOException {
|
||||
if (configManager.getMainConfig().isDownloadAccepted()) {
|
||||
if (configManager.getCoreConfig().isDownloadAccepted()) {
|
||||
try {
|
||||
Logger.global.logInfo("Downloading " + ResourcePack.MINECRAFT_CLIENT_URL + " to " + resourceFile.getCanonicalPath() + " ...");
|
||||
ResourcePack.downloadDefaultResource(resourceFile);
|
||||
@ -339,7 +339,7 @@ private boolean handleMissingResources(File resourceFile) throws IOException {
|
||||
} else {
|
||||
Logger.global.logWarning("BlueMap is missing important resources!");
|
||||
Logger.global.logWarning("You need to accept the download of the required files in order of BlueMap to work!");
|
||||
Logger.global.logWarning("Please check " + configManager.getMainConfigFile().getCanonicalPath() + " and try again!");
|
||||
Logger.global.logWarning("Please check " + configManager.getCoreConfigFile().getCanonicalPath() + " and try again!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -367,23 +367,23 @@ public static void main(String[] args) throws IOException, ParseResourceExceptio
|
||||
URL cliDefaultsUrl = BlueMapCLI.class.getResource("/bluemap-cli-defaults.conf");
|
||||
|
||||
ConfigManager config = new ConfigManager(configFolder, cliConfigUrl, cliDefaultsUrl);
|
||||
boolean configCreated = !config.getMainConfigFile().exists();
|
||||
boolean configCreated = !config.getCoreConfigFile().exists();
|
||||
config.loadMainConfig();
|
||||
|
||||
if (configCreated) {
|
||||
Logger.global.logInfo("No config file found! Created default config here: " + config.getMainConfigFile().getCanonicalPath());
|
||||
Logger.global.logInfo("No config file found! Created default config here: " + config.getCoreConfigFile().getCanonicalPath());
|
||||
return;
|
||||
}
|
||||
|
||||
WebFilesManager webFilesManager = new WebFilesManager(config.getMainConfig().getWebRoot());
|
||||
WebFilesManager webFilesManager = new WebFilesManager(config.getCoreConfig().getWebRoot());
|
||||
if (webFilesManager.needsUpdate()) {
|
||||
Logger.global.logInfo("Updating webfiles in " + config.getMainConfig().getWebRoot().normalize() + "...");
|
||||
Logger.global.logInfo("Updating webfiles in " + config.getCoreConfig().getWebRoot().normalize() + "...");
|
||||
webFilesManager.updateFiles();
|
||||
}
|
||||
|
||||
BlueMapCLI bluemap = new BlueMapCLI(config, configFolder, cmd.hasOption("f"));
|
||||
|
||||
if (config.getMainConfig().isWebserverEnabled()) {
|
||||
if (config.getCoreConfig().isWebserverEnabled()) {
|
||||
//start webserver
|
||||
bluemap.startWebserver();
|
||||
|
||||
@ -394,12 +394,12 @@ public static void main(String[] args) throws IOException, ParseResourceExceptio
|
||||
}
|
||||
|
||||
|
||||
if (!config.getMainConfig().getMapConfigs().isEmpty()) {
|
||||
if (!config.getCoreConfig().getMapConfigs().isEmpty()) {
|
||||
//load resources
|
||||
if (bluemap.loadResources()) {
|
||||
|
||||
//metrics
|
||||
if (config.getMainConfig().isMetricsEnabled()) Metrics.sendReportAsync("CLI");
|
||||
if (config.getCoreConfig().isMetricsEnabled()) Metrics.sendReportAsync("CLI");
|
||||
|
||||
//render maps
|
||||
bluemap.renderMaps();
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.common;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.bluecolored.bluemap.common.live.LiveAPIRequestHandler;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.core.config.LiveAPISettings;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.web.FileRequestHandler;
|
||||
import de.bluecolored.bluemap.core.web.WebFilesManager;
|
||||
import de.bluecolored.bluemap.core.web.WebServerConfig;
|
||||
import de.bluecolored.bluemap.core.webserver.WebServer;
|
||||
|
||||
public class BlueMapWebServer extends WebServer {
|
||||
|
||||
private WebFilesManager webFilesManager;
|
||||
|
||||
|
||||
public BlueMapWebServer(WebServerConfig config) {
|
||||
super(
|
||||
config.getWebserverPort(),
|
||||
config.getWebserverMaxConnections(),
|
||||
config.getWebserverBindAdress(),
|
||||
new FileRequestHandler(config.getWebRoot(), "BlueMap/Webserver")
|
||||
);
|
||||
|
||||
this.webFilesManager = new WebFilesManager(config.getWebRoot());
|
||||
}
|
||||
|
||||
public BlueMapWebServer(WebServerConfig config, LiveAPISettings liveSettings, ServerInterface server) {
|
||||
super(
|
||||
config.getWebserverPort(),
|
||||
config.getWebserverMaxConnections(),
|
||||
config.getWebserverBindAdress(),
|
||||
new LiveAPIRequestHandler(server, liveSettings, new FileRequestHandler(config.getWebRoot(), "BlueMap/Webserver"))
|
||||
);
|
||||
|
||||
this.webFilesManager = new WebFilesManager(config.getWebRoot());
|
||||
}
|
||||
|
||||
public void updateWebfiles() throws IOException {
|
||||
if (webFilesManager.needsUpdate()) {
|
||||
Logger.global.logInfo("Webfiles are missing or outdated, updating...");
|
||||
webFilesManager.updateFiles();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -55,25 +55,25 @@ public class BlueMapAPIImpl extends BlueMapAPI {
|
||||
|
||||
private static final String IMAGE_ROOT_PATH = "images";
|
||||
|
||||
public Plugin blueMap;
|
||||
public Plugin plugin;
|
||||
public RenderAPIImpl renderer;
|
||||
|
||||
public Map<UUID, BlueMapWorldImpl> worlds;
|
||||
public Map<String, BlueMapMapImpl> maps;
|
||||
|
||||
public BlueMapAPIImpl(Plugin blueMap) {
|
||||
this.blueMap = blueMap;
|
||||
public BlueMapAPIImpl(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.renderer = new RenderAPIImpl(this, blueMap.getRenderManager());
|
||||
this.renderer = new RenderAPIImpl(this, plugin.getRenderManager());
|
||||
|
||||
worlds = new HashMap<>();
|
||||
for (World world : blueMap.getWorlds()) {
|
||||
for (World world : plugin.getWorlds()) {
|
||||
BlueMapWorldImpl w = new BlueMapWorldImpl(this, world);
|
||||
worlds.put(w.getUuid(), w);
|
||||
}
|
||||
|
||||
maps = new HashMap<>();
|
||||
for (MapType map : blueMap.getMapTypes()) {
|
||||
for (MapType map : plugin.getMapTypes()) {
|
||||
BlueMapMapImpl m = new BlueMapMapImpl(this, map);
|
||||
maps.put(m.getId(), m);
|
||||
}
|
||||
@ -86,7 +86,7 @@ public RenderAPIImpl getRenderAPI() {
|
||||
|
||||
@Override
|
||||
public MarkerAPIImpl getMarkerAPI() throws IOException {
|
||||
return new MarkerAPIImpl(this, blueMap.getMainConfig().getWebDataPath().resolve("markers.json").toFile());
|
||||
return new MarkerAPIImpl(this, new File(plugin.getRenderConfig().getWebRoot(), "data" + File.separator + "markers.json"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,15 +104,9 @@ public String createImage(BufferedImage image, String path) throws IOException {
|
||||
path = path.replaceAll("[^a-zA-Z_\\.\\-\\/]", "_");
|
||||
String separator = FileSystems.getDefault().getSeparator();
|
||||
|
||||
Path webRoot = blueMap.getMainConfig().getWebRoot().toAbsolutePath();
|
||||
Path webDataRoot = blueMap.getMainConfig().getWebDataPath().toAbsolutePath();
|
||||
|
||||
Path imagePath;
|
||||
if (webDataRoot.startsWith(webRoot)) {
|
||||
imagePath = webDataRoot.resolve(Paths.get(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
|
||||
} else {
|
||||
imagePath = webRoot.resolve("assets").resolve(Paths.get(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
|
||||
}
|
||||
Path webRoot = plugin.getRenderConfig().getWebRoot().toPath().toAbsolutePath();
|
||||
Path webDataRoot = webRoot.resolve("data");
|
||||
Path imagePath = webDataRoot.resolve(Paths.get(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
|
||||
|
||||
File imageFile = imagePath.toFile();
|
||||
imageFile.getParentFile().mkdirs();
|
||||
|
@ -31,9 +31,9 @@
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.PluginConfig;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.core.config.LiveAPISettings;
|
||||
import de.bluecolored.bluemap.core.webserver.HttpRequest;
|
||||
import de.bluecolored.bluemap.core.webserver.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.core.webserver.HttpResponse;
|
||||
@ -45,9 +45,9 @@ public class LiveAPIRequestHandler implements HttpRequestHandler {
|
||||
private Map<String, HttpRequestHandler> liveAPIRequests;
|
||||
private ServerInterface server;
|
||||
|
||||
private LiveAPISettings config;
|
||||
private PluginConfig config;
|
||||
|
||||
public LiveAPIRequestHandler(ServerInterface server, LiveAPISettings config, HttpRequestHandler notFoundHandler) {
|
||||
public LiveAPIRequestHandler(ServerInterface server, PluginConfig config, HttpRequestHandler notFoundHandler) {
|
||||
this.server = server;
|
||||
this.notFoundHandler = notFoundHandler;
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -46,15 +45,18 @@
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
|
||||
import de.bluecolored.bluemap.common.BlueMapWebServer;
|
||||
import de.bluecolored.bluemap.common.MapType;
|
||||
import de.bluecolored.bluemap.common.RenderManager;
|
||||
import de.bluecolored.bluemap.common.api.BlueMapAPIImpl;
|
||||
import de.bluecolored.bluemap.common.live.LiveAPIRequestHandler;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.common.plugin.skins.PlayerSkinUpdater;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.config.ConfigManager;
|
||||
import de.bluecolored.bluemap.core.config.MainConfig;
|
||||
import de.bluecolored.bluemap.core.config.MainConfig.MapConfig;
|
||||
import de.bluecolored.bluemap.core.config.CoreConfig;
|
||||
import de.bluecolored.bluemap.core.config.MapConfig;
|
||||
import de.bluecolored.bluemap.core.config.RenderConfig;
|
||||
import de.bluecolored.bluemap.core.config.WebServerConfig;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.mca.MCAWorld;
|
||||
import de.bluecolored.bluemap.core.metrics.Metrics;
|
||||
@ -64,8 +66,11 @@
|
||||
import de.bluecolored.bluemap.core.render.lowres.LowresModelManager;
|
||||
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
|
||||
import de.bluecolored.bluemap.core.resourcepack.ResourcePack;
|
||||
import de.bluecolored.bluemap.core.web.FileRequestHandler;
|
||||
import de.bluecolored.bluemap.core.web.WebFilesManager;
|
||||
import de.bluecolored.bluemap.core.web.WebSettings;
|
||||
import de.bluecolored.bluemap.core.webserver.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.core.webserver.WebServer;
|
||||
import de.bluecolored.bluemap.core.world.SlicedWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
|
||||
@ -80,7 +85,12 @@ public class Plugin {
|
||||
|
||||
private ServerInterface serverInterface;
|
||||
|
||||
private MainConfig config;
|
||||
private ConfigManager configManager;
|
||||
private CoreConfig coreConfig;
|
||||
private RenderConfig renderConfig;
|
||||
private WebServerConfig webServerConfig;
|
||||
private PluginConfig pluginConfig;
|
||||
|
||||
private ResourcePack resourcePack;
|
||||
|
||||
private Map<UUID, World> worlds;
|
||||
@ -90,7 +100,7 @@ public class Plugin {
|
||||
private PlayerSkinUpdater skinUpdater;
|
||||
|
||||
private RenderManager renderManager;
|
||||
private BlueMapWebServer webServer;
|
||||
private WebServer webServer;
|
||||
|
||||
private Thread periodicalSaveThread;
|
||||
private Thread metricsThread;
|
||||
@ -110,20 +120,25 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
if (loaded) return;
|
||||
unload(); //ensure nothing is left running (from a failed load or something)
|
||||
|
||||
//load configs
|
||||
URL defaultSpongeConfig = Plugin.class.getResource("/bluemap-" + implementationType + ".conf");
|
||||
URL spongeConfigDefaults = Plugin.class.getResource("/bluemap-" + implementationType + "-defaults.conf");
|
||||
ConfigManager configManager = new ConfigManager(serverInterface.getConfigFolder(), defaultSpongeConfig, spongeConfigDefaults);
|
||||
configManager.loadMainConfig();
|
||||
config = configManager.getMainConfig();
|
||||
configManager = new ConfigManager();
|
||||
|
||||
//load core config
|
||||
File coreConfigFile = new File(serverInterface.getConfigFolder(), "core.conf");
|
||||
coreConfig = new CoreConfig(configManager.loadOrCreate(
|
||||
coreConfigFile,
|
||||
Plugin.class.getResource("/core.conf"),
|
||||
Plugin.class.getResource("/core-defaults.conf"),
|
||||
true,
|
||||
true
|
||||
));
|
||||
|
||||
//load resources
|
||||
File defaultResourceFile = config.getDataPath().resolve("minecraft-client-" + ResourcePack.MINECRAFT_CLIENT_VERSION + ".jar").toFile();
|
||||
File resourceExtensionsFile = config.getDataPath().resolve("resourceExtensions.zip").toFile();
|
||||
File textureExportFile = config.getWebDataPath().resolve("textures.json").toFile();
|
||||
File defaultResourceFile = new File(coreConfig.getDataFolder(), "minecraft-client-" + ResourcePack.MINECRAFT_CLIENT_VERSION + ".jar");
|
||||
File resourceExtensionsFile = new File(coreConfig.getDataFolder(), "resourceExtensions.zip");
|
||||
File textureExportFile = new File(coreConfig.getDataFolder(), "textures.json");
|
||||
|
||||
if (!defaultResourceFile.exists()) {
|
||||
if (config.isDownloadAccepted()) {
|
||||
if (coreConfig.isDownloadAccepted()) {
|
||||
|
||||
//download file
|
||||
try {
|
||||
@ -137,7 +152,7 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
} else {
|
||||
Logger.global.logWarning("BlueMap is missing important resources!");
|
||||
Logger.global.logWarning("You need to accept the download of the required files in order of BlueMap to work!");
|
||||
try { Logger.global.logWarning("Please check: " + configManager.getMainConfigFile().getCanonicalPath()); } catch (IOException ignored) {}
|
||||
try { Logger.global.logWarning("Please check: " + coreConfigFile.getCanonicalPath()); } catch (IOException ignored) {}
|
||||
Logger.global.logInfo("If you have changed the config you can simply reload the plugin using: /bluemap reload");
|
||||
|
||||
return;
|
||||
@ -163,10 +178,19 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
resourcePack.load(resources);
|
||||
resourcePack.saveTextureFile(textureExportFile);
|
||||
|
||||
configManager.loadResourceConfigs(resourcePack);
|
||||
configManager.loadResourceConfigs(serverInterface.getConfigFolder(), resourcePack);
|
||||
|
||||
//load render-config
|
||||
renderConfig = new RenderConfig(configManager.loadOrCreate(
|
||||
new File(serverInterface.getConfigFolder(), "render.conf"),
|
||||
Plugin.class.getResource("/render.conf"),
|
||||
Plugin.class.getResource("/render-defaults.conf"),
|
||||
true,
|
||||
true
|
||||
));
|
||||
|
||||
//load maps
|
||||
for (MapConfig mapConfig : config.getMapConfigs()) {
|
||||
for (MapConfig mapConfig : renderConfig.getMapConfigs()) {
|
||||
String id = mapConfig.getId();
|
||||
String name = mapConfig.getName();
|
||||
|
||||
@ -209,14 +233,14 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
}
|
||||
|
||||
HiresModelManager hiresModelManager = new HiresModelManager(
|
||||
config.getWebDataPath().resolve(id).resolve("hires"),
|
||||
renderConfig.getWebRoot().toPath().resolve("data").resolve(id).resolve("hires"),
|
||||
resourcePack,
|
||||
mapConfig,
|
||||
new Vector2i(mapConfig.getHiresTileSize(), mapConfig.getHiresTileSize())
|
||||
);
|
||||
|
||||
LowresModelManager lowresModelManager = new LowresModelManager(
|
||||
config.getWebDataPath().resolve(id).resolve("lowres"),
|
||||
renderConfig.getWebRoot().toPath().resolve("data").resolve(id).resolve("lowres"),
|
||||
new Vector2i(mapConfig.getLowresPointsPerLowresTile(), mapConfig.getLowresPointsPerLowresTile()),
|
||||
new Vector2i(mapConfig.getLowresPointsPerHiresTile(), mapConfig.getLowresPointsPerHiresTile()),
|
||||
mapConfig.useGzipCompression()
|
||||
@ -227,20 +251,20 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
MapType mapType = new MapType(id, name, world, tileRenderer);
|
||||
maps.put(id, mapType);
|
||||
}
|
||||
|
||||
if (maps.isEmpty()) {
|
||||
Logger.global.logWarning("There are no valid maps configured, please check your config! Disabling BlueMap...");
|
||||
Logger.global.logWarning("There are no valid maps configured, please check your render-config! Disabling BlueMap...");
|
||||
unload();
|
||||
return;
|
||||
}
|
||||
|
||||
//initialize render manager
|
||||
renderManager = new RenderManager(config.getRenderThreadCount());
|
||||
renderManager = new RenderManager(coreConfig.getRenderThreadCount());
|
||||
renderManager.start();
|
||||
|
||||
//load render-manager state
|
||||
try {
|
||||
File saveFile = config.getDataPath().resolve("rmstate").toFile();
|
||||
saveFile.getParentFile().mkdirs();
|
||||
File saveFile = getRenderManagerSaveFile();
|
||||
if (saveFile.exists()) {
|
||||
try (DataInputStream in = new DataInputStream(new GZIPInputStream(new FileInputStream(saveFile)))) {
|
||||
renderManager.readState(in, getMapTypes());
|
||||
@ -272,20 +296,15 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
this.updateHandler = new MapUpdateHandler(this);
|
||||
serverInterface.registerListener(updateHandler);
|
||||
|
||||
//start skin updater
|
||||
if (config.isLiveUpdatesEnabled()) {
|
||||
this.skinUpdater = new PlayerSkinUpdater(config.getWebRoot().resolve("assets").resolve("playerheads").toFile());
|
||||
serverInterface.registerListener(skinUpdater);
|
||||
}
|
||||
|
||||
//create/update webfiles
|
||||
WebFilesManager webFilesManager = new WebFilesManager(config.getWebRoot());
|
||||
//create/update web-app
|
||||
WebFilesManager webFilesManager = new WebFilesManager(renderConfig.getWebRoot());
|
||||
if (webFilesManager.needsUpdate()) {
|
||||
webFilesManager.updateFiles();
|
||||
}
|
||||
|
||||
WebSettings webSettings = new WebSettings(config.getWebDataPath().resolve("settings.json").toFile());
|
||||
webSettings.set(config.isUseCookies(), "useCookies");
|
||||
//create/update web-app settings
|
||||
WebSettings webSettings = new WebSettings(new File(renderConfig.getWebRoot(), "data" + File.separator + "settings.json"));
|
||||
webSettings.set(renderConfig.isUseCookies(), "useCookies");
|
||||
webSettings.setAllMapsEnabled(false);
|
||||
for (MapType map : maps.values()) {
|
||||
webSettings.setMapEnabled(true, map.getId());
|
||||
@ -293,17 +312,52 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
webSettings.setFrom(map.getWorld(), map.getId());
|
||||
}
|
||||
int ordinal = 0;
|
||||
for (MapConfig map : config.getMapConfigs()) {
|
||||
for (MapConfig map : renderConfig.getMapConfigs()) {
|
||||
if (!maps.containsKey(map.getId())) continue; //don't add not loaded maps
|
||||
webSettings.setOrdinal(ordinal++, map.getId());
|
||||
webSettings.setFrom(map, map.getId());
|
||||
}
|
||||
webSettings.save();
|
||||
|
||||
//start webserver
|
||||
if (config.isWebserverEnabled()) {
|
||||
webServer = new BlueMapWebServer(config, config, serverInterface);
|
||||
webServer.updateWebfiles();
|
||||
//load plugin config
|
||||
pluginConfig = new PluginConfig(configManager.loadOrCreate(
|
||||
new File(serverInterface.getConfigFolder(), "plugin.conf"),
|
||||
Plugin.class.getResource("/plugin.conf"),
|
||||
Plugin.class.getResource("/plugin-defaults.conf"),
|
||||
true,
|
||||
true
|
||||
));
|
||||
|
||||
//start skin updater
|
||||
if (pluginConfig.isLiveUpdatesEnabled()) {
|
||||
this.skinUpdater = new PlayerSkinUpdater(new File(renderConfig.getWebRoot(), "assets" + File.separator + "playerheads"));
|
||||
serverInterface.registerListener(skinUpdater);
|
||||
}
|
||||
|
||||
//load webserver config
|
||||
webServerConfig = new WebServerConfig(configManager.loadOrCreate(
|
||||
new File(serverInterface.getConfigFolder(), "webserver.conf"),
|
||||
Plugin.class.getResource("/webserver.conf"),
|
||||
Plugin.class.getResource("/webserver-defaults.conf"),
|
||||
true,
|
||||
true
|
||||
));
|
||||
|
||||
//create and start webserver
|
||||
if (webServerConfig.isWebserverEnabled()) {
|
||||
HttpRequestHandler requestHandler = new FileRequestHandler(webServerConfig.getWebRoot().toPath(), "BlueMap v" + BlueMap.VERSION);
|
||||
|
||||
//inject live api if enabled
|
||||
if (pluginConfig.isLiveUpdatesEnabled()) {
|
||||
requestHandler = new LiveAPIRequestHandler(serverInterface, pluginConfig, requestHandler);
|
||||
}
|
||||
|
||||
webServer = new WebServer(
|
||||
webServerConfig.getWebserverPort(),
|
||||
webServerConfig.getWebserverMaxConnections(),
|
||||
webServerConfig.getWebserverBindAdress(),
|
||||
requestHandler
|
||||
);
|
||||
webServer.start();
|
||||
}
|
||||
|
||||
@ -313,7 +367,7 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
Thread.sleep(TimeUnit.MINUTES.toMillis(1));
|
||||
|
||||
while (true) {
|
||||
if (serverInterface.isMetricsEnabled(config.isMetricsEnabled())) Metrics.sendReport(this.implementationType);
|
||||
if (serverInterface.isMetricsEnabled(coreConfig.isMetricsEnabled())) Metrics.sendReport(this.implementationType);
|
||||
Thread.sleep(TimeUnit.MINUTES.toMillis(30));
|
||||
}
|
||||
} catch (InterruptedException ex){
|
||||
@ -378,7 +432,10 @@ public synchronized void unload() {
|
||||
webServer = null;
|
||||
updateHandler = null;
|
||||
resourcePack = null;
|
||||
config = null;
|
||||
coreConfig = null;
|
||||
renderConfig = null;
|
||||
webServerConfig = null;
|
||||
pluginConfig = null;
|
||||
maps.clear();
|
||||
worlds.clear();
|
||||
|
||||
@ -386,8 +443,8 @@ public synchronized void unload() {
|
||||
}
|
||||
|
||||
public void saveRenderManagerState() throws IOException {
|
||||
File saveFile = config.getDataPath().resolve("rmstate").toFile();
|
||||
saveFile.getParentFile().mkdirs();
|
||||
File saveFile = getRenderManagerSaveFile();
|
||||
|
||||
if (saveFile.exists()) saveFile.delete();
|
||||
saveFile.createNewFile();
|
||||
|
||||
@ -405,8 +462,20 @@ public ServerInterface getServerInterface() {
|
||||
return serverInterface;
|
||||
}
|
||||
|
||||
public MainConfig getMainConfig() {
|
||||
return config;
|
||||
public CoreConfig getCoreConfig() {
|
||||
return coreConfig;
|
||||
}
|
||||
|
||||
public RenderConfig getRenderConfig() {
|
||||
return renderConfig;
|
||||
}
|
||||
|
||||
public WebServerConfig getWebServerConfig() {
|
||||
return webServerConfig;
|
||||
}
|
||||
|
||||
public PluginConfig getPluginConfig() {
|
||||
return pluginConfig;
|
||||
}
|
||||
|
||||
public ResourcePack getResourcePack() {
|
||||
@ -429,11 +498,20 @@ public RenderManager getRenderManager() {
|
||||
return renderManager;
|
||||
}
|
||||
|
||||
public File getRenderManagerSaveFile() {
|
||||
if (coreConfig == null) return null;
|
||||
|
||||
File saveFile = new File(coreConfig.getDataFolder(), "rmstate");
|
||||
saveFile.getParentFile().mkdirs();
|
||||
|
||||
return saveFile;
|
||||
}
|
||||
|
||||
public MapUpdateHandler getUpdateHandler() {
|
||||
return updateHandler;
|
||||
}
|
||||
|
||||
public BlueMapWebServer getWebServer() {
|
||||
public WebServer getWebServer() {
|
||||
return webServer;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.common.plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
public class PluginConfig {
|
||||
|
||||
private boolean liveUpdatesEnabled = false;
|
||||
private boolean skinDownloadEnabled = false;
|
||||
private Collection<String> hiddenGameModes = Collections.emptyList();
|
||||
private boolean hideInvisible = false;
|
||||
private boolean hideSneaking = false;
|
||||
|
||||
public PluginConfig(ConfigurationNode node) {
|
||||
|
||||
//liveUpdates
|
||||
liveUpdatesEnabled = node.getNode("liveUpdates").getBoolean(true);
|
||||
|
||||
//skinDownloadEnabled
|
||||
skinDownloadEnabled = node.getNode("skinDownload").getBoolean(true);
|
||||
|
||||
//hiddenGameModes
|
||||
hiddenGameModes = new ArrayList<>();
|
||||
for (ConfigurationNode gameModeNode : node.getNode("hiddenGameModes").getChildrenList()) {
|
||||
hiddenGameModes.add(gameModeNode.getString());
|
||||
}
|
||||
hiddenGameModes = Collections.unmodifiableCollection(hiddenGameModes);
|
||||
|
||||
//hideInvisible
|
||||
hideInvisible = node.getNode("hideInvisible").getBoolean(true);
|
||||
|
||||
//hideSneaking
|
||||
hideSneaking = node.getNode("hideSneaking").getBoolean(false);
|
||||
|
||||
}
|
||||
|
||||
public boolean isLiveUpdatesEnabled() {
|
||||
return this.liveUpdatesEnabled;
|
||||
}
|
||||
|
||||
public boolean isSkinDownloadEnabled() {
|
||||
return this.skinDownloadEnabled;
|
||||
}
|
||||
|
||||
public Collection<String> getHiddenGameModes() {
|
||||
return this.hiddenGameModes;
|
||||
}
|
||||
|
||||
public boolean isHideInvisible() {
|
||||
return this.hideInvisible;
|
||||
}
|
||||
|
||||
public boolean isHideSneaking() {
|
||||
return this.hideSneaking;
|
||||
}
|
||||
|
||||
}
|
@ -35,7 +35,7 @@ public class BlueMap {
|
||||
static {
|
||||
String version = "DEV";
|
||||
try {
|
||||
version = GsonConfigurationLoader.builder().setURL(BlueMap.class.getResource("/core.json")).build().load().getNode("version").getString("DEV");
|
||||
version = GsonConfigurationLoader.builder().setURL(BlueMap.class.getResource("/version.json")).build().load().getNode("version").getString("DEV");
|
||||
} catch (IOException ex) {
|
||||
Logger.global.logError("Failed to load core.json from resources!", ex);
|
||||
}
|
||||
|
@ -37,6 +37,8 @@
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.resourcepack.ResourcePack;
|
||||
@ -58,157 +60,22 @@ public class ConfigManager {
|
||||
CONFIG_PLACEHOLDERS.add(new Placeholder("minecraft-client-version", ResourcePack.MINECRAFT_CLIENT_VERSION));
|
||||
}
|
||||
|
||||
private File configFolder;
|
||||
|
||||
private URL defaultMainConfig;
|
||||
private URL mainConfigDefaultValues;
|
||||
|
||||
private MainConfig mainConfig;
|
||||
private BlockIdConfig blockIdConfig;
|
||||
private BlockPropertiesConfig blockPropertiesConfig;
|
||||
private BiomeConfig biomeConfig;
|
||||
|
||||
/**
|
||||
* Manages all configurations BlueMap needs to render stuff.
|
||||
* Loads or creates a config file for BlueMap.
|
||||
*
|
||||
* @param configFolder The folder containing all configuration-files
|
||||
* @param defaultMainConfig The default main-configuration file, used if a new configuration is generated
|
||||
* @param mainConfigDefaultValues The default values that are used for the main-configuration file (if they are undefined)
|
||||
* @param configFile The config file to load
|
||||
* @param defaultConfig The default config that is used as a template if the config file does not exist (can be null)
|
||||
* @param defaultValues The default values used if a key is not present in the config (can be null)
|
||||
* @param usePlaceholders Whether to replace placeholders from the defaultConfig if it is newly generated
|
||||
* @param generateEmptyConfig Whether to generate an empty config file if no default config is provided
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public ConfigManager(File configFolder, URL defaultMainConfig, URL mainConfigDefaultValues) {
|
||||
this.defaultMainConfig = defaultMainConfig;
|
||||
this.configFolder = configFolder;
|
||||
}
|
||||
|
||||
public MainConfig getMainConfig() {
|
||||
return mainConfig;
|
||||
}
|
||||
|
||||
public File getMainConfigFile() {
|
||||
return new File(configFolder, "bluemap.conf");
|
||||
}
|
||||
|
||||
public BlockIdConfig getBlockIdConfig() {
|
||||
return blockIdConfig;
|
||||
}
|
||||
|
||||
public File getBlockIdConfigFile() {
|
||||
return new File(configFolder, "blockIds.json");
|
||||
}
|
||||
|
||||
public BlockPropertiesConfig getBlockPropertiesConfig() {
|
||||
return blockPropertiesConfig;
|
||||
}
|
||||
|
||||
public File getBlockPropertiesConfigFile() {
|
||||
return new File(configFolder, "blockProperties.json");
|
||||
}
|
||||
|
||||
public BiomeConfig getBiomeConfig() {
|
||||
return biomeConfig;
|
||||
}
|
||||
|
||||
public File getBiomeConfigFile() {
|
||||
return new File(configFolder, "biomes.json");
|
||||
}
|
||||
|
||||
public File getBlockColorConfigFile() {
|
||||
return new File(configFolder, "blockColors.json");
|
||||
}
|
||||
|
||||
public void loadMainConfig() throws IOException {
|
||||
mainConfig = new MainConfig(
|
||||
loadOrCreate(
|
||||
getMainConfigFile(),
|
||||
defaultMainConfig,
|
||||
mainConfigDefaultValues,
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void loadResourceConfigs(ResourcePack resourcePack) throws IOException {
|
||||
|
||||
//load blockColors.json from resources, config-folder and resourcepack
|
||||
URL blockColorsConfigUrl = BlueMap.class.getResource("/blockColors.json");
|
||||
ConfigurationNode blockColorsConfigNode = loadOrCreate(
|
||||
getBlockColorConfigFile(),
|
||||
null,
|
||||
blockColorsConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
blockColorsConfigNode = joinFromResourcePack(resourcePack, "blockColors.json", blockColorsConfigNode);
|
||||
resourcePack.getBlockColorCalculator().loadColorConfig(blockColorsConfigNode);
|
||||
|
||||
//load blockIds.json from resources, config-folder and resourcepack
|
||||
URL blockIdsConfigUrl = BlueMap.class.getResource("/blockIds.json");
|
||||
ConfigurationNode blockIdsConfigNode = loadOrCreate(
|
||||
getBlockIdConfigFile(),
|
||||
null,
|
||||
blockIdsConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
blockIdsConfigNode = joinFromResourcePack(resourcePack, "blockIds.json", blockIdsConfigNode);
|
||||
blockIdConfig = new BlockIdConfig(
|
||||
blockIdsConfigNode,
|
||||
getLoader(makeAutogen(getBlockIdConfigFile()))
|
||||
);
|
||||
|
||||
//load blockProperties.json from resources, config-folder and resourcepack
|
||||
URL blockPropertiesConfigUrl = BlueMap.class.getResource("/blockProperties.json");
|
||||
ConfigurationNode blockPropertiesConfigNode = loadOrCreate(
|
||||
getBlockPropertiesConfigFile(),
|
||||
null,
|
||||
blockPropertiesConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
blockPropertiesConfigNode = joinFromResourcePack(resourcePack, "blockProperties.json", blockPropertiesConfigNode);
|
||||
blockPropertiesConfig = new BlockPropertiesConfig(
|
||||
blockPropertiesConfigNode,
|
||||
resourcePack,
|
||||
getLoader(makeAutogen(getBlockPropertiesConfigFile()))
|
||||
);
|
||||
|
||||
//load biomes.json from resources, config-folder and resourcepack
|
||||
URL biomeConfigUrl = BlueMap.class.getResource("/biomes.json");
|
||||
ConfigurationNode biomeConfigNode = loadOrCreate(
|
||||
getBiomeConfigFile(),
|
||||
null,
|
||||
biomeConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
biomeConfigNode = joinFromResourcePack(resourcePack, "biomes.json", biomeConfigNode);
|
||||
biomeConfig = new BiomeConfig(
|
||||
biomeConfigNode,
|
||||
getLoader(makeAutogen(getBiomeConfigFile()))
|
||||
);
|
||||
}
|
||||
|
||||
private ConfigurationNode joinFromResourcePack(ResourcePack resourcePack, String configFileName, ConfigurationNode defaultConfig) {
|
||||
ConfigurationNode joinedNode = null;
|
||||
for (Resource resource : resourcePack.getConfigAdditions(configFileName)) {
|
||||
try {
|
||||
ConfigurationNode node = getLoader(configFileName, resource.read()).load();
|
||||
if (joinedNode == null) joinedNode = node;
|
||||
else joinedNode.mergeValuesFrom(node);
|
||||
} catch (IOException ex) {
|
||||
Logger.global.logWarning("Failed to load an additional " + configFileName + " from the resource-pack! " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (joinedNode == null) return defaultConfig;
|
||||
|
||||
joinedNode.mergeValuesFrom(defaultConfig);
|
||||
|
||||
return joinedNode;
|
||||
}
|
||||
|
||||
private ConfigurationNode loadOrCreate(File configFile, URL defaultConfig, URL defaultValues, boolean usePlaceholders, boolean generateEmptyConfig) throws IOException {
|
||||
public ConfigurationNode loadOrCreate(File configFile, URL defaultConfig, URL defaultValues, boolean usePlaceholders, boolean generateEmptyConfig) throws IOException {
|
||||
|
||||
ConfigurationNode configNode;
|
||||
if (!configFile.exists()) {
|
||||
@ -255,6 +122,103 @@ private ConfigurationNode loadOrCreate(File configFile, URL defaultConfig, URL d
|
||||
return configNode;
|
||||
}
|
||||
|
||||
public void loadResourceConfigs(File configFolder, ResourcePack resourcePack) throws IOException {
|
||||
|
||||
//load blockColors.json from resources, config-folder and resourcepack
|
||||
URL blockColorsConfigUrl = BlueMap.class.getResource("/blockColors.json");
|
||||
File blockColorsConfigFile = new File(configFolder, "blockColors.json");
|
||||
ConfigurationNode blockColorsConfigNode = loadOrCreate(
|
||||
blockColorsConfigFile,
|
||||
null,
|
||||
blockColorsConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
blockColorsConfigNode = joinFromResourcePack(resourcePack, "blockColors.json", blockColorsConfigNode);
|
||||
resourcePack.getBlockColorCalculator().loadColorConfig(blockColorsConfigNode);
|
||||
|
||||
//load blockIds.json from resources, config-folder and resourcepack
|
||||
URL blockIdsConfigUrl = BlueMap.class.getResource("/blockIds.json");
|
||||
File blockIdsConfigFile = new File(configFolder, "blockIds.json");
|
||||
ConfigurationNode blockIdsConfigNode = loadOrCreate(
|
||||
blockIdsConfigFile,
|
||||
null,
|
||||
blockIdsConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
blockIdsConfigNode = joinFromResourcePack(resourcePack, "blockIds.json", blockIdsConfigNode);
|
||||
blockIdConfig = new BlockIdConfig(
|
||||
blockIdsConfigNode,
|
||||
getLoader(makeAutogen(blockIdsConfigFile))
|
||||
);
|
||||
|
||||
//load blockProperties.json from resources, config-folder and resourcepack
|
||||
URL blockPropertiesConfigUrl = BlueMap.class.getResource("/blockProperties.json");
|
||||
File blockPropertiesConfigFile = new File(configFolder, "blockProperties.json");
|
||||
ConfigurationNode blockPropertiesConfigNode = loadOrCreate(
|
||||
blockPropertiesConfigFile,
|
||||
null,
|
||||
blockPropertiesConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
blockPropertiesConfigNode = joinFromResourcePack(resourcePack, "blockProperties.json", blockPropertiesConfigNode);
|
||||
blockPropertiesConfig = new BlockPropertiesConfig(
|
||||
blockPropertiesConfigNode,
|
||||
resourcePack,
|
||||
getLoader(makeAutogen(blockPropertiesConfigFile))
|
||||
);
|
||||
|
||||
//load biomes.json from resources, config-folder and resourcepack
|
||||
URL biomeConfigUrl = BlueMap.class.getResource("/biomes.json");
|
||||
File biomeConfigFile = new File(configFolder, "biomes.json");
|
||||
ConfigurationNode biomeConfigNode = loadOrCreate(
|
||||
biomeConfigFile,
|
||||
null,
|
||||
biomeConfigUrl,
|
||||
false,
|
||||
false
|
||||
);
|
||||
biomeConfigNode = joinFromResourcePack(resourcePack, "biomes.json", biomeConfigNode);
|
||||
biomeConfig = new BiomeConfig(
|
||||
biomeConfigNode,
|
||||
getLoader(makeAutogen(biomeConfigFile))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public BlockIdConfig getBlockIdConfig() {
|
||||
return blockIdConfig;
|
||||
}
|
||||
|
||||
public BlockPropertiesConfig getBlockPropertiesConfig() {
|
||||
return blockPropertiesConfig;
|
||||
}
|
||||
|
||||
public BiomeConfig getBiomeConfig() {
|
||||
return biomeConfig;
|
||||
}
|
||||
|
||||
private ConfigurationNode joinFromResourcePack(ResourcePack resourcePack, String configFileName, ConfigurationNode defaultConfig) {
|
||||
ConfigurationNode joinedNode = null;
|
||||
for (Resource resource : resourcePack.getConfigAdditions(configFileName)) {
|
||||
try {
|
||||
ConfigurationNode node = getLoader(configFileName, resource.read()).load();
|
||||
if (joinedNode == null) joinedNode = node;
|
||||
else joinedNode.mergeValuesFrom(node);
|
||||
} catch (IOException ex) {
|
||||
Logger.global.logWarning("Failed to load an additional " + configFileName + " from the resource-pack! " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (joinedNode == null) return defaultConfig;
|
||||
|
||||
joinedNode.mergeValuesFrom(defaultConfig);
|
||||
|
||||
return joinedNode;
|
||||
}
|
||||
|
||||
private File makeAutogen(File file) throws IOException {
|
||||
File autogenFile = file.getCanonicalFile().toPath().getParent().resolve("missing-configs").resolve(file.getName()).toFile();
|
||||
autogenFile.getParentFile().mkdirs();
|
||||
@ -280,5 +244,14 @@ private ConfigurationLoader<? extends ConfigurationNode> getLoader(File file){
|
||||
if (file.getName().endsWith(".yaml") || file.getName().endsWith(".yml")) return YAMLConfigurationLoader.builder().setFile(file).build();
|
||||
else return HoconConfigurationLoader.builder().setFile(file).build();
|
||||
}
|
||||
|
||||
public static File toFolder(String pathString) throws IOException {
|
||||
Preconditions.checkNotNull(pathString);
|
||||
|
||||
File file = new File(pathString);
|
||||
if (file.exists() && !file.isDirectory()) throw new IOException("Invalid configuration: Path '" + file.getAbsolutePath() + "' is a file (should be a directory)");
|
||||
if (!file.exists() && !file.mkdirs()) throw new IOException("Invalid configuration: Folders to path '" + file.getAbsolutePath() + "' could not be created");
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,16 +24,52 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface LiveAPISettings {
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
boolean isLiveUpdatesEnabled();
|
||||
public class CoreConfig {
|
||||
|
||||
Collection<String> getHiddenGameModes();
|
||||
|
||||
boolean isHideInvisible();
|
||||
|
||||
boolean isHideSneaking();
|
||||
private boolean downloadAccepted = false;
|
||||
private int renderThreadCount = 0;
|
||||
private boolean metricsEnabled = false;
|
||||
private File dataFolder = new File("data");
|
||||
|
||||
|
||||
public CoreConfig(ConfigurationNode node) throws IOException {
|
||||
|
||||
//accept-download
|
||||
downloadAccepted = node.getNode("accept-download").getBoolean(false);
|
||||
|
||||
//renderThreadCount
|
||||
int processors = Runtime.getRuntime().availableProcessors();
|
||||
renderThreadCount = node.getNode("renderThreadCount").getInt(0);
|
||||
if (renderThreadCount <= 0) renderThreadCount = processors + renderThreadCount;
|
||||
if (renderThreadCount <= 0) renderThreadCount = 1;
|
||||
|
||||
//metrics
|
||||
metricsEnabled = node.getNode("metrics").getBoolean(false);
|
||||
|
||||
//data
|
||||
dataFolder = ConfigManager.toFolder(node.getNode("data").getString("data"));
|
||||
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
public boolean isDownloadAccepted() {
|
||||
return downloadAccepted;
|
||||
}
|
||||
|
||||
public boolean isMetricsEnabled() {
|
||||
return metricsEnabled;
|
||||
}
|
||||
|
||||
public int getRenderThreadCount() {
|
||||
return renderThreadCount;
|
||||
}
|
||||
|
||||
}
|
@ -1,389 +0,0 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import de.bluecolored.bluemap.core.render.RenderSettings;
|
||||
import de.bluecolored.bluemap.core.util.ConfigUtils;
|
||||
import de.bluecolored.bluemap.core.web.WebServerConfig;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
public class MainConfig implements WebServerConfig, LiveAPISettings {
|
||||
private static final Pattern VALID_ID_PATTERN = Pattern.compile("[a-zA-Z0-9_]+");
|
||||
|
||||
private boolean downloadAccepted = false;
|
||||
private boolean metricsEnabled = false;
|
||||
|
||||
private boolean webserverEnabled = true;
|
||||
private int webserverPort = 8100;
|
||||
private int webserverMaxConnections = 100;
|
||||
private InetAddress webserverBindAdress = null;
|
||||
private boolean useCookies;
|
||||
|
||||
private Path dataPath = Paths.get("data");
|
||||
|
||||
private Path webRoot = Paths.get("web");
|
||||
private Path webDataPath = webRoot.resolve("data");
|
||||
|
||||
private int renderThreadCount = 0;
|
||||
|
||||
private List<MapConfig> mapConfigs = new ArrayList<>();
|
||||
|
||||
private boolean liveUpdatesEnabled = false;
|
||||
private Collection<String> hiddenGameModes = Collections.emptyList();
|
||||
private boolean hideInvisible = false;
|
||||
private boolean hideSneaking = false;
|
||||
|
||||
public MainConfig(ConfigurationNode node) throws OutdatedConfigException, IOException {
|
||||
checkOutdated(node);
|
||||
|
||||
//acceppt-download
|
||||
downloadAccepted = node.getNode("accept-download").getBoolean(false);
|
||||
|
||||
//renderThreadCount
|
||||
int processors = Runtime.getRuntime().availableProcessors();
|
||||
renderThreadCount = node.getNode("renderThreadCount").getInt(0);
|
||||
if (renderThreadCount <= 0) renderThreadCount = processors + renderThreadCount;
|
||||
if (renderThreadCount <= 0) renderThreadCount = 1;
|
||||
|
||||
//metrics
|
||||
metricsEnabled = node.getNode("metrics").getBoolean(false);
|
||||
|
||||
//data
|
||||
dataPath = toFolder(node.getNode("data").getString("data"));
|
||||
|
||||
//webroot
|
||||
String webRootString = node.getNode("webroot").getString();
|
||||
if (webserverEnabled && webRootString == null) throw new IOException("Invalid configuration: Node webroot is not defined");
|
||||
webRoot = toFolder(webRootString);
|
||||
|
||||
//webdata
|
||||
String webDataString = node.getNode("webdata").getString();
|
||||
if (webDataString != null)
|
||||
webDataPath = toFolder(webDataString);
|
||||
else
|
||||
webDataPath = webRoot.resolve("data");
|
||||
|
||||
useCookies = node.getNode("useCookies").getBoolean(true);
|
||||
|
||||
//webserver
|
||||
loadWebConfig(node.getNode("webserver"));
|
||||
|
||||
//maps
|
||||
loadMapConfigs(node.getNode("maps"));
|
||||
|
||||
//live-updates
|
||||
ConfigurationNode liveNode = node.getNode("liveUpdates");
|
||||
liveUpdatesEnabled = liveNode.getNode("enabled").getBoolean(true);
|
||||
|
||||
hiddenGameModes = new ArrayList<>();
|
||||
for (ConfigurationNode gameModeNode : liveNode.getNode("hiddenGameModes").getChildrenList()) {
|
||||
hiddenGameModes.add(gameModeNode.getString());
|
||||
}
|
||||
hiddenGameModes = Collections.unmodifiableCollection(hiddenGameModes);
|
||||
|
||||
hideInvisible = liveNode.getNode("hideInvisible").getBoolean(true);
|
||||
hideSneaking = liveNode.getNode("hideSneaking").getBoolean(false);
|
||||
}
|
||||
|
||||
private void loadWebConfig(ConfigurationNode node) throws IOException {
|
||||
//enabled
|
||||
webserverEnabled = node.getNode("enabled").getBoolean(false);
|
||||
|
||||
if (webserverEnabled) {
|
||||
//ip
|
||||
String webserverBindAdressString = node.getNode("ip").getString("");
|
||||
if (webserverBindAdressString.isEmpty() || webserverBindAdressString.equals("0.0.0.0") || webserverBindAdressString.equals("::0")) {
|
||||
webserverBindAdress = new InetSocketAddress(0).getAddress(); // 0.0.0.0
|
||||
} else if (webserverBindAdressString.equals("#getLocalHost")) {
|
||||
webserverBindAdress = InetAddress.getLocalHost();
|
||||
} else {
|
||||
webserverBindAdress = InetAddress.getByName(webserverBindAdressString);
|
||||
}
|
||||
|
||||
//port
|
||||
webserverPort = node.getNode("port").getInt(8100);
|
||||
|
||||
//maxConnectionCount
|
||||
webserverMaxConnections = node.getNode("maxConnectionCount").getInt(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadMapConfigs(ConfigurationNode node) throws IOException {
|
||||
mapConfigs = new ArrayList<>();
|
||||
for (ConfigurationNode mapConfigNode : node.getChildrenList()) {
|
||||
mapConfigs.add(new MapConfig(mapConfigNode));
|
||||
}
|
||||
}
|
||||
|
||||
private Path toFolder(String pathString) throws IOException {
|
||||
Preconditions.checkNotNull(pathString);
|
||||
|
||||
File file = new File(pathString);
|
||||
if (file.exists() && !file.isDirectory()) throw new IOException("Invalid configuration: Path '" + file.getAbsolutePath() + "' is a file (should be a directory)");
|
||||
if (!file.exists() && !file.mkdirs()) throw new IOException("Invalid configuration: Folders to path '" + file.getAbsolutePath() + "' could not be created");
|
||||
return file.toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getWebRoot() {
|
||||
return webRoot;
|
||||
}
|
||||
|
||||
public Path getDataPath() {
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
public boolean isUseCookies() {
|
||||
return useCookies;
|
||||
}
|
||||
|
||||
public boolean isWebserverEnabled() {
|
||||
return webserverEnabled;
|
||||
}
|
||||
|
||||
|
||||
public Path getWebDataPath() {
|
||||
return webDataPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWebserverPort() {
|
||||
return webserverPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWebserverMaxConnections() {
|
||||
return webserverMaxConnections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getWebserverBindAdress() {
|
||||
return webserverBindAdress;
|
||||
}
|
||||
|
||||
public boolean isDownloadAccepted() {
|
||||
return downloadAccepted;
|
||||
}
|
||||
|
||||
public boolean isMetricsEnabled() {
|
||||
return metricsEnabled;
|
||||
}
|
||||
|
||||
public int getRenderThreadCount() {
|
||||
return renderThreadCount;
|
||||
}
|
||||
|
||||
public List<MapConfig> getMapConfigs(){
|
||||
return mapConfigs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLiveUpdatesEnabled() {
|
||||
return this.liveUpdatesEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getHiddenGameModes() {
|
||||
return this.hiddenGameModes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHideInvisible() {
|
||||
return this.hideInvisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHideSneaking() {
|
||||
return this.hideSneaking;
|
||||
}
|
||||
|
||||
public class MapConfig implements RenderSettings {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String world;
|
||||
|
||||
private Vector2i startPos;
|
||||
private int skyColor;
|
||||
private float ambientLight;
|
||||
|
||||
private boolean renderCaves;
|
||||
|
||||
private Vector3i min, max;
|
||||
private boolean renderEdges;
|
||||
|
||||
private boolean useGzip;
|
||||
private boolean ignoreMissingLightData;
|
||||
|
||||
private int hiresTileSize;
|
||||
|
||||
private int lowresPointsPerHiresTile;
|
||||
private int lowresPointsPerLowresTile;
|
||||
|
||||
private MapConfig(ConfigurationNode node) throws IOException {
|
||||
this.id = node.getNode("id").getString("");
|
||||
if (id.isEmpty()) throw new IOException("Invalid configuration: Node maps[?].id is not defined");
|
||||
if (!VALID_ID_PATTERN.matcher(id).matches()) throw new IOException("Invalid configuration: Node maps[?].id '" + id + "' has invalid characters in it");
|
||||
|
||||
this.name = node.getNode("name").getString(id);
|
||||
|
||||
this.world = node.getNode("world").getString("");
|
||||
if (world.isEmpty()) throw new IOException("Invalid configuration: Node maps[?].world is not defined");
|
||||
|
||||
if (!node.getNode("startPos").isVirtual()) this.startPos = ConfigUtils.readVector2i(node.getNode("startPos"));
|
||||
|
||||
if (!node.getNode("skyColor").isVirtual()) this.skyColor = ConfigUtils.readColorInt(node.getNode("skyColor"));
|
||||
else this.skyColor = 0x7dabff;
|
||||
|
||||
this.ambientLight = node.getNode("ambientLight").getFloat(0f);
|
||||
|
||||
this.renderCaves = node.getNode("renderCaves").getBoolean(false);
|
||||
|
||||
int minX = node.getNode("minX").getInt(RenderSettings.super.getMin().getX());
|
||||
int maxX = node.getNode("maxX").getInt(RenderSettings.super.getMax().getX());
|
||||
int minZ = node.getNode("minZ").getInt(RenderSettings.super.getMin().getZ());
|
||||
int maxZ = node.getNode("maxZ").getInt(RenderSettings.super.getMax().getZ());
|
||||
int minY = node.getNode("minY").getInt(RenderSettings.super.getMin().getY());
|
||||
int maxY = node.getNode("maxY").getInt(RenderSettings.super.getMax().getY());
|
||||
this.min = new Vector3i(minX, minY, minZ);
|
||||
this.max = new Vector3i(maxX, maxY, maxZ);
|
||||
|
||||
this.renderEdges = node.getNode("renderEdges").getBoolean(true);
|
||||
|
||||
this.useGzip = node.getNode("useCompression").getBoolean(true);
|
||||
this.ignoreMissingLightData = node.getNode("ignoreMissingLightData").getBoolean(false);
|
||||
|
||||
this.hiresTileSize = node.getNode("hires", "tileSize").getInt(32);
|
||||
|
||||
this.lowresPointsPerHiresTile = node.getNode("lowres", "pointsPerHiresTile").getInt(4);
|
||||
this.lowresPointsPerLowresTile = node.getNode("lowres", "pointsPerLowresTile").getInt(50);
|
||||
|
||||
//check valid configuration values
|
||||
double blocksPerPoint = (double) this.hiresTileSize / (double) this.lowresPointsPerHiresTile;
|
||||
if (blocksPerPoint != Math.floor(blocksPerPoint)) throw new IOException("Invalid configuration: Invalid map resolution settings of map " + id + ": hires.tileSize / lowres.pointsPerTile has to be an integer result");
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getWorldPath() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public Vector2i getStartPos() {
|
||||
return startPos;
|
||||
}
|
||||
|
||||
public int getSkyColor() {
|
||||
return skyColor;
|
||||
}
|
||||
|
||||
public float getAmbientLight() {
|
||||
return ambientLight;
|
||||
}
|
||||
|
||||
public boolean isRenderCaves() {
|
||||
return renderCaves;
|
||||
}
|
||||
|
||||
public int getHiresTileSize() {
|
||||
return hiresTileSize;
|
||||
}
|
||||
|
||||
public int getLowresPointsPerHiresTile() {
|
||||
return lowresPointsPerHiresTile;
|
||||
}
|
||||
|
||||
public int getLowresPointsPerLowresTile() {
|
||||
return lowresPointsPerLowresTile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExcludeFacesWithoutSunlight() {
|
||||
return !isRenderCaves();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3i getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3i getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRenderEdges() {
|
||||
return renderEdges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useGzipCompression() {
|
||||
return useGzip;
|
||||
}
|
||||
|
||||
public boolean isIgnoreMissingLightData() {
|
||||
return ignoreMissingLightData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkOutdated(ConfigurationNode node) throws OutdatedConfigException {
|
||||
// check for config-nodes from version 0.1.x
|
||||
assertNotPresent(node.getNode("version"));
|
||||
assertNotPresent(node.getNode("web"));
|
||||
for (ConfigurationNode map : node.getNode("maps").getChildrenList()) {
|
||||
assertNotPresent(map.getNode("sliceY"));
|
||||
}
|
||||
}
|
||||
|
||||
private void assertNotPresent(ConfigurationNode node) throws OutdatedConfigException {
|
||||
if (!node.isVirtual()) throw new OutdatedConfigException("Configurtion-node '" + ConfigUtils.nodePathToString(node) + "' is no longer used, please update your configuration!");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
|
||||
import de.bluecolored.bluemap.core.render.RenderSettings;
|
||||
import de.bluecolored.bluemap.core.util.ConfigUtils;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
public class MapConfig implements RenderSettings {
|
||||
private static final Pattern VALID_ID_PATTERN = Pattern.compile("[a-zA-Z0-9_]+");
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String world;
|
||||
|
||||
private Vector2i startPos;
|
||||
private int skyColor;
|
||||
private float ambientLight;
|
||||
|
||||
private boolean renderCaves;
|
||||
|
||||
private Vector3i min, max;
|
||||
private boolean renderEdges;
|
||||
|
||||
private boolean useGzip;
|
||||
private boolean ignoreMissingLightData;
|
||||
|
||||
private int hiresTileSize;
|
||||
|
||||
private int lowresPointsPerHiresTile;
|
||||
private int lowresPointsPerLowresTile;
|
||||
|
||||
public MapConfig(ConfigurationNode node) throws IOException {
|
||||
|
||||
//id
|
||||
this.id = node.getNode("id").getString("");
|
||||
if (id.isEmpty()) throw new IOException("Invalid configuration: Node maps[?].id is not defined");
|
||||
if (!VALID_ID_PATTERN.matcher(id).matches()) throw new IOException("Invalid configuration: Node maps[?].id '" + id + "' has invalid characters in it");
|
||||
|
||||
//name
|
||||
this.name = node.getNode("name").getString(id);
|
||||
|
||||
//world
|
||||
this.world = node.getNode("world").getString("");
|
||||
if (world.isEmpty()) throw new IOException("Invalid configuration: Node maps[?].world is not defined");
|
||||
|
||||
//startPos
|
||||
if (!node.getNode("startPos").isVirtual()) this.startPos = ConfigUtils.readVector2i(node.getNode("startPos"));
|
||||
|
||||
//skyColor
|
||||
if (!node.getNode("skyColor").isVirtual()) this.skyColor = ConfigUtils.readColorInt(node.getNode("skyColor"));
|
||||
else this.skyColor = 0x7dabff;
|
||||
|
||||
//ambientLight
|
||||
this.ambientLight = node.getNode("ambientLight").getFloat(0f);
|
||||
|
||||
//renderCaves
|
||||
this.renderCaves = node.getNode("renderCaves").getBoolean(false);
|
||||
|
||||
//bounds
|
||||
int minX = node.getNode("minX").getInt(RenderSettings.super.getMin().getX());
|
||||
int maxX = node.getNode("maxX").getInt(RenderSettings.super.getMax().getX());
|
||||
int minZ = node.getNode("minZ").getInt(RenderSettings.super.getMin().getZ());
|
||||
int maxZ = node.getNode("maxZ").getInt(RenderSettings.super.getMax().getZ());
|
||||
int minY = node.getNode("minY").getInt(RenderSettings.super.getMin().getY());
|
||||
int maxY = node.getNode("maxY").getInt(RenderSettings.super.getMax().getY());
|
||||
this.min = new Vector3i(minX, minY, minZ);
|
||||
this.max = new Vector3i(maxX, maxY, maxZ);
|
||||
|
||||
//renderEdges
|
||||
this.renderEdges = node.getNode("renderEdges").getBoolean(true);
|
||||
|
||||
//useCompression
|
||||
this.useGzip = node.getNode("useCompression").getBoolean(true);
|
||||
|
||||
//ignoreMissingLightData
|
||||
this.ignoreMissingLightData = node.getNode("ignoreMissingLightData").getBoolean(false);
|
||||
|
||||
//tile-settings
|
||||
this.hiresTileSize = node.getNode("hires", "tileSize").getInt(32);
|
||||
this.lowresPointsPerHiresTile = node.getNode("lowres", "pointsPerHiresTile").getInt(4);
|
||||
this.lowresPointsPerLowresTile = node.getNode("lowres", "pointsPerLowresTile").getInt(50);
|
||||
|
||||
//check valid tile configuration values
|
||||
double blocksPerPoint = (double) this.hiresTileSize / (double) this.lowresPointsPerHiresTile;
|
||||
if (blocksPerPoint != Math.floor(blocksPerPoint)) throw new IOException("Invalid configuration: Invalid map resolution settings of map " + id + ": hires.tileSize / lowres.pointsPerTile has to be an integer result");
|
||||
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getWorldPath() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public Vector2i getStartPos() {
|
||||
return startPos;
|
||||
}
|
||||
|
||||
public int getSkyColor() {
|
||||
return skyColor;
|
||||
}
|
||||
|
||||
public float getAmbientLight() {
|
||||
return ambientLight;
|
||||
}
|
||||
|
||||
public boolean isRenderCaves() {
|
||||
return renderCaves;
|
||||
}
|
||||
|
||||
public boolean isIgnoreMissingLightData() {
|
||||
return ignoreMissingLightData;
|
||||
}
|
||||
|
||||
public int getHiresTileSize() {
|
||||
return hiresTileSize;
|
||||
}
|
||||
|
||||
public int getLowresPointsPerHiresTile() {
|
||||
return lowresPointsPerHiresTile;
|
||||
}
|
||||
|
||||
public int getLowresPointsPerLowresTile() {
|
||||
return lowresPointsPerLowresTile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExcludeFacesWithoutSunlight() {
|
||||
return !isRenderCaves();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3i getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3i getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRenderEdges() {
|
||||
return renderEdges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useGzipCompression() {
|
||||
return useGzip;
|
||||
}
|
||||
|
||||
}
|
@ -24,19 +24,48 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OutdatedConfigException extends IOException {
|
||||
private static final long serialVersionUID = -942567050110586060L;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
public OutdatedConfigException() {}
|
||||
|
||||
public OutdatedConfigException(String message) {
|
||||
super(message);
|
||||
public class RenderConfig {
|
||||
|
||||
private File webRoot = new File("web");
|
||||
private boolean useCookies;
|
||||
private List<MapConfig> mapConfigs = new ArrayList<>();
|
||||
|
||||
public RenderConfig(ConfigurationNode node) throws IOException {
|
||||
|
||||
//webroot
|
||||
String webRootString = node.getNode("webroot").getString();
|
||||
if (webRootString == null) throw new IOException("Invalid configuration: Node webroot is not defined");
|
||||
webRoot = ConfigManager.toFolder(webRootString);
|
||||
|
||||
//cookies
|
||||
useCookies = node.getNode("useCookies").getBoolean(true);
|
||||
|
||||
//maps
|
||||
mapConfigs = new ArrayList<>();
|
||||
for (ConfigurationNode mapConfigNode : node.getChildrenList()) {
|
||||
mapConfigs.add(new MapConfig(mapConfigNode));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public File getWebRoot() {
|
||||
return webRoot;
|
||||
}
|
||||
|
||||
public OutdatedConfigException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
public boolean isUseCookies() {
|
||||
return useCookies;
|
||||
}
|
||||
|
||||
public List<MapConfig> getMapConfigs(){
|
||||
return mapConfigs;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
public class WebServerConfig {
|
||||
|
||||
private boolean enabled = true;
|
||||
private File webRoot = new File("web");
|
||||
|
||||
private InetAddress bindAdress = null;
|
||||
private int port = 8100;
|
||||
private int maxConnections = 100;
|
||||
|
||||
public WebServerConfig(ConfigurationNode node) throws IOException {
|
||||
|
||||
//enabled
|
||||
enabled = node.getNode("enabled").getBoolean(false);
|
||||
|
||||
if (enabled) {
|
||||
//webroot
|
||||
String webRootString = node.getNode("webroot").getString();
|
||||
if (webRootString == null) throw new IOException("Invalid configuration: Node webroot is not defined");
|
||||
webRoot = ConfigManager.toFolder(webRootString);
|
||||
|
||||
//ip
|
||||
String bindAdressString = node.getNode("ip").getString("");
|
||||
if (bindAdressString.isEmpty() || bindAdressString.equals("0.0.0.0") || bindAdressString.equals("::0")) {
|
||||
bindAdress = new InetSocketAddress(0).getAddress(); // 0.0.0.0
|
||||
} else if (bindAdressString.equals("#getLocalHost")) {
|
||||
bindAdress = InetAddress.getLocalHost();
|
||||
} else {
|
||||
bindAdress = InetAddress.getByName(bindAdressString);
|
||||
}
|
||||
|
||||
//port
|
||||
port = node.getNode("port").getInt(8100);
|
||||
|
||||
//maxConnectionCount
|
||||
maxConnections = node.getNode("maxConnectionCount").getInt(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isWebserverEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public File getWebRoot() {
|
||||
return webRoot;
|
||||
}
|
||||
|
||||
public InetAddress getWebserverBindAdress() {
|
||||
return bindAdress;
|
||||
}
|
||||
|
||||
public int getWebserverPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public int getWebserverMaxConnections() {
|
||||
return maxConnections;
|
||||
}
|
||||
|
||||
}
|
@ -27,7 +27,6 @@
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
@ -36,14 +35,14 @@
|
||||
|
||||
public class WebFilesManager {
|
||||
|
||||
private Path webRoot;
|
||||
private File webRoot;
|
||||
|
||||
public WebFilesManager(Path webRoot) {
|
||||
public WebFilesManager(File webRoot) {
|
||||
this.webRoot = webRoot;
|
||||
}
|
||||
|
||||
public boolean needsUpdate() {
|
||||
if (!webRoot.resolve("index.html").toFile().exists()) return true;
|
||||
if (!new File(webRoot, "index.html").exists()) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -58,9 +57,9 @@ public void updateFiles() throws IOException {
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry zipEntry = entries.nextElement();
|
||||
if (zipEntry.isDirectory()) webRoot.resolve(zipEntry.getName()).toFile().mkdirs();
|
||||
if (zipEntry.isDirectory()) new File(webRoot, zipEntry.getName()).mkdirs();
|
||||
else {
|
||||
File target = webRoot.resolve(zipEntry.getName()).toFile();
|
||||
File target = new File(webRoot, zipEntry.getName());
|
||||
FileUtils.copyInputStreamToFile(zipFile.getInputStream(zipEntry), target);
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of BlueMap, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.core.web;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface WebServerConfig {
|
||||
|
||||
Path getWebRoot();
|
||||
|
||||
InetAddress getWebserverBindAdress();
|
||||
|
||||
int getWebserverPort();
|
||||
|
||||
int getWebserverMaxConnections();
|
||||
|
||||
}
|
@ -32,7 +32,7 @@
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3f;
|
||||
|
||||
import de.bluecolored.bluemap.core.config.MainConfig.MapConfig;
|
||||
import de.bluecolored.bluemap.core.config.MapConfig;
|
||||
import de.bluecolored.bluemap.core.render.TileRenderer;
|
||||
import de.bluecolored.bluemap.core.util.MathUtils;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
|
Loading…
Reference in New Issue
Block a user