diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveBrightnessDataSupplier.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveBrightnessDataSupplier.java new file mode 100644 index 000000000..a1344619d --- /dev/null +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveBrightnessDataSupplier.java @@ -0,0 +1,78 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * 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.live; + +import com.google.gson.stream.JsonWriter; +import de.bluecolored.bluemap.common.serverinterface.Server; +import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Map; +import java.util.function.Supplier; + +public class LiveBrightnessDataSupplier implements Supplier { + + private final Server server; + + public LiveBrightnessDataSupplier(Server server) { + this.server = server; + } + + @Override + public String get() { + String dimensionName; + Key dimension; + + try (StringWriter jsonString = new StringWriter(); + JsonWriter json = new JsonWriter(jsonString)) { + + + json.beginObject(); + + json.name("brightness").beginArray(); + for (Map.Entry entry : this.server.getSkyBrightness().entrySet()) { + dimension = entry.getKey(); + dimensionName = dimension.getNamespace().equals("minecraft") ? + dimension.getValue() : dimension.getFormatted(); + json.beginObject(); + json.name("dimension").value(dimensionName); + json.name("val").value(entry.getValue()); + json.endObject(); + } + json.endArray(); + + json.endObject(); + + json.flush(); + return jsonString.toString(); + } catch (IOException ex) { + Logger.global.logError("Failed to write live/brightness json!", ex); + return "BlueMap - Exception handling this request"; + } + } + +} diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/serverinterface/Server.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/serverinterface/Server.java index 2430c39d5..f586b9858 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/serverinterface/Server.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/serverinterface/Server.java @@ -28,10 +28,12 @@ import de.bluecolored.bluemap.core.util.Tristate; import de.bluecolored.bluemap.core.world.World; import de.bluecolored.bluemap.core.world.mca.MCAWorld; +import de.bluecolored.bluemap.core.util.Key; import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.Collection; +import java.util.Map; import java.util.Optional; public interface Server { @@ -99,6 +101,9 @@ default Optional getServerWorld(Object world) { @DebugDump Collection getOnlinePlayers(); + @DebugDump + Map getSkyBrightness(); + /** * Registers a ServerEventListener, every method of this interface should be called on the specified events */ diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapRequestHandler.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapRequestHandler.java index eafe8dc62..422a9fda0 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapRequestHandler.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapRequestHandler.java @@ -27,6 +27,7 @@ import de.bluecolored.bluemap.common.config.PluginConfig; import de.bluecolored.bluemap.common.live.LiveMarkersDataSupplier; import de.bluecolored.bluemap.common.live.LivePlayersDataSupplier; +import de.bluecolored.bluemap.common.live.LiveBrightnessDataSupplier; import de.bluecolored.bluemap.common.serverinterface.Server; import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.map.BmMap; @@ -43,16 +44,18 @@ public class MapRequestHandler extends RoutingRequestHandler { public MapRequestHandler(BmMap map, Server serverInterface, PluginConfig pluginConfig, Predicate playerFilter) { this(map.getStorage(), createPlayersDataSupplier(map, serverInterface, pluginConfig, playerFilter), - new LiveMarkersDataSupplier(map.getMarkerSets())); + new LiveMarkersDataSupplier(map.getMarkerSets()), + new LiveBrightnessDataSupplier(serverInterface)); } public MapRequestHandler(MapStorage mapStorage) { - this(mapStorage, null, null); + this(mapStorage, null, null, null); } public MapRequestHandler(MapStorage mapStorage, @Nullable Supplier livePlayersDataSupplier, - @Nullable Supplier liveMarkerDataSupplier) { + @Nullable Supplier liveMarkerDataSupplier, + @Nullable Supplier liveBrightnessDataSupplier) { register(".*", new MapStorageRequestHandler(mapStorage)); @@ -67,6 +70,12 @@ public MapRequestHandler(MapStorage mapStorage, new CachedRateLimitDataSupplier(liveMarkerDataSupplier,10000) )); } + + if (liveBrightnessDataSupplier != null) { + register("live/brightness\\.json", "", new JsonDataRequestHandler( + new CachedRateLimitDataSupplier(liveBrightnessDataSupplier,1000) + )); + } } private static @Nullable LivePlayersDataSupplier createPlayersDataSupplier(BmMap map, Server serverInterface, PluginConfig pluginConfig, Predicate playerFilter) { diff --git a/BlueMapCommon/webapp/public/lang/en.conf b/BlueMapCommon/webapp/public/lang/en.conf index b3fbdfd93..167fbad62 100644 --- a/BlueMapCommon/webapp/public/lang/en.conf +++ b/BlueMapCommon/webapp/public/lang/en.conf @@ -53,6 +53,7 @@ } sunlight: "Sunlight" ambientLight: "Ambient-Light" + liveDaylightCycle: "Live Daylight Cycle" } resolution: { title: "Resolution" diff --git a/BlueMapCommon/webapp/src/components/Menu/SettingsMenu.vue b/BlueMapCommon/webapp/src/components/Menu/SettingsMenu.vue index 8cc6e45e5..c6893e35d 100644 --- a/BlueMapCommon/webapp/src/components/Menu/SettingsMenu.vue +++ b/BlueMapCommon/webapp/src/components/Menu/SettingsMenu.vue @@ -11,6 +11,7 @@ @update="mapViewer.uniforms.sunlightStrength.value = $event; $bluemap.mapViewer.redraw()">{{$t('lighting.sunlight')}} {{$t('lighting.ambientLight')}} + {{$t('lighting.liveDaylightCycle')}} diff --git a/BlueMapCommon/webapp/src/js/BlueMapApp.js b/BlueMapCommon/webapp/src/js/BlueMapApp.js index 9cde275cf..1ab76081d 100644 --- a/BlueMapCommon/webapp/src/js/BlueMapApp.js +++ b/BlueMapCommon/webapp/src/js/BlueMapApp.js @@ -97,7 +97,8 @@ export class BlueMapApp { showZoomButtons: true, invertMouse: false, enableFreeFlight: false, - pauseTileLoading: false + pauseTileLoading: false, + liveDaylightCycle: false, }, menu: this.mainMenu, maps: [], @@ -120,6 +121,7 @@ export class BlueMapApp { this.mapViewer.markers.add(this.popupMarkerSet); this.updateLoop = null; + this.updateDaylightCycle = null; this.hashUpdateTimeout = null; this.viewAnimation = null; @@ -182,6 +184,8 @@ export class BlueMapApp { // start app update loop if(this.updateLoop) clearTimeout(this.updateLoop); this.updateLoop = setTimeout(this.update, 1000); + if(this.updateDaylightCycle) clearTimeout(this.updateDaylightCycle); + this.updateDaylightCycle = setTimeout(this.updateDaylight, 1000); // save user settings this.saveUserSettings(); @@ -200,6 +204,24 @@ export class BlueMapApp { this.updateLoop = setTimeout(this.update, 1000); } + updateDaylight = () => { + if (!this.appState.controls.liveDaylightCycle) { + this.updateDaylightCycle = setTimeout(this.updateDaylight, 4000); + return; + } + if (!this.appState || !this.mapViewer.map) { + this.updateDaylightCycle = setTimeout(this.updateDaylight, 2000); + return; + } + this.updateBrightness().then(t => { + let timeout = Math.max(t, 2000); + this.updateDaylightCycle = setTimeout(this.updateDaylight, timeout); + }).catch(e => { + console.error(e); + this.updateDaylightCycle = setTimeout(this.updateDaylight, 3000); + }); + } + async followPlayerMarkerWorld() { /** @type {PlayerLike} */ let player = this.mapViewer.controlsManager.controls?.data.followingPlayer; @@ -383,6 +405,34 @@ export class BlueMapApp { }); } + async updateBrightness() { + /* + Fetch the brightness from the server and update the daylight cycle. + */ + return new Promise((resolve, reject) => { + let loader = new FileLoader(); + loader.setResponseType("json"); + loader.load(this.mapViewer.map.data.dataUrl + "live/brightness.json?" + generateCacheHash(), + fileData => { + if (!fileData || !fileData.brightness) { + reject("Failed to parse brightness.json"); + } + let world_name = this.mapViewer.map.data.name.match(/\(([^)]+)\)/)[1].toLowerCase(); + for (let idx=0; idx {}, () => { + reject("Failed to load brightness.json"); + } + ) + }); + } + initMarkerFileManager() { if (this.markerFileManager) this.markerFileManager.dispose(); @@ -612,6 +662,7 @@ export class BlueMapApp { this.appState.controls.mouseSensitivity = this.loadUserSetting("mouseSensitivity", this.appState.controls.mouseSensitivity); this.appState.controls.invertMouse = this.loadUserSetting("invertMouse", this.appState.controls.invertMouse); this.appState.controls.pauseTileLoading = this.loadUserSetting("pauseTileLoading", this.appState.controls.pauseTileLoading); + this.appState.controls.liveDaylightCycle = this.loadUserSetting("liveDaylightCycle", this.appState.controls.liveDaylightCycle); this.appState.controls.showZoomButtons = this.loadUserSetting("showZoomButtons", this.appState.controls.showZoomButtons); this.updateControlsSettings(); this.setTheme(this.loadUserSetting("theme", this.appState.theme)); @@ -635,6 +686,7 @@ export class BlueMapApp { this.saveUserSetting("mouseSensitivity", this.appState.controls.mouseSensitivity); this.saveUserSetting("invertMouse", this.appState.controls.invertMouse); this.saveUserSetting("pauseTileLoading", this.appState.controls.pauseTileLoading); + this.saveUserSetting("liveDaylightCycle", this.appState.controls.liveDaylightCycle); this.saveUserSetting("showZoomButtons", this.appState.controls.showZoomButtons); this.saveUserSetting("theme", this.appState.theme); this.saveUserSetting("screenshotClipboard", this.appState.screenshot.clipboard); diff --git a/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java b/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java index 1213b877b..159ab1d91 100644 --- a/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java +++ b/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -238,4 +239,13 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (net.minecraft.server.world.ServerWorld world : serverInstance.getWorlds()) { + skyBrightness.put(worlds.get(world).getDimension(), world.getAmbientDarkness()); + } + return skyBrightness; + } + } diff --git a/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java b/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java index 7a4a8d92a..818384dee 100644 --- a/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java +++ b/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -238,4 +239,13 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (net.minecraft.server.world.ServerWorld world : serverInstance.getWorlds()) { + skyBrightness.put(worlds.get(world).getDimension(), world.getAmbientDarkness()); + } + return skyBrightness; + } + } diff --git a/implementations/fabric-1.20.5/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java b/implementations/fabric-1.20.5/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java index 2d2c3fa19..f24594179 100644 --- a/implementations/fabric-1.20.5/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java +++ b/implementations/fabric-1.20.5/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -238,4 +239,13 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (net.minecraft.server.world.ServerWorld world : serverInstance.getWorlds()) { + skyBrightness.put(worlds.get(world).getDimension(), world.getAmbientDarkness()); + } + return skyBrightness; + } + } diff --git a/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java b/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java index 2a40f4b95..e65d13652 100644 --- a/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java +++ b/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -238,4 +239,13 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (net.minecraft.server.world.ServerWorld world : serverInstance.getWorlds()) { + skyBrightness.put(worlds.get(world).getDimension(), world.getAmbientDarkness()); + } + return skyBrightness; + } + } diff --git a/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java b/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java index 2d2c3fa19..f24594179 100644 --- a/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java +++ b/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -238,4 +239,13 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (net.minecraft.server.world.ServerWorld world : serverInstance.getWorlds()) { + skyBrightness.put(worlds.get(world).getDimension(), world.getAmbientDarkness()); + } + return skyBrightness; + } + } diff --git a/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index 41c0baf8a..91232752f 100644 --- a/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.minecraft.SharedConstants; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; @@ -254,4 +255,14 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + Iterable levels = serverInstance.getAllLevels(); + for (ServerLevel level : levels) { + skyBrightness.put(worlds.get(level).getDimension(), level.getSkyDarken()); + } + return skyBrightness; + } + } diff --git a/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index c774f3dbd..71e9300d0 100644 --- a/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.minecraft.SharedConstants; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -254,4 +255,14 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + Iterable levels = serverInstance.getAllLevels(); + for (ServerLevel level : levels) { + skyBrightness.put(worlds.get(level).getDimension(), level.getSkyDarken()); + } + return skyBrightness; + } + } diff --git a/implementations/forge-1.20.6/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/implementations/forge-1.20.6/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index 2a3277f1c..9f736853c 100644 --- a/implementations/forge-1.20.6/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/implementations/forge-1.20.6/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.minecraft.SharedConstants; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -259,4 +260,14 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + Iterable levels = serverInstance.getAllLevels(); + for (ServerLevel level : levels) { + skyBrightness.put(worlds.get(level).getDimension(), level.getSkyDarken()); + } + return skyBrightness; + } + } diff --git a/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index 77ed826e0..bdbd64968 100644 --- a/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.minecraft.SharedConstants; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -254,4 +255,14 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + Iterable levels = serverInstance.getAllLevels(); + for (ServerLevel level : levels) { + skyBrightness.put(worlds.get(level).getDimension(), level.getSkyDarken()); + } + return skyBrightness; + } + } diff --git a/implementations/forge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/implementations/forge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index 2a3277f1c..9f736853c 100644 --- a/implementations/forge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/implementations/forge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.minecraft.SharedConstants; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -259,4 +260,14 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + Iterable levels = serverInstance.getAllLevels(); + for (ServerLevel level : levels) { + skyBrightness.put(worlds.get(level).getDimension(), level.getSkyDarken()); + } + return skyBrightness; + } + } diff --git a/implementations/neoforge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/implementations/neoforge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index 60726dd3f..2c46fdd73 100644 --- a/implementations/neoforge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/implementations/neoforge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import net.minecraft.SharedConstants; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -247,4 +248,14 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + Iterable levels = serverInstance.getAllLevels(); + for (ServerLevel level : levels) { + skyBrightness.put(worlds.get(level).getDimension(), level.getSkyDarken()); + } + return skyBrightness; + } + } diff --git a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java index 661fdf906..5f2226e2f 100644 --- a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java +++ b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java @@ -258,4 +258,23 @@ private void initPlayer(org.bukkit.entity.Player bukkitPlayer) { ); } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (World world : getServer().getWorlds()) { + int darken = 0; + long time = world.getTime(); + + if (time >= 12100 && time <= 12800) darken = 3; + else if (time > 12800 && time <= 13200) darken = 6; + else if (time > 13200 && time <= 22700) darken = 11; + else if (time > 23000 && time <= 23400) darken = 6; + else if (time > 23400 && time <= 23850) darken = 3; + else darken = 0; + + skyBrightness.put(worlds.get(world).getDimension(), darken); + } + return skyBrightness; + } + } diff --git a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java index 8a9ec6ac9..399a1a442 100644 --- a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java +++ b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java @@ -284,4 +284,23 @@ private void updateSomePlayers() { } } + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (World world : getServer().getWorlds()) { + int darken = 0; + long time = world.getTime(); + + if (time >= 12100 && time <= 12800) darken = 3; + else if (time > 12800 && time <= 13200) darken = 6; + else if (time > 13200 && time <= 22700) darken = 11; + else if (time > 23000 && time <= 23400) darken = 6; + else if (time > 23400 && time <= 23850) darken = 3; + else darken = 0; + + skyBrightness.put(worlds.get(world).getDimension(), darken); + } + return skyBrightness; + } + } diff --git a/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java b/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java index 4d0abbc19..e5544ac1d 100644 --- a/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java +++ b/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java @@ -37,6 +37,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.sponge.SpongeCommands.SpongeCommandProxy; import org.spongepowered.api.ResourceKey; import org.spongepowered.api.Sponge; @@ -317,4 +318,23 @@ public Plugin getPlugin() { public static SpongePlugin getInstance() { return instance; } + + @Override + public Map getSkyBrightness() { + Map skyBrightness = new HashMap<>(); + for (var world : Sponge.server().worldManager().worlds()) { + int darken = 0; + long time = world.properties().dayTime().asTicks().ticks() % 24000; + + if (time >= 12100 && time <= 12800) darken = 3; + else if (time > 12800 && time <= 13200) darken = 6; + else if (time > 13200 && time <= 22700) darken = 11; + else if (time > 23000 && time <= 23400) darken = 6; + else if (time > 23400 && time <= 23850) darken = 3; + else darken = 0; + + skyBrightness.put(worlds.get(world).getDimension(), darken); + } + return skyBrightness; + } }