diff --git a/CHANGELOG.md b/CHANGELOG.md index f6d3e76..deb1b12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/pom.xml b/pom.xml index 1132ce1..be6d759 100644 --- a/pom.xml +++ b/pom.xml @@ -94,29 +94,29 @@ - - - deploy - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/me/despical/inventoryframework/pane/Fillable.java b/src/main/java/me/despical/inventoryframework/pane/Fillable.java new file mode 100644 index 0000000..7a699c8 --- /dev/null +++ b/src/main/java/me/despical/inventoryframework/pane/Fillable.java @@ -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 + *

+ * 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 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 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); +} \ No newline at end of file diff --git a/src/main/java/me/despical/inventoryframework/pane/StaticPane.java b/src/main/java/me/despical/inventoryframework/pane/StaticPane.java index dd8a2bd..cd6325d 100644 --- a/src/main/java/me/despical/inventoryframework/pane/StaticPane.java +++ b/src/main/java/me/despical/inventoryframework/pane/StaticPane.java @@ -26,7 +26,7 @@ *

* 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 @@ -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 action) { Set> locations = this.items.keySet(); boolean found = false; @@ -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 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 getItems() { return items.values();