diff --git a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java index 67052387bc..bf3b236b20 100644 --- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java +++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java @@ -1,9 +1,9 @@ package org.bukkit.craftbukkit.attribute; import com.google.common.base.Preconditions; +import net.minecraft.server.AttributeBase; import net.minecraft.server.AttributeMapBase; import net.minecraft.server.IRegistry; -import org.bukkit.NamespacedKey; import org.bukkit.Registry; import org.bukkit.attribute.Attributable; import org.bukkit.attribute.Attribute; @@ -21,12 +21,16 @@ public class CraftAttributeMap implements Attributable { @Override public AttributeInstance getAttribute(Attribute attribute) { Preconditions.checkArgument(attribute != null, "attribute"); - net.minecraft.server.AttributeModifiable nms = handle.a(IRegistry.ATTRIBUTE.get(CraftNamespacedKey.toMinecraft(attribute.getKey()))); + net.minecraft.server.AttributeModifiable nms = handle.a(toMinecraft(attribute)); return (nms == null) ? null : new CraftAttributeInstance(nms, attribute); } + public static AttributeBase toMinecraft(Attribute attribute) { + return IRegistry.ATTRIBUTE.get(CraftNamespacedKey.toMinecraft(attribute.getKey())); + } + public static Attribute fromMinecraft(String nms) { - return Registry.ATTRIBUTE.get(NamespacedKey.minecraft(nms)); + return Registry.ATTRIBUTE.get(CraftNamespacedKey.fromString(nms)); } } diff --git a/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java b/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java new file mode 100644 index 0000000000..586d044a06 --- /dev/null +++ b/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java @@ -0,0 +1,30 @@ +package org.bukkit.craftbukkit.attribute; + +import net.minecraft.server.AttributeBase; +import net.minecraft.server.IRegistry; +import net.minecraft.server.MinecraftKey; +import org.bukkit.attribute.Attribute; +import org.bukkit.support.AbstractTestingBase; +import org.junit.Assert; +import org.junit.Test; + +public class AttributeTest extends AbstractTestingBase { + + @Test + public void testToBukkit() { + for (MinecraftKey nms : IRegistry.ATTRIBUTE.keySet()) { + Attribute bukkit = CraftAttributeMap.fromMinecraft(nms.toString()); + + Assert.assertNotNull(nms.toString(), bukkit); + } + } + + @Test + public void testToNMS() { + for (Attribute attribute : Attribute.values()) { + AttributeBase nms = CraftAttributeMap.toMinecraft(attribute); + + Assert.assertNotNull(attribute.name(), nms); + } + } +}