Get world by resource location (#316)

This commit is contained in:
pop4959 2022-08-03 03:15:55 -07:00 committed by GitHub
parent e6548adf2b
commit fa361043c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 105 additions and 0 deletions

View File

@ -149,6 +149,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); return getWorld((Path) world);
if (world instanceof String) {
Identifier identifier = Identifier.tryParse((String) world);
if (identifier != null) world = identifier;
}
if (world instanceof Identifier) { if (world instanceof Identifier) {
DimensionType dimensionType = DimensionType.byId((Identifier) world); DimensionType dimensionType = DimensionType.byId((Identifier) world);
if (dimensionType != null) world = dimensionType; if (dimensionType != null) world = dimensionType;

View File

@ -43,6 +43,8 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; 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.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof RegistryKey) {
try { try {
world = serverInstance.getWorld((RegistryKey<World>) world); world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; 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.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof RegistryKey) {
try { try {
world = serverInstance.getWorld((RegistryKey<World>) world); world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; 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.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof RegistryKey) {
try { try {
world = serverInstance.getWorld((RegistryKey<World>) world); world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; 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.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof RegistryKey) {
try { try {
world = serverInstance.getWorld((RegistryKey<World>) world); world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; 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.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof RegistryKey) {
try { try {
world = serverInstance.getWorld((RegistryKey<World>) world); world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -162,6 +162,13 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof ResourceLocation) {
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world); DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
if (dimensionType != null) world = dimensionType; if (dimensionType != null) world = dimensionType;

View File

@ -162,6 +162,13 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof ResourceLocation) {
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world); DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
if (dimensionType != null) world = dimensionType; if (dimensionType != null) world = dimensionType;

View File

@ -39,6 +39,8 @@
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.RegistryKey; import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent.ServerTickEvent; import net.minecraftforge.event.TickEvent.ServerTickEvent;
@ -163,6 +165,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof RegistryKey) {
try { try {
world = serverInstance.getWorld((RegistryKey<World>) world); world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -35,7 +35,9 @@
import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof ResourceKey) {
try { try {
world = serverInstance.getLevel((ResourceKey<Level>) world); world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -35,7 +35,9 @@
import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof ResourceKey) {
try { try {
world = serverInstance.getLevel((ResourceKey<Level>) world); world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -35,7 +35,9 @@
import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof ResourceKey) {
try { try {
world = serverInstance.getLevel((ResourceKey<Level>) world); world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -35,7 +35,9 @@
import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); 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) { if (world instanceof ResourceKey) {
try { try {
world = serverInstance.getLevel((ResourceKey<Level>) world); world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -34,6 +34,7 @@
import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.util.Key;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
@ -200,6 +201,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (serverWorld != null) world = serverWorld; 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) { if (world instanceof UUID) {
var serverWorld = Bukkit.getWorld((UUID) world); var serverWorld = Bukkit.getWorld((UUID) world);
if (serverWorld != null) world = serverWorld; if (serverWorld != null) world = serverWorld;

View File

@ -232,6 +232,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); return getWorld((Path) world);
if (world instanceof String) {
ResourceKey resourceKey = ResourceKey.resolve((String) world);
if (resourceKey != null) world = resourceKey;
}
if (world instanceof ResourceKey) { if (world instanceof ResourceKey) {
var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null); var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null);
if (serverWorld != null) world = serverWorld; if (serverWorld != null) world = serverWorld;

View File

@ -232,6 +232,11 @@ public Optional<ServerWorld> getWorld(Object world) {
if (world instanceof Path) if (world instanceof Path)
return getWorld((Path) world); return getWorld((Path) world);
if (world instanceof String) {
ResourceKey resourceKey = ResourceKey.resolve((String) world);
if (resourceKey != null) world = resourceKey;
}
if (world instanceof ResourceKey) { if (world instanceof ResourceKey) {
var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null); var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null);
if (serverWorld != null) world = serverWorld; if (serverWorld != null) world = serverWorld;