Solved Accessing Inventories From Other Classes [PLEASE REPLY]

Discussion in 'Plugin Development' started by John Cena, Sep 17, 2015.

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

    John Cena

    I know there are other threads on Bukkit Forums about this, but I never was able to get this work and I have been searching for HOURS on end. I just want to be able to make it so I could open, setItem, and addItem in a inventory from a different class. I know you use constructors, but I cant get it to work so if someone could please show me an example of how to only create an inventory in a new class and use it in another.
     
  2. Offline

    SuperSniper

    @John Cena The easiest way to do this is through using a "static" modifier.
    That is not the best performance-wise way to do it.

    Then just use:
    Code:
    <classnameWithInventory>.<inventoryname>.method
    
     
    John Cena likes this.
  3. Offline

    John Cena

    So would my inventory class be:
    Code:
    <imports>
    
    public class <name>{
        public static Inventory  <invName> = bukkit.createInventory(<arguments>);
    }
    
    and would my other class be:
    Code:
    <imports>
    
    public class <name>{
        <classwithinv>.<invName>.setItem(<arguments>)
    }
    
     
  4. Offline

    SuperSniper

    @John Cena Yes, but replace <invName> <name> and <arguments> with the correct things lol
     
    John Cena likes this.
  5. Offline

    John Cena

    Ok I tested it and It worked perfectly I just want to say thanks and that you helped me SO much :)
     
  6. Offline

    SuperSniper

  7. Offline

    mythbusterma

    teej107 likes this.
Thread Status:
Not open for further replies.

Share This Page