Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/auto-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 17
- uses: actions/checkout@v2
name: Checkout code
- name: Checkout code
uses: actions/checkout@v2

- name: Run paper-nms init
if: steps.cache-paperclip-jars.outputs.cache-hit != 'true'
run: |
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/github-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path

name: Automatically build on GitHub Packages

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
name: 'Build Package'
steps:
- name: Cache Paper(clip) jars
id: cache-paperclip-jars
uses: actions/cache@v2
with:
path: |
.paper-nms
build
paperclip
~/.m2/repository/io/papermc/paper
~/.m2/repository/ca/bkaw/paper-nms
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-paperclip
- name: Download Paperclip jars
if: steps.cache-paperclip-jars.outputs.cache-hit != 'true'
run: |
mkdir -p paperclip
wget https://papermc.io/api/v2/projects/paper/versions/1.14.4/builds/243/downloads/paper-1.14.4-243.jar -O paperclip/paper-1.14.4.jar
wget https://papermc.io/api/v2/projects/paper/versions/1.15.2/builds/391/downloads/paper-1.15.2-391.jar -O paperclip/paper-1.15.2.jar
wget https://papermc.io/api/v2/projects/paper/versions/1.16.1/builds/138/downloads/paper-1.16.1-138.jar -O paperclip/paper-1.16.1.jar
wget https://papermc.io/api/v2/projects/paper/versions/1.16.3/builds/253/downloads/paper-1.16.3-253.jar -O paperclip/paper-1.16.3.jar
wget https://papermc.io/api/v2/projects/paper/versions/1.16.4/builds/416/downloads/paper-1.16.4-416.jar -O paperclip/paper-1.16.4.jar
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Generate 1.14 - 1.16 Paper jars
if: steps.cache-paperclip-jars.outputs.cache-hit != 'true'
working-directory: paperclip
run: |
java -jar paper-1.14.4.jar
java -jar paper-1.15.2.jar
java -jar paper-1.16.1.jar
java -jar paper-1.16.3.jar
java -jar paper-1.16.4.jar
- name: Install 1.14 - 1.16 Paper jars
if: steps.cache-paperclip-jars.outputs.cache-hit != 'true'
working-directory: paperclip
run: |
mvn install:install-file -Dfile=cache/patched_1.14.4.jar -DgroupId="io.papermc" -DartifactId="paper" -Dversion="1.14.4-R0.1-SNAPSHOT" -Dpackaging="jar"
mvn install:install-file -Dfile=cache/patched_1.15.2.jar -DgroupId="io.papermc" -DartifactId="paper" -Dversion="1.15.2-R0.1-SNAPSHOT" -Dpackaging="jar"
mvn install:install-file -Dfile=cache/patched_1.16.1.jar -DgroupId="io.papermc" -DartifactId="paper" -Dversion="1.16.1-R0.1-SNAPSHOT" -Dpackaging="jar"
mvn install:install-file -Dfile=cache/patched_1.16.3.jar -DgroupId="io.papermc" -DartifactId="paper" -Dversion="1.16.3-R0.1-SNAPSHOT" -Dpackaging="jar"
mvn install:install-file -Dfile=cache/patched_1.16.4.jar -DgroupId="io.papermc" -DartifactId="paper" -Dversion="1.16.4-R0.1-SNAPSHOT" -Dpackaging="jar"
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Checkout code
uses: actions/checkout@v2
- name: Run paper-nms init
if: steps.cache-paperclip-jars.outputs.cache-hit != 'true'
run: |
mvn paper-nms:init -pl nms/1_17_0
mvn paper-nms:init -pl nms/1_17_1
mvn paper-nms:init -pl nms/1_18_0
mvn paper-nms:init -pl nms/1_18_1
mvn paper-nms:init -pl nms/1_18_2
mvn paper-nms:init -pl nms/1_19_0
mvn paper-nms:init -pl nms/1_19_1
mvn paper-nms:init -pl nms/1_19_2
mvn paper-nms:init -pl nms/1_19_3
mvn paper-nms:init -pl nms/1_19_4
mvn paper-nms:init -pl nms/1_20
- name: Install package
run: |
mvn install
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ jobs:
mvn paper-nms:init -pl nms/1_19_4
mvn paper-nms:init -pl nms/1_20
- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn -B install --file pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.stefvanschie.inventoryframework.gui;

