mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-12 09:51:12 +01:00
SPIGOT-5805: NPE when getting an Attribute from a Player
This commit is contained in:
parent
b136f8430d
commit
38de0b81e2
2 changed files with 37 additions and 3 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue