Solved Teamchest

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

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

    TheGamblingMan

    How can i make a Teamchest? I tryed to store the ItemStacks in a HashMap and every time a Player opens the chest it opens that inventory but when 2 Players open the inventory at the same time they can both take out the same item so it's like a duplication chest.
     
  2. Offline

    teej107

    Are you creating an new inventory each time a player opens it? Show some code.
     
  3. Offline

    TheMcScavenger

    Like teej107 said, you're most likely creating a new inventory based on the hash map you provided. You should create one inventory per team, and open that existing inventory. That way, if one member opens it, it'll also take the items out when someone else takes an item out.
     
  4. Offline

    Monkey_Swag

    Why don't you use a normal minecraft chest and store the players in an arraylist, if the player isn't in the blue team he can't open red team's chest, etc.
     
  5. Offline

    TheGamblingMan

    So i create a inventory
    Code:java
    1. Inventory invor = Bukkit.createInventory(null, 27, "Teamchest");

    than i get the contents of the hashmap if something is in the hashmap
    Code:java
    1. if (!(main.teamchest.isEmpty())
    2. && main.teamchest.containsKey("orange")) {
    3. invor.setContents(Rush.teamchest.get("orange"));
    4. p.openInventory(invor);
    5.  

    and when someone closes the teamchest i save the contents in the hasmap? or do i save the contents in the hashmap when the player takes something out?
     
  6. Offline

    TeeePeee

    Code:java
    1. private final Inventory orangeInventory = Bukkit.createInventory(null, 27, "Orange Team");
    2.  
    3. public void openOrangeInventory(Player viewer) {
    4. viewer.openInventory(orangeInventory);
    5. }


    Don't bother with your HashMap nonsense, just have one inventory and multiple viewers.
     
  7. Offline

    TheGamblingMan

    Ah thanks :)
     
Thread Status:
Not open for further replies.

Share This Page