Reputation: 1
So I was trying to code a plugin that adds extra armor and stuff that vanilla doesn't have. (emerald armor emerald sword etc) Intellij says that the method "setDisplayName" will cause a NullPointerException, and I think it does because whenever I try to run the plugin, I get this error:
[12:39:07] [Server thread/INFO]: [ExtrasX] Enabling ExtrasX v1.0
[12:39:07] [Server thread/ERROR]: Error occurred while enabling ExtrasX v1.0 (Is it up to
date?)
java.lang.NullPointerException: Cannot invoke "[Ljava.lang.String;.clone()" because
"this.rows" is null
at org.bukkit.inventory.ShapedRecipe.getShape(ShapedRecipe.java:186) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at org.bukkit.craftbukkit.v1_17_R1.inventory.CraftShapedRecipe.fromBukkitRecipe(CraftShapedRecipe.java:33) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at org.bukkit.craftbukkit.v1_17_R1.CraftServer.addRecipe(CraftServer.java:1228) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at com.wasdnoob.extrasx.items.ItemManager.createEmeraldHelmet(ItemManager.java:60) ~[?:?]
at com.wasdnoob.extrasx.items.ItemManager.init(ItemManager.java:26) ~[?:?]
at com.wasdnoob.extrasx.ExtrasX.onEnable(ExtrasX.java:10) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:511) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:425) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at net.minecraft.server.MinecraftServer.loadWorld(MinecraftServer.java:619) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:266) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1010) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:305) ~[spigot-1.17.1.jar:3227-Spigot-3c1fc60-a0a37f4]
at java.lang.Thread.run(Thread.java:831) [?:?]
Here is my item manager class:
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import java.util.UUID;
public class ItemManager {
public static ItemStack emeraldhelmet;
public static ItemStack emeraldchestplate;
public static ItemStack emeraldleggings;
public static ItemStack emeraldboots;
public static void init() {
createEmeraldHelmet();
createEmeraldChestplate();
createEmeraldLeggings();
createEmeraldBoots();
}
public static void createEmeraldHelmet() {
ItemStack item = new ItemStack(Material.LEATHER_HELMET);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§2Emerald Helmet");
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(Color.GREEN);
AttributeModifier armor = new AttributeModifier(UUID.randomUUID(), "generic.armor", 3, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HEAD);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR, armor);
AttributeModifier armortoughness = new AttributeModifier(UUID.randomUUID(), "generic.armortoughness", 2, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HEAD);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, armortoughness);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
item.setItemMeta(meta);
emeraldhelmet = item;
ShapedRecipe sr = new ShapedRecipe(NamespacedKey.minecraft("emeraldhelmet"), item);
sr.shape("EEE",
"B B",
" ");
sr.setIngredient('E', Material.EMERALD);
sr.setIngredient('B', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(sr);
ShapedRecipe s = new ShapedRecipe(NamespacedKey.minecraft("emeraldhelmet"), item);
sr.shape(" ",
"EEE",
"B B");
sr.setIngredient('E', Material.EMERALD);
sr.setIngredient('B', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(s);
}
public static void createEmeraldChestplate() {
ItemStack item = new ItemStack(Material.LEATHER_CHESTPLATE);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§2Emerald Chestplate");
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(Color.GREEN);
AttributeModifier armor = new AttributeModifier(UUID.randomUUID(), "generic.armor", 8, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.CHEST);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR, armor);
AttributeModifier armortoughness = new AttributeModifier(UUID.randomUUID(), "generic.armortoughness", 3, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.CHEST);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, armortoughness);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
item.setItemMeta(meta);
emeraldchestplate = item;
ShapedRecipe sr = new ShapedRecipe(NamespacedKey.minecraft("emeraldchestplate"), item);
sr.shape("B B",
"EBE",
"EEE");
sr.setIngredient('E', Material.EMERALD);
sr.setIngredient('B', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(sr);
}
public static void createEmeraldLeggings() {
ItemStack item = new ItemStack(Material.LEATHER_LEGGINGS);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§2Emerald Leggings");
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(Color.GREEN);
AttributeModifier armor = new AttributeModifier(UUID.randomUUID(), "generic.armor", 6, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.LEGS);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR, armor);
AttributeModifier armortoughness = new AttributeModifier(UUID.randomUUID(), "generic.armortoughness", 3, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.LEGS);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, armortoughness);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
item.setItemMeta(meta);
emeraldleggings = item;
ShapedRecipe sr = new ShapedRecipe(NamespacedKey.minecraft("emeraldleggings"), item);
sr.shape("BBB",
"E E",
"E E");
sr.setIngredient('E', Material.EMERALD);
sr.setIngredient('B', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(sr);
}
public static void createEmeraldBoots() {
ItemStack item = new ItemStack(Material.LEATHER_BOOTS);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§2Emerald Boots");
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(Color.GREEN);
AttributeModifier armor = new AttributeModifier(UUID.randomUUID(), "generic.armor", 3, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.FEET);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR, armor);
AttributeModifier armortoughness = new AttributeModifier(UUID.randomUUID(), "generic.armortoughness", 2, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.FEET);
meta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, armortoughness);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
item.setItemMeta(meta);
emeraldboots = item;
ShapedRecipe sr = new ShapedRecipe(NamespacedKey.minecraft("emeraldboots"), item);
sr.shape("E E",
"B B",
" ");
sr.setIngredient('E', Material.EMERALD);
sr.setIngredient('B', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(sr);
ShapedRecipe s = new ShapedRecipe(NamespacedKey.minecraft("emeraldboots"), item);
sr.shape(" ",
"E E",
"B B");
sr.setIngredient('E', Material.EMERALD);
sr.setIngredient('B', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(s);
}
}
help pls
Upvotes: 0
Views: 777
Reputation: 645
You have two ShapedRecipe. One you named sr
and one s
. But you added the shape and the ingredients only to sr
and not to s
. So s
has no ingredients and no shape! Change from row 55 to 59 sr
to s
like below:
ShapedRecipe s = new ShapedRecipe(NamespacedKey.minecraft("emeraldhelmet"), item);
s.shape(" ",
"EEE",
"B B");
s.setIngredient('E', Material.EMERALD);
s.setIngredient('B', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(s);
PS: Your boots need the same change. xD
Upvotes: 1