Solved Item Manager function not working

Discussion in 'Plugin Development' started by voltywolty, Jan 2, 2024.

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

    voltywolty

    So I have an ItemManager that has a function called giveItem that gets called all over the plugin. It started to work, then suddenly didn't want to work. I have no idea how it happened, but maybe someone here can help me out.

    Here is my onJoin event where the player gets the item:
    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
    
            itemManager.giveItem(player, "dwarf_magma_cream", plugin.configManager.dwarfConfig);
        }
    Then here is my giveItem function:
    Code:
    public void giveItem(Player player, String itemName, FileConfiguration config) {
            plugin.getLogger().info("Calling giveItem function.");
    
            if (config.contains("custom-items." + itemName)) {
                ConfigurationSection itemConfig = config.getConfigurationSection("custom-items." + itemName);
    
                Material type = Material.matchMaterial(itemConfig.getString("type", "").toUpperCase());
                if (type == null) {
                    plugin.getLogger().warning("Invalid material type for item: " + itemName);
                    return;
                }
    
                String name = ChatColor.translateAlternateColorCodes('&', itemConfig.getString("name", ""));
                int amount = itemConfig.getInt("amount", 1);
                List<String> lore = itemConfig.getStringList("lore");
    
                ItemStack customItem = new ItemStack(type, amount);
                ItemMeta meta = customItem.getItemMeta();
    
                if (meta != null) {
                    meta.setDisplayName(name);
                    meta.setLore(lore);
    
                    customItem.setItemMeta(meta);
                    player.getInventory().addItem(customItem);
                }
            }
        }
    The function is being called, but there is no item. No idea what caused it to stop working, but I believe it should work. My config is below:
    Code:
    custom-items:
      dwarf_magma_cream:
        type: magma_cream
        name: "&bOpen Dwarf Class Menu"
        lore:
          - "&eL-Click: Opens a menu to get one or more"
          - "&erandom dwarf class."
    
      builder_disc:
        type: music_disc_13
        name: "&bBuilder Class"
        lore:
          - "&eL-Click: Become a builder dwarf."
          - "&5&oBuild a keep to protect all dwarves"
          - "&5&ofrom the monsters. Don't forget to"
          - "&5&oreinforce the walls!"
    It's really stumped me on why it isn't working, not too sure what I caused for it to change, but suddenly it did. It's pretty annoying.
     
Thread Status:
Not open for further replies.

Share This Page