#I think something is wrong with my custom item code

1 messages · Page 1 of 1 (latest)

lucid plaza
#

I get an error when I use my command to give a custom item.
I use a customitem class i made to make it easiers to make new items
Test item class

public class Test extends CustomItem{
    public static ItemStack WaterItem = itemStackName;
    public static void waterItemMeta() {
        List<String> lore = new ArrayList();
        lore.add("Hello!");
        itemMeta("iron_ingot", "Water Item", lore, true, true, Enchantment.FIRE_ASPECT, 2);

    }
}

Custom Item class

    public static ItemStack itemStackName;
    public static void itemMeta(String materialName, String displayName, List<String> itemLore, boolean isUnbreakable,
                                boolean enchanted, Enchantment ench, int lvl) {

        Material material = Material.matchMaterial(materialName);
        ItemStack customItem = new ItemStack(material);
        ItemMeta customMeta = customItem.getItemMeta();

        customMeta.setDisplayName(displayName);
        customMeta.setLore(itemLore);
        customMeta.setUnbreakable(isUnbreakable);
        customMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE);

        if (enchanted = true) {
            customMeta.addEnchant(ench, lvl, true);
        }

        customItem.setItemMeta(customMeta);
        itemStackName = customItem;
    }
#

It said ERROR: null before the unhandled exception thing

vagrant adder
#

...

#

Send the error

lucid plaza
vagrant adder
#

?paste

#

Ow

#

Anyway use a paste site

lucid plaza
vagrant adder
#

The error isn't even from what you sent

lucid plaza
#

Ok?

#

Thats the full error that I got from my console so...

vagrant adder
#

Yeah it's not caused by the code you sent

#

You did something wrong in the command class

lucid plaza
#

o ok

#

everything looks fine in my command class, it didnt do this before i used the new customitem class

vagrant adder
#

I'm telling you

lucid plaza
#

Have a look maybe you will find something

public class GiveCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("hitem")) {
            if (sender instanceof Player) {

                Player player = (Player) sender;

                if (args[0].equalsIgnoreCase("fire_blade")) {
                    player.getInventory().addItem(FireSword.FireSword);

                } else if (args[0].equalsIgnoreCase("inferno_charm")) {
                    player.getInventory().addItem(InfernoCharm.InfernoCharm);

                } else if (args[0].equalsIgnoreCase("enhanced_gold")) {
                    player.getInventory().addItem(EnhancedGold.EnhancedGold);

                } else if (args[0].equalsIgnoreCase("wateritem")) {
                    player.getInventory().addItem(Test.WaterItem);
                }

                if (args.length == 0) {
                    player.sendMessage(ChatColor.RED + "Error! You have to specify an item.");
                }
            }

            else if (!(sender instanceof Player)){
                System.out.println("Error! You cannot use this command.");
            }
        }
        return true;
    }
}