import com.github.stefvanschie.inventoryframework.util.UUIDTagType;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -153,7 +154,8 @@ public GuiItem copy() {
ItemMeta meta = guiItem.item.getItemMeta();

if (meta == null) {
throw new IllegalArgumentException("item must be able to have ItemMeta (it mustn't be AIR)");
throw new IllegalArgumentException("item must be able to have ItemMeta (it mustn't be AIR). If you want to " +
"click an AIR item, use a StaticNullablePane instead!");
}

meta.getPersistentDataContainer().set(keyUUID, UUIDTagType.INSTANCE, guiItem.uuid);
Expand All @@ -162,6 +164,23 @@ public GuiItem copy() {
return guiItem;
}

@NotNull
@Contract(pure = true)
public GuiItem unsafeCopy() {
GuiItem guiItem = new GuiItem(item.clone(), action, this.logger, this.keyUUID);

guiItem.visible = visible;
guiItem.uuid = uuid;
guiItem.properties = new ArrayList<>(properties);
ItemMeta meta = guiItem.item.getItemMeta();

if (meta != null) {
meta.getPersistentDataContainer().set(keyUUID, UUIDTagType.INSTANCE, guiItem.uuid);
guiItem.item.setItemMeta(meta);
}
return guiItem;
}

/**
* Calls the handler of the {@link InventoryClickEvent}
* if such a handler was specified in the constructor.
Expand Down Expand Up @@ -251,6 +270,17 @@ public ItemStack getItem() {
return item;
}

/**
* Returns the action
* @return the action fired when this item is clicked
* @since 0.10.12
*/
@Nullable
@Contract(pure = true)
public Consumer<InventoryClickEvent> getAction() {
return action;
}

/**
* Gets the namespaced key used for this item.
*
Expand Down Expand Up @@ -293,4 +323,8 @@ public boolean isVisible() {
public void setVisible(boolean visible) {
this.visible = visible;
}

public static GuiItem air(@NotNull Consumer<InventoryClickEvent> action) {
return new GuiItem(new ItemStack(Material.AIR), action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased;
import com.github.stefvanschie.inventoryframework.pane.Pane;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -111,9 +112,9 @@ public void addPane(@NotNull Pane pane) {
* component's size + the offset specified.
*
* @param inventory the inventory to place the items in
* @param offset the offset from which to start counting the slots
* @since 0.8.0
* @param offset the offset from which to start counting the slots
* @see #display(PlayerInventory, int)
* @since 0.8.0
*/
public void display(@NotNull Inventory inventory, int offset) {
display();
Expand All @@ -131,9 +132,9 @@ public void display(@NotNull Inventory inventory, int offset) {
* the normal ordering of a {@link PlayerInventory}'s slots its documentation.
*
* @param inventory the inventory to place the items in
* @param offset the offset from which to start counting the slots
* @since 0.8.0
* @param offset the offset from which to start counting the slots
* @see #display(Inventory, int)
* @since 0.8.0
*/
public void display(@NotNull PlayerInventory inventory, int offset) {
display();
Expand All @@ -149,9 +150,9 @@ public void display(@NotNull PlayerInventory inventory, int offset) {
* contrast to {@link #display(PlayerInventory, int)} this does not render the panes of this component.
*
* @param inventory the inventory to place the items in
* @param offset the offset from which to start counting the slots
* @since 0.8.0
* @param offset the offset from which to start counting the slots
* @see #placeItems(Inventory, int)
* @since 0.8.0
*/
public void placeItems(@NotNull PlayerInventory inventory, int offset) {
for (int x = 0; x < getLength(); x++) {
Expand All @@ -175,9 +176,9 @@ public void placeItems(@NotNull PlayerInventory inventory, int offset) {
* {@link #display(Inventory, int)} this does not render the panes of this component.
*
* @param inventory the inventory to place the items in
* @param offset the offset from which to start counting the slots
* @since 0.8.0
* @param offset the offset from which to start counting the slots
* @see #placeItems(PlayerInventory, int)
* @since 0.8.0
*/
public void placeItems(@NotNull Inventory inventory, int offset) {
for (int x = 0; x < getLength(); x++) {
Expand All @@ -192,9 +193,9 @@ public void placeItems(@NotNull Inventory inventory, int offset) {
* {@link Pane#click(Gui, InventoryComponent, InventoryClickEvent, int, int, int, int, int)} on each pane until the
* right item has been found.
*
* @param gui the gui this inventory component belongs to
* @param gui the gui this inventory component belongs to
* @param event the event to delegate
* @param slot the slot that was clicked
* @param slot the slot that was clicked
* @since 0.8.0
*/
public void click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int slot) {
Expand All @@ -203,7 +204,7 @@ public void click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int slot
//loop panes in reverse, because the highest priority pane (last in list) is most likely to have the right item
for (int i = panes.size() - 1; i >= 0; i--) {
if (panes.get(i).click(
gui, this, event, slot, 0, 0, getLength(), getHeight()
gui, this, event, slot, 0, 0, getLength(), getHeight()
)) {
break;
}
Expand Down Expand Up @@ -253,7 +254,7 @@ public InventoryComponent copy() {
* not included in this inventory component, and {@link IllegalArgumentException} will be thrown.
*
* @param from the starting index of the range
* @param end the ending index of the range
* @param end the ending index of the range
* @return the new, shrunk inventory component
* @since 0.8.0
*/
Expand All @@ -263,7 +264,7 @@ public InventoryComponent excludeRows(int from, int end) {
if (from < 0 || end >= getHeight()) {
throw new IllegalArgumentException("Specified range includes non-existent rows");
}

int newHeight = getHeight() - (end - from + 1);

InventoryComponent newInventoryComponent = new InventoryComponent(getLength(), newHeight);
Expand Down Expand Up @@ -298,7 +299,7 @@ public InventoryComponent excludeRows(int from, int end) {
* mutate this component.
*
* @param instance the instance to apply field and method references on
* @param element the element to load
* @param element the element to load
* @since 0.8.0
* @deprecated superseded by {@link #load(Object, Element, Plugin)}
*/
Expand All @@ -312,8 +313,8 @@ public void load(@NotNull Object instance, @NotNull Element element) {
* mutate this component.
*
* @param instance the instance to apply field and method references on
* @param element the element to load
* @param plugin the plugin to load the panes with
* @param element the element to load
* @param plugin the plugin to load the panes with
* @since 0.10.12
*/
public void load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) {
Expand Down Expand Up @@ -354,8 +355,8 @@ public boolean hasItem() {
* displayed according to their priority, with the lowest priority rendering first and the highest priority (note:
* highest priority, not {@link Pane.Priority#HIGHEST} priority) rendering last.
*
* @since 0.8.0
* @see #display(Inventory, int)
* @since 0.8.0
*/
public void display() {
clearItems();
Expand All @@ -376,8 +377,8 @@ public void display() {
* @param x the x coordinate
* @param y the y coordinate
* @return true if an item exists at the given coordinates, false otherwise
* @since 0.8.0
* @throws IllegalArgumentException when the coordinates are out of bounds
* @since 0.8.0
*/
@Contract(pure = true)
public boolean hasItem(int x, int y) {
Expand All @@ -391,15 +392,15 @@ public boolean hasItem(int x, int y) {
* @param x the x coordinate
* @param y the y coordinate
* @return the item or null
* @since 0.8.0
* @throws IllegalArgumentException when the coordinates are out of bounds
* @since 0.8.0
*/
@Nullable
@Contract(pure = true)
public ItemStack getItem(int x, int y) {
if (!isInBounds(x, y)) {
throw new IllegalArgumentException("Coordinates must be in-bounds: x = " + x + ", y = " + y +
"; should be below " + getLength() + " and " + getHeight());
"; should be below " + getLength() + " and " + getHeight());
}

return this.items[x][y];
Expand All @@ -425,14 +426,14 @@ public List<Pane> getPanes() {
* component, an {@link IllegalArgumentException} will be thrown.
*
* @param guiItem the item to place in this inventory component
* @param x the x coordinate of the item
* @param y the y coordinate of the item
* @param x the x coordinate of the item
* @param y the y coordinate of the item
* @since 0.9.3
*/
public void setItem(@NotNull GuiItem guiItem, int x, int y) {
if (!isInBounds(x, y)) {
throw new IllegalArgumentException("Coordinates must be in-bounds: x = " + x + ", y = " + y +
"; should be below " + getLength() + " and " + getHeight());
"; should be below " + getLength() + " and " + getHeight());
}

GuiItem copy = guiItem.copy();
Expand All @@ -441,14 +442,39 @@ public void setItem(@NotNull GuiItem guiItem, int x, int y) {
this.items[x][y] = copy.getItem();
}

/**
* Unsafe version of #setItem(GuiItem, int, int) method.
* Warning: this method does not abort if the item's material is AIR! Use it only
* if you know what you're doing
*
* @param guiItem
* @param x
* @param y
*/
public void setItemUnsafe(@NotNull GuiItem guiItem, int x, int y) {
if (!isInBounds(x, y)) {
throw new IllegalArgumentException("Coordinates must be in-bounds: x = " + x + ", y = " + y +
"; should be below " + getLength() + " and " + getHeight());
}
GuiItem copy;
if (guiItem.getItem().getType().isAir()) {
copy = guiItem.unsafeCopy();
} else {
copy = guiItem.copy();
copy.applyUUID();
}

this.items[x][y] = copy.getItem();
}

/**
* Adds the specified item in the slot at the specified positions. This will override an already set item if it
* resides in the same position as specified. If the position specified is outside of the boundaries set by this
* component, an {@link IllegalArgumentException} will be thrown.
*
* @param item the item to place in this inventory component
* @param x the x coordinate of the item
* @param y the y coordinate of the item
* @param x the x coordinate of the item
* @param y the y coordinate of the item
* @since 0.8.0
* @deprecated usage of {@link #setItem(GuiItem, int, int)} is preferred so gui item's item meta can be freely
* edited without losing important internal data
Expand All @@ -457,7 +483,7 @@ public void setItem(@NotNull GuiItem guiItem, int x, int y) {
public void setItem(@NotNull ItemStack item, int x, int y) {
if (!isInBounds(x, y)) {
throw new IllegalArgumentException("Coordinates must be in-bounds: x = " + x + ", y = " + y +
"; should be below " + getLength() + " and " + getHeight());
"; should be below " + getLength() + " and " + getHeight());
}

this.items[x][y] = item;
Expand Down Expand Up @@ -546,7 +572,7 @@ private Pane getPane(int index) {
*
* @param lowerBound the lower bound of the range
* @param upperBound the upper bound of the range
* @param value the value to check
* @param value the value to check
* @return true if the value is within the bounds, false otherwise
* @since 0.8.0
*/
Expand Down
Loading