ItemStacks and ItemMeta being Accessed from Separate Classes

Discussion in 'Plugin Development' started by MineStein, Jul 30, 2014.

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

    MineStein

    Title pretty much says everything. I am trying to access ItemStacks that have custom display names and lore from separate classes. The problem is whenever I try and give these ItemStacks to a player or put them inside an opened inventory, they don't have meta or lore. Any help about this?
     
  2. Offline

    MCForger

  3. Offline

    MineStein

    MCForger
    PHP:
    static ItemStack exampleItem = new ItemStack(Material.DIAMOND); {
            
    ItemMeta exampleItemMeta exampleItem.getItemMeta();
            
    exampleItemMeta.setDisplayName("Test");
            
    exampleItem.setItemMeta(exampleItemMeta);
        }
    PHP:
    @EventHandler
        
    public void onJoin(PlayerJoinEvent event) {
            
    player event.getPlayer();
            
    PlayerInventory playerInventory player.getInventory();
     
            
    event.setJoinMessage("§e§o" player.getName() + " §3has joined the server.");
     
            
    player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT1F1F);
     
            
    player.setHealth(20.0);
            
    player.setFoodLevel(20);
            
    player.setSaturation(8F);
            
    player.setExp(0F);
            
    player.setLevel(0);
            
    player.setGameMode(GameMode.SURVIVAL);
     
            
    playerInventory.clear();
            
    playerInventory.setArmorContents(null);
     
            
    playerInventory.setItem(4Menu.exampleItem);
        }
     
  4. Offline

    MCForger

    MineStein
    Why not just put the code for the ItemStack initialization on your onEnable and see what happens. Also you say there is no lore, thats because you never use the method itemMeta.setLore(...)
     
  5. Offline

    MineStein

    MCForger I am aware of not having the inside of that specific item. I wanted everything organized by having it spread out. I also keep my join listener in a separate class so I need to have the ItemMeta and lore available to that class. I don't want to recreate the private fields if there is a different way I could do it.
     
  6. Offline

    MCForger

    MineStein
    You keep the variable public static I am just saying you initialize in the onEnable. Also if the lore is not showing its possible the class you set it in is not loaded so the code to set the lore never executes.
     
  7. Offline

    MineStein

  8. Offline

    ZodiacTheories

    MineStein

    Try to use static as little as possible, why not just pass it through a constructor and then get the item from there?
     
Thread Status:
Not open for further replies.

Share This Page