Skip to content

Commit

Permalink
Added new methods to fill a row line vertically with given item
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed Jan 27, 2021
1 parent a9fbfe3 commit a028b14
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### 1.0.8 Release (10.01.2021)
### 1.0.8 Release (10.01.2021 - 27.01.2020)
* Added new methods to fill a row line vertically with given item.
* Added `Fillable` interface that includes some filling methods.
* Added `StaticPane#fillBorder` method to fill GUI's border.
* Added `Gui#setOnDrag` as a tag to XML usage.
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/me/despical/inventoryframework/pane/Fillable.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ public interface Fillable {
*/
void fillHorizontallyWith(@NotNull ItemStack itemStack, int line);

/**
* Fills specified row line vertically with given {@code itemStack}
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param line Line to fill with {@code itemStack}
* @param action The action called whenever an interaction with the item happens
* @since 1.0.8
*/
void fillVerticallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action);

/**
* Fills specified row line vertically with given {@code itemStack}
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param line Line to fill with {@code itemStack}
* @since 1.0.8
*/
void fillVerticallyWith(@NotNull ItemStack itemStack, int line);

/**
* Fills inventory borders with given {@code itemStack}
*
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/me/despical/inventoryframework/pane/StaticPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int p
}

clickedItem.getAction().accept(event);

return true;
}

Expand All @@ -177,6 +176,7 @@ public void setRotation(int rotation) {
if (length != height) {
throw new UnsupportedOperationException("Length and height are different!");
}

if (rotation % 90 != 0) {
throw new IllegalArgumentException("Rotation isn't divisible by 90!");
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public void fillWith(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryC
}

if (!found) {
this.addItem(new GuiItem(itemStack, action), x, y);
addItem(new GuiItem(itemStack, action), x, y);
}
}
}
Expand All @@ -223,12 +223,11 @@ public void fillWith(@NotNull ItemStack itemStack) {
}

public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action) {
Set<Map.Entry<Integer, Integer>> locations = this.items.keySet();
boolean found = false;

for (int y = 0; y < this.getHeight(); y++) {
for (int x = 0; x < this.getLength(); x++) {
for (Map.Entry<Integer, Integer> location : locations) {
for (Map.Entry<Integer, Integer> location : items.keySet()) {
if (location.getKey() == x && location.getValue() == y) {
found = true;
break;
Expand All @@ -239,7 +238,7 @@ public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line, @Nullab

if (!found) {
for (int x = 0; x < this.getLength(); x++) {
this.addItem(new GuiItem(itemStack, action), x, line);
addItem(new GuiItem(itemStack, action), x, line);
}
}
}
Expand All @@ -248,6 +247,33 @@ public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line) {
this.fillHorizontallyWith(itemStack, line, null);
}

@Override
public void fillVerticallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action) {
boolean found = false;

for (int y = 0; y < this.getHeight(); y++) {
for (int x = 0; x < this.getLength(); x++) {
for (Map.Entry<Integer, Integer> location : items.keySet()) {
if (location.getKey() == x && location.getValue() == y) {
found = true;
break;
}
}
}
}

if (!found) {
for (int y = 0; y < this.getHeight(); y++) {
addItem(new GuiItem(itemStack, action), line, y);
}
}
}

@Override
public void fillVerticallyWith(@NotNull ItemStack itemStack, int line) {
this.fillVerticallyWith(itemStack, line, null);
}

@Override
public void fillBorder(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryClickEvent> action) {
// Top
Expand Down

0 comments on commit a028b14

Please sign in to comment.