Skip to content

Commit

Permalink
New Fillable interface and StaticPane#fillBorder method
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed Jan 18, 2021
1 parent 06e4a86 commit a9fbfe3
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### 1.0.8 Release (10.01.2021)
* 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.
* Added coloring to gui titles.
* Changed some exception messages.
Expand Down
46 changes: 23 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,29 @@
</repository>
</distributionManagement>

<profiles>
<profile>
<id>deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- <profiles>-->
<!-- <profile>-->
<!-- <id>deploy</id>-->
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!-- <version>1.6</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>sign-artifacts</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<!-- </profile>-->
<!-- </profiles>-->

<build>
<plugins>
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/me/despical/inventoryframework/pane/Fillable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package me.despical.inventoryframework.pane;

import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;

/**
* An interface for panes that can be fillable
*
* @author Despical
* @since 1.0.8
* <p>
* Created at 18.01.2021
*/
public interface Fillable {

/**
* Fills specified row line horizontally 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.5
*/
void fillHorizontallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action);

/**
* Fills specified row line horizontally 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.5
*/
void fillHorizontallyWith(@NotNull ItemStack itemStack, int line);

/**
* Fills inventory borders with given {@code itemStack}
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param action The action called whenever an interaction with the item happens
* @since 1.0.8
*/
void fillBorder(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryClickEvent> action);

/**
* Fills inventory borders with given {@code itemStack}
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @since 1.0.8
*/
void fillBorder(@NotNull ItemStack itemStack);
}
43 changes: 26 additions & 17 deletions src/main/java/me/despical/inventoryframework/pane/StaticPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* <p>
* Created at 04.09.2020
*/
public class StaticPane extends Pane implements Flippable, Rotatable {
public class StaticPane extends Pane implements Flippable, Rotatable, Fillable {

/**
* A map of locations inside this pane and their item. The locations are stored in a way where the x coordinate is
Expand Down Expand Up @@ -222,14 +222,6 @@ public void fillWith(@NotNull ItemStack itemStack) {
this.fillWith(itemStack, null);
}

/**
* Fills specified row line horizontally 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.5
*/
public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action) {
Set<Map.Entry<Integer, Integer>> locations = this.items.keySet();
boolean found = false;
Expand All @@ -252,18 +244,35 @@ public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line, @Nullab
}
}

/**
* Fills specified row line horizontally 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.5
*/
public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line) {
this.fillHorizontallyWith(itemStack, line, null);
}

@NotNull
@Override
public void fillBorder(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryClickEvent> action) {
// Top
for (int i = 0; i < 9; i++)
this.addItem(new GuiItem(itemStack, action), i, 0);

// Bottom
for (int i = 0; i < 9; i++)
this.addItem(new GuiItem(itemStack, action), i, y - 1);

// Left
for (int i = 0; i < y * 9; i += 9)
this.addItem(new GuiItem(itemStack, action), 0, i % (y - 1));

// Right
for (int i = 8; i < y * 9; i += 9)
this.addItem(new GuiItem(itemStack, action), 8, i % (y - 1));
}

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

@NotNull
@Override
public Collection<GuiItem> getItems() {
return items.values();
Expand Down

0 comments on commit a9fbfe3

Please sign in to comment.