Skip to content

Commit

Permalink
Add more fillWith methods, and add option to avoid overwriting existi…
Browse files Browse the repository at this point in the history
…ng ItemStacks
  • Loading branch information
Burchard36 committed Dec 15, 2021
1 parent 879577c commit 540a912
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/com/burchard36/inventory/ClickableItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public ClickableItem onClick(final GuiClickableItem clickableItemAction) {
return this;
}

public

public ItemStack build() {
return this.wrapper.getItemStack();
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/burchard36/inventory/PluginInventory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.burchard36.inventory;

import com.burchard36.Logger;
import com.burchard36.inventory.actions.ClickableItemAction;
import com.burchard36.inventory.actions.InventoryClickAction;
import com.burchard36.inventory.actions.InventoryCloseAction;
Expand Down Expand Up @@ -150,15 +151,28 @@ public PluginInventory addClickableItems(final List<ClickableItem> items) {
/**
* Fills an inventory with a specific ClickableItem
* @param item ClickableItem to click
* @param overwrite if true, it will overwrite an existing item there if it exists
* @return instance of this class
*/
public PluginInventory fillWith(final ClickableItem item) {
public PluginInventory fillWith(final ClickableItem item, final boolean overwrite) {
for (int x = 0; x <= (this.inventory.getSize() - 1); x++) {
if (!overwrite) if (this.inventory.getItem(x) != null) continue;
this.addClickableItemAtSlot(x, item);
}
return this;
}

public PluginInventory fillWith(final List<ClickableItem> items, final boolean overwrite) {
for (int x = 0; x <= (this.inventory.getSize() - 1); x++) {
if (!overwrite) if (this.inventory.getItem(x) != null) continue;
try {
this.addClickableItemAtSlot(x, items.get(x));
} catch (final IndexOutOfBoundsException ex) {
Logger.warn("IndexOutOfBounds exception encountered! This is an API level error please contact a developer");
}
}
}

/**
* Opens a inventory to a Player
* @param player Player to open inventory to
Expand Down

0 comments on commit 540a912

Please sign in to comment.