Allow empty paths in namespaced keys (#12687)

This commit is contained in:
Lulu13022002
2025-06-21 07:56:45 +02:00
committed by GitHub
parent d61a51e81e
commit 29fc853271
4 changed files with 28 additions and 81 deletions

View File

@@ -39,7 +39,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
}
public static org.bukkit.loot.LootTable minecraftToBukkit(ResourceKey<LootTable> minecraft) {
return (minecraft == null || minecraft.location().getPath().isEmpty()) ? null : Bukkit.getLootTable(CraftLootTable.minecraftToBukkitKey(minecraft)); // Paper - fix some NamespacedKey parsing
return (minecraft == null) ? null : Bukkit.getLootTable(CraftLootTable.minecraftToBukkitKey(minecraft));
}
public static NamespacedKey minecraftToBukkitKey(ResourceKey<LootTable> minecraft) {

View File

@@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.util;
import net.minecraft.resources.ResourceLocation;
import org.bukkit.NamespacedKey;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
public final class CraftNamespacedKey {
@@ -11,14 +10,6 @@ public final class CraftNamespacedKey {
public CraftNamespacedKey() {
}
public static @Nullable NamespacedKey fromStringOrNull(@Nullable String string) {
if (string == null || string.isEmpty()) {
return null;
}
ResourceLocation minecraft = ResourceLocation.tryParse(string);
return (minecraft == null || minecraft.getPath().isEmpty()) ? null : CraftNamespacedKey.fromMinecraft(minecraft); // Paper - Bukkit's parser does not match Vanilla for empty paths
}
public static NamespacedKey fromString(String string) {
return CraftNamespacedKey.fromMinecraft(ResourceLocation.parse(string));
}