broken-arrow

Untitled

May 31st, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1.     /**
  2.      * @param itemStacks count number of itemstacks and return
  3.      *                   a number of stacks some you put in.
  4.      */
  5.  
  6.  
  7.     public int countItemStacks(ItemStack[] itemStacks) {
  8.         if (itemStacks == null)
  9.             return 0;
  10.         return itemStacks.length;
  11.     }
  12.  
  13.     /**
  14.      * @param location Set items in the chest on this cords,
  15.      *                 if you have more an one page, it will
  16.      *                 set items on this too (if slots not has items
  17.      *                 it will return air (slots will be empty)).
  18.      */
  19.     public void setContents(Location location) {
  20.         ItemStack[] itemStacks = ChestRegistry.getInstance().getcontents(location);
  21.  
  22.         if (itemStacks == null)
  23.             itemStacks = new ItemStack[0];
  24.         //System.out.println("itemstack orginal" + Arrays.toString(itemStacks1));
  25.         int currentInventory = 0;
  26.         int conterItems = 0;
  27.         //System.out.println("Itemstacks before" + Arrays.toString(itemStacks1));
  28.         try {
  29.             do {
  30.                 for (int i = 0; i < countItemStacks(itemStacks); i++) {
  31.                     Inventory inventory = getPage(currentInventory, location);
  32.                     if (i < GuiSize) {
  33.                         inventory.setItem(i, itemStacks[conterItems]);
  34.                         conterItems++;
  35.                         //System.out.println("itemstack " + itemStacks[i] + "value i = " + conterItems);
  36.                     }
  37.  
  38.                 }
  39.                 currentInventory++;
  40.             } while (currentInventory < getPageIndex);
  41.         } catch (ArrayIndexOutOfBoundsException ex) {
  42.             Common.log("&4Warning!!&c you has change gui size of the chest from " + (conterItems - GuiSize) + " to " + GuiSize
  43.                     + " if you made gui size smaller you can lose items");
  44.         }
  45.  
  46.     }
  47.  
Add Comment
Please, Sign In to add comment