WIP - Compiling and starting without exceptions :)
This commit is contained in:
parent
00149330f1
commit
d1452faa52
|
@ -26,10 +26,16 @@ package de.bluecolored.bluemap.common;
|
|||
|
||||
import de.bluecolored.bluemap.common.config.*;
|
||||
import de.bluecolored.bluemap.common.config.storage.StorageConfig;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
public interface BlueMapConfiguration {
|
||||
|
||||
MinecraftVersion getMinecraftVersion();
|
||||
|
||||
CoreConfig getCoreConfig();
|
||||
|
||||
WebappConfig getWebappConfig();
|
||||
|
@ -42,4 +48,8 @@ public interface BlueMapConfiguration {
|
|||
|
||||
Map<String, StorageConfig> getStorageConfigs();
|
||||
|
||||
@Nullable Path getResourcePacksFolder();
|
||||
|
||||
@Nullable Path getModsFolder();
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ import de.bluecolored.bluemap.core.util.FileHelper;
|
|||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
|
@ -74,10 +73,17 @@ public class BlueMapService implements Closeable {
|
|||
private final BlueMapConfiguration config;
|
||||
private final WebFilesManager webFilesManager;
|
||||
|
||||
private final Map<WorldKey, World> worlds;
|
||||
private ResourcePack resourcePack;
|
||||
private final Map<String, World> worlds;
|
||||
private final Map<String, BmMap> maps;
|
||||
private final Map<String, Storage> storages;
|
||||
|
||||
|
||||
public BlueMapService(BlueMapConfiguration configuration, @Nullable ResourcePack preloadedResourcePack) {
|
||||
this(configuration);
|
||||
this.resourcePack = preloadedResourcePack;
|
||||
}
|
||||
|
||||
public BlueMapService(BlueMapConfiguration configuration) {
|
||||
this.config = configuration;
|
||||
this.webFilesManager = new WebFilesManager(config.getWebappConfig().getWebroot());
|
||||
|
@ -119,29 +125,45 @@ public class BlueMapService implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
public @Nullable Collection<World> getWorlds() {
|
||||
return worlds.values();
|
||||
/**
|
||||
* Gets all loaded maps.
|
||||
* @return A map of loaded maps
|
||||
*/
|
||||
public Map<String, BmMap> getMaps() {
|
||||
return Collections.unmodifiableMap(maps);
|
||||
}
|
||||
|
||||
public @Nullable Map<String, BmMap> getMaps() {
|
||||
return maps;
|
||||
/**
|
||||
* Gets all loaded worlds.
|
||||
* @return A map of loaded worlds
|
||||
*/
|
||||
public Map<String, World> getWorlds() {
|
||||
return Collections.unmodifiableMap(worlds);
|
||||
}
|
||||
|
||||
public Map<String, BmMap> loadMaps() throws InterruptedException {
|
||||
loadWorldsAndMaps(mapId -> true);
|
||||
return maps;
|
||||
/**
|
||||
* Gets or loads configured maps.
|
||||
* @return A map of loaded maps
|
||||
*/
|
||||
public Map<String, BmMap> getOrLoadMaps() throws InterruptedException {
|
||||
return getOrLoadMaps(mapId -> true);
|
||||
}
|
||||
|
||||
public Map<String, BmMap> loadMaps(Predicate<String> mapFilter) throws InterruptedException {
|
||||
loadWorldsAndMaps(mapFilter);
|
||||
return maps;
|
||||
}
|
||||
|
||||
private synchronized void loadWorldsAndMaps(Predicate<String> mapFilter) throws InterruptedException {
|
||||
/**
|
||||
* Gets or loads configured maps.
|
||||
* @param filter A predicate filtering map-ids that should be loaded
|
||||
* (if maps are already loaded, they will be returned as well)
|
||||
* @return A map of all loaded maps
|
||||
*/
|
||||
public synchronized Map<String, BmMap> getOrLoadMaps(Predicate<String> filter) throws InterruptedException {
|
||||
for (var entry : config.getMapConfigs().entrySet()) {
|
||||
if (!mapFilter.test(entry.getKey())) continue;
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
if (!filter.test(entry.getKey())) continue;
|
||||
if (maps.containsKey(entry.getKey())) continue;
|
||||
|
||||
try {
|
||||
loadMapConfig(entry.getKey(), entry.getValue());
|
||||
loadMap(entry.getKey(), entry.getValue());
|
||||
} catch (ConfigurationException ex) {
|
||||
Logger.global.logWarning(ex.getFormattedExplanation());
|
||||
Throwable cause = ex.getRootCause();
|
||||
|
@ -150,9 +172,10 @@ public class BlueMapService implements Closeable {
|
|||
}
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(maps);
|
||||
}
|
||||
|
||||
private synchronized void loadMapConfig(String id, MapConfig mapConfig) throws ConfigurationException, InterruptedException {
|
||||
private synchronized void loadMap(String id, MapConfig mapConfig) throws ConfigurationException, InterruptedException {
|
||||
String name = mapConfig.getName();
|
||||
if (name == null) name = id;
|
||||
|
||||
|
@ -171,22 +194,22 @@ public class BlueMapService implements Closeable {
|
|||
"Check if the 'world' setting in the config-file for that map is correct, or remove the entire config-file if you don't want that map.");
|
||||
}
|
||||
|
||||
WorldKey worldKey = new WorldKey(worldFolder, dimension);
|
||||
World world = worlds.get(worldKey);
|
||||
String worldId = MCAWorld.id(worldFolder, dimension);
|
||||
World world = worlds.get(worldId);
|
||||
if (world == null) {
|
||||
try {
|
||||
Logger.global.logInfo("Loading world " + worldKey + " ...");
|
||||
Logger.global.logDebug("Loading world " + worldId + " ...");
|
||||
world = MCAWorld.load(worldFolder, dimension);
|
||||
worlds.put(worldKey, world);
|
||||
worlds.put(worldId, world);
|
||||
} catch (IOException ex) {
|
||||
throw new ConfigurationException(
|
||||
"Failed to load world " + worldKey + "!\n" +
|
||||
"Failed to load world " + worldId + "!\n" +
|
||||
"Is the level.dat of that world present and not corrupted?",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
Storage storage = getStorage(mapConfig.getStorage());
|
||||
Storage storage = getOrLoadStorage(mapConfig.getStorage());
|
||||
|
||||
try {
|
||||
|
||||
|
@ -196,7 +219,7 @@ public class BlueMapService implements Closeable {
|
|||
name,
|
||||
world,
|
||||
storage,
|
||||
loadResourcePack(),
|
||||
getOrLoadResourcePack(),
|
||||
mapConfig
|
||||
);
|
||||
maps.put(id, map);
|
||||
|
@ -227,7 +250,7 @@ public class BlueMapService implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized Storage getStorage(String storageId) throws ConfigurationException {
|
||||
public synchronized Storage getOrLoadStorage(String storageId) throws ConfigurationException, InterruptedException {
|
||||
Storage storage = storages.get(storageId);
|
||||
|
||||
if (storage == null) {
|
||||
|
@ -265,24 +288,30 @@ public class BlueMapService implements Closeable {
|
|||
return storage;
|
||||
}
|
||||
|
||||
public synchronized ResourcePack loadResourcePack() throws ConfigurationException, InterruptedException {
|
||||
public @Nullable ResourcePack getResourcePack() {
|
||||
return resourcePack;
|
||||
}
|
||||
|
||||
public synchronized ResourcePack getOrLoadResourcePack() throws ConfigurationException, InterruptedException {
|
||||
if (resourcePack == null) {
|
||||
MinecraftVersion minecraftVersion = serverInterface.getMinecraftVersion();
|
||||
MinecraftVersion minecraftVersion = config.getMinecraftVersion();
|
||||
@Nullable Path resourcePackFolder = config.getResourcePacksFolder();
|
||||
@Nullable Path modsFolder = config.getModsFolder();
|
||||
|
||||
Path defaultResourceFile = config.getCoreConfig().getData().resolve("minecraft-client-" + minecraftVersion.getResource().getVersion().getVersionString() + ".jar");
|
||||
Path resourceExtensionsFile = config.getCoreConfig().getData().resolve("resourceExtensions.zip");
|
||||
|
||||
Path resourcePackFolder = serverInterface.getConfigFolder().resolve("resourcepacks");
|
||||
try {
|
||||
FileHelper.createDirectories(resourcePackFolder);
|
||||
} catch (IOException ex) {
|
||||
throw new ConfigurationException(
|
||||
"BlueMap failed to create this folder:\n" +
|
||||
resourcePackFolder + "\n" +
|
||||
"Does BlueMap have sufficient permissions?",
|
||||
ex);
|
||||
}
|
||||
|
||||
try {
|
||||
FileHelper.createDirectories(resourcePackFolder);
|
||||
} catch (IOException ex) {
|
||||
throw new ConfigurationException(
|
||||
"BlueMap failed to create this folder:\n" +
|
||||
resourcePackFolder + "\n" +
|
||||
"Does BlueMap have sufficient permissions?",
|
||||
ex);
|
||||
}
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
if (!Files.exists(defaultResourceFile)) {
|
||||
if (config.getCoreConfig().isAcceptDownload()) {
|
||||
|
@ -304,37 +333,43 @@ public class BlueMapService implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
try {
|
||||
Files.deleteIfExists(resourceExtensionsFile);
|
||||
FileHelper.createDirectories(resourceExtensionsFile.getParent());
|
||||
URL resourceExtensionsUrl = Objects.requireNonNull(
|
||||
Plugin.class.getResource(
|
||||
"/de/bluecolored/bluemap/" + minecraftVersion.getResource().getResourcePrefix() +
|
||||
"/resourceExtensions.zip")
|
||||
"/resourceExtensions.zip")
|
||||
);
|
||||
FileUtils.copyURLToFile(resourceExtensionsUrl, resourceExtensionsFile.toFile(), 10000, 10000);
|
||||
} catch (IOException ex) {
|
||||
throw new ConfigurationException(
|
||||
"Failed to create resourceExtensions.zip!\n" +
|
||||
"Does BlueMap has sufficient write permissions?",
|
||||
"Does BlueMap has sufficient write permissions?",
|
||||
ex);
|
||||
}
|
||||
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
try {
|
||||
resourcePack = new ResourcePack();
|
||||
ResourcePack resourcePack = new ResourcePack();
|
||||
|
||||
List<Path> resourcePackRoots = new ArrayList<>();
|
||||
// load from resourcepack folder
|
||||
try (Stream<Path> resourcepackFiles = Files.list(resourcePackFolder)) {
|
||||
resourcepackFiles
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.forEach(resourcePackRoots::add);
|
||||
|
||||
if (resourcePackFolder != null) {
|
||||
// load from resourcepack folder
|
||||
try (Stream<Path> resourcepackFiles = Files.list(resourcePackFolder)) {
|
||||
resourcepackFiles
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.forEach(resourcePackRoots::add);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.getCoreConfig().isScanForModResources()) {
|
||||
|
||||
// load from mods folder
|
||||
Path modsFolder = serverInterface.getModsFolder().orElse(null);
|
||||
if (modsFolder != null && Files.isDirectory(modsFolder)) {
|
||||
try (Stream<Path> resourcepackFiles = Files.list(modsFolder)) {
|
||||
resourcepackFiles
|
||||
|
@ -360,18 +395,15 @@ public class BlueMapService implements Closeable {
|
|||
resourcePackRoots.add(defaultResourceFile);
|
||||
|
||||
resourcePack.loadResources(resourcePackRoots);
|
||||
|
||||
this.resourcePack = resourcePack;
|
||||
} catch (IOException | RuntimeException e) {
|
||||
throw new ConfigurationException("Failed to parse resources!\n" +
|
||||
"Is one of your resource-packs corrupted?", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resourcePack;
|
||||
}
|
||||
|
||||
public Optional<ResourcePack> getResourcePackIfLoaded() {
|
||||
return Optional.ofNullable(this.resourcePack);
|
||||
return this.resourcePack;
|
||||
}
|
||||
|
||||
private Collection<Path> getWorldFolders() {
|
||||
|
@ -410,21 +442,4 @@ public class BlueMapService implements Closeable {
|
|||
throw exception;
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
private static class WorldKey {
|
||||
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public WorldKey(Path worldFolder, Key dimension) {
|
||||
this.worldFolder = worldFolder;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return worldFolder + "[" + dimension + "]";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import de.bluecolored.bluemap.api.BlueMapAPI;
|
|||
import de.bluecolored.bluemap.api.BlueMapMap;
|
||||
import de.bluecolored.bluemap.api.BlueMapWorld;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
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.map.BmMap;
|
||||
|
@ -76,9 +77,7 @@ public class BlueMapAPIImpl extends BlueMapAPI {
|
|||
|
||||
@Override
|
||||
public Collection<BlueMapMap> getMaps() {
|
||||
Map<String, BmMap> maps = plugin.getMaps();
|
||||
if (maps == null) return Collections.emptyList();
|
||||
|
||||
Map<String, BmMap> maps = plugin.getBlueMap().getMaps();
|
||||
return maps.values().stream()
|
||||
.map(map -> {
|
||||
try {
|
||||
|
@ -94,9 +93,7 @@ public class BlueMapAPIImpl extends BlueMapAPI {
|
|||
|
||||
@Override
|
||||
public Collection<BlueMapWorld> getWorlds() {
|
||||
Map<String, World> worlds = plugin.getWorlds();
|
||||
if (worlds == null) return Collections.emptyList();
|
||||
|
||||
Map<String, World> worlds = plugin.getBlueMap().getWorlds();
|
||||
return worlds.values().stream()
|
||||
.map(world -> getWorld(world).orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
|
@ -109,36 +106,19 @@ public class BlueMapAPIImpl extends BlueMapAPI {
|
|||
}
|
||||
|
||||
public Optional<BlueMapWorld> getWorldUncached(Object world) {
|
||||
var worlds = plugin.getWorlds();
|
||||
if (worlds == null) return Optional.empty();
|
||||
|
||||
if (world instanceof UUID) {
|
||||
var coreWorld = worlds.get(world.toString());
|
||||
if (coreWorld != null) world = coreWorld;
|
||||
}
|
||||
|
||||
if (world instanceof String) {
|
||||
var coreWorld = worlds.get(world);
|
||||
if (coreWorld != null) world = coreWorld;
|
||||
}
|
||||
|
||||
if (world instanceof MCAWorld) {
|
||||
var coreWorld = (MCAWorld) world;
|
||||
return Optional.of(new BlueMapWorldImpl(plugin, coreWorld));
|
||||
}
|
||||
|
||||
var serverWorld = plugin.getServerInterface().getWorld(world).orElse(null);
|
||||
ServerWorld serverWorld = plugin.getServerInterface().getServerWorld(world).orElse(null);
|
||||
if (serverWorld == null) return Optional.empty();
|
||||
|
||||
String id = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
World coreWorld = worlds.get(id);
|
||||
World coreWorld = plugin.getWorld(serverWorld);
|
||||
if (coreWorld == null) return Optional.empty();
|
||||
|
||||
if (coreWorld instanceof MCAWorld)
|
||||
return Optional.of(new BlueMapWorldImpl(plugin, (MCAWorld) coreWorld));
|
||||
|
||||
return Optional.empty();
|
||||
|
||||
return Optional.of(new BlueMapWorldImpl(plugin, coreWorld));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,8 +127,7 @@ public class BlueMapAPIImpl extends BlueMapAPI {
|
|||
}
|
||||
|
||||
public Optional<BlueMapMap> getMapUncached(String id) {
|
||||
var maps = plugin.getMaps();
|
||||
if (maps == null) return Optional.empty();
|
||||
var maps = plugin.getBlueMap().getMaps();
|
||||
|
||||
var map = maps.get(id);
|
||||
if (map == null) return Optional.empty();
|
||||
|
|
|
@ -30,7 +30,6 @@ import de.bluecolored.bluemap.common.plugin.Plugin;
|
|||
import de.bluecolored.bluemap.core.world.World;
|
||||
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
@ -39,13 +38,13 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class BlueMapWorldImpl implements BlueMapWorld {
|
||||
|
||||
private final WeakReference<Plugin> plugin;
|
||||
private final String id;
|
||||
private final WeakReference<MCAWorld> world;
|
||||
private final WeakReference<Plugin> plugin;
|
||||
private final WeakReference<World> world;
|
||||
|
||||
public BlueMapWorldImpl(Plugin plugin, MCAWorld world) throws IOException {
|
||||
public BlueMapWorldImpl(Plugin plugin, World world) {
|
||||
this.id = world.getId();
|
||||
this.plugin = new WeakReference<>(plugin);
|
||||
this.id = plugin.getBlueMap().getWorldId(world.getDimensionFolder());
|
||||
this.world = new WeakReference<>(world);
|
||||
}
|
||||
|
||||
|
@ -59,13 +58,19 @@ public class BlueMapWorldImpl implements BlueMapWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Path getSaveFolder() {
|
||||
return unpack(world).getDimensionFolder();
|
||||
World world = unpack(this.world);
|
||||
if (world instanceof MCAWorld) {
|
||||
return ((MCAWorld) world).getDimensionFolder();
|
||||
} else {
|
||||
throw new UnsupportedOperationException("This world-type has no save-folder.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BlueMapMap> getMaps() {
|
||||
return unpack(plugin).getMaps().values().stream()
|
||||
return unpack(plugin).getBlueMap().getMaps().values().stream()
|
||||
.filter(map -> map.getWorld().equals(unpack(world)))
|
||||
.map(map -> new BlueMapMapImpl(unpack(plugin), map, this))
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
|
|
|
@ -82,7 +82,7 @@ public class RenderManagerImpl implements RenderManager {
|
|||
@Override
|
||||
public void start() {
|
||||
if (!isRunning()){
|
||||
renderManager.start(plugin.getConfigs().getCoreConfig().getRenderThreadCount());
|
||||
renderManager.start(plugin.getBlueMap().getConfig().getCoreConfig().getRenderThreadCount());
|
||||
}
|
||||
plugin.getPluginState().setRenderThreadsEnabled(true);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class WebAppImpl implements WebApp {
|
|||
|
||||
@Override
|
||||
public Path getWebRoot() {
|
||||
return plugin.getConfigs().getWebappConfig().getWebroot();
|
||||
return plugin.getBlueMap().getConfig().getWebappConfig().getWebroot();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,6 +98,7 @@ public class WebAppImpl implements WebApp {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated(forRemoval = true)
|
||||
public Map<String, String> availableImages() throws IOException {
|
||||
Path webRoot = getWebRoot().toAbsolutePath();
|
||||
String separator = webRoot.getFileSystem().getSeparator();
|
||||
|
|
|
@ -29,6 +29,7 @@ import de.bluecolored.bluemap.common.BlueMapConfiguration;
|
|||
import de.bluecolored.bluemap.common.config.storage.StorageConfig;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.util.FileHelper;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
|
@ -49,21 +50,27 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
|
||||
private final ConfigManager configManager;
|
||||
|
||||
private final MinecraftVersion minecraftVersion;
|
||||
private final CoreConfig coreConfig;
|
||||
private final WebserverConfig webserverConfig;
|
||||
private final WebappConfig webappConfig;
|
||||
private final PluginConfig pluginConfig;
|
||||
private final Map<String, MapConfig> mapConfigs;
|
||||
private final Map<String, StorageConfig> storageConfigs;
|
||||
private final Path resourcePacksFolder;
|
||||
private final @Nullable Path modsFolder;
|
||||
|
||||
@Builder(buildMethodName = "")
|
||||
@Builder
|
||||
private BlueMapConfigManager(
|
||||
@NonNull MinecraftVersion minecraftVersion,
|
||||
@NonNull Path configRoot,
|
||||
@Nullable Path defaultDataFolder,
|
||||
@Nullable Path defaultWebroot,
|
||||
@Nullable Collection<ServerWorld> autoConfigWorlds,
|
||||
@Nullable Boolean usePluginConfig,
|
||||
@Nullable Boolean useMetricsConfig
|
||||
@Nullable Boolean useMetricsConfig,
|
||||
@Nullable Path resourcePacksFolder,
|
||||
@Nullable Path modsFolder
|
||||
) throws ConfigurationException {
|
||||
// set defaults
|
||||
if (defaultDataFolder == null) defaultDataFolder = Path.of("bluemap");
|
||||
|
@ -71,8 +78,10 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
if (autoConfigWorlds == null) autoConfigWorlds = Collections.emptyList();
|
||||
if (usePluginConfig == null) usePluginConfig = true;
|
||||
if (useMetricsConfig == null) useMetricsConfig = true;
|
||||
if (resourcePacksFolder == null) resourcePacksFolder = configRoot.resolve("resourcepacks");
|
||||
|
||||
// load
|
||||
this.minecraftVersion = minecraftVersion;
|
||||
this.configManager = new ConfigManager(configRoot);
|
||||
this.coreConfig = loadCoreConfig(defaultDataFolder, useMetricsConfig);
|
||||
this.webappConfig = loadWebappConfig(defaultWebroot);
|
||||
|
@ -80,9 +89,11 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
this.pluginConfig = usePluginConfig ? loadPluginConfig() : new PluginConfig();
|
||||
this.storageConfigs = Collections.unmodifiableMap(loadStorageConfigs(webappConfig.getWebroot()));
|
||||
this.mapConfigs = Collections.unmodifiableMap(loadMapConfigs(autoConfigWorlds));
|
||||
this.resourcePacksFolder = resourcePacksFolder;
|
||||
this.modsFolder = modsFolder;
|
||||
}
|
||||
|
||||
private synchronized CoreConfig loadCoreConfig(Path defaultDataFolder, boolean useMetricsConfig) throws ConfigurationException {
|
||||
private CoreConfig loadCoreConfig(Path defaultDataFolder, boolean useMetricsConfig) throws ConfigurationException {
|
||||
Path configFileRaw = Path.of("core");
|
||||
Path configFile = configManager.findConfigPath(configFileRaw);
|
||||
Path configFolder = configFile.getParent();
|
||||
|
@ -127,7 +138,7 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
return presetRenderThreadCount;
|
||||
}
|
||||
|
||||
private synchronized WebserverConfig loadWebserverConfig(Path defaultWebroot, Path dataRoot) throws ConfigurationException {
|
||||
private WebserverConfig loadWebserverConfig(Path defaultWebroot, Path dataRoot) throws ConfigurationException {
|
||||
Path configFileRaw = Path.of("webserver");
|
||||
Path configFile = configManager.findConfigPath(configFileRaw);
|
||||
Path configFolder = configFile.getParent();
|
||||
|
@ -152,7 +163,7 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
return configManager.loadConfig(configFileRaw, WebserverConfig.class);
|
||||
}
|
||||
|
||||
private synchronized WebappConfig loadWebappConfig(Path defaultWebroot) throws ConfigurationException {
|
||||
private WebappConfig loadWebappConfig(Path defaultWebroot) throws ConfigurationException {
|
||||
Path configFileRaw = Path.of("webapp");
|
||||
Path configFile = configManager.findConfigPath(configFileRaw);
|
||||
Path configFolder = configFile.getParent();
|
||||
|
@ -175,7 +186,7 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
return configManager.loadConfig(configFileRaw, WebappConfig.class);
|
||||
}
|
||||
|
||||
private synchronized PluginConfig loadPluginConfig() throws ConfigurationException {
|
||||
private PluginConfig loadPluginConfig() throws ConfigurationException {
|
||||
Path configFileRaw = Path.of("plugin");
|
||||
Path configFile = configManager.findConfigPath(configFileRaw);
|
||||
Path configFolder = configFile.getParent();
|
||||
|
@ -197,7 +208,7 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
return configManager.loadConfig(configFileRaw, PluginConfig.class);
|
||||
}
|
||||
|
||||
private synchronized Map<String, MapConfig> loadMapConfigs(Collection<ServerWorld> autoConfigWorlds) throws ConfigurationException {
|
||||
private Map<String, MapConfig> loadMapConfigs(Collection<ServerWorld> autoConfigWorlds) throws ConfigurationException {
|
||||
Map<String, MapConfig> mapConfigs = new HashMap<>();
|
||||
|
||||
Path mapFolder = Paths.get("maps");
|
||||
|
@ -207,22 +218,23 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
try {
|
||||
FileHelper.createDirectories(mapConfigFolder);
|
||||
if (autoConfigWorlds.isEmpty()) {
|
||||
Path worldFolder = Path.of("world");
|
||||
Files.writeString(
|
||||
mapConfigFolder.resolve("overworld.conf"),
|
||||
createOverworldMapTemplate("Overworld", Path.of("world"),
|
||||
createOverworldMapTemplate("Overworld", worldFolder,
|
||||
new Key("minecraft", "overworld"), 0).build(),
|
||||
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING
|
||||
);
|
||||
Files.writeString(
|
||||
mapConfigFolder.resolve("nether.conf"),
|
||||
createNetherMapTemplate("Nether", Path.of("world", "DIM-1"),
|
||||
new Key("minecraft", "overworld"), 0).build(),
|
||||
createNetherMapTemplate("Nether", worldFolder,
|
||||
new Key("minecraft", "the_nether"), 0).build(),
|
||||
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING
|
||||
);
|
||||
Files.writeString(
|
||||
mapConfigFolder.resolve("end.conf"),
|
||||
createEndMapTemplate("End", Path.of("world", "DIM1"),
|
||||
new Key("minecraft", "overworld"), 0).build(),
|
||||
createEndMapTemplate("End", worldFolder,
|
||||
new Key("minecraft", "the_end"), 0).build(),
|
||||
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING
|
||||
);
|
||||
} else {
|
||||
|
@ -296,7 +308,7 @@ public class BlueMapConfigManager implements BlueMapConfiguration {
|
|||
return mapConfigs;
|
||||
}
|
||||
|
||||
private synchronized Map<String, StorageConfig> loadStorageConfigs(Path defaultWebroot) throws ConfigurationException {
|
||||
private Map<String, StorageConfig> loadStorageConfigs(Path defaultWebroot) throws ConfigurationException {
|
||||
Map<String, StorageConfig> storageConfigs = new HashMap<>();
|
||||
|
||||
Path storageFolder = Paths.get("storages");
|
||||
|
|
|
@ -25,8 +25,10 @@
|
|||
package de.bluecolored.bluemap.common.config;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import de.bluecolored.bluemap.common.config.typeserializer.KeyTypeSerializer;
|
||||
import de.bluecolored.bluemap.common.config.typeserializer.Vector2iTypeSerializer;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
@ -165,6 +167,7 @@ public class ConfigManager {
|
|||
.path(path)
|
||||
.defaultOptions(o -> o.serializers(b -> {
|
||||
b.register(Vector2i.class, new Vector2iTypeSerializer());
|
||||
b.register(Key.class, new KeyTypeSerializer());
|
||||
}))
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.lang.reflect.Type;
|
|||
public class KeyTypeSerializer implements TypeSerializer<Key> {
|
||||
|
||||
@Override
|
||||
public Key deserialize(Type type, ConfigurationNode node) throws SerializationException {
|
||||
public Key deserialize(Type type, ConfigurationNode node) {
|
||||
String formatted = node.getString();
|
||||
return formatted != null ? new Key(node.getString()) : null;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
|
|||
import de.bluecolored.bluemap.common.rendermanager.RenderManager;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Server;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.common.web.*;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpServer;
|
||||
import de.bluecolored.bluemap.core.debug.StateDumper;
|
||||
|
@ -46,7 +47,9 @@ import de.bluecolored.bluemap.core.metrics.Metrics;
|
|||
import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack;
|
||||
import de.bluecolored.bluemap.core.storage.Storage;
|
||||
import de.bluecolored.bluemap.core.util.FileHelper;
|
||||
import de.bluecolored.bluemap.core.util.Tristate;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
@ -118,11 +121,18 @@ public class Plugin implements ServerEventListener {
|
|||
unload(); //ensure nothing is left running (from a failed load or something)
|
||||
|
||||
//load configs
|
||||
blueMap = new BlueMapService(serverInterface, new BlueMapConfigManager(serverInterface), preloadedResourcePack);
|
||||
CoreConfig coreConfig = getConfigs().getCoreConfig();
|
||||
WebserverConfig webserverConfig = getConfigs().getWebserverConfig();
|
||||
WebappConfig webappConfig = getConfigs().getWebappConfig();
|
||||
PluginConfig pluginConfig = getConfigs().getPluginConfig();
|
||||
BlueMapConfigManager configManager = BlueMapConfigManager.builder()
|
||||
.minecraftVersion(serverInterface.getMinecraftVersion())
|
||||
.configRoot(serverInterface.getConfigFolder())
|
||||
.resourcePacksFolder(serverInterface.getConfigFolder().resolve("resourcepacks"))
|
||||
.modsFolder(serverInterface.getModsFolder().orElse(null))
|
||||
.useMetricsConfig(serverInterface.isMetricsEnabled() == Tristate.UNDEFINED)
|
||||
.autoConfigWorlds(serverInterface.getLoadedServerWorlds())
|
||||
.build();
|
||||
CoreConfig coreConfig = configManager.getCoreConfig();
|
||||
WebserverConfig webserverConfig = configManager.getWebserverConfig();
|
||||
WebappConfig webappConfig = configManager.getWebappConfig();
|
||||
PluginConfig pluginConfig = configManager.getPluginConfig();
|
||||
|
||||
//apply new file-logger config
|
||||
if (coreConfig.getLog().getFile() != null) {
|
||||
|
@ -146,9 +156,12 @@ public class Plugin implements ServerEventListener {
|
|||
pluginState = new PluginState();
|
||||
}
|
||||
|
||||
//create bluemap-service
|
||||
blueMap = new BlueMapService(configManager, preloadedResourcePack);
|
||||
|
||||
//try load resources
|
||||
try {
|
||||
blueMap.loadResourcePack();
|
||||
blueMap.getOrLoadResourcePack();
|
||||
} catch (MissingResourcesException ex) {
|
||||
Logger.global.logWarning("BlueMap is missing important resources!");
|
||||
Logger.global.logWarning("You must accept the required file download in order for BlueMap to work!");
|
||||
|
@ -165,7 +178,7 @@ public class Plugin implements ServerEventListener {
|
|||
}
|
||||
|
||||
//load maps
|
||||
Map<String, BmMap> maps = blueMap.loadMaps();
|
||||
Map<String, BmMap> maps = blueMap.getOrLoadMaps();
|
||||
|
||||
//create and start webserver
|
||||
if (webserverConfig.isEnabled()) {
|
||||
|
@ -178,7 +191,7 @@ public class Plugin implements ServerEventListener {
|
|||
routingRequestHandler.register(".*", new FileRequestHandler(webroot));
|
||||
|
||||
// map route
|
||||
for (var mapConfigEntry : getConfigs().getMapConfigs().entrySet()) {
|
||||
for (var mapConfigEntry : configManager.getMapConfigs().entrySet()) {
|
||||
String id = mapConfigEntry.getKey();
|
||||
MapConfig mapConfig = mapConfigEntry.getValue();
|
||||
|
||||
|
@ -187,7 +200,7 @@ public class Plugin implements ServerEventListener {
|
|||
if (map != null) {
|
||||
mapRequestHandler = new MapRequestHandler(map, serverInterface, pluginConfig, Predicate.not(pluginState::isPlayerHidden));
|
||||
} else {
|
||||
Storage storage = blueMap.getStorage(mapConfig.getStorage());
|
||||
Storage storage = blueMap.getOrLoadStorage(mapConfig.getStorage());
|
||||
mapRequestHandler = new MapRequestHandler(id, storage);
|
||||
}
|
||||
|
||||
|
@ -472,7 +485,7 @@ public class Plugin implements ServerEventListener {
|
|||
}
|
||||
|
||||
// hold and reuse loaded resourcepack
|
||||
ResourcePack preloadedResourcePack = this.blueMap.getResourcePackIfLoaded().orElse(null);
|
||||
ResourcePack preloadedResourcePack = this.blueMap.getResourcePack();
|
||||
|
||||
unload();
|
||||
load(preloadedResourcePack);
|
||||
|
@ -484,6 +497,8 @@ public class Plugin implements ServerEventListener {
|
|||
}
|
||||
|
||||
public synchronized void save() {
|
||||
if (blueMap == null) return;
|
||||
|
||||
if (pluginState != null) {
|
||||
try {
|
||||
GsonConfigurationLoader loader = GsonConfigurationLoader.builder()
|
||||
|
@ -496,40 +511,40 @@ public class Plugin implements ServerEventListener {
|
|||
}
|
||||
|
||||
var maps = blueMap.getMaps();
|
||||
if (maps != null) {
|
||||
for (BmMap map : maps.values()) {
|
||||
map.save();
|
||||
}
|
||||
for (BmMap map : maps.values()) {
|
||||
map.save();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveMarkerStates() {
|
||||
if (blueMap == null) return;
|
||||
|
||||
var maps = blueMap.getMaps();
|
||||
if (maps != null) {
|
||||
for (BmMap map : maps.values()) {
|
||||
map.saveMarkerState();
|
||||
}
|
||||
for (BmMap map : maps.values()) {
|
||||
map.saveMarkerState();
|
||||
}
|
||||
}
|
||||
|
||||
public void savePlayerStates() {
|
||||
if (blueMap == null) return;
|
||||
|
||||
var maps = blueMap.getMaps();
|
||||
if (maps != null) {
|
||||
for (BmMap map : maps.values()) {
|
||||
var dataSupplier = new LivePlayersDataSupplier(
|
||||
serverInterface,
|
||||
getConfigs().getPluginConfig(),
|
||||
map.getWorldId(),
|
||||
Predicate.not(pluginState::isPlayerHidden)
|
||||
);
|
||||
try (
|
||||
OutputStream out = map.getStorage().writeMeta(map.getId(), BmMap.META_FILE_PLAYERS);
|
||||
Writer writer = new OutputStreamWriter(out)
|
||||
) {
|
||||
writer.write(dataSupplier.get());
|
||||
} catch (Exception ex) {
|
||||
Logger.global.logError("Failed to save players for map '" + map.getId() + "'!", ex);
|
||||
}
|
||||
for (BmMap map : maps.values()) {
|
||||
var serverWorld = serverInterface.getServerWorld(map.getWorld()).orElse(null);
|
||||
if (serverWorld == null) continue;
|
||||
var dataSupplier = new LivePlayersDataSupplier(
|
||||
serverInterface,
|
||||
getBlueMap().getConfig().getPluginConfig(),
|
||||
serverWorld,
|
||||
Predicate.not(pluginState::isPlayerHidden)
|
||||
);
|
||||
try (
|
||||
OutputStream out = map.getStorage().writeMeta(map.getId(), BmMap.META_FILE_PLAYERS);
|
||||
Writer writer = new OutputStreamWriter(out)
|
||||
) {
|
||||
writer.write(dataSupplier.get());
|
||||
} catch (Exception ex) {
|
||||
Logger.global.logError("Failed to save players for map '" + map.getId() + "'!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -554,7 +569,7 @@ public class Plugin implements ServerEventListener {
|
|||
}
|
||||
|
||||
public boolean flushWorldUpdates(World world) throws IOException {
|
||||
var implWorld = serverInterface.getWorld(world.getSaveFolder()).orElse(null);
|
||||
var implWorld = serverInterface.getServerWorld(world).orElse(null);
|
||||
if (implWorld != null) return implWorld.persistWorldChanges();
|
||||
return false;
|
||||
}
|
||||
|
@ -584,8 +599,8 @@ public class Plugin implements ServerEventListener {
|
|||
}
|
||||
|
||||
public boolean checkPausedByPlayerCount() {
|
||||
CoreConfig coreConfig = getConfigs().getCoreConfig();
|
||||
PluginConfig pluginConfig = getConfigs().getPluginConfig();
|
||||
CoreConfig coreConfig = getBlueMap().getConfig().getCoreConfig();
|
||||
PluginConfig pluginConfig = getBlueMap().getConfig().getPluginConfig();
|
||||
|
||||
if (
|
||||
pluginConfig.getPlayerRenderLimit() > 0 &&
|
||||
|
@ -600,6 +615,11 @@ public class Plugin implements ServerEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
public @Nullable World getWorld(ServerWorld serverWorld) {
|
||||
String id = MCAWorld.id(serverWorld.getWorldFolder(), serverWorld.getDimension());
|
||||
return getBlueMap().getWorlds().get(id);
|
||||
}
|
||||
|
||||
public Server getServerInterface() {
|
||||
return serverInterface;
|
||||
}
|
||||
|
@ -608,10 +628,6 @@ public class Plugin implements ServerEventListener {
|
|||
return blueMap;
|
||||
}
|
||||
|
||||
public BlueMapConfigManager getConfigs() {
|
||||
return blueMap.getConfig();
|
||||
}
|
||||
|
||||
public PluginState getPluginState() {
|
||||
return pluginState;
|
||||
}
|
||||
|
|
|
@ -25,12 +25,14 @@
|
|||
package de.bluecolored.bluemap.common.plugin;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.common.rendermanager.RenderManager;
|
||||
import de.bluecolored.bluemap.common.rendermanager.WorldRegionRenderTask;
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.map.BmMap;
|
||||
import de.bluecolored.bluemap.core.util.FileHelper;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
|
@ -45,7 +47,7 @@ public class RegionFileWatchService extends Thread {
|
|||
private final RenderManager renderManager;
|
||||
private final WatchService watchService;
|
||||
|
||||
private boolean verbose;
|
||||
private final boolean verbose;
|
||||
private volatile boolean closed;
|
||||
|
||||
private Timer delayTimer;
|
||||
|
@ -60,7 +62,9 @@ public class RegionFileWatchService extends Thread {
|
|||
this.closed = false;
|
||||
this.scheduledUpdates = new HashMap<>();
|
||||
|
||||
Path folder = map.getWorld().getSaveFolder().resolve("region");
|
||||
World world = map.getWorld();
|
||||
if (!(world instanceof MCAWorld)) throw new UnsupportedOperationException("world-type is not supported");
|
||||
Path folder = ((MCAWorld) world).getRegionFolder();
|
||||
FileHelper.createDirectories(folder);
|
||||
|
||||
this.watchService = folder.getFileSystem().newWatchService();
|
||||
|
|
|
@ -30,7 +30,6 @@ import de.bluecolored.bluemap.common.plugin.text.TextColor;
|
|||
import de.bluecolored.bluemap.common.plugin.text.TextFormat;
|
||||
import de.bluecolored.bluemap.common.rendermanager.RenderManager;
|
||||
import de.bluecolored.bluemap.common.rendermanager.RenderTask;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import org.apache.commons.lang3.time.DurationFormatUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -106,7 +105,7 @@ public class CommandHelper {
|
|||
if (plugin.checkPausedByPlayerCount()) {
|
||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||
Text.of(TextColor.GOLD, "paused")));
|
||||
lines.add(Text.of(TextColor.GRAY, TextFormat.ITALIC, "\u00A0\u00A0\u00A0(there are " + plugin.getConfigs().getPluginConfig().getPlayerRenderLimit() + " or more players online)"));
|
||||
lines.add(Text.of(TextColor.GRAY, TextFormat.ITALIC, "\u00A0\u00A0\u00A0(there are " + plugin.getBlueMap().getConfig().getPluginConfig().getPlayerRenderLimit() + " or more players online)"));
|
||||
} else {
|
||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||
Text.of(TextColor.RED, "stopped")
|
||||
|
@ -134,20 +133,22 @@ public class CommandHelper {
|
|||
|
||||
public Text worldHelperHover() {
|
||||
StringJoiner joiner = new StringJoiner("\n");
|
||||
for (World world : plugin.getWorlds().values()) {
|
||||
joiner.add(world.getName());
|
||||
for (String worldId : plugin.getBlueMap().getWorlds().keySet()) {
|
||||
joiner.add(worldId);
|
||||
}
|
||||
|
||||
return Text.of("world").setHoverText(Text.of(TextColor.WHITE, "Available worlds: \n", TextColor.GRAY, joiner.toString()));
|
||||
return Text.of(TextFormat.UNDERLINED, "world")
|
||||
.setHoverText(Text.of(TextColor.WHITE, "Available worlds: \n", TextColor.GRAY, joiner.toString()));
|
||||
}
|
||||
|
||||
public Text mapHelperHover() {
|
||||
StringJoiner joiner = new StringJoiner("\n");
|
||||
for (String mapId : plugin.getMaps().keySet()) {
|
||||
for (String mapId : plugin.getBlueMap().getMaps().keySet()) {
|
||||
joiner.add(mapId);
|
||||
}
|
||||
|
||||
return Text.of("map").setHoverText(Text.of(TextColor.WHITE, "Available maps: \n", TextColor.GRAY, joiner.toString()));
|
||||
return Text.of(TextFormat.UNDERLINED, "map")
|
||||
.setHoverText(Text.of(TextColor.WHITE, "Available maps: \n", TextColor.GRAY, joiner.toString()));
|
||||
}
|
||||
|
||||
public synchronized Optional<RenderTask> getTaskForRef(String ref) {
|
||||
|
|
|
@ -281,10 +281,10 @@ public class Commands<S> {
|
|||
}
|
||||
}
|
||||
|
||||
private Optional<World> parseWorld(String worldName) {
|
||||
for (World world : plugin.getWorlds().values()) {
|
||||
if (world.getName().equalsIgnoreCase(worldName)) {
|
||||
return Optional.of(world);
|
||||
private Optional<World> parseWorld(String worldId) {
|
||||
for (var entry : plugin.getBlueMap().getWorlds().entrySet()) {
|
||||
if (entry.getKey().equals(worldId)) {
|
||||
return Optional.of(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,8 +292,8 @@ public class Commands<S> {
|
|||
}
|
||||
|
||||
private Optional<BmMap> parseMap(String mapId) {
|
||||
for (BmMap map : plugin.getMaps().values()) {
|
||||
if (map.getId().equalsIgnoreCase(mapId)) {
|
||||
for (BmMap map : plugin.getBlueMap().getMaps().values()) {
|
||||
if (map.getId().equals(mapId)) {
|
||||
return Optional.of(map);
|
||||
}
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public class Commands<S> {
|
|||
public int debugClearCacheCommand(CommandContext<S> context) {
|
||||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
|
||||
for (World world : plugin.getWorlds().values()) {
|
||||
for (World world : plugin.getBlueMap().getWorlds().values()) {
|
||||
world.invalidateChunkCache();
|
||||
}
|
||||
|
||||
|
@ -436,7 +436,7 @@ public class Commands<S> {
|
|||
world = parseWorld(worldName.get()).orElse(null);
|
||||
|
||||
if (world == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.worldHelperHover(), " with this name: ", TextColor.WHITE, worldName.get()));
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.worldHelperHover(), " with this id: ", TextColor.WHITE, worldName.get()));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
|
@ -482,7 +482,7 @@ public class Commands<S> {
|
|||
position = new Vector3d(x.get(), y.get(), z.get());
|
||||
|
||||
if (world == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.worldHelperHover(), " with this name: ", TextColor.WHITE, worldName.get()));
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.worldHelperHover(), " with this id: ", TextColor.WHITE, worldName.get()));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
|
@ -499,7 +499,7 @@ public class Commands<S> {
|
|||
// collect and output debug info
|
||||
Vector3i blockPos = position.floor().toInt();
|
||||
Block<?> block = new Block<>(world, blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
Block<?> blockBelow = new Block<>(null, 0, 0, 0).copy(block, 0, -1, 0);
|
||||
Block<?> blockBelow = new Block<>(world, blockPos.getX(), blockPos.getY() - 1, blockPos.getZ());
|
||||
|
||||
// populate lazy-loaded values
|
||||
block.getBlockState();
|
||||
|
@ -523,7 +523,7 @@ public class Commands<S> {
|
|||
final CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
|
||||
try {
|
||||
Path file = plugin.getConfigs().getCoreConfig().getData().resolve("dump.json");
|
||||
Path file = plugin.getBlueMap().getConfig().getCoreConfig().getData().resolve("dump.json");
|
||||
StateDumper.global().dump(file);
|
||||
|
||||
source.sendMessage(Text.of(TextColor.GREEN, "Dump created at: " + file));
|
||||
|
@ -562,7 +562,7 @@ public class Commands<S> {
|
|||
new Thread(() -> {
|
||||
plugin.getPluginState().setRenderThreadsEnabled(true);
|
||||
|
||||
plugin.getRenderManager().start(plugin.getConfigs().getCoreConfig().resolveRenderThreadCount());
|
||||
plugin.getRenderManager().start(plugin.getBlueMap().getConfig().getCoreConfig().resolveRenderThreadCount());
|
||||
source.sendMessage(Text.of(TextColor.GREEN, "Render-Threads started!"));
|
||||
|
||||
plugin.save();
|
||||
|
@ -583,7 +583,7 @@ public class Commands<S> {
|
|||
BmMap map = parseMap(mapString).orElse(null);
|
||||
|
||||
if (map == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.mapHelperHover(), " with this name: ", TextColor.WHITE, mapString));
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.mapHelperHover(), " with this id: ", TextColor.WHITE, mapString));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -624,7 +624,7 @@ public class Commands<S> {
|
|||
BmMap map = parseMap(mapString).orElse(null);
|
||||
|
||||
if (map == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.mapHelperHover(), " with this name: ", TextColor.WHITE, mapString));
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.mapHelperHover(), " with this id: ", TextColor.WHITE, mapString));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -671,7 +671,8 @@ public class Commands<S> {
|
|||
mapToRender = parseMap(worldOrMap.get()).orElse(null);
|
||||
|
||||
if (mapToRender == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.worldHelperHover(), " or ", helper.mapHelperHover(), " with this name: ", TextColor.WHITE, worldOrMap.get()));
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.worldHelperHover(), " or ",
|
||||
helper.mapHelperHover(), " with this id: ", TextColor.WHITE, worldOrMap.get()));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
|
@ -682,7 +683,8 @@ public class Commands<S> {
|
|||
mapToRender = null;
|
||||
|
||||
if (worldToRender == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "Can't detect a world from this command-source, you'll have to define a world or a map to update!").setHoverText(Text.of(TextColor.GRAY, "/bluemap " + (force ? "force-update" : "update") + " <world|map>")));
|
||||
source.sendMessage(Text.of(TextColor.RED, "Can't detect a world from this command-source, you'll have to define a world or a map to update!")
|
||||
.setHoverText(Text.of(TextColor.GRAY, "/bluemap " + (force ? "force-update" : "update") + " <world|map>")));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -699,7 +701,8 @@ public class Commands<S> {
|
|||
} else {
|
||||
Vector3d position = source.getPosition().orElse(null);
|
||||
if (position == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "Can't detect a position from this command-source, you'll have to define x,z coordinates to update with a radius!").setHoverText(Text.of(TextColor.GRAY, "/bluemap " + (force ? "force-update" : "update") + " <x> <z> " + radius)));
|
||||
source.sendMessage(Text.of(TextColor.RED, "Can't detect a position from this command-source, you'll have to define x,z coordinates to update with a radius!")
|
||||
.setHoverText(Text.of(TextColor.GRAY, "/bluemap " + (force ? "force-update" : "update") + " <x> <z> " + radius)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -714,16 +717,12 @@ public class Commands<S> {
|
|||
try {
|
||||
List<BmMap> maps = new ArrayList<>();
|
||||
if (worldToRender != null) {
|
||||
var world = plugin.getServerInterface().getWorld(worldToRender.getWorldFolder()).orElse(null);
|
||||
if (world != null) world.persistWorldChanges();
|
||||
|
||||
for (BmMap map : plugin.getMaps().values()) {
|
||||
if (map.getWorld().getWorldFolder().equals(worldToRender.getWorldFolder())) maps.add(map);
|
||||
plugin.flushWorldUpdates(worldToRender);
|
||||
for (BmMap map : plugin.getBlueMap().getMaps().values()) {
|
||||
if (map.getWorld().equals(worldToRender)) maps.add(map);
|
||||
}
|
||||
} else {
|
||||
var world = plugin.getServerInterface().getWorld(mapToRender.getWorld().getWorldFolder()).orElse(null);
|
||||
if (world != null) world.persistWorldChanges();
|
||||
|
||||
plugin.flushWorldUpdates(mapToRender.getWorld());
|
||||
maps.add(mapToRender);
|
||||
}
|
||||
|
||||
|
@ -741,7 +740,8 @@ public class Commands<S> {
|
|||
updateTask.getRegions().forEach(region -> state.setRenderTime(region, -1));
|
||||
}
|
||||
|
||||
source.sendMessage(Text.of(TextColor.GREEN, "Created new Update-Task for map '" + map.getId() + "' ", TextColor.GRAY, "(" + updateTask.getRegions().size() + " regions, ~" + updateTask.getRegions().size() * 1024L + " chunks)"));
|
||||
source.sendMessage(Text.of(TextColor.GREEN, "Created new Update-Task for map '" + map.getId() + "' ",
|
||||
TextColor.GRAY, "(" + updateTask.getRegions().size() + " regions, ~" + updateTask.getRegions().size() * 1024L + " chunks)"));
|
||||
}
|
||||
source.sendMessage(Text.of(TextColor.GREEN, "Use ", TextColor.GRAY, "/bluemap", TextColor.GREEN, " to see the progress."));
|
||||
|
||||
|
@ -790,7 +790,7 @@ public class Commands<S> {
|
|||
BmMap map = parseMap(mapString).orElse(null);
|
||||
|
||||
if (map == null) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.mapHelperHover(), " with this name: ", TextColor.WHITE, mapString));
|
||||
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.mapHelperHover(), " with this id: ", TextColor.WHITE, mapString));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -831,8 +831,8 @@ public class Commands<S> {
|
|||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
|
||||
source.sendMessage(Text.of(TextColor.BLUE, "Worlds loaded by BlueMap:"));
|
||||
for (var entry : plugin.getWorlds().entrySet()) {
|
||||
source.sendMessage(Text.of(TextColor.GRAY, " - ", TextColor.WHITE, entry.getValue().getName()).setHoverText(Text.of(entry.getValue().getWorldFolder(), TextColor.GRAY, " (" + entry.getKey() + ")")));
|
||||
for (var entry : plugin.getBlueMap().getWorlds().entrySet()) {
|
||||
source.sendMessage(Text.of(TextColor.GRAY, " - ", TextColor.WHITE, entry.getKey()));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -842,7 +842,7 @@ public class Commands<S> {
|
|||
List<Text> lines = new ArrayList<>();
|
||||
lines.add(Text.of(TextColor.BLUE, "Maps loaded by BlueMap:"));
|
||||
|
||||
for (BmMap map : plugin.getMaps().values()) {
|
||||
for (BmMap map : plugin.getBlueMap().getMaps().values()) {
|
||||
boolean frozen = !plugin.getPluginState().getMapState(map).isUpdateEnabled();
|
||||
|
||||
lines.add(Text.of(TextColor.GRAY, " - ",
|
||||
|
@ -850,7 +850,7 @@ public class Commands<S> {
|
|||
TextColor.GRAY, " (" + map.getName() + ")"));
|
||||
|
||||
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0World: ",
|
||||
TextColor.DARK_GRAY, map.getWorld().getName()));
|
||||
TextColor.DARK_GRAY, map.getWorld().getId()));
|
||||
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Last Update: ",
|
||||
TextColor.DARK_GRAY, helper.formatTime(map.getRenderState().getLatestRenderTime())));
|
||||
|
||||
|
@ -884,9 +884,10 @@ public class Commands<S> {
|
|||
|
||||
Storage storage;
|
||||
try {
|
||||
storage = plugin.getBlueMap().getStorage(storageId);
|
||||
} catch (ConfigurationException ex) {
|
||||
source.sendMessage(Text.of(TextColor.RED, ex.getMessage()));
|
||||
storage = plugin.getBlueMap().getOrLoadStorage(storageId);
|
||||
} catch (ConfigurationException | InterruptedException ex) {
|
||||
Logger.global.logError("Unexpected exception trying to load storage '" + storageId + "'!", ex);
|
||||
source.sendMessage(Text.of(TextColor.RED, "There was an unexpected exception trying to load this storage. Please check the console for more details..."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -894,8 +895,8 @@ public class Commands<S> {
|
|||
try {
|
||||
mapIds = storage.collectMapIds();
|
||||
} catch (IOException ex) {
|
||||
source.sendMessage(Text.of(TextColor.RED, "There was an unexpected exception trying to access this storage. Please check the console for more details..."));
|
||||
Logger.global.logError("Unexpected exception trying to load mapIds from storage '" + storageId + "'!", ex);
|
||||
source.sendMessage(Text.of(TextColor.RED, "There was an unexpected exception trying to access this storage. Please check the console for more details..."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -904,7 +905,7 @@ public class Commands<S> {
|
|||
source.sendMessage(Text.of(TextColor.GRAY, " <empty storage>"));
|
||||
} else {
|
||||
for (String mapId : mapIds) {
|
||||
BmMap map = plugin.getMaps().get(mapId);
|
||||
BmMap map = plugin.getBlueMap().getMaps().get(mapId);
|
||||
boolean isLoaded = map != null && map.getStorage().equals(storage);
|
||||
|
||||
if (isLoaded) {
|
||||
|
@ -925,13 +926,14 @@ public class Commands<S> {
|
|||
|
||||
Storage storage;
|
||||
try {
|
||||
storage = plugin.getBlueMap().getStorage(storageId);
|
||||
} catch (ConfigurationException ex) {
|
||||
source.sendMessage(Text.of(TextColor.RED, ex.getMessage()));
|
||||
storage = plugin.getBlueMap().getOrLoadStorage(storageId);
|
||||
} catch (ConfigurationException | InterruptedException ex) {
|
||||
Logger.global.logError("Unexpected exception trying to load storage '" + storageId + "'!", ex);
|
||||
source.sendMessage(Text.of(TextColor.RED, "There was an unexpected exception trying to load this storage. Please check the console for more details..."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
BmMap map = plugin.getMaps().get(mapId);
|
||||
BmMap map = plugin.getBlueMap().getMaps().get(mapId);
|
||||
boolean isLoaded = map != null && map.getStorage().equals(storage);
|
||||
if (isLoaded) {
|
||||
Text purgeCommand = Text.of(TextColor.WHITE, "/bluemap purge " + mapId)
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
package de.bluecolored.bluemap.common.plugin.commands;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.core.map.BmMap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -40,7 +39,7 @@ public class MapSuggestionProvider<S> extends AbstractSuggestionProvider<S> {
|
|||
|
||||
@Override
|
||||
public Collection<String> getPossibleValues() {
|
||||
return new HashSet<>(plugin.getMaps().keySet());
|
||||
return new HashSet<>(plugin.getBlueMap().getMaps().keySet());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
package de.bluecolored.bluemap.common.plugin.commands;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -41,13 +40,8 @@ public class WorldOrMapSuggestionProvider<S> extends AbstractSuggestionProvider<
|
|||
@Override
|
||||
public Collection<String> getPossibleValues() {
|
||||
Collection<String> values = new HashSet<>();
|
||||
|
||||
for (World world : plugin.getWorlds().values()) {
|
||||
values.add(world.getName());
|
||||
}
|
||||
|
||||
values.addAll(plugin.getMaps().keySet());
|
||||
|
||||
values.addAll(plugin.getBlueMap().getWorlds().keySet());
|
||||
values.addAll(plugin.getBlueMap().getMaps().keySet());
|
||||
return values;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
package de.bluecolored.bluemap.common.plugin.commands;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -40,13 +39,7 @@ public class WorldSuggestionProvider<S> extends AbstractSuggestionProvider<S> {
|
|||
|
||||
@Override
|
||||
public Collection<String> getPossibleValues() {
|
||||
Collection<String> values = new HashSet<>();
|
||||
|
||||
for (World world : plugin.getWorlds().values()) {
|
||||
values.add(world.getName());
|
||||
}
|
||||
|
||||
return values;
|
||||
return new HashSet<>(plugin.getBlueMap().getWorlds().keySet());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class PlayerSkinUpdater implements ServerEventListener {
|
|||
return;
|
||||
}
|
||||
|
||||
Map<String, BmMap> maps = plugin.getMaps();
|
||||
Map<String, BmMap> maps = plugin.getBlueMap().getMaps();
|
||||
if (maps == null) {
|
||||
Logger.global.logDebug("Could not update skin, since the plugin seems not to be ready.");
|
||||
return;
|
||||
|
|
|
@ -1,51 +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.serverinterface;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public enum Dimension {
|
||||
|
||||
OVERWORLD ("Overworld", Path.of("")),
|
||||
NETHER ("Nether", Path.of("DIM-1")),
|
||||
END ("End", Path.of("DIM1"));
|
||||
|
||||
private final String name;
|
||||
private final Path dimensionSubPath;
|
||||
|
||||
Dimension(String name, Path dimensionSubPath) {
|
||||
this.name = name;
|
||||
this.dimensionSubPath = dimensionSubPath;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Path getDimensionSubPath() {
|
||||
return dimensionSubPath;
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ import de.bluecolored.bluemap.api.debug.DebugDump;
|
|||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.util.Tristate;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
@ -61,16 +62,28 @@ public interface Server {
|
|||
/**
|
||||
* Returns the correct {@link ServerWorld} for a {@link World} if there is any.
|
||||
*/
|
||||
Optional<ServerWorld> getWorld(World world);
|
||||
default Optional<ServerWorld> getServerWorld(World world) {
|
||||
if (world instanceof MCAWorld) {
|
||||
MCAWorld mcaWorld = (MCAWorld) world;
|
||||
return getLoadedServerWorlds().stream()
|
||||
.filter(serverWorld ->
|
||||
serverWorld.getWorldFolder().toAbsolutePath().normalize()
|
||||
.equals(mcaWorld.getWorldFolder().toAbsolutePath().normalize()) &&
|
||||
serverWorld.getDimension().equals(mcaWorld.getDimension())
|
||||
)
|
||||
.findAny();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correct {@link ServerWorld} for any Object if there is any, this should return the correct ServerWorld
|
||||
* for any implementation-specific object that represent or identify a world in any way.<br>
|
||||
* Used for the API implementation.
|
||||
*/
|
||||
default Optional<ServerWorld> getWorld(Object world) {
|
||||
default Optional<ServerWorld> getServerWorld(Object world) {
|
||||
if (world instanceof World)
|
||||
return getWorld((World) world);
|
||||
return getServerWorld((World) world);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
@ -78,7 +91,7 @@ public interface Server {
|
|||
* Returns all loaded worlds of this server.
|
||||
*/
|
||||
@DebugDump
|
||||
Collection<ServerWorld> getLoadedWorlds();
|
||||
Collection<ServerWorld> getLoadedServerWorlds();
|
||||
|
||||
/**
|
||||
* Returns a collection of the states of players that are currently online
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.common.serverinterface;
|
||||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -31,8 +32,10 @@ import java.nio.file.Path;
|
|||
|
||||
public interface ServerWorld {
|
||||
|
||||
@DebugDump
|
||||
Path getWorldFolder();
|
||||
|
||||
@DebugDump
|
||||
Key getDimension();
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.common.web;
|
||||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequest;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpResponse;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpStatusCode;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
|
||||
@DebugDump
|
||||
public class BlueMapResponseModifier implements HttpRequestHandler {
|
||||
|
||||
private final HttpRequestHandler delegate;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.common.web;
|
||||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.common.web.http.*;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
|
||||
|
@ -38,6 +39,7 @@ import java.util.Locale;
|
|||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@DebugDump
|
||||
public class FileRequestHandler implements HttpRequestHandler {
|
||||
|
||||
private final Path webRoot;
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.common.web;
|
||||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.common.web.http.*;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
|
||||
@DebugDump
|
||||
public class LoggingRequestHandler implements HttpRequestHandler {
|
||||
|
||||
private final HttpRequestHandler delegate;
|
||||
|
|
|
@ -28,6 +28,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.serverinterface.Server;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.map.BmMap;
|
||||
import de.bluecolored.bluemap.core.storage.Storage;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -40,7 +41,7 @@ public class MapRequestHandler extends RoutingRequestHandler {
|
|||
|
||||
public MapRequestHandler(BmMap map, Server serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
|
||||
this(map.getId(), map.getStorage(),
|
||||
new LivePlayersDataSupplier(serverInterface, pluginConfig, map.getWorldId(), playerFilter),
|
||||
createPlayersDataSupplier(map, serverInterface, pluginConfig, playerFilter),
|
||||
new LiveMarkersDataSupplier(map.getMarkerSets()));
|
||||
}
|
||||
|
||||
|
@ -67,4 +68,10 @@ public class MapRequestHandler extends RoutingRequestHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static @Nullable LivePlayersDataSupplier createPlayersDataSupplier(BmMap map, Server serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
|
||||
ServerWorld world = serverInterface.getServerWorld(map.getWorld()).orElse(null);
|
||||
if (world == null) return null;
|
||||
return new LivePlayersDataSupplier(serverInterface, pluginConfig, world, playerFilter);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ package de.bluecolored.bluemap.common.web;
|
|||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import de.bluecolored.bluemap.api.ContentTypeRegistry;
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.common.web.http.*;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.map.BmMap;
|
||||
|
@ -41,6 +42,7 @@ import java.util.*;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@DebugDump
|
||||
public class MapStorageRequestHandler implements HttpRequestHandler {
|
||||
|
||||
private static final Pattern TILE_PATTERN = Pattern.compile("tiles/([\\d/]+)/x(-?[\\d/]+)z(-?[\\d/]+).*");
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.common.web;
|
||||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequest;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpResponse;
|
||||
|
@ -34,6 +35,7 @@ import java.util.LinkedList;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@DebugDump
|
||||
public class RoutingRequestHandler implements HttpRequestHandler {
|
||||
|
||||
public LinkedList<Route> routes;
|
||||
|
@ -77,6 +79,7 @@ public class RoutingRequestHandler implements HttpRequestHandler {
|
|||
return new HttpResponse(HttpStatusCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@DebugDump
|
||||
private static class Route {
|
||||
|
||||
private final Pattern routePattern;
|
||||
|
|
|
@ -24,8 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.common.web.http;
|
||||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@DebugDump
|
||||
public class HttpServer extends Server {
|
||||
|
||||
private final HttpRequestHandler requestHandler;
|
||||
|
|
|
@ -69,6 +69,7 @@ dependencies {
|
|||
api ("com.github.BlueMap-Minecraft:BlueNBT:v1.3.0")
|
||||
api ("org.apache.commons:commons-dbcp2:2.9.0")
|
||||
api ("io.airlift:aircompressor:0.24")
|
||||
api ("org.lz4:lz4-java:1.8.0")
|
||||
|
||||
api ("de.bluecolored.bluemap.api:BlueMapAPI")
|
||||
|
||||
|
|
|
@ -32,12 +32,13 @@ public class DataPack {
|
|||
return dimensionTypes.get(key);
|
||||
}
|
||||
|
||||
public void load(Path root) {
|
||||
public void load(Path root) throws InterruptedException {
|
||||
Logger.global.logDebug("Loading datapack from: " + root + " ...");
|
||||
loadPath(root);
|
||||
}
|
||||
|
||||
private void loadPath(Path root) {
|
||||
private void loadPath(Path root) throws InterruptedException {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
if (!Files.isDirectory(root)) {
|
||||
try (FileSystem fileSystem = FileSystems.newFileSystem(root, (ClassLoader) null)) {
|
||||
for (Path fsRoot : fileSystem.getRootDirectories()) {
|
||||
|
|
|
@ -183,20 +183,26 @@ public class ResourcePack {
|
|||
return props.build();
|
||||
}
|
||||
|
||||
public synchronized void loadResources(Iterable<Path> roots) throws IOException {
|
||||
public synchronized void loadResources(Iterable<Path> roots) throws IOException, InterruptedException {
|
||||
Logger.global.logInfo("Loading resources...");
|
||||
|
||||
for (Path root : roots) {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
Logger.global.logDebug("Loading resources from: " + root + " ...");
|
||||
loadResourcePath(root, this::loadResources);
|
||||
}
|
||||
|
||||
Logger.global.logInfo("Loading textures...");
|
||||
for (Path root : roots) {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
Logger.global.logDebug("Loading textures from: " + root + " ...");
|
||||
loadResourcePath(root, this::loadTextures);
|
||||
}
|
||||
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
Logger.global.logInfo("Baking resources...");
|
||||
bake();
|
||||
|
||||
|
@ -204,7 +210,8 @@ public class ResourcePack {
|
|||
Logger.global.logInfo("Resources loaded.");
|
||||
}
|
||||
|
||||
private void loadResourcePath(Path root, PathLoader resourceLoader) throws IOException {
|
||||
private void loadResourcePath(Path root, PathLoader resourceLoader) throws IOException, InterruptedException {
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
if (!Files.isDirectory(root)) {
|
||||
try (FileSystem fileSystem = FileSystems.newFileSystem(root, (ClassLoader) null)) {
|
||||
for (Path fsRoot : fileSystem.getRootDirectories()) {
|
||||
|
@ -387,7 +394,7 @@ public class ResourcePack {
|
|||
}
|
||||
}
|
||||
|
||||
private void bake() throws IOException {
|
||||
private void bake() throws IOException, InterruptedException {
|
||||
|
||||
// fill path maps
|
||||
blockStates.keySet().forEach(path -> blockStatePaths.put(path.getFormatted(), path));
|
||||
|
@ -399,11 +406,15 @@ public class ResourcePack {
|
|||
model.optimize(this);
|
||||
}
|
||||
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
// apply model parents
|
||||
for (BlockModel model : blockModels.values()) {
|
||||
model.applyParent(this);
|
||||
}
|
||||
|
||||
if (Thread.interrupted()) throw new InterruptedException();
|
||||
|
||||
// calculate model properties
|
||||
for (BlockModel model : blockModels.values()) {
|
||||
model.calculateProperties(this);
|
||||
|
|
|
@ -26,19 +26,25 @@ package de.bluecolored.bluemap.core.storage;
|
|||
|
||||
import io.airlift.compress.zstd.ZstdInputStream;
|
||||
import io.airlift.compress.zstd.ZstdOutputStream;
|
||||
import net.jpountz.lz4.LZ4FrameInputStream;
|
||||
import net.jpountz.lz4.LZ4FrameOutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.zip.*;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
public enum Compression {
|
||||
|
||||
NONE("none", "", out -> out, in -> in),
|
||||
GZIP("gzip", ".gz", GZIPOutputStream::new, GZIPInputStream::new),
|
||||
DEFLATE("deflate", ".deflate", DeflaterOutputStream::new, InflaterInputStream::new),
|
||||
ZSTD("zstd", ".zst", ZstdOutputStream::new, ZstdInputStream::new);
|
||||
ZSTD("zstd", ".zst", ZstdOutputStream::new, ZstdInputStream::new),
|
||||
LZ4("lz4", ".lz4", LZ4FrameOutputStream::new, LZ4FrameInputStream::new);
|
||||
|
||||
private final String typeId;
|
||||
private final String fileSuffix;
|
||||
|
|
|
@ -26,10 +26,15 @@ package de.bluecolored.bluemap.core.util;
|
|||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
|
||||
@DebugDump
|
||||
public class Key {
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
private static final String MINECRAFT_NAMESPACE = "minecraft";
|
||||
@DebugDump
|
||||
public class Key implements Keyed {
|
||||
|
||||
private static final ConcurrentHashMap<String, String> STRING_INTERN_POOL = new ConcurrentHashMap<>();
|
||||
|
||||
public static final String MINECRAFT_NAMESPACE = "minecraft";
|
||||
public static final String BLUEMAP_NAMESPACE = "bluemap";
|
||||
|
||||
private final String namespace;
|
||||
private final String value;
|
||||
|
@ -44,15 +49,15 @@ public class Key {
|
|||
value = formatted.substring(namespaceSeparator + 1);
|
||||
}
|
||||
|
||||
this.namespace = namespace.intern();
|
||||
this.value = value.intern();
|
||||
this.formatted = (this.namespace + ":" + this.value).intern();
|
||||
this.namespace = intern(namespace);
|
||||
this.value = intern(value);
|
||||
this.formatted = intern(this.namespace + ":" + this.value);
|
||||
}
|
||||
|
||||
public Key(String namespace, String value) {
|
||||
this.namespace = namespace.intern();
|
||||
this.value = value.intern();
|
||||
this.formatted = (this.namespace + ":" + this.value).intern();
|
||||
this.namespace = intern(namespace);
|
||||
this.value = intern(value);
|
||||
this.formatted = intern(this.namespace + ":" + this.value);
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
|
@ -67,6 +72,11 @@ public class Key {
|
|||
return formatted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getKey() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("StringEquality")
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
@ -78,11 +88,36 @@ public class Key {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getFormatted().hashCode();
|
||||
return formatted.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return formatted;
|
||||
}
|
||||
|
||||
public static Key parse(String formatted) {
|
||||
return new Key(formatted);
|
||||
}
|
||||
|
||||
public static Key parse(String formatted, String defaultNamespace) {
|
||||
String namespace = defaultNamespace;
|
||||
String value = formatted;
|
||||
int namespaceSeparator = formatted.indexOf(':');
|
||||
if (namespaceSeparator > 0) {
|
||||
namespace = formatted.substring(0, namespaceSeparator);
|
||||
value = formatted.substring(namespaceSeparator + 1);
|
||||
}
|
||||
|
||||
return new Key(namespace, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Using our own function instead of {@link String#intern()} since the ConcurrentHashMap is much faster.
|
||||
*/
|
||||
private static String intern(String string) {
|
||||
String interned = STRING_INTERN_POOL.putIfAbsent(string, string);
|
||||
return interned != null ? interned : string;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package de.bluecolored.bluemap.core.util;
|
||||
|
||||
public interface Keyed {
|
||||
|
||||
Key getKey();
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package de.bluecolored.bluemap.core.util;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Registry<T extends Keyed> {
|
||||
|
||||
private final ConcurrentHashMap<Key, T> entries;
|
||||
|
||||
public Registry() {
|
||||
this.entries = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new entry, only if there is no entry with the same key registered already.
|
||||
* Does nothing otherwise.
|
||||
* @param entry The new entry to be added to this registry
|
||||
* @return true if the entry has been added, false if there is already an entry with the same key registered
|
||||
*/
|
||||
public boolean register(T entry) {
|
||||
Objects.requireNonNull(entry, "registry entry can not be null");
|
||||
return entries.putIfAbsent(entry.getKey(), entry) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an entry from this registry for a key.
|
||||
* @param key The key to search for
|
||||
* @return The entry with the key, or null if there is no entry for this key
|
||||
*/
|
||||
public @Nullable T get(Key key) {
|
||||
return entries.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable set of all keys this registry contains entries for
|
||||
*/
|
||||
public Set<Key> keys() {
|
||||
return Collections.unmodifiableSet(entries.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection of entries in this registry
|
||||
*/
|
||||
public Collection<T> values() {
|
||||
return Collections.unmodifiableCollection(entries.values());
|
||||
}
|
||||
|
||||
}
|
|
@ -38,6 +38,8 @@ import java.util.Collection;
|
|||
*/
|
||||
public interface World {
|
||||
|
||||
String getId();
|
||||
|
||||
String getName();
|
||||
|
||||
Vector3i getSpawnPoint();
|
||||
|
|
|
@ -103,22 +103,6 @@ public class Block<T extends Block<T>> {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* copy with offset
|
||||
*/
|
||||
public T copy(Block<?> source, int dx, int dy, int dz) {
|
||||
this.world = source.world;
|
||||
this.x = source.x + dx;
|
||||
this.y = source.y + dy;
|
||||
this.z = source.z + dz;
|
||||
|
||||
this.chunk = null;
|
||||
|
||||
reset();
|
||||
|
||||
return self();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,19 @@ public class BlockNeighborhood<T extends BlockNeighborhood<T>> extends ExtendedB
|
|||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set(int x, int y, int z) {
|
||||
return copy(getBlock(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set(World world, int x, int y, int z) {
|
||||
if (getWorld() == world)
|
||||
return copy(getBlock(x, y, z));
|
||||
else
|
||||
return super.set(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() {
|
||||
super.reset();
|
||||
|
@ -68,25 +81,28 @@ public class BlockNeighborhood<T extends BlockNeighborhood<T>> extends ExtendedB
|
|||
}
|
||||
|
||||
public ExtendedBlock<?> getNeighborBlock(int dx, int dy, int dz) {
|
||||
int i = neighborIndex(dx, dy, dz);
|
||||
if (i == thisIndex()) return this;
|
||||
return neighborhood[i].set(
|
||||
getWorld(),
|
||||
return getBlock(
|
||||
getX() + dx,
|
||||
getY() + dy,
|
||||
getZ() + dz
|
||||
);
|
||||
}
|
||||
|
||||
private ExtendedBlock<?> getBlock(int x, int y, int z) {
|
||||
int i = index(x, y, z);
|
||||
if (i == thisIndex()) return this;
|
||||
return neighborhood[i].set(getWorld(), x, y, z);
|
||||
}
|
||||
|
||||
private int thisIndex() {
|
||||
if (thisIndex == -1) thisIndex = neighborIndex(0, 0, 0);
|
||||
if (thisIndex == -1) thisIndex = index(getX(), getY(), getZ());
|
||||
return thisIndex;
|
||||
}
|
||||
|
||||
private int neighborIndex(int dx, int dy, int dz) {
|
||||
return ((getX() + dx) & DIAMETER_MASK) * DIAMETER_SQUARED +
|
||||
((getY() + dy) & DIAMETER_MASK) * DIAMETER +
|
||||
((getZ() + dz) & DIAMETER_MASK);
|
||||
private int index(int x, int y, int z) {
|
||||
return (x & DIAMETER_MASK) * DIAMETER_SQUARED +
|
||||
(y & DIAMETER_MASK) * DIAMETER +
|
||||
(z & DIAMETER_MASK);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Objects;
|
|||
public class ExtendedBlock<T extends ExtendedBlock<T>> extends Block<T> {
|
||||
private final ResourcePack resourcePack;
|
||||
private final RenderSettings renderSettings;
|
||||
|
||||
private BlockProperties properties;
|
||||
private Biome biome;
|
||||
|
||||
|
@ -56,6 +57,21 @@ public class ExtendedBlock<T extends ExtendedBlock<T>> extends Block<T> {
|
|||
this.isCaveCalculated = false;
|
||||
}
|
||||
|
||||
public T copy(ExtendedBlock<?> source) {
|
||||
super.copy(source);
|
||||
|
||||
this.properties = source.properties;
|
||||
this.biome = source.biome;
|
||||
|
||||
this.insideRenderBoundsCalculated = source.insideRenderBoundsCalculated;
|
||||
this.insideRenderBounds = source.insideRenderBounds;
|
||||
|
||||
this.isCaveCalculated = source.isCaveCalculated;
|
||||
this.isCave = source.isCave;
|
||||
|
||||
return self();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState() {
|
||||
if (renderSettings.isRenderEdges() && !isInsideRenderBounds()) return BlockState.AIR;
|
||||
|
|
|
@ -4,13 +4,17 @@ import com.flowpowered.math.vector.Vector2i;
|
|||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.resources.datapack.DataPack;
|
||||
import de.bluecolored.bluemap.core.util.Grid;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import de.bluecolored.bluemap.core.util.Vector2iCache;
|
||||
import de.bluecolored.bluemap.core.world.*;
|
||||
import de.bluecolored.bluemap.core.world.Chunk;
|
||||
import de.bluecolored.bluemap.core.world.DimensionType;
|
||||
import de.bluecolored.bluemap.core.world.Region;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import de.bluecolored.bluemap.core.world.mca.chunk.ChunkLoader;
|
||||
import de.bluecolored.bluemap.core.world.mca.data.LevelData;
|
||||
import de.bluecolored.bluemap.core.world.mca.region.RegionType;
|
||||
|
@ -23,7 +27,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -31,6 +34,7 @@ import java.util.zip.GZIPInputStream;
|
|||
|
||||
@Getter
|
||||
@ToString
|
||||
@DebugDump
|
||||
public class MCAWorld implements World {
|
||||
|
||||
private static final Grid CHUNK_GRID = new Grid(16);
|
||||
|
@ -61,8 +65,8 @@ public class MCAWorld implements World {
|
|||
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||
.build(this::loadChunk);
|
||||
|
||||
public MCAWorld(String id, Path worldFolder, Key dimension, LevelData levelData, DataPack dataPack) {
|
||||
this.id = id;
|
||||
private MCAWorld(Path worldFolder, Key dimension, LevelData levelData, DataPack dataPack) {
|
||||
this.id = id(worldFolder, dimension);
|
||||
this.worldFolder = worldFolder;
|
||||
this.dimension = dimension;
|
||||
this.levelData = levelData;
|
||||
|
@ -88,7 +92,7 @@ public class MCAWorld implements World {
|
|||
levelData.getData().getSpawnZ()
|
||||
);
|
||||
this.dimensionFolder = resolveDimensionFolder(worldFolder, dimension);
|
||||
this.regionFolder = getWorldFolder().resolve("region");
|
||||
this.regionFolder = dimensionFolder.resolve("region");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -219,18 +223,7 @@ public class MCAWorld implements World {
|
|||
return Chunk.EMPTY_CHUNK;
|
||||
}
|
||||
|
||||
public static MCAWorld load(Path worldFolder, Key dimension) throws IOException {
|
||||
// load or create bluemap.id
|
||||
Path idFile = worldFolder.resolve("bluemap.id");
|
||||
String id;
|
||||
if (!Files.exists(idFile)) {
|
||||
id = UUID.randomUUID().toString();
|
||||
Files.writeString(idFile, id, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
} else {
|
||||
id = Files.readString(idFile);
|
||||
}
|
||||
id += "-" + dimension.getFormatted();
|
||||
|
||||
public static MCAWorld load(Path worldFolder, Key dimension) throws IOException, InterruptedException {
|
||||
// load level.dat
|
||||
Path levelFile = worldFolder.resolve("level.dat");
|
||||
InputStream levelFileIn = new GZIPInputStream(new BufferedInputStream(Files.newInputStream(levelFile)));
|
||||
|
@ -253,10 +246,20 @@ public class MCAWorld implements World {
|
|||
dataPack.bake();
|
||||
|
||||
// create world
|
||||
return new MCAWorld(id, worldFolder, dimension, levelData, dataPack);
|
||||
return new MCAWorld(worldFolder, dimension, levelData, dataPack);
|
||||
}
|
||||
|
||||
private static Path resolveDimensionFolder(Path worldFolder, Key dimension) {
|
||||
public static String id(Path worldFolder, Key dimension) {
|
||||
worldFolder = worldFolder.toAbsolutePath().normalize();
|
||||
|
||||
Path workingDir = Path.of("").toAbsolutePath().normalize();
|
||||
if (worldFolder.startsWith(workingDir))
|
||||
worldFolder = workingDir.relativize(worldFolder);
|
||||
|
||||
return "MCA#" + worldFolder + "#" + dimension.getFormatted();
|
||||
}
|
||||
|
||||
public static Path resolveDimensionFolder(Path worldFolder, Key dimension) {
|
||||
if (DataPack.DIMENSION_OVERWORLD.equals(dimension)) return worldFolder;
|
||||
if (DataPack.DIMENSION_THE_NETHER.equals(dimension)) return worldFolder.resolve("DIM-1");
|
||||
if (DataPack.DIMENSION_THE_END.equals(dimension)) return worldFolder.resolve("DIM1");
|
||||
|
|
|
@ -7,6 +7,7 @@ import lombok.Getter;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -28,13 +29,18 @@ public class ChunkLoader {
|
|||
|
||||
// try last used version
|
||||
ChunkVersionLoader<?> usedLoader = lastUsedLoader;
|
||||
MCAChunk chunk = usedLoader.load(region, compression.decompress(in));
|
||||
MCAChunk chunk;
|
||||
try (InputStream decompressedIn = new BufferedInputStream(compression.decompress(in))) {
|
||||
chunk = usedLoader.load(region, decompressedIn);
|
||||
}
|
||||
|
||||
// check version and reload chunk if the wrong loader has been used and a better one has been found
|
||||
ChunkVersionLoader<?> actualLoader = findBestLoaderForVersion(chunk.getDataVersion());
|
||||
if (actualLoader != null && usedLoader != actualLoader) {
|
||||
in.reset(); // reset read position
|
||||
chunk = actualLoader.load(region, compression.decompress(in));
|
||||
try (InputStream decompressedIn = new BufferedInputStream(compression.decompress(in))) {
|
||||
chunk = actualLoader.load(region, decompressedIn);
|
||||
}
|
||||
lastUsedLoader = actualLoader;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.bluecolored.bluemap.core.world.mca.data;
|
||||
|
||||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -7,11 +8,13 @@ import java.util.Map;
|
|||
|
||||
@Getter
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@DebugDump
|
||||
public class LevelData {
|
||||
|
||||
private Data data = new Data();
|
||||
|
||||
@Getter
|
||||
@DebugDump
|
||||
public static class Data {
|
||||
private String levelName = "world";
|
||||
private int spawnX = 0, spawnY = 0, spawnZ = 0;
|
||||
|
@ -19,11 +22,13 @@ public class LevelData {
|
|||
}
|
||||
|
||||
@Getter
|
||||
@DebugDump
|
||||
public static class WGSettings {
|
||||
private Map<String, Dimension> dimensions = new HashMap<>();
|
||||
}
|
||||
|
||||
@Getter
|
||||
@DebugDump
|
||||
public static class Dimension {
|
||||
private String type = "minecraft:overworld";
|
||||
}
|
||||
|
|
|
@ -91,7 +91,13 @@ public class MCARegion implements Region {
|
|||
int size = header[3] * 4096;
|
||||
|
||||
if (size == 0) return Chunk.EMPTY_CHUNK;
|
||||
return loadChunk(channel, offset, size, new byte[size]);
|
||||
|
||||
byte[] chunkDataBuffer = new byte[size];
|
||||
|
||||
channel.position(offset);
|
||||
readFully(channel, chunkDataBuffer, 0, size);
|
||||
|
||||
return loadChunk(chunkDataBuffer, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +146,10 @@ public class MCARegion implements Region {
|
|||
if (chunkDataBuffer == null || chunkDataBuffer.length < size)
|
||||
chunkDataBuffer = new byte[size];
|
||||
|
||||
MCAChunk chunk = loadChunk(channel, offset, size, chunkDataBuffer);
|
||||
channel.position(offset);
|
||||
readFully(channel, chunkDataBuffer, 0, size);
|
||||
|
||||
MCAChunk chunk = loadChunk(chunkDataBuffer, size);
|
||||
consumer.accept(chunkX, chunkZ, chunk);
|
||||
}
|
||||
}
|
||||
|
@ -148,21 +157,19 @@ public class MCARegion implements Region {
|
|||
}
|
||||
}
|
||||
|
||||
private MCAChunk loadChunk(FileChannel channel, int offset, int size, byte[] dataBuffer) throws IOException {
|
||||
channel.position(offset);
|
||||
readFully(channel, dataBuffer, 0, size);
|
||||
|
||||
int compressionTypeId = dataBuffer[4];
|
||||
private MCAChunk loadChunk(byte[] data, int size) throws IOException {
|
||||
int compressionTypeId = data[4];
|
||||
Compression compression;
|
||||
switch (compressionTypeId) {
|
||||
case 0 :
|
||||
case 3 : compression = Compression.NONE; break;
|
||||
case 1 : compression = Compression.GZIP; break;
|
||||
case 2 : compression = Compression.DEFLATE; break;
|
||||
case 4 : compression = Compression.LZ4; break;
|
||||
default: throw new IOException("Unknown chunk compression-id: " + compressionTypeId);
|
||||
}
|
||||
|
||||
return world.getChunkLoader().load(this, dataBuffer, 5, size - 5, compression);
|
||||
return world.getChunkLoader().load(this, data, 5, size - 5, compression);
|
||||
}
|
||||
|
||||
public static String getRegionFileName(int regionX, int regionZ) {
|
||||
|
@ -175,14 +182,16 @@ public class MCARegion implements Region {
|
|||
}
|
||||
|
||||
private static void readFully(ReadableByteChannel src, ByteBuffer bb, int off, int len) throws IOException {
|
||||
int n = 0;
|
||||
while (n < len) {
|
||||
bb.limit(Math.min(off + len, bb.capacity()));
|
||||
bb.position(off);
|
||||
int count = src.read(bb);
|
||||
if (count < 0) throw new EOFException();
|
||||
n += count;
|
||||
}
|
||||
int limit = off + len;
|
||||
if (limit > bb.capacity()) throw new IllegalArgumentException("buffer too small");
|
||||
|
||||
bb.limit(limit);
|
||||
bb.position(off);
|
||||
|
||||
do {
|
||||
int read = src.read(bb);
|
||||
if (read < 0) throw new EOFException();
|
||||
} while (bb.remaining() > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,10 +35,6 @@ import de.bluecolored.bluemap.common.plugin.RegionFileWatchService;
|
|||
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
|
||||
import de.bluecolored.bluemap.common.rendermanager.RenderManager;
|
||||
import de.bluecolored.bluemap.common.rendermanager.RenderTask;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Server;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.common.web.*;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
|
||||
import de.bluecolored.bluemap.common.web.http.HttpServer;
|
||||
|
@ -67,10 +63,10 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class BlueMapCLI implements Server {
|
||||
public class BlueMapCLI {
|
||||
|
||||
private MinecraftVersion minecraftVersion = MinecraftVersion.LATEST_SUPPORTED;
|
||||
private Path configFolder;
|
||||
private Path configFolder = Path.of("config");
|
||||
|
||||
public void renderMaps(BlueMapService blueMap, boolean watch, boolean forceRender, boolean forceGenerateWebapp,
|
||||
@Nullable String mapsToRender) throws ConfigurationException, IOException, InterruptedException {
|
||||
|
@ -82,7 +78,7 @@ public class BlueMapCLI implements Server {
|
|||
blueMap.createOrUpdateWebApp(forceGenerateWebapp);
|
||||
|
||||
//try load resources
|
||||
blueMap.loadResourcePack();
|
||||
blueMap.getOrLoadResourcePack();
|
||||
|
||||
//create renderManager
|
||||
RenderManager renderManager = new RenderManager();
|
||||
|
@ -93,7 +89,7 @@ public class BlueMapCLI implements Server {
|
|||
Set<String> mapsToRenderSet = Set.of(mapsToRender.split(","));
|
||||
mapFilter = mapsToRenderSet::contains;
|
||||
}
|
||||
Map<String, BmMap> maps = blueMap.getMaps(mapFilter);
|
||||
Map<String, BmMap> maps = blueMap.getOrLoadMaps(mapFilter);
|
||||
|
||||
//watcher
|
||||
List<RegionFileWatchService> regionFileWatchServices = new ArrayList<>();
|
||||
|
@ -205,7 +201,7 @@ public class BlueMapCLI implements Server {
|
|||
|
||||
// map route
|
||||
for (var mapConfigEntry : blueMap.getConfig().getMapConfigs().entrySet()) {
|
||||
Storage storage = blueMap.getStorage(mapConfigEntry.getValue().getStorage());
|
||||
Storage storage = blueMap.getOrLoadStorage(mapConfigEntry.getValue().getStorage());
|
||||
|
||||
routingRequestHandler.register(
|
||||
"maps/" + Pattern.quote(mapConfigEntry.getKey()) + "/(.*)",
|
||||
|
@ -252,47 +248,6 @@ public class BlueMapCLI implements Server {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftVersion getMinecraftVersion() {
|
||||
return minecraftVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(ServerEventListener listener) {}
|
||||
|
||||
@Override
|
||||
public void unregisterAllListeners() {}
|
||||
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Path worldFolder) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getConfigFolder() {
|
||||
return configFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Path> getModsFolder() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> getOnlinePlayers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
|
||||
|
@ -324,7 +279,6 @@ public class BlueMapCLI implements Server {
|
|||
}
|
||||
|
||||
//config folder
|
||||
cli.configFolder = Path.of("config");
|
||||
if (cmd.hasOption("c")) {
|
||||
cli.configFolder = Path.of(cmd.getOptionValue("c"));
|
||||
FileHelper.createDirectories(cli.configFolder);
|
||||
|
@ -342,7 +296,13 @@ public class BlueMapCLI implements Server {
|
|||
}
|
||||
}
|
||||
|
||||
BlueMapConfigManager configs = new BlueMapConfigManager(cli, Path.of("data"), Path.of("web"), false);
|
||||
BlueMapConfigManager configs = BlueMapConfigManager.builder()
|
||||
.minecraftVersion(cli.minecraftVersion)
|
||||
.configRoot(cli.configFolder)
|
||||
.usePluginConfig(false)
|
||||
.defaultDataFolder(Path.of("data"))
|
||||
.defaultWebroot(Path.of("web"))
|
||||
.build();
|
||||
|
||||
//apply new file-logger config
|
||||
CoreConfig coreConfig = configs.getCoreConfig();
|
||||
|
@ -354,7 +314,7 @@ public class BlueMapCLI implements Server {
|
|||
));
|
||||
}
|
||||
|
||||
blueMap = new BlueMapService(cli, configs);
|
||||
blueMap = new BlueMapService(configs);
|
||||
boolean noActions = true;
|
||||
|
||||
if (cmd.hasOption("w")) {
|
||||
|
@ -479,23 +439,7 @@ public class BlueMapCLI implements Server {
|
|||
private static void printHelp() {
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
|
||||
String filename = "bluemap-cli.jar";
|
||||
try {
|
||||
File file = new File(BlueMapCLI.class.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.getPath());
|
||||
|
||||
if (file.isFile()) {
|
||||
try {
|
||||
filename = "." + File.separator + new File("").getCanonicalFile().toPath().relativize(file.toPath());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
filename = file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
String command = "java -jar " + filename;
|
||||
String command = getCliCommand();
|
||||
|
||||
@SuppressWarnings("StringBufferReplaceableByString")
|
||||
StringBuilder footer = new StringBuilder();
|
||||
|
@ -512,6 +456,25 @@ public class BlueMapCLI implements Server {
|
|||
formatter.printHelp(command + " [options]", "\nOptions:", createOptions(), "\n" + footer);
|
||||
}
|
||||
|
||||
private static String getCliCommand() {
|
||||
String filename = "bluemap-cli.jar";
|
||||
try {
|
||||
File file = new File(BlueMapCLI.class.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.getPath());
|
||||
|
||||
if (file.isFile()) {
|
||||
try {
|
||||
filename = "." + File.separator + new File("").getCanonicalFile().toPath().relativize(file.toPath());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
filename = file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
} catch (IOException ignore) {}
|
||||
return "java -jar " + filename;
|
||||
}
|
||||
|
||||
private static void printVersion() {
|
||||
System.out.printf("%s\n%s\n", BlueMap.VERSION, BlueMap.GIT_HASH);
|
||||
}
|
||||
|
|
|
@ -26,14 +26,14 @@ package de.bluecolored.bluemap.fabric;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricCommandSource implements CommandSource {
|
||||
|
@ -75,13 +75,8 @@ public class FabricCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getWorld());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getWorld());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,17 +29,17 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
|||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.commands.Commands;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Server;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -141,7 +141,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (net.minecraft.server.world.ServerWorld serverWorld : serverInstance.getWorlds()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -150,9 +150,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
|
@ -170,12 +168,12 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
if (world instanceof net.minecraft.server.world.ServerWorld)
|
||||
return Optional.of(getWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
return Optional.of(getServerWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
public ServerWorld getServerWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
return worlds.get(serverWorld);
|
||||
}
|
||||
|
||||
|
@ -220,11 +218,6 @@ public class FabricMod implements ModInitializer, Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -36,7 +37,6 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -54,12 +54,11 @@ public class FabricPlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -84,7 +83,7 @@ public class FabricPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -108,11 +107,6 @@ public class FabricPlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -133,16 +127,10 @@ public class FabricPlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -151,7 +139,6 @@ public class FabricPlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3d pos = player.getPos();
|
||||
this.position = new Vector3d(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
@ -161,12 +148,7 @@ public class FabricPlayer implements Player {
|
|||
this.skyLight = player.getServerWorld().getLightingProvider().get(LightType.SKY).getLightLevel(player.getBlockPos());
|
||||
this.blockLight = player.getServerWorld().getLightingProvider().get(LightType.BLOCK).getLightLevel(player.getBlockPos());
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getServerWorld());
|
||||
this.world = mod.getPluginInstance().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getServerWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.fabric;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import de.bluecolored.bluemap.core.resources.datapack.DataPack;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -38,25 +40,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class FabricWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<net.minecraft.server.world.ServerWorld> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public FabricWorld(net.minecraft.server.world.ServerWorld delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
this.saveFolder = delegate.getDimension().getType()
|
||||
.getSaveDirectory(delegate.getSaveHandler().getWorldDir()).toPath()
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getSaveHandler().getWorldDir().toPath();
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
net.minecraft.server.world.ServerWorld world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.getDimension().getType().equals(DimensionType.THE_NETHER)) return Dimension.NETHER;
|
||||
if (world.getDimension().getType().equals(DimensionType.THE_END)) return Dimension.END;
|
||||
if (world.getDimension().getType().equals(DimensionType.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
Identifier id = Registry.DIMENSION_TYPE.getId(delegate.getDimension().getType());
|
||||
this.dimension = id != null ?
|
||||
new Key(id.getNamespace(), id.getPath()) :
|
||||
DataPack.DIMENSION_OVERWORLD;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,8 +82,13 @@ public class FabricWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
|||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -26,14 +26,14 @@ package de.bluecolored.bluemap.fabric;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricCommandSource implements CommandSource {
|
||||
|
@ -75,13 +75,8 @@ public class FabricCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getWorld());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getWorld());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import java.util.UUID;
|
|||
|
||||
public class FabricEventForwarder {
|
||||
|
||||
private FabricMod mod;
|
||||
private Collection<ServerEventListener> eventListeners;
|
||||
private final FabricMod mod;
|
||||
private final Collection<ServerEventListener> eventListeners;
|
||||
|
||||
public FabricEventForwarder(FabricMod mod) {
|
||||
this.mod = mod;
|
||||
|
|
|
@ -29,17 +29,17 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
|||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.commands.Commands;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Server;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -143,7 +143,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (net.minecraft.server.world.ServerWorld serverWorld : serverInstance.getWorlds()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -153,9 +153,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
|
@ -169,12 +167,12 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
if (world instanceof net.minecraft.server.world.ServerWorld)
|
||||
return Optional.of(getWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
return Optional.of(getServerWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
public ServerWorld getServerWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
return worlds.get(serverWorld);
|
||||
}
|
||||
|
||||
|
@ -219,11 +217,6 @@ public class FabricMod implements ModInitializer, Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -36,7 +37,6 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -54,12 +54,11 @@ public class FabricPlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -84,7 +83,7 @@ public class FabricPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -108,11 +107,6 @@ public class FabricPlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -133,16 +127,10 @@ public class FabricPlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -151,7 +139,6 @@ public class FabricPlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3d pos = player.getPos();
|
||||
this.position = new Vector3d(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
@ -161,12 +148,7 @@ public class FabricPlayer implements Player {
|
|||
this.skyLight = player.getServerWorld().getLightingProvider().get(LightType.SKY).getLightLevel(player.getBlockPos());
|
||||
this.blockLight = player.getServerWorld().getLightingProvider().get(LightType.BLOCK).getLightLevel(player.getBlockPos());
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getServerWorld());
|
||||
this.world = mod.getPluginInstance().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getServerWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.fabric;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -41,27 +40,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class FabricWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<net.minecraft.server.world.ServerWorld> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public FabricWorld(net.minecraft.server.world.ServerWorld delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getRunDirectory().toPath().resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
this.saveFolder = DimensionType.getSaveDirectory(delegate.getRegistryKey(), worldFolder.toFile()).toPath()
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getRunDirectory().toPath()
|
||||
.resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
net.minecraft.server.world.ServerWorld world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.getRegistryKey().equals(World.NETHER)) return Dimension.NETHER;
|
||||
if (world.getRegistryKey().equals(World.END)) return Dimension.END;
|
||||
if (world.getRegistryKey().equals(World.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
Identifier id = delegate.getRegistryKey().getValue();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,8 +82,13 @@ public class FabricWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
|||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -26,14 +26,14 @@ package de.bluecolored.bluemap.fabric;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricCommandSource implements CommandSource {
|
||||
|
@ -75,13 +75,8 @@ public class FabricCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getWorld());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getWorld());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import java.util.UUID;
|
|||
|
||||
public class FabricEventForwarder {
|
||||
|
||||
private FabricMod mod;
|
||||
private Collection<ServerEventListener> eventListeners;
|
||||
private final FabricMod mod;
|
||||
private final Collection<ServerEventListener> eventListeners;
|
||||
|
||||
public FabricEventForwarder(FabricMod mod) {
|
||||
this.mod = mod;
|
||||
|
|
|
@ -143,7 +143,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (net.minecraft.server.world.ServerWorld serverWorld : serverInstance.getWorlds()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -153,9 +153,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
|
@ -169,12 +167,12 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
if (world instanceof net.minecraft.server.world.ServerWorld)
|
||||
return Optional.of(getWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
return Optional.of(getServerWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
public ServerWorld getServerWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
return worlds.get(serverWorld);
|
||||
}
|
||||
|
||||
|
@ -219,11 +217,6 @@ public class FabricMod implements ModInitializer, Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -36,7 +37,6 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -53,12 +53,11 @@ public class FabricPlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -83,7 +82,7 @@ public class FabricPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -107,11 +106,6 @@ public class FabricPlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -132,16 +126,10 @@ public class FabricPlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -150,7 +138,6 @@ public class FabricPlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3d pos = player.getPos();
|
||||
this.position = new Vector3d(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
@ -160,12 +147,7 @@ public class FabricPlayer implements Player {
|
|||
this.skyLight = player.getServerWorld().getLightingProvider().get(LightType.SKY).getLightLevel(player.getBlockPos());
|
||||
this.blockLight = player.getServerWorld().getLightingProvider().get(LightType.BLOCK).getLightLevel(player.getBlockPos());
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getServerWorld());
|
||||
this.world = mod.getPluginInstance().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getServerWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.fabric;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -41,27 +40,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class FabricWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<net.minecraft.server.world.ServerWorld> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public FabricWorld(net.minecraft.server.world.ServerWorld delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getRunDirectory().toPath().resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
this.saveFolder = DimensionType.getSaveDirectory(delegate.getRegistryKey(), worldFolder.toFile()).toPath()
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getRunDirectory().toPath()
|
||||
.resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
net.minecraft.server.world.ServerWorld world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.getRegistryKey().equals(World.NETHER)) return Dimension.NETHER;
|
||||
if (world.getRegistryKey().equals(World.END)) return Dimension.END;
|
||||
if (world.getRegistryKey().equals(World.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
Identifier id = delegate.getRegistryKey().getValue();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,8 +82,13 @@ public class FabricWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
|||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -26,14 +26,14 @@ package de.bluecolored.bluemap.fabric;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricCommandSource implements CommandSource {
|
||||
|
@ -75,13 +75,8 @@ public class FabricCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getWorld());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getWorld());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import java.util.UUID;
|
|||
|
||||
public class FabricEventForwarder {
|
||||
|
||||
private FabricMod mod;
|
||||
private Collection<ServerEventListener> eventListeners;
|
||||
private final FabricMod mod;
|
||||
private final Collection<ServerEventListener> eventListeners;
|
||||
|
||||
public FabricEventForwarder(FabricMod mod) {
|
||||
this.mod = mod;
|
||||
|
|
|
@ -143,7 +143,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (net.minecraft.server.world.ServerWorld serverWorld : serverInstance.getWorlds()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -153,9 +153,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
|
@ -169,12 +167,12 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
if (world instanceof net.minecraft.server.world.ServerWorld)
|
||||
return Optional.of(getWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
return Optional.of(getServerWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
public ServerWorld getServerWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
return worlds.get(serverWorld);
|
||||
}
|
||||
|
||||
|
@ -219,11 +217,6 @@ public class FabricMod implements ModInitializer, Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -36,7 +37,6 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -53,12 +53,11 @@ public class FabricPlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -83,7 +82,7 @@ public class FabricPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -107,11 +106,6 @@ public class FabricPlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -132,16 +126,10 @@ public class FabricPlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -150,7 +138,6 @@ public class FabricPlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3d pos = player.getPos();
|
||||
this.position = new Vector3d(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
@ -160,12 +147,7 @@ public class FabricPlayer implements Player {
|
|||
this.skyLight = player.getWorld().getLightingProvider().get(LightType.SKY).getLightLevel(player.getBlockPos());
|
||||
this.blockLight = player.getWorld().getLightingProvider().get(LightType.BLOCK).getLightLevel(player.getBlockPos());
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getWorld());
|
||||
this.world = mod.getPluginInstance().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.fabric;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -41,27 +40,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class FabricWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<net.minecraft.server.world.ServerWorld> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public FabricWorld(net.minecraft.server.world.ServerWorld delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getRunDirectory().toPath().resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
this.saveFolder = DimensionType.getSaveDirectory(delegate.getRegistryKey(), worldFolder)
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getRunDirectory().toPath()
|
||||
.resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
net.minecraft.server.world.ServerWorld world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.getRegistryKey().equals(World.NETHER)) return Dimension.NETHER;
|
||||
if (world.getRegistryKey().equals(World.END)) return Dimension.END;
|
||||
if (world.getRegistryKey().equals(World.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
Identifier id = delegate.getRegistryKey().getValue();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,8 +82,13 @@ public class FabricWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
|||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -26,14 +26,14 @@ package de.bluecolored.bluemap.fabric;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricCommandSource implements CommandSource {
|
||||
|
@ -75,13 +75,8 @@ public class FabricCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getWorld());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getWorld());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import java.util.UUID;
|
|||
|
||||
public class FabricEventForwarder {
|
||||
|
||||
private FabricMod mod;
|
||||
private Collection<ServerEventListener> eventListeners;
|
||||
private final FabricMod mod;
|
||||
private final Collection<ServerEventListener> eventListeners;
|
||||
|
||||
public FabricEventForwarder(FabricMod mod) {
|
||||
this.mod = mod;
|
||||
|
|
|
@ -148,7 +148,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (net.minecraft.server.world.ServerWorld serverWorld : serverInstance.getWorlds()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -158,9 +158,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
|
@ -174,12 +172,12 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
if (world instanceof net.minecraft.server.world.ServerWorld)
|
||||
return Optional.of(getWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
return Optional.of(getServerWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
public ServerWorld getServerWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
return worlds.get(serverWorld);
|
||||
}
|
||||
|
||||
|
@ -224,11 +222,6 @@ public class FabricMod implements ModInitializer, Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -36,7 +37,6 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -53,12 +53,11 @@ public class FabricPlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -83,7 +82,7 @@ public class FabricPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -107,11 +106,6 @@ public class FabricPlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -132,16 +126,10 @@ public class FabricPlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -150,7 +138,6 @@ public class FabricPlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3d pos = player.getPos();
|
||||
this.position = new Vector3d(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
@ -160,12 +147,7 @@ public class FabricPlayer implements Player {
|
|||
this.skyLight = player.getWorld().getLightingProvider().get(LightType.SKY).getLightLevel(player.getBlockPos());
|
||||
this.blockLight = player.getWorld().getLightingProvider().get(LightType.BLOCK).getLightLevel(player.getBlockPos());
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getWorld());
|
||||
this.world = mod.getPluginInstance().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.fabric;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -41,27 +40,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class FabricWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<net.minecraft.server.world.ServerWorld> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public FabricWorld(net.minecraft.server.world.ServerWorld delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getRunDirectory().toPath().resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
this.saveFolder = DimensionType.getSaveDirectory(delegate.getRegistryKey(), worldFolder)
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getRunDirectory().toPath()
|
||||
.resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
net.minecraft.server.world.ServerWorld world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.getRegistryKey().equals(World.NETHER)) return Dimension.NETHER;
|
||||
if (world.getRegistryKey().equals(World.END)) return Dimension.END;
|
||||
if (world.getRegistryKey().equals(World.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
Identifier id = delegate.getRegistryKey().getValue();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,8 +82,13 @@ public class FabricWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
|||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -26,14 +26,14 @@ package de.bluecolored.bluemap.fabric;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FabricCommandSource implements CommandSource {
|
||||
|
@ -75,13 +75,8 @@ public class FabricCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getWorld());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getWorld());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import java.util.UUID;
|
|||
|
||||
public class FabricEventForwarder {
|
||||
|
||||
private FabricMod mod;
|
||||
private Collection<ServerEventListener> eventListeners;
|
||||
private final FabricMod mod;
|
||||
private final Collection<ServerEventListener> eventListeners;
|
||||
|
||||
public FabricEventForwarder(FabricMod mod) {
|
||||
this.mod = mod;
|
||||
|
|
|
@ -148,7 +148,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (net.minecraft.server.world.ServerWorld serverWorld : serverInstance.getWorlds()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -158,9 +158,7 @@ public class FabricMod implements ModInitializer, Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
|
@ -174,12 +172,12 @@ public class FabricMod implements ModInitializer, Server {
|
|||
}
|
||||
|
||||
if (world instanceof net.minecraft.server.world.ServerWorld)
|
||||
return Optional.of(getWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
return Optional.of(getServerWorld((net.minecraft.server.world.ServerWorld) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
public ServerWorld getServerWorld(net.minecraft.server.world.ServerWorld serverWorld) {
|
||||
return worlds.get(serverWorld);
|
||||
}
|
||||
|
||||
|
@ -224,11 +222,6 @@ public class FabricMod implements ModInitializer, Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -36,7 +37,6 @@ import net.minecraft.util.math.Vec3d;
|
|||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -53,12 +53,11 @@ public class FabricPlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -83,7 +82,7 @@ public class FabricPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -107,11 +106,6 @@ public class FabricPlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -132,16 +126,10 @@ public class FabricPlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -150,7 +138,6 @@ public class FabricPlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3d pos = player.getPos();
|
||||
this.position = new Vector3d(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
@ -160,12 +147,7 @@ public class FabricPlayer implements Player {
|
|||
this.skyLight = player.getWorld().getLightingProvider().get(LightType.SKY).getLightLevel(player.getBlockPos());
|
||||
this.blockLight = player.getWorld().getLightingProvider().get(LightType.BLOCK).getLightLevel(player.getBlockPos());
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getWorld()).orElse(null);
|
||||
this.world = world != null ? mod.getPluginInstance().getBlueMap().getWorldId(world.getSaveFolder()) : "unknown";
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getServerWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.fabric;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -41,27 +40,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class FabricWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<net.minecraft.server.world.ServerWorld> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public FabricWorld(net.minecraft.server.world.ServerWorld delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getRunDirectory().toPath().resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
this.saveFolder = DimensionType.getSaveDirectory(delegate.getRegistryKey(), worldFolder)
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getRunDirectory().toPath()
|
||||
.resolve(server.getSavePath(WorldSavePath.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
net.minecraft.server.world.ServerWorld world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.getRegistryKey().equals(World.NETHER)) return Dimension.NETHER;
|
||||
if (world.getRegistryKey().equals(World.END)) return Dimension.END;
|
||||
if (world.getRegistryKey().equals(World.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
Identifier id = delegate.getRegistryKey().getValue();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,8 +82,13 @@ public class FabricWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,13 +26,13 @@ package de.bluecolored.bluemap.forge;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ForgeCommandSource implements CommandSource {
|
||||
|
@ -67,13 +67,8 @@ public class ForgeCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getLevel());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getLevel());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (ServerLevel serverWorld : serverInstance.getAllLevels()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -165,9 +165,7 @@ public class ForgeMod implements Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
|
@ -181,12 +179,12 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
if (world instanceof ServerLevel)
|
||||
return Optional.of(getWorld((ServerLevel) world));
|
||||
return Optional.of(getServerWorld((ServerLevel) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(ServerLevel world) {
|
||||
public ServerWorld getServerWorld(ServerLevel world) {
|
||||
return worlds.get(world);
|
||||
}
|
||||
|
||||
|
@ -235,11 +233,6 @@ public class ForgeMod implements Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -37,7 +38,6 @@ import net.minecraft.world.level.GameType;
|
|||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -54,12 +54,11 @@ public class ForgePlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -84,7 +83,7 @@ public class ForgePlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -108,11 +107,6 @@ public class ForgePlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -133,16 +127,10 @@ public class ForgePlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.getOrDefault(player.gameMode.getGameModeForPlayer(), Gamemode.SURVIVAL);
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -151,7 +139,6 @@ public class ForgePlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3 pos = player.getPosition(1f);
|
||||
this.position = new Vector3d(pos.x(), pos.y(), pos.z());
|
||||
|
@ -161,12 +148,7 @@ public class ForgePlayer implements Player {
|
|||
this.skyLight = player.getLevel().getChunkSource().getLightEngine().getLayerListener(LightLayer.SKY).getLightValue(new BlockPos(player.getX(), player.getY(), player.getZ()));
|
||||
this.blockLight = player.getLevel().getChunkSource().getLightEngine().getLayerListener(LightLayer.BLOCK).getLightValue(new BlockPos(player.getX(), player.getY(), player.getZ()));
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getLevel());
|
||||
this.world = mod.getPlugin().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getLevel());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.forge;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,27 +41,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class ForgeWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<ServerLevel> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public ForgeWorld(ServerLevel delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getServerDirectory().toPath().resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
this.saveFolder = DimensionType.getStorageFolder(delegate.dimension(), worldFolder.toFile()).toPath()
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getServerDirectory().toPath()
|
||||
.resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
ServerLevel world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.dimension().equals(Level.NETHER)) return Dimension.NETHER;
|
||||
if (world.dimension().equals(Level.END)) return Dimension.END;
|
||||
if (world.dimension().equals(Level.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
ResourceLocation id = delegate.dimension().location();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +83,13 @@ public class ForgeWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,13 +24,12 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.forge;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -26,13 +26,13 @@ package de.bluecolored.bluemap.forge;
|
|||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ForgeCommandSource implements CommandSource {
|
||||
|
@ -67,13 +67,8 @@ public class ForgeCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getLevel());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getLevel());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (ServerLevel serverWorld : serverInstance.getAllLevels()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -165,9 +165,7 @@ public class ForgeMod implements Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
|
@ -181,12 +179,12 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
if (world instanceof ServerLevel)
|
||||
return Optional.of(getWorld((ServerLevel) world));
|
||||
return Optional.of(getServerWorld((ServerLevel) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(ServerLevel world) {
|
||||
public ServerWorld getServerWorld(ServerLevel world) {
|
||||
return worlds.get(world);
|
||||
}
|
||||
|
||||
|
@ -235,11 +233,6 @@ public class ForgeMod implements Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -37,7 +38,6 @@ import net.minecraft.world.level.GameType;
|
|||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -54,12 +54,11 @@ public class ForgePlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -84,7 +83,7 @@ public class ForgePlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -108,11 +107,6 @@ public class ForgePlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -133,16 +127,10 @@ public class ForgePlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.getOrDefault(player.gameMode.getGameModeForPlayer(), Gamemode.SURVIVAL);
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -151,7 +139,6 @@ public class ForgePlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3 pos = player.getPosition(1f);
|
||||
this.position = new Vector3d(pos.x(), pos.y(), pos.z());
|
||||
|
@ -161,12 +148,7 @@ public class ForgePlayer implements Player {
|
|||
this.skyLight = player.getLevel().getChunkSource().getLightEngine().getLayerListener(LightLayer.SKY).getLightValue(new BlockPos(player.getX(), player.getY(), player.getZ()));
|
||||
this.blockLight = player.getLevel().getChunkSource().getLightEngine().getLayerListener(LightLayer.BLOCK).getLightValue(new BlockPos(player.getX(), player.getY(), player.getZ()));
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getLevel());
|
||||
this.world = mod.getPlugin().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getLevel());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.forge;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,27 +41,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class ForgeWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<ServerLevel> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public ForgeWorld(ServerLevel delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getServerDirectory().toPath().resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
this.saveFolder = DimensionType.getStorageFolder(delegate.dimension(), worldFolder)
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getServerDirectory().toPath()
|
||||
.resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
ServerLevel world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.dimension().equals(Level.NETHER)) return Dimension.NETHER;
|
||||
if (world.dimension().equals(Level.END)) return Dimension.END;
|
||||
if (world.dimension().equals(Level.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
ResourceLocation id = delegate.dimension().location();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +83,13 @@ public class ForgeWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
|||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -28,11 +28,11 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ForgeCommandSource implements CommandSource {
|
||||
|
@ -67,13 +67,8 @@ public class ForgeCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getLevel());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getLevel());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
|||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.commands.Commands;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Server;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
|
@ -160,7 +160,7 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (ServerLevel serverWorld : serverInstance.getAllLevels()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -170,9 +170,7 @@ public class ForgeMod implements Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
|
@ -186,12 +184,12 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
if (world instanceof ServerLevel)
|
||||
return Optional.of(getWorld((ServerLevel) world));
|
||||
return Optional.of(getServerWorld((ServerLevel) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(ServerLevel world) {
|
||||
public ServerWorld getServerWorld(ServerLevel world) {
|
||||
return worlds.get(world);
|
||||
}
|
||||
|
||||
|
@ -240,11 +238,6 @@ public class ForgeMod implements Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -37,7 +38,6 @@ import net.minecraft.world.level.GameType;
|
|||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -54,12 +54,11 @@ public class ForgePlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -84,7 +83,7 @@ public class ForgePlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -108,11 +107,6 @@ public class ForgePlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -133,16 +127,10 @@ public class ForgePlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.getOrDefault(player.gameMode.getGameModeForPlayer(), Gamemode.SURVIVAL);
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -151,7 +139,6 @@ public class ForgePlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3 pos = player.getPosition(1f);
|
||||
this.position = new Vector3d(pos.x(), pos.y(), pos.z());
|
||||
|
@ -161,12 +148,7 @@ public class ForgePlayer implements Player {
|
|||
this.skyLight = player.getLevel().getChunkSource().getLightEngine().getLayerListener(LightLayer.SKY).getLightValue(new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()));
|
||||
this.blockLight = player.getLevel().getChunkSource().getLightEngine().getLayerListener(LightLayer.BLOCK).getLightValue(new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()));
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.getLevel());
|
||||
this.world = mod.getPlugin().getBlueMap().getWorldId(world.getSaveFolder());
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.getLevel());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.forge;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,27 +41,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class ForgeWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<ServerLevel> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public ForgeWorld(ServerLevel delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getServerDirectory().toPath().resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
this.saveFolder = DimensionType.getStorageFolder(delegate.dimension(), worldFolder)
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getServerDirectory().toPath()
|
||||
.resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
ServerLevel world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.dimension().equals(Level.NETHER)) return Dimension.NETHER;
|
||||
if (world.dimension().equals(Level.END)) return Dimension.END;
|
||||
if (world.dimension().equals(Level.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
ResourceLocation id = delegate.dimension().location();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +83,13 @@ public class ForgeWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import de.bluecolored.bluemap.core.logger.AbstractLogger;
|
|||
|
||||
public class Log4jLogger extends AbstractLogger {
|
||||
|
||||
private Logger out;
|
||||
private final Logger out;
|
||||
|
||||
public Log4jLogger(Logger out) {
|
||||
this.out = out;
|
||||
|
|
|
@ -28,11 +28,11 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ForgeCommandSource implements CommandSource {
|
||||
|
@ -67,13 +67,8 @@ public class ForgeCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getLevel());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getLevel());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (ServerLevel serverWorld : serverInstance.getAllLevels()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -170,9 +170,7 @@ public class ForgeMod implements Server {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
|
@ -186,12 +184,12 @@ public class ForgeMod implements Server {
|
|||
}
|
||||
|
||||
if (world instanceof ServerLevel)
|
||||
return Optional.of(getWorld((ServerLevel) world));
|
||||
return Optional.of(getServerWorld((ServerLevel) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(ServerLevel world) {
|
||||
public ServerWorld getServerWorld(ServerLevel world) {
|
||||
return worlds.get(world);
|
||||
}
|
||||
|
||||
|
@ -240,11 +238,6 @@ public class ForgeMod implements Server {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -37,7 +38,6 @@ import net.minecraft.world.level.GameType;
|
|||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -54,12 +54,11 @@ public class ForgePlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -84,7 +83,7 @@ public class ForgePlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -108,11 +107,6 @@ public class ForgePlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -133,16 +127,10 @@ public class ForgePlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.getOrDefault(player.gameMode.getGameModeForPlayer(), Gamemode.SURVIVAL);
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -151,7 +139,6 @@ public class ForgePlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3 pos = player.getPosition(1f);
|
||||
this.position = new Vector3d(pos.x(), pos.y(), pos.z());
|
||||
|
@ -161,12 +148,7 @@ public class ForgePlayer implements Player {
|
|||
this.skyLight = player.level().getChunkSource().getLightEngine().getLayerListener(LightLayer.SKY).getLightValue(new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()));
|
||||
this.blockLight = player.level().getChunkSource().getLightEngine().getLayerListener(LightLayer.BLOCK).getLightValue(new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()));
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.level()).orElse(null);
|
||||
this.world = world != null ? mod.getPlugin().getBlueMap().getWorldId(world.getSaveFolder()) : "unknown";
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.serverLevel());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.forge;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,27 +41,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class ForgeWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<ServerLevel> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public ForgeWorld(ServerLevel delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getServerDirectory().toPath().resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
this.saveFolder = DimensionType.getStorageFolder(delegate.dimension(), worldFolder)
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getServerDirectory().toPath()
|
||||
.resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
ServerLevel world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.dimension().equals(Level.NETHER)) return Dimension.NETHER;
|
||||
if (world.dimension().equals(Level.END)) return Dimension.END;
|
||||
if (world.dimension().equals(Level.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
ResourceLocation id = delegate.dimension().location();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +83,13 @@ public class ForgeWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ForgeCommandSource implements CommandSource {
|
||||
|
@ -67,13 +67,8 @@ public class ForgeCommandSource implements CommandSource {
|
|||
|
||||
@Override
|
||||
public Optional<World> getWorld() {
|
||||
try {
|
||||
var serverWorld = mod.getWorld(delegate.getLevel());
|
||||
String worldId = plugin.getBlueMap().getWorldId(serverWorld.getSaveFolder());
|
||||
return Optional.ofNullable(plugin.getWorlds().get(worldId));
|
||||
} catch (IOException ignore) {}
|
||||
|
||||
return Optional.empty();
|
||||
ServerWorld serverWorld = mod.getServerWorld(delegate.getLevel());
|
||||
return Optional.ofNullable(plugin.getWorld(serverWorld));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
|||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.commands.Commands;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Server;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
|
@ -63,7 +63,7 @@ import java.util.*;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Mod(Plugin.PLUGIN_ID)
|
||||
public class ForgeMod implements ServerInterface {
|
||||
public class ForgeMod implements Server {
|
||||
|
||||
private final Plugin pluginInstance;
|
||||
private MinecraftServer serverInstance = null;
|
||||
|
@ -159,7 +159,7 @@ public class ForgeMod implements ServerInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ServerWorld> getLoadedWorlds() {
|
||||
public Collection<ServerWorld> getLoadedServerWorlds() {
|
||||
Collection<ServerWorld> loadedWorlds = new ArrayList<>(3);
|
||||
for (ServerLevel serverWorld : serverInstance.getAllLevels()) {
|
||||
loadedWorlds.add(worlds.get(serverWorld));
|
||||
|
@ -169,9 +169,7 @@ public class ForgeMod implements ServerInterface {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
public Optional<ServerWorld> getServerWorld(Object world) {
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
|
@ -185,12 +183,12 @@ public class ForgeMod implements ServerInterface {
|
|||
}
|
||||
|
||||
if (world instanceof ServerLevel)
|
||||
return Optional.of(getWorld((ServerLevel) world));
|
||||
return Optional.of(getServerWorld((ServerLevel) world));
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(ServerLevel world) {
|
||||
public ServerWorld getServerWorld(ServerLevel world) {
|
||||
return worlds.get(world);
|
||||
}
|
||||
|
||||
|
@ -239,11 +237,6 @@ public class ForgeMod implements ServerInterface {
|
|||
return onlinePlayerMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer(UUID uuid) {
|
||||
return Optional.ofNullable(onlinePlayerMap.get(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Only update some of the online players each tick to minimize performance impact on the server-thread.
|
||||
* Only call this method on the server-thread.
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
|
|||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -37,7 +38,6 @@ import net.minecraft.world.level.GameType;
|
|||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -54,12 +54,11 @@ public class ForgePlayer implements Player {
|
|||
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private String world;
|
||||
private ServerWorld world;
|
||||
private Vector3d position;
|
||||
private Vector3d rotation;
|
||||
private int skyLight;
|
||||
private int blockLight;
|
||||
private boolean online;
|
||||
private boolean sneaking;
|
||||
private boolean invisible;
|
||||
private Gamemode gamemode;
|
||||
|
@ -84,7 +83,7 @@ public class ForgePlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getWorld() {
|
||||
public ServerWorld getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
@ -108,11 +107,6 @@ public class ForgePlayer implements Player {
|
|||
return blockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return this.sneaking;
|
||||
|
@ -133,16 +127,10 @@ public class ForgePlayer implements Player {
|
|||
*/
|
||||
public void update() {
|
||||
MinecraftServer server = mod.getServer();
|
||||
if (server == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (server == null) return;
|
||||
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
|
||||
if (player == null) {
|
||||
this.online = false;
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
|
||||
this.gamemode = GAMEMODE_MAP.getOrDefault(player.gameMode.getGameModeForPlayer(), Gamemode.SURVIVAL);
|
||||
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
|
||||
|
@ -151,7 +139,6 @@ public class ForgePlayer implements Player {
|
|||
this.invisible = invis != null && invis.getDuration() > 0;
|
||||
|
||||
this.name = Text.of(player.getName().getString());
|
||||
this.online = true;
|
||||
|
||||
Vec3 pos = player.getPosition(1f);
|
||||
this.position = new Vector3d(pos.x(), pos.y(), pos.z());
|
||||
|
@ -161,12 +148,7 @@ public class ForgePlayer implements Player {
|
|||
this.skyLight = player.level().getChunkSource().getLightEngine().getLayerListener(LightLayer.SKY).getLightValue(new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()));
|
||||
this.blockLight = player.level().getChunkSource().getLightEngine().getLayerListener(LightLayer.BLOCK).getLightValue(new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()));
|
||||
|
||||
try {
|
||||
var world = mod.getWorld(player.level()).orElse(null);
|
||||
this.world = world != null ? mod.getPlugin().getBlueMap().getWorldId(world.getSaveFolder()) : "unknown";
|
||||
} catch (IOException | NullPointerException e) { // NullPointerException -> the plugin isn't fully loaded
|
||||
this.world = "unknown";
|
||||
}
|
||||
this.world = mod.getServerWorld(player.serverLevel());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
*/
|
||||
package de.bluecolored.bluemap.forge;
|
||||
|
||||
import de.bluecolored.bluemap.common.serverinterface.Dimension;
|
||||
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
|
||||
import de.bluecolored.bluemap.core.util.Key;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,27 +41,18 @@ import java.util.concurrent.ExecutionException;
|
|||
public class ForgeWorld implements ServerWorld {
|
||||
|
||||
private final WeakReference<ServerLevel> delegate;
|
||||
private final Path saveFolder;
|
||||
private final Path worldFolder;
|
||||
private final Key dimension;
|
||||
|
||||
public ForgeWorld(ServerLevel delegate) {
|
||||
this.delegate = new WeakReference<>(delegate);
|
||||
|
||||
MinecraftServer server = delegate.getServer();
|
||||
Path worldFolder = delegate.getServer().getServerDirectory().toPath().resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
this.saveFolder = DimensionType.getStorageFolder(delegate.dimension(), worldFolder)
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
this.worldFolder = delegate.getServer().getServerDirectory().toPath()
|
||||
.resolve(server.getWorldPath(LevelResource.ROOT));
|
||||
|
||||
@Override
|
||||
public Dimension getDimension() {
|
||||
ServerLevel world = delegate.get();
|
||||
if (world != null) {
|
||||
if (world.dimension().equals(Level.NETHER)) return Dimension.NETHER;
|
||||
if (world.dimension().equals(Level.END)) return Dimension.END;
|
||||
if (world.dimension().equals(Level.OVERWORLD)) return Dimension.OVERWORLD;
|
||||
}
|
||||
|
||||
return ServerWorld.super.getDimension();
|
||||
ResourceLocation id = delegate.dimension().location();
|
||||
this.dimension = new Key(id.getNamespace(), id.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +83,13 @@ public class ForgeWorld implements ServerWorld {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Path getSaveFolder() {
|
||||
return this.saveFolder;
|
||||
public Path getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue