diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index de168983ea..1358c99c9f 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -33,6 +33,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.MojangsonParser; import net.minecraft.server.NBTBase; import net.minecraft.server.NBTTagCompound; +import net.minecraft.server.NBTTagString; import net.minecraft.server.SavedFile; import net.minecraft.server.SharedConstants; import org.bukkit.Bukkit; @@ -169,6 +170,7 @@ public final class CraftMagicNumbers implements UnsafeValues { @Override public Material getMaterial(String material, int version) { + Preconditions.checkArgument(material != null, "material == null"); Preconditions.checkArgument(version <= this.getDataVersion(), "Newer version! Server downgrades are not supported!"); // Fastpath up to date materials @@ -176,13 +178,14 @@ public final class CraftMagicNumbers implements UnsafeValues { return Material.getMaterial(material); } - NBTTagCompound stack = new NBTTagCompound(); - stack.setString("id", "minecraft:" + material.toLowerCase(Locale.ROOT)); + Dynamic name = new Dynamic<>(DynamicOpsNBT.a, NBTTagString.a("minecraft:" + material.toLowerCase(Locale.ROOT))); + Dynamic converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_NAME, name, version, this.getDataVersion()); - Dynamic converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_STACK, new Dynamic<>(DynamicOpsNBT.a, stack), version, this.getDataVersion()); - String newId = converted.get("id").asString(""); + if (name.equals(converted)) { + converted = DataConverterRegistry.a().update(DataConverterTypes.BLOCK_NAME, name, version, this.getDataVersion()); + } - return Material.matchMaterial(newId); + return Material.matchMaterial(converted.asString("")); } /** diff --git a/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java b/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java index fc5e16917f..e39b87ae6d 100644 --- a/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java +++ b/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; import org.bukkit.Material; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.material.MaterialData; import org.bukkit.support.AbstractTestingBase; import org.junit.Assert; @@ -116,4 +117,10 @@ public class LegacyTest extends AbstractTestingBase { Assert.assertFalse("Must iterate only modern materials", material.isLegacy()); } } + + @Test + public void testManual() { + Assert.assertEquals(Material.YELLOW_DYE, CraftMagicNumbers.INSTANCE.getMaterial("dandelion_yellow", 1631)); + Assert.assertEquals(Material.OAK_WALL_SIGN, CraftMagicNumbers.INSTANCE.getMaterial("wall_sign", 1631)); + } }