java.lang.NullPointerException

Discussion in 'Plugin Development' started by ReflectionCraft, Jul 28, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    ReflectionCraft

    I'm trying to check if an item has specific lore and I'm having trouble doing so.
    The error is as follows
    Error (open)

    [21:09:16 ERROR]: Could not pass event PrepareAnvilEvent to Dust v1.0
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPrepareAnvilEvent(CraftEventFactory.java:1015) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.ContainerAnvil.e(ContainerAnvil.java:156) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.ContainerAnvil.a(ContainerAnvil.java:109) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.ContainerAnvil$1.update(ContainerAnvil.java:20) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.Slot.f(SourceFile:84) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.Container.a(Container.java:546) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.ContainerAnvil.shiftClick(ContainerAnvil.java:333) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.Container.a(Container.java:251) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1899) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:33) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:10) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_211]
    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.lang.NullPointerException
    at me.alton.Dust.Events.EventsClass.onPrepareAnvil(EventsClass.java:45) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
    ... 23 more


    Line 45 is this
    Code:
    if (firstItem.getItemMeta().getLore().contains("Tier: Common") && secondItem.getType().equals(Material.GLOWSTONE_DUST) && secondItem.getItemMeta().getLore().contains(common))

    This error happens when I try to add the correct item into the second slot


    EventsClass.java (open)

    Code:
    package me.alton.Dust.Events;
    
    
    
    import java.util.ArrayList;
    import java.util.Map;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.PrepareAnvilEvent;
    import org.bukkit.inventory.AnvilInventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class EventsClass implements Listener{
        String errorPrefix = ChatColor.RED + "" + ChatColor.BOLD + ">> ";
        String prefix = ChatColor.GREEN + "" + ChatColor.BOLD + ">> ";
        String test = ChatColor.YELLOW + "" + ChatColor.BOLD + "TEST";
      
        //String tier = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: ";
        String common = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.WHITE + "" + ChatColor.BOLD + "Common";      
        String magical = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.AQUA + "" + ChatColor.BOLD + "Magical";     
        String uncommon = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.GREEN + "" + ChatColor.BOLD + "Uncommon";
        String rare = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.GOLD + "" + ChatColor.BOLD + "Rare";
        String epic = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Epic";
      
        @EventHandler
        public void onPrepareAnvil(PrepareAnvilEvent event)
        {
            AnvilInventory anvil = event.getInventory();
            ItemStack firstItem = event.getInventory().getItem(0);
            ItemStack secondItem = event.getInventory().getItem(1);
            if (secondItem == null)
            {
                return;
            }
            if (firstItem != null && !secondItem.getType().equals(Material.GLOWSTONE_DUST)) //if second item isn't dust
            {
                return;
            }
            if (firstItem.getItemMeta().getLore().contains("Tier: Common") && secondItem.getType().equals(Material.GLOWSTONE_DUST) && secondItem.getItemMeta().getLore().contains(common))
            {
                    event.getView().getPlayer().sendMessage(errorPrefix + "This is already common tier");
                    event.getView().getPlayer().getOpenInventory().close();
            }
          
            if (!firstItem.getItemMeta().getLore().contains(common) && secondItem.getType().equals(Material.GLOWSTONE_DUST) && secondItem.getItemMeta().getLore().contains(common))
            {
          
                    Player p = (Player) event.getView().getPlayer();
                  
                    Material firstitemMat = firstItem.getType();
                    ItemStack result = new ItemStack(firstitemMat);
                    ItemMeta firstMeta = firstItem.getItemMeta();
                    ItemMeta resultMeta = firstMeta;
                  
                    Map<Enchantment, Integer> firstItemEnch = (Map<Enchantment, Integer>) firstItem.getEnchantments();
                    result.addUnsafeEnchantments(firstItemEnch);
                  
                    ArrayList<String> dustLore = (ArrayList<String>) secondItem.getItemMeta().getLore(); //lore of dust (TIER)
                    ArrayList<String> resultLore = new ArrayList<String>();
                    resultLore.addAll(firstItem.getItemMeta().getLore());
                    resultLore.addAll(dustLore);
                  
                    resultMeta.setLore(resultLore);
                    result.setItemMeta(resultMeta);
                  
                    anvil.clear();
                    p.getOpenInventory().close();
                    p.getInventory().addItem(result);
                    p.sendMessage(prefix + "You have made a " + ChatColor.WHITE + "COMMON " + ChatColor.GREEN + "" + ChatColor.BOLD + "item");
            }
         
              
              
         }
    
      
    }
    

    Main.java (open)

    Code:
    package me.alton.Dust;
    
    import org.bukkit.ChatColor;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.alton.Dust.Events.EventsClass;
    
    public class Main extends JavaPlugin{
    
        String version = "v1.0";
        private Commands commands = new Commands(); //Imports Commands class
      
        public void onEnable()
        {
            getCommand(commands.cmd1).setExecutor(commands); //Registers Command based on string its tied to
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "\n\n[Dust " + version + "] Enabled\n\n");
            getServer().getPluginManager().registerEvents(new EventsClass(), this);
            loadConfig();
        }
        public void onDisable()
        {
            getServer().getConsoleSender().sendMessage(ChatColor.RED + "\n\n[Dust " + version + "] Disabled\n\n");
        }
      
        public void loadConfig()
        {      
                getConfig().options().copyDefaults(true);
                saveConfig();
        }
    }
    

    Items.java (open)

    Code:
    package me.alton.Dust;
    
    import java.util.ArrayList;
    
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class Items {
        public static ItemStack dust = new ItemStack(Material.GLOWSTONE_DUST);
        public static ItemStack dust1 = new ItemStack(Material.GLOWSTONE_DUST);
        public static ItemStack dust2 = new ItemStack(Material.GLOWSTONE_DUST);
        public static ItemStack dust3 = new ItemStack(Material.GLOWSTONE_DUST);
        public static ItemStack dust4 = new ItemStack(Material.GLOWSTONE_DUST);
    
      
        //
        //DEFAULT TIER
        //
        public static void getDefault(Player player) //Creates the dust item
        {      
            //ItemStack dust = new ItemStack(Material.GLOWSTONE_DUST);
            ItemMeta dustMeta = dust.getItemMeta();
            dustMeta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Magic Dust");
            ArrayList<String> dustLore = new ArrayList<String>();
            dustLore.add(ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.WHITE + "" + ChatColor.BOLD + "Common");
          
            dustMeta.setLore(dustLore);
            dust.setItemMeta(dustMeta);  
          
            player.getInventory().addItem(dust);
        }
        //
        //DEFAULT TIER
        //
      
        //
        //TIER 1
        //
        public static void getT1(Player player) //Creates the dust item
        {      
            //ItemStack dust1 = new ItemStack(Material.GLOWSTONE_DUST);
            ItemMeta dust1Meta = dust1.getItemMeta();
            dust1Meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Magic Dust");
            dust1Meta.addEnchant(Enchantment.DURABILITY, 1, true);
            ArrayList<String> dust1Lore = new ArrayList<String>();
            dust1Lore.add(ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.AQUA + "" + ChatColor.BOLD + "Magical");
          
            dust1Meta.setLore(dust1Lore);
            dust1.setItemMeta(dust1Meta);  
          
            player.getInventory().addItem(dust1);
        }
        //
        //TIER 1
        //
      
        //
        //TIER 2
        //
        public static void getT2(Player player) //Creates the dust item
        {      
            //ItemStack dust2 = new ItemStack(Material.GLOWSTONE_DUST);
            ItemMeta dust2Meta = dust2.getItemMeta();
            dust2Meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Magic Dust");
            dust2Meta.addEnchant(Enchantment.DURABILITY, 2, true);
            ArrayList<String> dust2Lore = new ArrayList<String>();
            dust2Lore.add(ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.GREEN + "" + ChatColor.BOLD + "Uncommon");;
          
            dust2Meta.setLore(dust2Lore);
            dust2.setItemMeta(dust2Meta);  
          
            player.getInventory().addItem(dust2);
        }
        //
        //TIER 2
        //
      
        //
        //TIER 3
        //
        public static void getT3(Player player) //Creates the dust item
        {      
            //ItemStack dust3 = new ItemStack(Material.GLOWSTONE_DUST);
            ItemMeta dust3Meta = dust3.getItemMeta();
            dust3Meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Magic Dust");
            dust3Meta.addEnchant(Enchantment.DURABILITY, 3, true);
            ArrayList<String> dust3Lore = new ArrayList<String>();
            dust3Lore.add(ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.GOLD + "" + ChatColor.BOLD + "Rare");
          
            dust3Meta.setLore(dust3Lore);
            dust3.setItemMeta(dust3Meta);  
          
            player.getInventory().addItem(dust3);
        }
        //
        //TIER 3
        //
      
        //
        //TIER 4
        //
        public static void getT4(Player player) //Creates the dust item
        {      
            //ItemStack dust4 = new ItemStack(Material.GLOWSTONE_DUST);
            ItemMeta dust4Meta = dust4.getItemMeta();
            dust4Meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Magic Dust");
            dust4Meta.addEnchant(Enchantment.DURABILITY, 4, true);
            ArrayList<String> dust4Lore = new ArrayList<String>();
            dust4Lore.add(ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Epic");
          
            dust4Meta.setLore(dust4Lore);
            dust4.setItemMeta(dust4Meta);  
          
            player.getInventory().addItem(dust4);
        }
        //
        //TIER 4
        //
    
    
      
    
    }
    

    commands.java (open)

    Code:
    package me.alton.Dust;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    
    import net.minecraft.server.v1_12_R1.CommandExecute;
    
    public class Commands extends CommandExecute implements Listener, CommandExecutor{
      
        String cmd1 = "dust";
        String errorPrefix = ChatColor.RED + "" + ChatColor.BOLD + ">> ";
        String prefix = ChatColor.GREEN + "" + ChatColor.BOLD + ">> ";
    
    
      
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) {
            Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase(cmd1))
            {
                if (args.length == 1)
                {
                    if (args[0].equals("1"))
                    {
                        Items.getT1(player);
                        player.sendMessage(prefix + "Recieved Magical "  + ChatColor.YELLOW  + "Magic Dust");
                    }
                    else if (args[0].equals("2"))
                    {
                        Items.getT2(player);
                        player.sendMessage(prefix + "Recieved Uncommon "  + ChatColor.YELLOW  + "Magic Dust");
                    }
                    else if (args[0].equals("3"))
                    {
                        Items.getT3(player);
                        player.sendMessage(prefix + "Recieved Rare "  + ChatColor.YELLOW  + "Magic Dust");
                    }
                    else if (args[0].equals("4"))
                    {
                        Items.getT4(player);
                        player.sendMessage(prefix + "Recieved Epic "  + ChatColor.YELLOW  + "Magic Dust");
                    }
                    else if (!args[0].equals("1") &&
                            !args[0].equals("2") &&
                            !args[0].equals("3") &&
                            !args[0].equals("4") &&
                            !args[0].equals(null))
                    {
                        player.sendMessage(errorPrefix + "That is not a Tier, only 1-4");
                    }
                }
                else
                {
                    Items.getDefault(player);
                    player.sendMessage(prefix + "Recieved " + ChatColor.YELLOW + "Magic Dust");
                }
                  
                    return true;
            }
          
            return true;
        }
    
    }
    
     
  2. Offline

    Machine Maker

    @ReflectionCraft can you post the error on https://pastebin.com?


    Also, out of curiosity, why does your Commands class extend CommandExecute? Unless I'm missing something, you shouldn't have that.

    EDIT: If I had to guess without the error log, it would be that you are using getItemMeta() in the PrepareAnvilEvent without checking to see if the item actually has any MetaData. You should use the hasItemMeta() method before getItemMeta()

    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/inventory/ItemStack.html#hasItemMeta--


    FURTHER EDIT AFTER YOU POSTED THE ERROR:
    @ReflectionCraft So yeah, I'm almost positive that the issue is that getItemMeta() returns null if there is no metadata. So use hasItemMeta() before that. Also, use hasLore() before using getLore() on the ItemMeta.
    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/inventory/meta/ItemMeta.html#hasLore--
     
    Last edited: Jul 28, 2019
  3. Offline

    KarimAKL

    @ReflectionCraft First check if the item is null, then check if it has an ItemMeta (this step might not be needed, i don't think it returns null), then check if it has a lore.
    Also, you should compare enums with '==' instead of '.equals()', it does the same but, '.equals()' is not null safe.
     
  4. Offline

    Machine Maker

  5. Offline

    KarimAKL

    @X1machinemaker1X Calling a method on something that is null still throws a NullPointerException, so i would still recommend '==' instead.
     
  6. Offline

    Machine Maker

    @KarimAKL oh I see what you meant. I mean I think there’s still some personal preference in there. I mean I use == for enums, but there shouldn’t be any situations when .equals doesn’t work for enums because it was null.

    But kinda off of the OP at this point:p
     
    KarimAKL likes this.
  7. Offline

    ReflectionCraft

    Ive changed up my code a little bit
    new code (open)

    Code:
    package me.alton.Dust.Events;
    
    
    
    import java.util.ArrayList;
    import java.util.Map;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.PrepareAnvilEvent;
    import org.bukkit.inventory.AnvilInventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class EventsClass implements Listener{
        String errorPrefix = ChatColor.RED + "" + ChatColor.BOLD + ">> ";
        String prefix = ChatColor.GREEN + "" + ChatColor.BOLD + ">> ";
        String test = ChatColor.YELLOW + "" + ChatColor.BOLD + "TEST";
       
        String common = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.WHITE + "" + ChatColor.BOLD + "Common";       
        String magical = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.AQUA + "" + ChatColor.BOLD + "Magical";      
        String uncommon = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.GREEN + "" + ChatColor.BOLD + "Uncommon";
        String rare = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.GOLD + "" + ChatColor.BOLD + "Rare";
        String epic = ChatColor.GRAY + "" + ChatColor.BOLD + "Tier: " + ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Epic";
       
        @EventHandler
        public void onPrepareAnvil(PrepareAnvilEvent event)
        {
            Player p = (Player) event.getView().getPlayer();
            AnvilInventory anvil = event.getInventory();
            ItemStack firstItem = event.getInventory().getItem(0);
            ItemStack secondItem = event.getInventory().getItem(1);
            if (secondItem == null) //if therse nothing in the one of the slots but on in other vise versa
            {
                return;
            }
            if (firstItem != null && secondItem.getType() != Material.GLOWSTONE_DUST) //if combining to uncombinable items
            {
                return;
            }
            if (firstItem.hasItemMeta())
            {
                if (firstItem.getItemMeta().hasLore()) //first slot has lore
                {
                    if (firstItem.getType() == Material.GLOWSTONE_DUST //first slot is dust
                            && firstItem.getItemMeta().getLore().contains("Tier: ")
                            && secondItem.getType() == Material.GLOWSTONE_DUST //second slot is dust
                            && secondItem.getItemMeta().getLore().contains("Tier: "))
                    {
                        //Player trying to add dust to dust
                        p.getOpenInventory().close();
                        p.sendMessage(errorPrefix + "You cannot combine dust!");
                    }
                    if (firstItem.getItemMeta().getLore().contains("Tier: ")  //First slot is tiered and not dust
                            && firstItem.getType() != Material.GLOWSTONE_DUST
                            && secondItem.getType() == Material.GLOWSTONE_DUST //second slot is dust
                            && secondItem.getItemMeta().getLore().contains("Tier: "))
                    {
                        //Player trying to add dust to Item with tier
                        p.getOpenInventory().close();
                        p.sendMessage(errorPrefix + "This item is already tiered!");
                    }
                }
                else //first slot dosnt have lore
                {
                    if (firstItem.getType() != Material.GLOWSTONE_DUST //First item isnt dust
                            && secondItem.getType() == Material.GLOWSTONE_DUST //Second item is dust
                            && secondItem.getItemMeta().getLore().contains("Tier: "))
                    {
                        //Player adding common dust to non Tiered Item
                        p.getOpenInventory().close();
                        p.sendMessage(prefix + "Good!");
                    }
                }
            }
            else
            {
                return;
            }
           
          
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
            /*if (!firstItem.getItemMeta().getLore().contains(common) && secondItem.getType().equals(Material.GLOWSTONE_DUST) && secondItem.getItemMeta().getLore().contains(common))
            {
           
                    Player p = (Player) event.getView().getPlayer();
                   
                    Material firstitemMat = firstItem.getType();
                    ItemStack result = new ItemStack(firstitemMat);
                    ItemMeta firstMeta = firstItem.getItemMeta();
                    ItemMeta resultMeta = firstMeta;
                   
                    Map<Enchantment, Integer> firstItemEnch = (Map<Enchantment, Integer>) firstItem.getEnchantments();
                    result.addUnsafeEnchantments(firstItemEnch);
                   
                    ArrayList<String> dustLore = (ArrayList<String>) secondItem.getItemMeta().getLore(); //lore of dust (TIER)
                    ArrayList<String> resultLore = new ArrayList<String>();
                    resultLore.addAll(firstItem.getItemMeta().getLore());
                    resultLore.addAll(dustLore);
                   
                    resultMeta.setLore(resultLore);
                    result.setItemMeta(resultMeta);
                   
                    anvil.clear();
                    p.getOpenInventory().close();
                    p.getInventory().addItem(result);
                    p.sendMessage(prefix + "You have made a " + ChatColor.WHITE + "COMMON " + ChatColor.GREEN + "" + ChatColor.BOLD + "item");
            }*/
               
               
         }
    
       
    }
    

    I'm still getting an error but now its with the line where I check if the item has meta "if (firstItem.hasItemMeta())"
     
  8. Offline

    Machine Maker

    @ReflectionCraft I'm guessing that firstItem is null, which will give you an NPE if you use hasItemMeta() on it.

    the if statement above that line probably should have firstItem == null not firstItem != null
     
Thread Status:
Not open for further replies.

Share This Page