Item Stacks

Discussion in 'Plugin Development' started by Jellydude, Jul 15, 2013.

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

    Jellydude

    How could I store all my items stacks in a seperate class to where I'm giving them.

    ItemStacks.Class (example)
    Code:java
    1. ItemStack dsword = new ItemStack(Material.DIAMOND_SWORD);
    2. ItemStack ihelm = new ItemStack(Material.IRON_HELMET);
    3. ItemStack ichest = new ItemStack(Material.IRON_CHESTPLATE);
    4. ItemStack ilegs = new ItemStack(Material.IRON_LEGGINGS);


    PvPKit.Class (example)

    Code:java
    1. player.getInventory().addItem(dsword);
    2. dsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    3. player.getInventory().setHelmet(ihelm);
    4. player.getInventory().setChestplate(ichest);
    5. player.getInventory().setLeggings(ilegs);
     
  2. Offline

    ZeusAllMighty11

    Make them global public variables.

    Then access via class instance?
     
  3. Offline

    xTrollxDudex

    Jellydude
    In my opinion it's kinda stupid to keep your itemstacks in one class and use it in another. Unless you happen to be using it in more than 2 classes of course
     
  4. Offline

    Jellydude

    xTrollxDudex
    I need to use them in many many classes
     
  5. Offline

    xTrollxDudex

    Jellydude
    You don't really need to tahg me and quote at the same time tahging does the trick.
    And use TheGreenGamerHD 's method
     
  6. Offline

    Jellydude

    xTrollxDudex
    It's because I've just been pressing reply. sorry

    TheGreenGamerHD
    I'm new to java how would I do that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    xTrollxDudex

    Jellydude
    Just tipping :) it's shorter to just tahg me and it doesn't spam up my alerts.
    And
    Code:php
    1. declare the itemstacks public
    2. Statically access te ItemStack class
     
  8. Offline

    Jellydude

    xTrollxDudex
    Alright, I made the item stacks public but I've got no idea how to access them in the Kit.class
     
  9. Offline

    ZeusAllMighty11

    You need a reference to the class. Either statically or via constructor.

    If you don't know what that means, try google
     
  10. Offline

    xTrollxDudex

    Jellydude
    In your items class have this:
    PHP:
    ItemStacks is = new ItemStacks();
    public static 
    void getInstance(){
    return 
    is;
    }
    This assumes that your items class is named ItemStacks. Change all the ItemStacks into your items class name.

    To access, use this:
    PHP:
    ItemStacks.getInstance().dsword
    To get the dsword ItemStack.
     
  11. Offline

    Jellydude

    xTrollxDudex
    I fixed it now anyway using a different method. I put it in a class that all the other classes extend and it worked. I had to ask my friend though for the help.
     
  12. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page