mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-25 12:05:13 +01:00
Get world by resource location (#316)
This commit is contained in:
parent
e6548adf2b
commit
fa361043c5
@ -149,6 +149,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
if (identifier != null) world = identifier;
|
||||
}
|
||||
|
||||
if (world instanceof Identifier) {
|
||||
DimensionType dimensionType = DimensionType.byId((Identifier) world);
|
||||
if (dimensionType != null) world = dimensionType;
|
||||
|
@ -43,6 +43,8 @@
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.DIMENSION, identifier));
|
||||
}
|
||||
|
||||
if (world instanceof RegistryKey) {
|
||||
try {
|
||||
world = serverInstance.getWorld((RegistryKey<World>) world);
|
||||
|
@ -43,6 +43,8 @@
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.DIMENSION, identifier));
|
||||
}
|
||||
|
||||
if (world instanceof RegistryKey) {
|
||||
try {
|
||||
world = serverInstance.getWorld((RegistryKey<World>) world);
|
||||
|
@ -43,6 +43,8 @@
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
|
||||
}
|
||||
|
||||
if (world instanceof RegistryKey) {
|
||||
try {
|
||||
world = serverInstance.getWorld((RegistryKey<World>) world);
|
||||
|
@ -43,6 +43,8 @@
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
|
||||
}
|
||||
|
||||
if (world instanceof RegistryKey) {
|
||||
try {
|
||||
world = serverInstance.getWorld((RegistryKey<World>) world);
|
||||
|
@ -43,6 +43,8 @@
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
Identifier identifier = Identifier.tryParse((String) world);
|
||||
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
|
||||
}
|
||||
|
||||
if (world instanceof RegistryKey) {
|
||||
try {
|
||||
world = serverInstance.getWorld((RegistryKey<World>) world);
|
||||
|
@ -162,6 +162,13 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
|
||||
DimensionType dimensionType = null;
|
||||
if (resourceLocation != null) dimensionType = DimensionType.byName(resourceLocation);
|
||||
if (dimensionType != null) world = serverInstance.getWorld(dimensionType);
|
||||
}
|
||||
|
||||
if (world instanceof ResourceLocation) {
|
||||
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
|
||||
if (dimensionType != null) world = dimensionType;
|
||||
|
@ -162,6 +162,13 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
|
||||
DimensionType dimensionType = null;
|
||||
if (resourceLocation != null) dimensionType = DimensionType.byName(resourceLocation);
|
||||
if (dimensionType != null) world = serverInstance.getWorld(dimensionType);
|
||||
}
|
||||
|
||||
if (world instanceof ResourceLocation) {
|
||||
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
|
||||
if (dimensionType != null) world = dimensionType;
|
||||
|
@ -39,6 +39,8 @@
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent.ServerTickEvent;
|
||||
@ -163,6 +165,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
|
||||
if (resourceLocation != null) world = serverInstance.getWorld(RegistryKey.func_240903_a_(Registry.field_239699_ae_, resourceLocation));
|
||||
}
|
||||
|
||||
if (world instanceof RegistryKey) {
|
||||
try {
|
||||
world = serverInstance.getWorld((RegistryKey<World>) world);
|
||||
|
@ -35,7 +35,9 @@
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
|
||||
}
|
||||
|
||||
if (world instanceof ResourceKey) {
|
||||
try {
|
||||
world = serverInstance.getLevel((ResourceKey<Level>) world);
|
||||
|
@ -35,7 +35,9 @@
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
|
||||
}
|
||||
|
||||
if (world instanceof ResourceKey) {
|
||||
try {
|
||||
world = serverInstance.getLevel((ResourceKey<Level>) world);
|
||||
|
@ -35,7 +35,9 @@
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
|
||||
}
|
||||
|
||||
if (world instanceof ResourceKey) {
|
||||
try {
|
||||
world = serverInstance.getLevel((ResourceKey<Level>) world);
|
||||
|
@ -35,7 +35,9 @@
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
|
||||
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
|
||||
}
|
||||
|
||||
if (world instanceof ResourceKey) {
|
||||
try {
|
||||
world = serverInstance.getLevel((ResourceKey<Level>) world);
|
||||
|
@ -34,6 +34,7 @@
|
||||
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.Key;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -200,6 +201,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (serverWorld != null) world = serverWorld;
|
||||
}
|
||||
|
||||
if (world instanceof String) {
|
||||
var serverWorld = Bukkit.getWorld(new Key((String) world).getValue());
|
||||
if (serverWorld != null) world = serverWorld;
|
||||
}
|
||||
|
||||
if (world instanceof UUID) {
|
||||
var serverWorld = Bukkit.getWorld((UUID) world);
|
||||
if (serverWorld != null) world = serverWorld;
|
||||
|
@ -232,6 +232,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceKey resourceKey = ResourceKey.resolve((String) world);
|
||||
if (resourceKey != null) world = resourceKey;
|
||||
}
|
||||
|
||||
if (world instanceof ResourceKey) {
|
||||
var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null);
|
||||
if (serverWorld != null) world = serverWorld;
|
||||
|
@ -232,6 +232,11 @@ public Optional<ServerWorld> getWorld(Object world) {
|
||||
if (world instanceof Path)
|
||||
return getWorld((Path) world);
|
||||
|
||||
if (world instanceof String) {
|
||||
ResourceKey resourceKey = ResourceKey.resolve((String) world);
|
||||
if (resourceKey != null) world = resourceKey;
|
||||
}
|
||||
|
||||
if (world instanceof ResourceKey) {
|
||||
var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null);
|
||||
if (serverWorld != null) world = serverWorld;
|
||||
|
Loading…
Reference in New Issue
Block a user