Items dissaperaring after taking them out of a chest

Discussion in 'Plugin Development' started by XxXLuisXxX, Jul 20, 2012.

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

    XxXLuisXxX

    Hey,

    I've got a strange problem with Chests :\
    I use this code to safe the Location and the Items containing in the chest in two ArrayLists (SavedLocations and SavedItemStacks):
    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent event) {
    2. //some If's here
    3. ItemStack[] i = ((Chest) event.getClickedBlock().getState()).getInventory().getContents();
    4. Location l = event.getClickedBlock().getState().getLocation();
    5. if (!(plugin.SavedLocations.contains(l))) {
    6. plugin.SavedLocations.add(l);
    7. plugin.SavedItemStacks.add(i);
    8. }
    9. }
    10. }

    And then I use this code to set the Inventory of the Chest which was opened to the Inventory which was safed by using this code:
    Code:java
    1. for (int count = 0; count < plugin.SavedLocations.size(); count++) {
    2. Location l = plugin.SavedLocations.get(count);
    3. World world = l.getWorld();
    4. BlockState b = world.getBlockAt(l).getState();
    5. if (b instanceof Chest) {
    6. Chest chest = (Chest) b;
    7. ItemStack[] stacks = plugin.SavedItemStacks.get(count);
    8. chest.getInventory().setContents(stacks);
    9. }
    10. }

    This works really fine, no errors in the console, the items are in the chest and I can take them, but if i want to do anything with them (like attacking a player or destroying a block), they dissapear from my inventory. The items which was in the chest, before restoring it, worked fine, but after restoring the chest, this happends to all of the items of the chest and I really don't know why.

    Has anyone an idea how I can solve this problem?

    Greets from Germany
    Luis
     
Thread Status:
Not open for further replies.

Share This Page