Advertisement
broken-arrow

Untitled

Oct 22nd, 2021
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. import lombok.Getter;
  2. import org.broken.cheststorage.ChestStorage;
  3. import org.broken.cheststorage.api.ContainerRegistryAPI;
  4. import org.broken.cheststorage.api.containerholders.InventoryholderStorageUnit;
  5. import org.broken.cheststorage.util.ItemUtily;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.inventory.Inventory;
  9. import org.bukkit.inventory.ItemStack;
  10. import org.mineacademy.fo.Common;
  11.  
  12. import java.util.Map;
  13.  
  14. public class AddItemsToStorageUnit {
  15.     @Getter
  16.     private static final AddItemsToStorageUnit instance = new AddItemsToStorageUnit();
  17.     private final ChestStorage plugin = ChestStorage.getInstance();
  18.  
  19.     public void getItemsFromStorageUnit(Location location, ContainerRegistryAPI registry) {
  20.  
  21.         //LagCatcher.start("STORAGEUNIT getItemsFromStorageUnit");
  22.  
  23.         InventoryholderStorageUnit container = (InventoryholderStorageUnit) plugin.getClassinstans().createObjektInventoryHolder(location, null);
  24.  
  25.         if (container.getPage(location, 0) == null) {
  26.             container.setInventoryHopper();
  27.         } else {
  28.             Inventory inventory = container.getPage(location, 0);
  29.             ItemStack items = inventory.getItem(2);
  30.  
  31.             //System.out.println("items " + items);
  32.             if (items == null) return;
  33.             Map<Integer, ItemStack> leftOvers = container.addItems(items);
  34.             if (leftOvers.isEmpty()) {
  35.                 System.out.println("leftovers isEmpty " + leftOvers);
  36.                 Common.runLaterAsync(0, () -> container.updateInventoryTitle(registry.getAmontOfItems(location), null));
  37.                 registry.saveItemsStorage(location, new ItemStack[]{ItemUtily.createItemStackAsOne(items)});
  38.             } else {
  39.                 System.out.println("leftovers " + leftOvers);
  40.                 location.getWorld().dropItemNaturally(location, leftOvers.get(0));
  41.             }
  42.  
  43.             inventory.setItem(2, new ItemStack(Material.AIR));
  44.             //}
  45.         }
  46.         //LagCatcher.end("STORAGEUNIT getItemsFromStorageUnit");
  47.     }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement