mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-22 10:35:16 +01:00
Add live-api configurations
This commit is contained in:
parent
3a5dac58ea
commit
1716098622
@ -9,3 +9,9 @@ webserver {
|
||||
port: 8100
|
||||
maxConnectionCount: 100
|
||||
}
|
||||
liveUpdates {
|
||||
enabled: true
|
||||
hiddenGameModes: []
|
||||
hideInvisible: true
|
||||
hideSneaking: false
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ webroot: "bluemap/web"
|
||||
#webdata: "path/to/data/folder"
|
||||
|
||||
# If the web-application should use cookies to save the configurations of a user.
|
||||
# Default is true
|
||||
useCookies: true
|
||||
|
||||
webserver {
|
||||
@ -165,3 +166,23 @@ maps: [
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
liveUpdates {
|
||||
# If the server should send live-updates and player-positions.
|
||||
# Default is true
|
||||
enabled: true
|
||||
|
||||
# A list of gamemodes that will prevent a player from appearing on the map.
|
||||
# Possible values are: survival, creative, spectator, adventure
|
||||
hiddenGameModes: [
|
||||
"spectator"
|
||||
]
|
||||
|
||||
# If this is true, players that have an invisibility (potion-)effect will be hidden on the map.
|
||||
# Default is true
|
||||
hideInvisible: true
|
||||
|
||||
# If this is true, players that are sneaking will be hidden on the map.
|
||||
# Default is false
|
||||
hideSneaking: false
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
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;
|
||||
@ -50,12 +51,12 @@ public BlueMapWebServer(WebServerConfig config) {
|
||||
this.webFilesManager = new WebFilesManager(config.getWebRoot());
|
||||
}
|
||||
|
||||
public BlueMapWebServer(WebServerConfig config, ServerInterface server) {
|
||||
public BlueMapWebServer(WebServerConfig config, LiveAPISettings liveSettings, ServerInterface server) {
|
||||
super(
|
||||
config.getWebserverPort(),
|
||||
config.getWebserverMaxConnections(),
|
||||
config.getWebserverBindAdress(),
|
||||
new LiveAPIRequestHandler(server, new FileRequestHandler(config.getWebRoot(), "BlueMap/Webserver"))
|
||||
new LiveAPIRequestHandler(server, liveSettings, new FileRequestHandler(config.getWebRoot(), "BlueMap/Webserver"))
|
||||
);
|
||||
|
||||
this.webFilesManager = new WebFilesManager(config.getWebRoot());
|
||||
|
@ -31,9 +31,9 @@
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Gamemode;
|
||||
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,7 +45,9 @@ public class LiveAPIRequestHandler implements HttpRequestHandler {
|
||||
private Map<String, HttpRequestHandler> liveAPIRequests;
|
||||
private ServerInterface server;
|
||||
|
||||
public LiveAPIRequestHandler(ServerInterface server, HttpRequestHandler notFoundHandler) {
|
||||
private LiveAPISettings config;
|
||||
|
||||
public LiveAPIRequestHandler(ServerInterface server, LiveAPISettings config, HttpRequestHandler notFoundHandler) {
|
||||
this.server = server;
|
||||
this.notFoundHandler = notFoundHandler;
|
||||
|
||||
@ -53,10 +55,14 @@ public LiveAPIRequestHandler(ServerInterface server, HttpRequestHandler notFound
|
||||
|
||||
this.liveAPIRequests.put("live", this::handleLivePingRequest);
|
||||
this.liveAPIRequests.put("live/players", this::handlePlayersRequest);
|
||||
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResponse handle(HttpRequest request) {
|
||||
if (!config.isLiveUpdatesEnabled()) this.notFoundHandler.handle(request);
|
||||
|
||||
HttpRequestHandler handler = liveAPIRequests.get(request.getPath());
|
||||
if (handler != null) return handler.handle(request);
|
||||
|
||||
@ -81,9 +87,9 @@ public HttpResponse handlePlayersRequest(HttpRequest request) {
|
||||
json.name("players").beginArray();
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
|
||||
if (player.isInvisible()) continue;
|
||||
if (player.isSneaking()) continue;
|
||||
if (player.getGamemode() == Gamemode.SPECTATOR) continue;
|
||||
if (config.isHideInvisible() && player.isInvisible()) continue;
|
||||
if (config.isHideSneaking() && player.isSneaking()) continue;
|
||||
if (config.getHiddenGameModes().contains(player.getGamemode().getId())) continue;
|
||||
|
||||
json.beginObject();
|
||||
json.name("uuid").value(player.getUuid().toString());
|
||||
|
@ -272,8 +272,10 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
serverInterface.registerListener(updateHandler);
|
||||
|
||||
//start skin updater
|
||||
this.skinUpdater = new PlayerSkinUpdater(config.getWebRoot().resolve("assets").resolve("playerheads").toFile());
|
||||
serverInterface.registerListener(skinUpdater);
|
||||
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());
|
||||
@ -299,7 +301,7 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
|
||||
//start webserver
|
||||
if (config.isWebserverEnabled()) {
|
||||
webServer = new BlueMapWebServer(config, serverInterface);
|
||||
webServer = new BlueMapWebServer(config, config, serverInterface);
|
||||
webServer.updateWebfiles();
|
||||
webServer.start();
|
||||
}
|
||||
|
@ -26,9 +26,29 @@
|
||||
|
||||
public enum Gamemode {
|
||||
|
||||
SURVIVAL,
|
||||
CREATIVE,
|
||||
ADVENTURE,
|
||||
SPECTATOR
|
||||
SURVIVAL ("survival"),
|
||||
CREATIVE ("creative"),
|
||||
ADVENTURE ("adventure"),
|
||||
SPECTATOR ("spectator");
|
||||
|
||||
private final String id;
|
||||
|
||||
Gamemode(String id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Gamemode getById(String id) {
|
||||
if (id == null) throw new NullPointerException("id cannot be null");
|
||||
|
||||
for (Gamemode gamemode : values()) {
|
||||
if (gamemode.id.equals(id)) return gamemode;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("There is no Gamemode with id: '" + id + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.util.Collection;
|
||||
|
||||
public interface LiveAPISettings {
|
||||
|
||||
boolean isLiveUpdatesEnabled();
|
||||
|
||||
Collection<String> getHiddenGameModes();
|
||||
|
||||
boolean isHideInvisible();
|
||||
|
||||
boolean isHideSneaking();
|
||||
|
||||
}
|
@ -31,6 +31,8 @@
|
||||
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;
|
||||
|
||||
@ -43,7 +45,7 @@
|
||||
import de.bluecolored.bluemap.core.web.WebServerConfig;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
|
||||
public class MainConfig implements WebServerConfig {
|
||||
public class MainConfig implements WebServerConfig, LiveAPISettings {
|
||||
private static final Pattern VALID_ID_PATTERN = Pattern.compile("[a-zA-Z0-9_]+");
|
||||
|
||||
private boolean downloadAccepted = false;
|
||||
@ -64,6 +66,11 @@ public class MainConfig implements WebServerConfig {
|
||||
|
||||
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);
|
||||
|
||||
@ -101,6 +108,19 @@ public MainConfig(ConfigurationNode node) throws OutdatedConfigException, IOExce
|
||||
|
||||
//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 {
|
||||
@ -196,6 +216,26 @@ 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;
|
||||
|
@ -9,3 +9,9 @@ webserver {
|
||||
port: 8100
|
||||
maxConnectionCount: 100
|
||||
}
|
||||
liveUpdates {
|
||||
enabled: true
|
||||
hiddenGameModes: []
|
||||
hideInvisible: true
|
||||
hideSneaking: false
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ webroot: "bluemap/web"
|
||||
#webdata: "path/to/data/folder"
|
||||
|
||||
# If the web-application should use cookies to save the configurations of a user.
|
||||
# Default is true
|
||||
useCookies: true
|
||||
|
||||
webserver {
|
||||
@ -165,3 +166,23 @@ maps: [
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
liveUpdates {
|
||||
# If the server should send live-updates and player-positions.
|
||||
# Default is true
|
||||
enabled: true
|
||||
|
||||
# A list of gamemodes that will prevent a player from appearing on the map.
|
||||
# Possible values are: survival, creative, spectator, adventure
|
||||
hiddenGameModes: [
|
||||
"spectator"
|
||||
]
|
||||
|
||||
# If this is true, players that have an invisibility (potion-)effect will be hidden on the map.
|
||||
# Default is true
|
||||
hideInvisible: true
|
||||
|
||||
# If this is true, players that are sneaking will be hidden on the map.
|
||||
# Default is false
|
||||
hideSneaking: false
|
||||
}
|
||||
|
@ -9,3 +9,9 @@ webserver {
|
||||
port: 8100
|
||||
maxConnectionCount: 100
|
||||
}
|
||||
liveUpdates {
|
||||
enabled: true
|
||||
hiddenGameModes: []
|
||||
hideInvisible: true
|
||||
hideSneaking: false
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ webroot: "bluemap/web"
|
||||
#webdata: "path/to/data/folder"
|
||||
|
||||
# If the web-application should use cookies to save the configurations of a user.
|
||||
# Default is true
|
||||
useCookies: true
|
||||
|
||||
webserver {
|
||||
@ -165,3 +166,23 @@ maps: [
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
liveUpdates {
|
||||
# If the server should send live-updates and player-positions.
|
||||
# Default is true
|
||||
enabled: true
|
||||
|
||||
# A list of gamemodes that will prevent a player from appearing on the map.
|
||||
# Possible values are: survival, creative, spectator, adventure
|
||||
hiddenGameModes: [
|
||||
"spectator"
|
||||
]
|
||||
|
||||
# If this is true, players that have an invisibility (potion-)effect will be hidden on the map.
|
||||
# Default is true
|
||||
hideInvisible: true
|
||||
|
||||
# If this is true, players that are sneaking will be hidden on the map.
|
||||
# Default is false
|
||||
hideSneaking: false
|
||||
}
|
||||
|
@ -9,3 +9,9 @@ webserver {
|
||||
port: 8100
|
||||
maxConnectionCount: 100
|
||||
}
|
||||
liveUpdates {
|
||||
enabled: true
|
||||
hiddenGameModes: []
|
||||
hideInvisible: true
|
||||
hideSneaking: false
|
||||
}
|
||||
|
@ -160,3 +160,23 @@ maps: [
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
liveUpdates {
|
||||
# If the server should send live-updates and player-positions.
|
||||
# Default is true
|
||||
enabled: true
|
||||
|
||||
# A list of gamemodes that will prevent a player from appearing on the map.
|
||||
# Possible values are: survival, creative, spectator, adventure
|
||||
hiddenGameModes: [
|
||||
"spectator"
|
||||
]
|
||||
|
||||
# If this is true, players that have an invisibility (potion-)effect will be hidden on the map.
|
||||
# Default is true
|
||||
hideInvisible: true
|
||||
|
||||
# If this is true, players that are sneaking will be hidden on the map.
|
||||
# Default is false
|
||||
hideSneaking: false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user