SPIGOT-5805: NPE when getting an Attribute from a Player
By: md_5 <git@md-5.net>
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user