From f899a4a72a6c7ecd0ffb241a05c020e816dcbb8d Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Sun, 17 Sep 2023 22:32:51 +0200 Subject: [PATCH 01/20] Added StaticNullablePane --- .../pane/StaticNullablePane.java | 95 +++++++++++++++++++ .../inventoryframework/pane/StaticPane.java | 2 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java new file mode 100644 index 000000000..6962c74cd --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java @@ -0,0 +1,95 @@ +package com.github.stefvanschie.inventoryframework.pane; + +import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * A pane for static items and stuff. All items will have to be specified a slot, or will be added in the next position. + *

+ * This pane allows you to specify the positions of the items either in the form of an x and y coordinate pair or as an + * index, in which case the indexing starts from the top left and continues to the right and bottom, with the horizontal + * axis taking priority. There are nuances at play with regard to mixing these two types of positioning systems within + * the same pane. It's recommended to only use one of these systems per pane and to not mix them. + *

+ */ +public class StaticNullablePane extends StaticPane { + + /** + * Creates a new static pane. + * + * @param slot the slot of the pane + * @param length the length of the pane + * @param height the height of the pane + * @param priority the priority of the pane + * @since 0.10.12 + */ + public StaticNullablePane(Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); + } + + public StaticNullablePane(int x, int y, int length, int height, @NotNull Priority priority) { + this(Slot.fromXY(x, y), length, height, priority); + } + + /** + * Creates a new static nullable pane. + * + * @param slot the slot of the pane + * @param length the length of the pane + * @param height the height of the pane + * @since 0.10.12 + */ + public StaticNullablePane(Slot slot, int length, int height) { + this(slot, length, height, Priority.NORMAL); + } + + public StaticNullablePane(int x, int y, int length, int height) { + this(x, y, length, height, Priority.NORMAL); + } + + public StaticNullablePane(int length, int height) { + this(0, 0, length, height); + } + + @Override + public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComponent, + @NotNull InventoryClickEvent event, int slot, int paneOffsetX, int paneOffsetY, int maxLength, + int maxHeight) { + int length = Math.min(this.length, maxLength); + int height = Math.min(this.height, maxHeight); + + Slot paneSlot = getSlot(); + + int xPosition = paneSlot.getX(maxLength); + int yPosition = paneSlot.getY(maxLength); + + int totalLength = inventoryComponent.getLength(); + + int adjustedSlot = slot - (xPosition + paneOffsetX) - totalLength * (yPosition + paneOffsetY); + + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; + + //this isn't our item + if (x < 0 || x >= length || y < 0 || y >= height) { + return false; + } + + callOnClick(event); + + GuiItem clickedItem = this.items.get(Slot.fromIndex(adjustedSlot)); + + if (clickedItem == null) { + return false; + } + + clickedItem.callAction(event); + + return true; + } +} diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java index 1661708a0..bbf122dda 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java @@ -36,7 +36,7 @@ public class StaticPane extends Pane implements Flippable, Rotatable { * the key and the y coordinate is the value. */ @NotNull - private final Map items; + protected final Map items; /** * The clockwise rotation of this pane in degrees From 6e183dc7f9565178021289b301c05023792f5e71 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Sun, 17 Sep 2023 23:21:06 +0200 Subject: [PATCH 02/20] Added #setRenameText --- .../inventoryframework/gui/type/util/Gui.java | 2 ++ nms/1_17_0/pom.xml | 2 +- nms/1_17_1/pom.xml | 2 +- nms/1_18_0/pom.xml | 2 +- nms/1_18_1/pom.xml | 2 +- nms/1_18_2/pom.xml | 2 +- nms/1_19_0/pom.xml | 2 +- nms/1_19_1/pom.xml | 2 +- nms/1_19_2/pom.xml | 2 +- nms/1_19_3/pom.xml | 2 +- nms/1_19_4/pom.xml | 2 +- nms/1_20/pom.xml | 2 +- .../inventoryframework/abstraction/AnvilInventory.java | 9 +++++++++ 13 files changed, 22 insertions(+), 11 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/Gui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/Gui.java index a1d721021..a872485b6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/Gui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/Gui.java @@ -714,6 +714,8 @@ public static Pane loadPane(@NotNull Object instance, @NotNull Node node) { (TriFunction) PatternPane::load); registerPane("staticpane", (TriFunction) StaticPane::load); + registerPane("staticnullablepane", + (TriFunction) StaticNullablePane::load); registerPane("cyclebutton", (TriFunction) CycleButton::load); diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 629c471c9..c63ba67ea 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 99a543afe..fb8f6d60c 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 5518d0086..201812650 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 5b258a71d..b07d75f02 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 9d40f2898..6b62d5908 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 5a10a9f0a..54546b4d6 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index d26681873..8014592eb 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 4a93f0eb3..699c6b207 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 511b4bf79..2d9dbd6de 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 8b823d780..daa3a87c6 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/1_20/pom.xml b/nms/1_20/pom.xml index 4971afa5d..1f5bf47fa 100644 --- a/nms/1_20/pom.xml +++ b/nms/1_20/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.2 process-classes diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/AnvilInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/AnvilInventory.java index 44f5bfb7b..40375d9a5 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/AnvilInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/AnvilInventory.java @@ -180,6 +180,15 @@ public String getRenameText() { return text; } + /** + * Sets the text shown in the rename slot of the anvil + * @param text + * @since 0.10.12 + */ + public void setRenameText(@NotNull String text) { + observableText.set(text); + } + /** * Subscribes to changes of the name input. * From d514204c90f8c703283b99bb756a7278c6dd1ce3 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Sun, 17 Sep 2023 23:24:32 +0200 Subject: [PATCH 03/20] Create maven-publish.yml --- .github/workflows/maven-publish.yml | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 000000000..217fd364e --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,34 @@ +# 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: Maven Package + +on: + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 16 + uses: actions/setup-java@v3 + with: + java-version: '16' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} From 220e066f03cec69a076e69664f4aaaa585982eac Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Mon, 18 Sep 2023 00:10:17 +0200 Subject: [PATCH 04/20] Added unsafe versions of GuiItem#copy and InventoryComponent#setItem --- .../inventoryframework/gui/GuiItem.java | 28 +++++++ .../gui/InventoryComponent.java | 80 ++++++++++++------- .../pane/StaticNullablePane.java | 53 ++++++++++++ 3 files changed, 134 insertions(+), 27 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java index 4b7773bd3..9e565a554 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java @@ -162,6 +162,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. @@ -251,6 +268,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 getAction() { + return action; + } + /** * Gets the namespaced key used for this item. * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java index fa23496f5..90eb1cecd 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java @@ -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; @@ -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(); @@ -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(); @@ -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++) { @@ -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++) { @@ -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) { @@ -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; } @@ -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 */ @@ -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); @@ -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)} */ @@ -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) { @@ -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(); @@ -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) { @@ -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]; @@ -425,14 +426,14 @@ public List 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(); @@ -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 @@ -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; @@ -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 */ diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java index 6962c74cd..b29e9574b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java @@ -4,10 +4,13 @@ import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.util.Slot; +import com.github.stefvanschie.inventoryframework.util.GeometryUtil; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import java.util.Map; + /** * A pane for static items and stuff. All items will have to be specified a slot, or will be added in the next position. *

@@ -92,4 +95,54 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp return true; } + + /** + * {@inheritDoc} + * + * If there are multiple items in the same position when displaying the items, either one of those items may be + * shown. In particular, there is no guarantee that a specific item will be shown. + * + * @param inventoryComponent {@inheritDoc} + * @param paneOffsetX {@inheritDoc} + * @param paneOffsetY {@inheritDoc} + * @param maxLength {@inheritDoc} + * @param maxHeight {@inheritDoc} + */ + @Override + public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, + int maxHeight) { + int length = Math.min(this.length, maxLength); + int height = Math.min(this.height, maxHeight); + + items.entrySet().stream().filter(entry -> entry.getValue().isVisible()).forEach(entry -> { + Slot location = entry.getKey(); + + int x = location.getX(getLength()); + int y = location.getY(getLength()); + + if (isFlippedHorizontally()) + x = length - x - 1; + + if (isFlippedVertically()) + y = height - y - 1; + + Map.Entry coordinates = GeometryUtil.processClockwiseRotation(x, y, length, height, + getRotation()); + + x = coordinates.getKey(); + y = coordinates.getValue(); + + if (x < 0 || x >= length || y < 0 || y >= height) { + return; + } + + GuiItem item = entry.getValue(); + + Slot slot = getSlot(); + int finalRow = slot.getY(maxLength) + y + paneOffsetY; + int finalColumn = slot.getX(maxLength) + x + paneOffsetX; + + inventoryComponent.setItemUnsafe(item, finalColumn, finalRow); + }); + } } From c37623c0a007b4f9575913f4138b958621651556 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Tue, 19 Sep 2023 13:50:22 +0200 Subject: [PATCH 05/20] Added GuiItem.air() Added rectangular button support --- .../inventoryframework/gui/GuiItem.java | 8 ++- .../pane/StaticNullablePane.java | 56 ++++++++++++++++++- .../inventoryframework/pane/util/Slot.java | 1 - 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java index 9e565a554..52dc84b3e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java @@ -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; @@ -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); @@ -321,4 +323,8 @@ public boolean isVisible() { public void setVisible(boolean visible) { this.visible = visible; } + + public static GuiItem air(@NotNull Consumer action) { + return new GuiItem(new ItemStack(Material.AIR), action); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java index b29e9574b..c14dfd7c6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticNullablePane.java @@ -6,7 +6,6 @@ import com.github.stefvanschie.inventoryframework.pane.util.Slot; import com.github.stefvanschie.inventoryframework.util.GeometryUtil; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -85,8 +84,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp callOnClick(event); - GuiItem clickedItem = this.items.get(Slot.fromIndex(adjustedSlot)); - + GuiItem clickedItem = this.items.get(Slot.fromXY(x, y)); if (clickedItem == null) { return false; } @@ -145,4 +143,56 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs inventoryComponent.setItemUnsafe(item, finalColumn, finalRow); }); } + + /** + * Adds a rectangular area of the same GuiItem to the pane. + * @param guiItem the item to add + * @param startingX the starting x coordinate (north-west corner) + * @param startingY the starting y coordinate (north-west corner) + * @param xLength the length of the area + * @param yLength the height of the area + * @since 0.10.12 + */ + public void addItem(@NotNull GuiItem guiItem, int startingX, int startingY, int xLength, int yLength) { + for(int i = startingX; i < startingX + xLength; i++) { + for(int j = startingY; j < startingY + yLength; j++) { + addItem(guiItem, i, j); + } + } + } + + /** + * Adds a rectangular area of the same GuiItem to the pane. + * @param guiItem the item to add + * @param slot the starting slot (north-west corner) + * @param xLength the length of the area + * @param yLength the height of the area + * @since 0.10.12 + */ + public void addItem(@NotNull GuiItem guiItem, Slot slot, int xLength, int yLength) { + addItem(guiItem, slot.getX(getLength()), slot.getY(getLength()), xLength, yLength); + } + + /** + * Adds a SQUARED area of the same GuiItem to the pane. + * @param guiItem the item to add + * @param startingX the starting x coordinate (north-west corner) + * @param startingY the starting y coordinate (north-west corner) + * @param length the length and height of the squared area + * @since 0.10.12 + */ + public void addItem(@NotNull GuiItem guiItem, int startingX, int startingY, int length) { + addItem(guiItem, startingX, startingY, length, length); + } + + /** + * Adds a SQUARED area of the same GuiItem to the pane. + * @param guiItem the item to add + * @param slot the starting slot (north-west corner) + * @param length the length and height of the squared area + * @since 0.10.12 + */ + public void addItem(@NotNull GuiItem guiItem, Slot slot, int length) { + this.addItem(guiItem, slot, length, length); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Slot.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Slot.java index d1306fe42..288a30f03 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Slot.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Slot.java @@ -237,7 +237,6 @@ public boolean equals(@Nullable Object object) { } Indexed indexed = (Indexed) object; - return index == indexed.index; } From e4ec524bac0eed55eec86c575e2f85b7387aaf4f Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Tue, 26 Sep 2023 17:02:33 +0200 Subject: [PATCH 06/20] Minor modifications --- .github/workflows/auto-deploy.yml | 5 +- .github/workflows/github-packages.yml | 80 +++++++++++++++++++ .github/workflows/maven-publish.yml | 34 -------- .../inventoryframework/gui/type/AnvilGui.java | 12 +++ .../StaticNullablePaneTest.java | 36 +++++++++ .../nms/v1_19_4/AnvilInventoryImpl.java | 1 + 6 files changed, 132 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/github-packages.yml delete mode 100644 .github/workflows/maven-publish.yml create mode 100644 IF/src/test/java/com/github/stefvanschie/inventoryframework/StaticNullablePaneTest.java diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index c6cc10730..48dd0b4cc 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -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: | diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml new file mode 100644 index 000000000..06f65e1b4 --- /dev/null +++ b/.github/workflows/github-packages.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml deleted file mode 100644 index 217fd364e..000000000 --- a/.github/workflows/maven-publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -# 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: Maven Package - -on: - release: - types: [created] - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 16 - uses: actions/setup-java@v3 - with: - java-version: '16' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Publish to GitHub Packages Apache Maven - run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/AnvilGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/AnvilGui.java index 7a8e875dc..452898143 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/AnvilGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/AnvilGui.java @@ -257,6 +257,18 @@ public String getRenameText() { return anvilInventory.getRenameText(); } + /** + * Sets the rename text currently specified in the anvil. + * + * @param text the new rename text + * @since 0.10.12 + * @see AnvilInventory#setRenameText(String) + */ + @Contract(pure = true) + public void setRenameText(String text) { + anvilInventory.setRenameText(text); + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { diff --git a/IF/src/test/java/com/github/stefvanschie/inventoryframework/StaticNullablePaneTest.java b/IF/src/test/java/com/github/stefvanschie/inventoryframework/StaticNullablePaneTest.java new file mode 100644 index 000000000..6ca8d508c --- /dev/null +++ b/IF/src/test/java/com/github/stefvanschie/inventoryframework/StaticNullablePaneTest.java @@ -0,0 +1,36 @@ +package com.github.stefvanschie.inventoryframework; + +import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.pane.StaticNullablePane; +import com.github.stefvanschie.inventoryframework.pane.StaticPane; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +public class StaticNullablePaneTest { + + @Test + void testCopy() { + StaticNullablePane original = new StaticNullablePane(5, 1, 1, 1, Pane.Priority.MONITOR); + original.setVisible(false); + original.setRotation(90); + original.flipHorizontally(false); + original.flipVertically(true); + + StaticPane copy = original.copy(); + + assertNotSame(original, copy); + + assertEquals(original.getX(), copy.getX()); + assertEquals(original.getY(), copy.getY()); + assertEquals(original.getLength(), copy.getLength()); + assertEquals(original.getHeight(), copy.getHeight()); + assertEquals(original.getPriority(), copy.getPriority()); + assertEquals(original.isVisible(), copy.isVisible()); + assertEquals(original.getRotation(), copy.getRotation()); + assertEquals(original.isFlippedHorizontally(), copy.isFlippedHorizontally()); + assertEquals(original.isFlippedVertically(), copy.isFlippedVertically()); + assertEquals(original.getUUID(), copy.getUUID()); + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/AnvilInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/AnvilInventoryImpl.java index 877668403..b48fd0e12 100644 --- a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/AnvilInventoryImpl.java +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/AnvilInventoryImpl.java @@ -60,6 +60,7 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title Component message = TextHolderUtil.toComponent(title); ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + //subscribeToNameInputChanges(containerAnvil::setItemName); Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); From b0480e45bd826698d135f198862d7102c243b7b5 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Tue, 26 Sep 2023 17:03:06 +0200 Subject: [PATCH 07/20] Minor modifications --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fbd9b627c..eb5840851 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -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 From 3697952ef99f7229b34c4f215c6ab43c3f5e0f44 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Tue, 4 Mar 2025 15:54:13 +0100 Subject: [PATCH 08/20] fix --- .../inventoryframework/gui/InventoryComponent.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java index 90eb1cecd..4949b0a22 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/InventoryComponent.java @@ -456,13 +456,9 @@ public void setItemUnsafe(@NotNull GuiItem guiItem, int x, int 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(); - } + GuiItem copy = guiItem.copy(); + //if (guiItem.getItem().getType().isAir()) + copy.applyUUID(); this.items[x][y] = copy.getItem(); } From 2cbf21237a8841aee9ed6d9304028ce0aea484f6 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Tue, 4 Mar 2025 15:55:49 +0100 Subject: [PATCH 09/20] fix --- .github/workflows/auto-deploy.yml | 2 +- .github/workflows/github-packages.yml | 2 +- .github/workflows/maven.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 80d388c0a..57d66fd94 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Cache Paper(clip) jars id: cache-paperclip-jars - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | .paper-nms diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml index 06f65e1b4..b42e91d7a 100644 --- a/.github/workflows/github-packages.yml +++ b/.github/workflows/github-packages.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Cache Paper(clip) jars id: cache-paperclip-jars - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | .paper-nms diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 3b54f85f3..0806a6e50 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Cache Paper(clip) jars id: cache-paperclip-jars - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | .paper-nms From 757db9e06ccc20ba6eaefbc3121f7ddeb77d5640 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Tue, 4 Mar 2025 15:57:15 +0100 Subject: [PATCH 10/20] fix --- .github/workflows/github-packages.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml index b42e91d7a..7a3e909bd 100644 --- a/.github/workflows/github-packages.yml +++ b/.github/workflows/github-packages.yml @@ -28,11 +28,11 @@ jobs: 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 + wget https://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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: From 82b1fe2efa989c5540624a3b5d0f2cef60281bbf Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 15:32:40 +0100 Subject: [PATCH 11/20] fix deploy pipeline --- .github/deployment/deploy.sh | 8 +++++--- .gitlab-ci.yml | 0 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.github/deployment/deploy.sh b/.github/deployment/deploy.sh index ccf6f861c..cdc4d4705 100644 --- a/.github/deployment/deploy.sh +++ b/.github/deployment/deploy.sh @@ -17,11 +17,13 @@ if ! mvn clean install -B; then exit 1 fi -if ! mvn deploy -N -pl :IF-parent -P deploy -s ./.github/deployment/settings.xml -B -Dgpg.passphrase="$1" -Ddeploy.username="$2" -Ddeploy.password="$3"; then +if ! mvn deploy -N -pl :IF-parent -P deploy -s ./.github/deployment/settings.xml -B \ + -Dgpg.passphrase="$1" -Ddeploy.username="$2" -Ddeploy.password="$3"; then echo "Unable to deploy IF-parent" exit 1 fi -if ! mvn deploy -pl :IF -P deploy -s ./.github/deployment/settings.xml -B -Dgpg.passphrase="$1" -Ddeploy.username="$2" -Ddeploy.password="$3"; then +if ! mvn deploy -pl :IF -P deploy -s ./.github/deployment/settings.xml -B \ + -Dgpg.passphrase="$1" -Ddeploy.username="$2" -Ddeploy.password="$3"; then echo "Unable to deploy IF" -fi +fi \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..e69de29bb From 34dff980998433aae502a4e608912358060f2549 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 15:40:32 +0100 Subject: [PATCH 12/20] update workflow --- .github/workflows/github-packages.yml | 57 ++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml index 7a3e909bd..32f211932 100644 --- a/.github/workflows/github-packages.yml +++ b/.github/workflows/github-packages.yml @@ -74,7 +74,62 @@ jobs: 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 + mvn paper-nms:init -pl nms/1_20_0 + mvn paper-nms:init -pl nms/1_20_1 + mvn paper-nms:init -pl nms/1_20_2 + mvn paper-nms:init -pl nms/1_20_3-4 + - name: 'Run BuildTools 1.20.5-1.20.6, 1.21' + if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + run: | + mkdir -p build + cd build/ + wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar + + git clone https://hub.spigotmc.org/stash/scm/spigot/bukkit.git Bukkit + cd Bukkit + git checkout 304e83eb384c338546aa96eea51388e0e8407e26 + cd .. + + git clone https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git CraftBukkit + cd CraftBukkit + git checkout 91b1fc3f1cf89e2591367dca1fa7362fe376f289 + cd .. + + git clone https://hub.spigotmc.org/stash/scm/spigot/spigot.git Spigot + cd Spigot + git checkout b698b49caf14f97a717afd67e13fd7ac59f51089 + cd .. + + git clone https://hub.spigotmc.org/stash/scm/spigot/builddata.git BuildData + cd BuildData + git checkout a7f7c2118b877fde4cf0f32f1f730ffcdee8e9ee + cd .. + + java -jar BuildTools.jar --remapped --disable-java-check --dont-update + java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check + + cd Bukkit + git checkout 2ec53f498e32b3af989cb24672fc54dfab087154 + cd .. + + cd CraftBukkit + git checkout 8ee6fd1b8db9896590aa321d0199453de1fc35db + cd .. + + cd Spigot + git checkout fb8fb722a327a2f9f097f2ded700ac5de8157408 + cd .. + + cd BuildData + git checkout ae1e7b1e31cd3a3892bb05a6ccdcecc48c73c455 + cd .. + + java -jar BuildTools.jar --remapped --disable-java-check --dont-update + java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check + java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check + java -jar BuildTools.jar --rev 1.21.4 --remapped --disable-java-check + + cd ../ - name: Install package run: | mvn install \ No newline at end of file From 6f6e29e48109837892e4698b55fd420031232859 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 15:49:56 +0100 Subject: [PATCH 13/20] update workflow --- .github/workflows/github-packages.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml index 32f211932..c3e943662 100644 --- a/.github/workflows/github-packages.yml +++ b/.github/workflows/github-packages.yml @@ -78,6 +78,10 @@ jobs: mvn paper-nms:init -pl nms/1_20_1 mvn paper-nms:init -pl nms/1_20_2 mvn paper-nms:init -pl nms/1_20_3-4 + - name: Set up JDK 21 + uses: actions/setup-java@v1 + with: + java-version: 21 - name: 'Run BuildTools 1.20.5-1.20.6, 1.21' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | From dee75c7bd5a455dd3b359cd5b42dce2322118bc5 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 16:15:47 +0100 Subject: [PATCH 14/20] dump backwards compatibility from 1.14 to 1.16.5 due to older repos outages --- .github/workflows/auto-deploy.yml | 31 -- .github/workflows/github-packages.yml | 31 -- .github/workflows/maven.yml | 31 -- IF/pom.xml | 30 -- .../inventoryframework/pane/StaticPane.java | 2 +- .../util/version/VersionMatcher.java | 32 +- buildtools.sh | 46 +++ nms/1_14/pom.xml | 33 -- .../nms/v1_14/AnvilInventoryImpl.java | 381 ----------------- .../nms/v1_14/BeaconInventoryImpl.java | 181 -------- .../v1_14/CartographyTableInventoryImpl.java | 201 --------- .../v1_14/EnchantingTableInventoryImpl.java | 196 --------- .../nms/v1_14/GrindstoneInventoryImpl.java | 272 ------------ .../nms/v1_14/MerchantInventoryImpl.java | 95 ----- .../nms/v1_14/StonecutterInventoryImpl.java | 201 --------- .../nms/v1_14/util/TextHolderUtil.java | 66 --- nms/1_15/pom.xml | 33 -- .../nms/v1_15/AnvilInventoryImpl.java | 381 ----------------- .../nms/v1_15/BeaconInventoryImpl.java | 181 -------- .../v1_15/CartographyTableInventoryImpl.java | 201 --------- .../v1_15/EnchantingTableInventoryImpl.java | 196 --------- .../nms/v1_15/GrindstoneInventoryImpl.java | 272 ------------ .../nms/v1_15/MerchantInventoryImpl.java | 95 ----- .../nms/v1_15/StonecutterInventoryImpl.java | 201 --------- .../nms/v1_15/util/TextHolderUtil.java | 66 --- nms/1_16_1/pom.xml | 33 -- .../nms/v1_16_1/AnvilInventoryImpl.java | 386 ------------------ .../nms/v1_16_1/BeaconInventoryImpl.java | 181 -------- .../CartographyTableInventoryImpl.java | 201 --------- .../v1_16_1/EnchantingTableInventoryImpl.java | 196 --------- .../nms/v1_16_1/GrindstoneInventoryImpl.java | 268 ------------ .../nms/v1_16_1/MerchantInventoryImpl.java | 95 ----- .../v1_16_1/SmithingTableInventoryImpl.java | 233 ----------- .../nms/v1_16_1/StonecutterInventoryImpl.java | 201 --------- .../nms/v1_16_1/util/TextHolderUtil.java | 66 --- nms/1_16_2-3/pom.xml | 33 -- .../nms/v1_16_2_3/AnvilInventoryImpl.java | 386 ------------------ .../nms/v1_16_2_3/BeaconInventoryImpl.java | 178 -------- .../CartographyTableInventoryImpl.java | 198 --------- .../EnchantingTableInventoryImpl.java | 193 --------- .../v1_16_2_3/GrindstoneInventoryImpl.java | 271 ------------ .../nms/v1_16_2_3/MerchantInventoryImpl.java | 95 ----- .../v1_16_2_3/SmithingTableInventoryImpl.java | 231 ----------- .../v1_16_2_3/StonecutterInventoryImpl.java | 198 --------- .../nms/v1_16_2_3/util/TextHolderUtil.java | 66 --- nms/1_16_4-5/pom.xml | 34 -- .../nms/v1_16_4_5/AnvilInventoryImpl.java | 386 ------------------ .../nms/v1_16_4_5/BeaconInventoryImpl.java | 181 -------- .../CartographyTableInventoryImpl.java | 201 --------- .../EnchantingTableInventoryImpl.java | 196 --------- .../v1_16_4_5/GrindstoneInventoryImpl.java | 268 ------------ .../nms/v1_16_4_5/MerchantInventoryImpl.java | 95 ----- .../v1_16_4_5/SmithingTableInventoryImpl.java | 234 ----------- .../v1_16_4_5/StonecutterInventoryImpl.java | 201 --------- .../nms/v1_16_4_5/util/TextHolderUtil.java | 66 --- pom.xml | 9 +- 56 files changed, 65 insertions(+), 8970 deletions(-) create mode 100644 buildtools.sh delete mode 100644 nms/1_14/pom.xml delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/AnvilInventoryImpl.java delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/BeaconInventoryImpl.java delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/CartographyTableInventoryImpl.java delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/EnchantingTableInventoryImpl.java delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/GrindstoneInventoryImpl.java delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/MerchantInventoryImpl.java delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/StonecutterInventoryImpl.java delete mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/util/TextHolderUtil.java delete mode 100644 nms/1_15/pom.xml delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/BeaconInventoryImpl.java delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/CartographyTableInventoryImpl.java delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/EnchantingTableInventoryImpl.java delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/GrindstoneInventoryImpl.java delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/MerchantInventoryImpl.java delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/StonecutterInventoryImpl.java delete mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/util/TextHolderUtil.java delete mode 100644 nms/1_16_1/pom.xml delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/BeaconInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/CartographyTableInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/EnchantingTableInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/GrindstoneInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/MerchantInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/SmithingTableInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/StonecutterInventoryImpl.java delete mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/util/TextHolderUtil.java delete mode 100644 nms/1_16_2-3/pom.xml delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/BeaconInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/CartographyTableInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/EnchantingTableInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/MerchantInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/SmithingTableInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/StonecutterInventoryImpl.java delete mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/util/TextHolderUtil.java delete mode 100644 nms/1_16_4-5/pom.xml delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/BeaconInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/CartographyTableInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/EnchantingTableInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/MerchantInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/SmithingTableInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/StonecutterInventoryImpl.java delete mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/util/TextHolderUtil.java diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 57d66fd94..fa5f42030 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -22,37 +22,6 @@ jobs: ~/.m2/repository/ca/bkaw/paper-nms ~/.m2/repository/org/spigotmc/spigot 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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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 21 uses: actions/setup-java@v1 with: diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml index c3e943662..0e9ecdcf4 100644 --- a/.github/workflows/github-packages.yml +++ b/.github/workflows/github-packages.yml @@ -24,37 +24,6 @@ jobs: ~/.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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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: diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0806a6e50..61a5d3003 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -28,37 +28,6 @@ jobs: ~/.m2/repository/ca/bkaw/paper-nms ~/.m2/repository/org/spigotmc/spigot 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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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://api.papermc.io/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 21 uses: actions/setup-java@v1 with: diff --git a/IF/pom.xml b/IF/pom.xml index 4700a2ed6..f4e67e135 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -41,36 +41,6 @@ ${project.version} compile - - com.github.stefvanschie.inventoryframework - 1_14 - ${project.version} - compile - - - com.github.stefvanschie.inventoryframework - 1_15 - ${project.version} - compile - - - com.github.stefvanschie.inventoryframework - 1_16_1 - ${project.version} - compile - - - com.github.stefvanschie.inventoryframework - 1_16_2-3 - ${project.version} - compile - - - com.github.stefvanschie.inventoryframework - 1_16_4-5 - ${project.version} - compile - com.github.stefvanschie.inventoryframework 1_17_0 diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java index bbf122dda..62e9b78e6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/StaticPane.java @@ -29,7 +29,7 @@ * the same pane. It's recommended to only use one of these systems per pane and to not mix them. *

*/ -public class StaticPane extends Pane implements Flippable, Rotatable { +public class StaticPane extends Pane implements Flippable, Rotatable { /** * A map of locations inside this pane and their item. The locations are stored in a way where the x coordinate is diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/VersionMatcher.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/VersionMatcher.java index 60650ea04..aa90e446d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/VersionMatcher.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/VersionMatcher.java @@ -275,7 +275,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers static { ANVIL_INVENTORIES = new EnumMap<>(Version.class); - ANVIL_INVENTORIES.put(Version.V1_14, + /*ANVIL_INVENTORIES.put(Version.V1_14, com.github.stefvanschie.inventoryframework.nms.v1_14.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_15, com.github.stefvanschie.inventoryframework.nms.v1_15.AnvilInventoryImpl.class); @@ -284,7 +284,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers ANVIL_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.AnvilInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.AnvilInventoryImpl.class);*/ ANVIL_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_17_1, @@ -327,7 +327,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_4.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); - BEACON_INVENTORIES.put(Version.V1_14, + /*BEACON_INVENTORIES.put(Version.V1_14, com.github.stefvanschie.inventoryframework.nms.v1_14.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_15, com.github.stefvanschie.inventoryframework.nms.v1_15.BeaconInventoryImpl.class); @@ -336,7 +336,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers BEACON_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.BeaconInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.BeaconInventoryImpl.class);*/ BEACON_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_17_1, @@ -379,7 +379,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_4.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, + /*CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, com.github.stefvanschie.inventoryframework.nms.v1_14.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_15, com.github.stefvanschie.inventoryframework.nms.v1_15.CartographyTableInventoryImpl.class); @@ -388,7 +388,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.CartographyTableInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.CartographyTableInventoryImpl.class);*/ CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_17_1, @@ -431,7 +431,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_4.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, + /*ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, com.github.stefvanschie.inventoryframework.nms.v1_14.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_15, com.github.stefvanschie.inventoryframework.nms.v1_15.EnchantingTableInventoryImpl.class); @@ -440,7 +440,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers ENCHANTING_TABLE_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.EnchantingTableInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.EnchantingTableInventoryImpl.class);*/ ENCHANTING_TABLE_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_17_1, @@ -483,7 +483,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_4.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); - GRINDSTONE_INVENTORIES.put(Version.V1_14, + /*GRINDSTONE_INVENTORIES.put(Version.V1_14, com.github.stefvanschie.inventoryframework.nms.v1_14.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_15, com.github.stefvanschie.inventoryframework.nms.v1_15.GrindstoneInventoryImpl.class); @@ -492,7 +492,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers GRINDSTONE_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.GrindstoneInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.GrindstoneInventoryImpl.class);*/ GRINDSTONE_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_17_1, @@ -535,7 +535,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_4.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); - MERCHANT_INVENTORIES.put(Version.V1_14, + /*MERCHANT_INVENTORIES.put(Version.V1_14, com.github.stefvanschie.inventoryframework.nms.v1_14.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_15, com.github.stefvanschie.inventoryframework.nms.v1_15.MerchantInventoryImpl.class); @@ -544,7 +544,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers MERCHANT_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.MerchantInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.MerchantInventoryImpl.class);*/ MERCHANT_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_17_1, @@ -611,12 +611,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_4.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); - LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, + /*LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, com.github.stefvanschie.inventoryframework.nms.v1_16_1.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.SmithingTableInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.SmithingTableInventoryImpl.class);*/ LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_17_1, @@ -639,7 +639,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers LegacySmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); - STONECUTTER_INVENTORIES.put(Version.V1_14, + /*STONECUTTER_INVENTORIES.put(Version.V1_14, com.github.stefvanschie.inventoryframework.nms.v1_14.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_15, com.github.stefvanschie.inventoryframework.nms.v1_15.StonecutterInventoryImpl.class); @@ -648,7 +648,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers STONECUTTER_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_16_4_5, - com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.StonecutterInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.StonecutterInventoryImpl.class);*/ STONECUTTER_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_17_1, diff --git a/buildtools.sh b/buildtools.sh new file mode 100644 index 000000000..03551fd51 --- /dev/null +++ b/buildtools.sh @@ -0,0 +1,46 @@ +#!/bin/zsh +wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar + +git clone https://hub.spigotmc.org/stash/scm/spigot/bukkit.git Bukkit +cd Bukkit +git checkout 304e83eb384c338546aa96eea51388e0e8407e26 +cd .. + +git clone https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git CraftBukkit +cd CraftBukkit +git checkout 91b1fc3f1cf89e2591367dca1fa7362fe376f289 +cd .. + +git clone https://hub.spigotmc.org/stash/scm/spigot/spigot.git Spigot +cd Spigot +git checkout b698b49caf14f97a717afd67e13fd7ac59f51089 +cd .. + +git clone https://hub.spigotmc.org/stash/scm/spigot/builddata.git BuildData +cd BuildData +git checkout a7f7c2118b877fde4cf0f32f1f730ffcdee8e9ee +cd .. + +java -jar BuildTools.jar --remapped --disable-java-check --dont-update +java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check + +cd Bukkit +git checkout 2ec53f498e32b3af989cb24672fc54dfab087154 +cd .. + +cd CraftBukkit +git checkout 8ee6fd1b8db9896590aa321d0199453de1fc35db +cd .. + +cd Spigot +git checkout fb8fb722a327a2f9f097f2ded700ac5de8157408 +cd .. + +cd BuildData +git checkout ae1e7b1e31cd3a3892bb05a6ccdcecc48c73c455 +cd .. + +java -jar BuildTools.jar --remapped --disable-java-check --dont-update +java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.21.4 --remapped --disable-java-check \ No newline at end of file diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml deleted file mode 100644 index 2ffb27656..000000000 --- a/nms/1_14/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 - ../../pom.xml - - 4.0.0 - - 1_14 - - - true - - - - - io.papermc - paper - 1.14.4-R0.1-SNAPSHOT - provided - - - com.github.stefvanschie.inventoryframework - abstraction - ${project.version} - compile - - - \ No newline at end of file diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/AnvilInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/AnvilInventoryImpl.java deleted file mode 100644 index 9b30ed8bc..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/AnvilInventoryImpl.java +++ /dev/null @@ -1,381 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14.util.TextHolderUtil; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal anvil inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class AnvilInventoryImpl extends AnvilInventory { - - public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, message); - - Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int containerId = containerAnvil.getContainerId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); - entityPlayer.activeContainer = containerAnvil; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.a); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - @Deprecated - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The index of the result slot - */ - private static final int RESULT_SLOT_INDEX = 2; - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for whom this anvil container is - * @param title the title of the inventory - * @since 0.10.8 - */ - public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.checkReachable = false; - - try { - //stores all the registered container properties - Field dField = Container.class.getDeclaredField("d"); - dField.setAccessible(true); - - //get rid of the level cost property - ((List) dField.get(this)).clear(); - } catch (NoSuchFieldException | IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'd'", exception); - } - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - //register a new property for the level cost - ContainerProperty levelCost = a(new ContainerProperty() { - private int value; - - @Override - public int get() { - return value; - } - - @Override - public void set(int value) { - this.value = value; - } - - /* - This checks whether there have been any changes, but we want to override the client prediction. This - means the server should be sending the data to the client, even if it didn't change server-side. To - force this, we tell the server the data has always changed. - */ - @Override - public boolean c() { - return true; - } - }); - - levelCost.set(AnvilInventoryImpl.super.cost); - - setTitle(title); - - Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - - Slot newSlot = new Slot(originalSlot.inventory, originalSlot.index, originalSlot.e, originalSlot.f) { - @Override - public boolean isAllowed(ItemStack itemStack) { - return true; - } - - @Override - public boolean isAllowed(EntityHuman entityHuman) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return itemStack; - } - }; - - this.slots.set(RESULT_SLOT_INDEX, newSlot); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - @Override - public void a(@Nullable String name) { - name = name == null ? "" : name; - - /* Only update if the name is actually different. This may be called even if the name is not different, - particularly when putting an item in the first slot. */ - if (!name.equals(AnvilInventoryImpl.super.observableText.get())) { - AnvilInventoryImpl.super.observableText.set(name); - } - - //the client predicts the output result, so we broadcast the state again to override it - forceUpdate(); - } - - @Override - public void e() {} - - @Override - public void b(EntityHuman entityHuman) {} - - @Override - protected void a(EntityHuman entityHuman, World world, @NotNull IInventory inventory) {} - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - public int getContainerId() { - return this.windowId; - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - c(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - } -} diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/BeaconInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/BeaconInventoryImpl.java deleted file mode 100644 index 407358326..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/BeaconInventoryImpl.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14; - -import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryBeacon; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal beacon inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class BeaconInventoryImpl extends BeaconInventory { - - public BeaconInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(entityPlayer, item); - - entityPlayer.activeContainer = containerBeacon; - - int id = containerBeacon.windowId; - ChatMessage message = new ChatMessage("Beacon"); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.BEACON, message)); - - sendItem(player, item); - } - - @Override - public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - NonNullList items = NonNullList.a( - ItemStack.a, //the first item doesn't count for some reason, so send a dummy item - CraftItemStack.asNMSCopy(item) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), items)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container beacon - * - * @since 0.8.0 - */ - private class ContainerBeaconImpl extends ContainerBeacon { - - /** - * The player for this beacon container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container beacon - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the beacon field - */ - @NotNull - private final Field beaconField; - - public ContainerBeaconImpl(@NotNull EntityPlayer entityPlayer, @Nullable org.bukkit.inventory.ItemStack item) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.beaconField = ContainerBeacon.class.getDeclaredField("beacon"); - this.beaconField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - ItemStack itemStack = CraftItemStack.asNMSCopy(item); - - ((IInventory) beaconField.get(this)).setItem(0, itemStack); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryBeacon((IInventory) beaconField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/CartographyTableInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/CartographyTableInventoryImpl.java deleted file mode 100644 index fe2798387..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/CartographyTableInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14.util.TextHolderUtil; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCartography; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal cartography table inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class CartographyTableInventoryImpl extends CartographyTableInventory { - - public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a cartography table should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( - entityPlayer, items - ); - - entityPlayer.activeContainer = containerCartographyTable; - - int id = containerCartographyTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container cartography table - * - * @since 0.8.0 - */ - private class ContainerCartographyTableImpl extends ContainerCartography { - - /** - * The player for this cartography table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container cartography table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerCartographyTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerCartography.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryCartography(super.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - } -} diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/EnchantingTableInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/EnchantingTableInventoryImpl.java deleted file mode 100644 index ae6bb4e44..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/EnchantingTableInventoryImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14.util.TextHolderUtil; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryEnchanting; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal enchanting table inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class EnchantingTableInventoryImpl extends EnchantingTableInventory { - - public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for an enchanting table should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerEnchantingTableImpl extends ContainerEnchantTable { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the enchant slots field - */ - @NotNull - private final Field enchantSlotsField; - - public ContainerEnchantingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.enchantSlotsField = ContainerEnchantTable.class.getDeclaredField("enchantSlots"); - this.enchantSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - IInventory input = (IInventory) enchantSlotsField.get(this); - - input.setItem(0, CraftItemStack.asNMSCopy(items[0])); - input.setItem(1, CraftItemStack.asNMSCopy(items[1])); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryEnchanting((IInventory) enchantSlotsField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - exception.printStackTrace(); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/GrindstoneInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/GrindstoneInventoryImpl.java deleted file mode 100644 index f382990ab..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/GrindstoneInventoryImpl.java +++ /dev/null @@ -1,272 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14.util.TextHolderUtil; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal grindstone inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); - - Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int windowId = containerGrindstone.getWindowId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, Containers.GRINDSTONE, message)); - entityPlayer.activeContainer = containerGrindstone; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - @Deprecated - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container grindstone - * - * @since 0.8.0 - */ - private static class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new grindstone container - * - * @param entityPlayer the player for whom this container should be opened - * @since 0.10.8 - */ - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - Slot firstSlot = this.slots.get(0); - Slot secondSlot = this.slots.get(1); - Slot thirdSlot = this.slots.get(2); - - this.slots.set(0, new Slot(firstSlot.inventory, firstSlot.rawSlotIndex, firstSlot.e, firstSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(1, new Slot(secondSlot.inventory, secondSlot.rawSlotIndex, secondSlot.e, secondSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(2, new Slot(thirdSlot.inventory, thirdSlot.rawSlotIndex, thirdSlot.e, thirdSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, ItemStack itemStack) { - return itemStack; - } - }); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - c(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityHuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityHuman) {} - - public int getWindowId() { - return this.windowId; - } - } -} diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/MerchantInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/MerchantInventoryImpl.java deleted file mode 100644 index 326c2ed8d..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/MerchantInventoryImpl.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14; - -import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; -import net.minecraft.server.v1_14_R1.EntityPlayer; -import net.minecraft.server.v1_14_R1.MerchantRecipeList; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Map; - -/** - * Internal merchant inventory for 1.14 - * - * @since 0.10.1 - */ -public class MerchantInventoryImpl extends MerchantInventory { - - @Override - public void sendMerchantOffers(@NotNull Player player, - @NotNull List> trades, - int level, int experience) { - MerchantRecipeList offers = new MerchantRecipeList(); - - for (Map.Entry entry : trades) { - MerchantRecipe recipe = entry.getKey(); - List ingredients = recipe.getIngredients(); - - if (ingredients.size() < 1) { - throw new IllegalStateException("Merchant recipe has no ingredients"); - } - - ItemStack itemA = ingredients.get(0); - ItemStack itemB = null; - - if (ingredients.size() >= 2) { - itemB = ingredients.get(1); - } - - net.minecraft.server.v1_14_R1.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); - net.minecraft.server.v1_14_R1.ItemStack nmsItemB = net.minecraft.server.v1_14_R1.ItemStack.a; - net.minecraft.server.v1_14_R1.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); - - if (itemB != null) { - nmsItemB = CraftItemStack.asNMSCopy(itemB); - } - - int uses = recipe.getUses(); - int maxUses = recipe.getMaxUses(); - int exp = recipe.getVillagerExperience(); - float multiplier = recipe.getPriceMultiplier(); - - net.minecraft.server.v1_14_R1.MerchantRecipe merchantOffer = new net.minecraft.server.v1_14_R1.MerchantRecipe( - nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier - ); - merchantOffer.setSpecialPrice(entry.getValue()); - - offers.add(merchantOffer); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - entityPlayer.openTrade(getWindowId(entityPlayer), offers, level, experience, true, false); - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.10.1 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.10.1 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } -} diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/StonecutterInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/StonecutterInventoryImpl.java deleted file mode 100644 index 877624db6..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/StonecutterInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14.util.TextHolderUtil; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryStonecutter; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal stonecutter inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class StonecutterInventoryImpl extends StonecutterInventory { - - public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for a stonecutter should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerStonecutterImpl extends ContainerStonecutter { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerStonecutterImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerStonecutter.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[1])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryStonecutter(this.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - public IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} diff --git a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/util/TextHolderUtil.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/util/TextHolderUtil.java deleted file mode 100644 index 5f628de0d..000000000 --- a/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/util/TextHolderUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14.util; - -import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import net.minecraft.server.v1_14_R1.ChatComponentText; -import net.minecraft.server.v1_14_R1.IChatBaseComponent; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -/** - * A utility class for adding {@link TextHolder} support. - * - * @since 0.10.0 - */ -public final class TextHolderUtil { - - private TextHolderUtil() { - //private constructor to prevent construction - } - - /** - * Converts the specified value to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { - if (holder instanceof StringHolder) { - return toComponent((StringHolder) holder); - } else { - return toComponent((ComponentHolder) holder); - } - } - - /** - * Converts the specified legacy string holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { - return new ChatComponentText(holder.asLegacyString()); - } - - /** - * Converts the specified Adventure component holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { - return Objects.requireNonNull(IChatBaseComponent.ChatSerializer.a(holder.asJson())); - } -} diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml deleted file mode 100644 index c6c7da224..000000000 --- a/nms/1_15/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 - ../../pom.xml - - 4.0.0 - - 1_15 - - - true - - - - - io.papermc - paper - 1.15.2-R0.1-SNAPSHOT - provided - - - com.github.stefvanschie.inventoryframework - abstraction - ${project.version} - compile - - - \ No newline at end of file diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java deleted file mode 100644 index aff83a514..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java +++ /dev/null @@ -1,381 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15.util.TextHolderUtil; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal anvil inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class AnvilInventoryImpl extends AnvilInventory { - - public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, message); - - Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int containerId = containerAnvil.getContainerId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); - entityPlayer.activeContainer = containerAnvil; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.a); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - @Deprecated - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The index of the result slot - */ - private static final int RESULT_SLOT_INDEX = 2; - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for whom this anvil container is - * @param title the title of the inventory - * @since 0.10.8 - */ - public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.checkReachable = false; - - try { - //stores all the registered container properties - Field dField = Container.class.getDeclaredField("d"); - dField.setAccessible(true); - - //get rid of the level cost property - ((List) dField.get(this)).clear(); - } catch (NoSuchFieldException | IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'd'", exception); - } - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - //register a new property for the level cost - ContainerProperty levelCost = a(new ContainerProperty() { - private int value; - - @Override - public int get() { - return value; - } - - @Override - public void set(int value) { - this.value = value; - } - - /* - This checks whether there have been any changes, but we want to override the client prediction. This - means the server should be sending the data to the client, even if it didn't change server-side. To - force this, we tell the server the data has always changed. - */ - @Override - public boolean c() { - return true; - } - }); - - levelCost.set(AnvilInventoryImpl.super.cost); - - setTitle(title); - - Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - - Slot newSlot = new Slot(originalSlot.inventory, originalSlot.index, originalSlot.e, originalSlot.f) { - @Override - public boolean isAllowed(ItemStack itemStack) { - return true; - } - - @Override - public boolean isAllowed(EntityHuman entityHuman) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return itemStack; - } - }; - - this.slots.set(RESULT_SLOT_INDEX, newSlot); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - @Override - public void a(@Nullable String name) { - name = name == null ? "" : name; - - /* Only update if the name is actually different. This may be called even if the name is not different, - particularly when putting an item in the first slot. */ - if (!name.equals(AnvilInventoryImpl.super.observableText.get())) { - AnvilInventoryImpl.super.observableText.set(name); - } - - //the client predicts the output result, so we broadcast the state again to override it - forceUpdate(); - } - - @Override - public void e() {} - - @Override - public void b(EntityHuman entityHuman) {} - - @Override - protected void a(EntityHuman entityHuman, World world, @NotNull IInventory inventory) {} - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - public int getContainerId() { - return this.windowId; - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - c(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - } -} diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/BeaconInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/BeaconInventoryImpl.java deleted file mode 100644 index f6cc4814a..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/BeaconInventoryImpl.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15; - -import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryBeacon; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal beacon inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class BeaconInventoryImpl extends BeaconInventory { - - public BeaconInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(entityPlayer, item); - - entityPlayer.activeContainer = containerBeacon; - - int id = containerBeacon.windowId; - ChatMessage message = new ChatMessage("Beacon"); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.BEACON, message)); - - sendItem(player, item); - } - - @Override - public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - NonNullList items = NonNullList.a( - ItemStack.a, //the first item doesn't count for some reason, so send a dummy item - CraftItemStack.asNMSCopy(item) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), items)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container beacon - * - * @since 0.8.0 - */ - private class ContainerBeaconImpl extends ContainerBeacon { - - /** - * The player for this beacon container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container beacon - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the beacon field - */ - @NotNull - private final Field beaconField; - - public ContainerBeaconImpl(@NotNull EntityPlayer entityPlayer, @Nullable org.bukkit.inventory.ItemStack item) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.beaconField = ContainerBeacon.class.getDeclaredField("beacon"); - this.beaconField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - ItemStack itemStack = CraftItemStack.asNMSCopy(item); - - ((IInventory) beaconField.get(this)).setItem(0, itemStack); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryBeacon((IInventory) beaconField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/CartographyTableInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/CartographyTableInventoryImpl.java deleted file mode 100644 index bc6ada39f..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/CartographyTableInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15.util.TextHolderUtil; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCartography; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal cartography table inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class CartographyTableInventoryImpl extends CartographyTableInventory { - - public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a cartography table should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( - entityPlayer, items - ); - - entityPlayer.activeContainer = containerCartographyTable; - - int id = containerCartographyTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container cartography table - * - * @since 0.8.0 - */ - private class ContainerCartographyTableImpl extends ContainerCartography { - - /** - * The player for this cartography table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container cartography table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerCartographyTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerCartography.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryCartography(super.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - } -} diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/EnchantingTableInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/EnchantingTableInventoryImpl.java deleted file mode 100644 index 280f3e242..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/EnchantingTableInventoryImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15.util.TextHolderUtil; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryEnchanting; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal enchanting table inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class EnchantingTableInventoryImpl extends EnchantingTableInventory { - - public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for an enchanting table should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerEnchantingTableImpl extends ContainerEnchantTable { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the enchant slots field - */ - @NotNull - private final Field enchantSlotsField; - - public ContainerEnchantingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.enchantSlotsField = ContainerEnchantTable.class.getDeclaredField("enchantSlots"); - this.enchantSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - IInventory input = (IInventory) enchantSlotsField.get(this); - - input.setItem(0, CraftItemStack.asNMSCopy(items[0])); - input.setItem(1, CraftItemStack.asNMSCopy(items[1])); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryEnchanting((IInventory) enchantSlotsField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - exception.printStackTrace(); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/GrindstoneInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/GrindstoneInventoryImpl.java deleted file mode 100644 index e34d4fbdd..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/GrindstoneInventoryImpl.java +++ /dev/null @@ -1,272 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15.util.TextHolderUtil; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal grindstone inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); - - Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int windowId = containerGrindstone.getWindowId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, Containers.GRINDSTONE, message)); - entityPlayer.activeContainer = containerGrindstone; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - @Deprecated - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container grindstone - * - * @since 0.8.0 - */ - private static class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new grindstone container - * - * @param entityPlayer the player for whom this container should be opened - * @since 0.10.8 - */ - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - Slot firstSlot = this.slots.get(0); - Slot secondSlot = this.slots.get(1); - Slot thirdSlot = this.slots.get(2); - - this.slots.set(0, new Slot(firstSlot.inventory, firstSlot.rawSlotIndex, firstSlot.e, firstSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(1, new Slot(secondSlot.inventory, secondSlot.rawSlotIndex, secondSlot.e, secondSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(2, new Slot(thirdSlot.inventory, thirdSlot.rawSlotIndex, thirdSlot.e, thirdSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, ItemStack itemStack) { - return itemStack; - } - }); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - c(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityHuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityHuman) {} - - public int getWindowId() { - return this.windowId; - } - } -} diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/MerchantInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/MerchantInventoryImpl.java deleted file mode 100644 index 2b296f202..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/MerchantInventoryImpl.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15; - -import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; -import net.minecraft.server.v1_15_R1.EntityPlayer; -import net.minecraft.server.v1_15_R1.MerchantRecipeList; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Map; - -/** - * Internal merchant inventory for 1.15 - * - * @since 0.10.1 - */ -public class MerchantInventoryImpl extends MerchantInventory { - - @Override - public void sendMerchantOffers(@NotNull Player player, - @NotNull List> trades, - int level, int experience) { - MerchantRecipeList offers = new MerchantRecipeList(); - - for (Map.Entry entry : trades) { - MerchantRecipe recipe = entry.getKey(); - List ingredients = recipe.getIngredients(); - - if (ingredients.size() < 1) { - throw new IllegalStateException("Merchant recipe has no ingredients"); - } - - ItemStack itemA = ingredients.get(0); - ItemStack itemB = null; - - if (ingredients.size() >= 2) { - itemB = ingredients.get(1); - } - - net.minecraft.server.v1_15_R1.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); - net.minecraft.server.v1_15_R1.ItemStack nmsItemB = net.minecraft.server.v1_15_R1.ItemStack.a; - net.minecraft.server.v1_15_R1.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); - - if (itemB != null) { - nmsItemB = CraftItemStack.asNMSCopy(itemB); - } - - int uses = recipe.getUses(); - int maxUses = recipe.getMaxUses(); - int exp = recipe.getVillagerExperience(); - float multiplier = recipe.getPriceMultiplier(); - - net.minecraft.server.v1_15_R1.MerchantRecipe merchantOffer = new net.minecraft.server.v1_15_R1.MerchantRecipe( - nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier - ); - merchantOffer.setSpecialPrice(entry.getValue()); - - offers.add(merchantOffer); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - entityPlayer.openTrade(getWindowId(entityPlayer), offers, level, experience, true, false); - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.10.1 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.10.1 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } -} diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/StonecutterInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/StonecutterInventoryImpl.java deleted file mode 100644 index 88118970e..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/StonecutterInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15.util.TextHolderUtil; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryStonecutter; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal stonecutter inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class StonecutterInventoryImpl extends StonecutterInventory { - - public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for a stonecutter should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.a, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerStonecutterImpl extends ContainerStonecutter { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerStonecutterImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerStonecutter.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[1])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryStonecutter(this.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - public IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} diff --git a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/util/TextHolderUtil.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/util/TextHolderUtil.java deleted file mode 100644 index 7554a5bc6..000000000 --- a/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/util/TextHolderUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15.util; - -import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import net.minecraft.server.v1_15_R1.ChatComponentText; -import net.minecraft.server.v1_15_R1.IChatBaseComponent; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -/** - * A utility class for adding {@link TextHolder} support. - * - * @since 0.10.0 - */ -public final class TextHolderUtil { - - private TextHolderUtil() { - //private constructor to prevent construction - } - - /** - * Converts the specified value to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { - if (holder instanceof StringHolder) { - return toComponent((StringHolder) holder); - } else { - return toComponent((ComponentHolder) holder); - } - } - - /** - * Converts the specified legacy string holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { - return new ChatComponentText(holder.asLegacyString()); - } - - /** - * Converts the specified Adventure component holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { - return Objects.requireNonNull(IChatBaseComponent.ChatSerializer.a(holder.asJson())); - } -} diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml deleted file mode 100644 index a19bca91f..000000000 --- a/nms/1_16_1/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 - ../../pom.xml - - 4.0.0 - - 1_16_1 - - - true - - - - - io.papermc - paper - 1.16.1-R0.1-SNAPSHOT - provided - - - com.github.stefvanschie.inventoryframework - abstraction - ${project.version} - compile - - - \ No newline at end of file diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java deleted file mode 100644 index 098c90241..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java +++ /dev/null @@ -1,386 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_1.util.TextHolderUtil; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal anvil inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class AnvilInventoryImpl extends AnvilInventory { - - public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, message); - - Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int containerId = containerAnvil.getContainerId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); - entityPlayer.activeContainer = containerAnvil; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.b); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - @Deprecated - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The index of the result slot - */ - private static final int RESULT_SLOT_INDEX = 2; - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for whom this anvil container is - * @param title the title of the inventory - * @since 0.10.8 - */ - public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.checkReachable = false; - - try { - //stores all the registered container properties - Field dField = Container.class.getDeclaredField("d"); - dField.setAccessible(true); - - //get rid of the level cost property - ((List) dField.get(this)).clear(); - } catch (NoSuchFieldException | IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'd'", exception); - } - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - //register a new property for the level cost - ContainerProperty levelCost = a(new ContainerProperty() { - private int value; - - @Override - public int get() { - return value; - } - - @Override - public void set(int value) { - this.value = value; - } - - /* - This checks whether there have been any changes, but we want to override the client prediction. This - means the server should be sending the data to the client, even if it didn't change server-side. To - force this, we tell the server the data has always changed. - */ - @Override - public boolean c() { - return true; - } - }); - - levelCost.set(AnvilInventoryImpl.super.cost); - - setTitle(title); - - Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - - Slot newSlot = new Slot(originalSlot.inventory, originalSlot.index, originalSlot.e, originalSlot.f) { - @Override - public boolean isAllowed(ItemStack itemStack) { - return true; - } - - @Override - public boolean isAllowed(EntityHuman entityHuman) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return originalSlot.a(entityHuman, itemStack); - } - }; - - this.slots.set(RESULT_SLOT_INDEX, newSlot); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - @Override - public void a(@Nullable String name) { - name = name == null ? "" : name; - - /* Only update if the name is actually different. This may be called even if the name is not different, - particularly when putting an item in the first slot. */ - if (!name.equals(AnvilInventoryImpl.super.observableText.get())) { - AnvilInventoryImpl.super.observableText.set(name); - } - - //the client predicts the output result, so we broadcast the state again to override it - forceUpdate(); - } - - @Override - public void e() {} - - @Override - public void b(EntityHuman entityHuman) {} - - @Override - protected void a(EntityHuman entityHuman, World world, @NotNull IInventory inventory) {} - - @Override - protected ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return itemStack; - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - public int getContainerId() { - return this.windowId; - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - c(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/BeaconInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/BeaconInventoryImpl.java deleted file mode 100644 index 68183b72b..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/BeaconInventoryImpl.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryBeacon; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal beacon inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class BeaconInventoryImpl extends BeaconInventory { - - public BeaconInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(entityPlayer, item); - - entityPlayer.activeContainer = containerBeacon; - - int id = containerBeacon.windowId; - ChatMessage message = new ChatMessage("Beacon"); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.BEACON, message)); - - sendItem(player, item); - } - - @Override - public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - NonNullList items = NonNullList.a( - ItemStack.b, //the first item doesn't count for some reason, so send a dummy item - CraftItemStack.asNMSCopy(item) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), items)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container beacon - * - * @since 0.8.0 - */ - private class ContainerBeaconImpl extends ContainerBeacon { - - /** - * The player for this beacon container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container beacon - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the beacon field - */ - @NotNull - private final Field beaconField; - - public ContainerBeaconImpl(@NotNull EntityPlayer entityPlayer, @Nullable org.bukkit.inventory.ItemStack item) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.beaconField = ContainerBeacon.class.getDeclaredField("beacon"); - this.beaconField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - ItemStack itemStack = CraftItemStack.asNMSCopy(item); - - ((IInventory) beaconField.get(this)).setItem(0, itemStack); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryBeacon((IInventory) beaconField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/CartographyTableInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/CartographyTableInventoryImpl.java deleted file mode 100644 index b80f7bafb..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/CartographyTableInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_1.util.TextHolderUtil; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryCartography; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal cartography table inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class CartographyTableInventoryImpl extends CartographyTableInventory { - - public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a cartography table should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( - entityPlayer, items - ); - - entityPlayer.activeContainer = containerCartographyTable; - - int id = containerCartographyTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container cartography table - * - * @since 0.8.0 - */ - private class ContainerCartographyTableImpl extends ContainerCartography { - - /** - * The player for this cartography table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container cartography table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerCartographyTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerCartography.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryCartography(super.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/EnchantingTableInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/EnchantingTableInventoryImpl.java deleted file mode 100644 index 73a9c5f62..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/EnchantingTableInventoryImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_1.util.TextHolderUtil; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryEnchanting; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal enchanting table inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class EnchantingTableInventoryImpl extends EnchantingTableInventory { - - public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for an enchanting table should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerEnchantingTableImpl extends ContainerEnchantTable { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the enchant slots field - */ - @NotNull - private final Field enchantSlotsField; - - public ContainerEnchantingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.enchantSlotsField = ContainerEnchantTable.class.getDeclaredField("enchantSlots"); - this.enchantSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - IInventory input = (IInventory) enchantSlotsField.get(this); - - input.setItem(0, CraftItemStack.asNMSCopy(items[0])); - input.setItem(1, CraftItemStack.asNMSCopy(items[1])); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryEnchanting((IInventory) enchantSlotsField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - exception.printStackTrace(); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/GrindstoneInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/GrindstoneInventoryImpl.java deleted file mode 100644 index c349af46c..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/GrindstoneInventoryImpl.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_1.util.TextHolderUtil; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal grindstone inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); - - Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int windowId = containerGrindstone.getWindowId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, Containers.GRINDSTONE, message)); - entityPlayer.activeContainer = containerGrindstone; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container grindstone - * - * @since 0.8.0 - */ - private static class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new grindstone container - * - * @param entityPlayer the player for whom this container should be opened - * @since 0.10.8 - */ - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - Slot firstSlot = this.slots.get(0); - Slot secondSlot = this.slots.get(1); - Slot thirdSlot = this.slots.get(2); - - this.slots.set(0, new Slot(firstSlot.inventory, firstSlot.rawSlotIndex, firstSlot.e, firstSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(1, new Slot(secondSlot.inventory, secondSlot.rawSlotIndex, secondSlot.e, secondSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(2, new Slot(thirdSlot.inventory, thirdSlot.rawSlotIndex, thirdSlot.e, thirdSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, ItemStack itemStack) { - return itemStack; - } - }); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - notifyListeners(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityHuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityHuman) {} - - public int getWindowId() { - return this.windowId; - } - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/MerchantInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/MerchantInventoryImpl.java deleted file mode 100644 index b54526b3e..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/MerchantInventoryImpl.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; -import net.minecraft.server.v1_16_R1.EntityPlayer; -import net.minecraft.server.v1_16_R1.MerchantRecipeList; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Map; - -/** - * Internal merchant inventory for 1.16.1 - * - * @since 0.10.1 - */ -public class MerchantInventoryImpl extends MerchantInventory { - - @Override - public void sendMerchantOffers(@NotNull Player player, - @NotNull List> trades, - int level, int experience) { - MerchantRecipeList offers = new MerchantRecipeList(); - - for (Map.Entry entry : trades) { - MerchantRecipe recipe = entry.getKey(); - List ingredients = recipe.getIngredients(); - - if (ingredients.size() < 1) { - throw new IllegalStateException("Merchant recipe has no ingredients"); - } - - ItemStack itemA = ingredients.get(0); - ItemStack itemB = null; - - if (ingredients.size() >= 2) { - itemB = ingredients.get(1); - } - - net.minecraft.server.v1_16_R1.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); - net.minecraft.server.v1_16_R1.ItemStack nmsItemB = net.minecraft.server.v1_16_R1.ItemStack.b; - net.minecraft.server.v1_16_R1.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); - - if (itemB != null) { - nmsItemB = CraftItemStack.asNMSCopy(itemB); - } - - int uses = recipe.getUses(); - int maxUses = recipe.getMaxUses(); - int exp = recipe.getVillagerExperience(); - float multiplier = recipe.getPriceMultiplier(); - - net.minecraft.server.v1_16_R1.MerchantRecipe merchantOffer = new net.minecraft.server.v1_16_R1.MerchantRecipe( - nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier - ); - merchantOffer.setSpecialPrice(entry.getValue()); - - offers.add(merchantOffer); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - entityPlayer.openTrade(getWindowId(entityPlayer), offers, level, experience, true, false); - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.10.1 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.10.1 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/SmithingTableInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/SmithingTableInventoryImpl.java deleted file mode 100644 index d662e556c..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/SmithingTableInventoryImpl.java +++ /dev/null @@ -1,233 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_1.util.TextHolderUtil; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventorySmithing; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Internal smithing table inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class SmithingTableInventoryImpl extends SmithingTableInventory { - - public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Nullable - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a stonecutter should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerSmithingTable; - - int id = containerSmithingTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items, null); - - return null; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.b); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - */ - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - */ - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container smithing table - * - * @since 0.8.0 - */ - private class ContainerSmithingTableImpl extends ContainerSmithing { - - /** - * The player for this smithing table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container smithing table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - public ContainerSmithingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.player = entityPlayer.getBukkitEntity(); - - repairInventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - repairInventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultInventory.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventorySmithing(repairInventory, resultInventory) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/StonecutterInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/StonecutterInventoryImpl.java deleted file mode 100644 index aa9889fcd..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/StonecutterInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_1.util.TextHolderUtil; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryStonecutter; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal stonecutter inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class StonecutterInventoryImpl extends StonecutterInventory { - - public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for a stonecutter should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerStonecutterImpl extends ContainerStonecutter { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerStonecutterImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerStonecutter.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[1])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryStonecutter(this.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - public IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} diff --git a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/util/TextHolderUtil.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/util/TextHolderUtil.java deleted file mode 100644 index 1e805f59b..000000000 --- a/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/util/TextHolderUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_1.util; - -import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import net.minecraft.server.v1_16_R1.ChatComponentText; -import net.minecraft.server.v1_16_R1.IChatBaseComponent; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -/** - * A utility class for adding {@link TextHolder} support. - * - * @since 0.10.0 - */ -public final class TextHolderUtil { - - private TextHolderUtil() { - //private constructor to prevent construction - } - - /** - * Converts the specified value to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { - if (holder instanceof StringHolder) { - return toComponent((StringHolder) holder); - } else { - return toComponent((ComponentHolder) holder); - } - } - - /** - * Converts the specified legacy string holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { - return new ChatComponentText(holder.asLegacyString()); - } - - /** - * Converts the specified Adventure component holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { - return Objects.requireNonNull(IChatBaseComponent.ChatSerializer.a(holder.asJson())); - } -} diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml deleted file mode 100644 index 343fbc45f..000000000 --- a/nms/1_16_2-3/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 - ../../pom.xml - - 4.0.0 - - 1_16_2-3 - - - true - - - - - io.papermc - paper - 1.16.3-R0.1-SNAPSHOT - provided - - - com.github.stefvanschie.inventoryframework - abstraction - ${project.version} - compile - - - \ No newline at end of file diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java deleted file mode 100644 index 83b57373d..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java +++ /dev/null @@ -1,386 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.util.TextHolderUtil; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal anvil inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class AnvilInventoryImpl extends AnvilInventory { - - public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, message); - - Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int containerId = containerAnvil.getContainerId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); - entityPlayer.activeContainer = containerAnvil; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.b); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - @Deprecated - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The index of the result slot - */ - private static final int RESULT_SLOT_INDEX = 2; - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for whom this anvil container is - * @param title the title of the inventory - * @since 0.10.8 - */ - public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.checkReachable = false; - - try { - //stores all the registered container properties - Field dField = Container.class.getDeclaredField("d"); - dField.setAccessible(true); - - //get rid of the level cost property - ((List) dField.get(this)).clear(); - } catch (NoSuchFieldException | IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'd'", exception); - } - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - //register a new property for the level cost - ContainerProperty levelCost = a(new ContainerProperty() { - private int value; - - @Override - public int get() { - return value; - } - - @Override - public void set(int value) { - this.value = value; - } - - /* - This checks whether there have been any changes, but we want to override the client prediction. This - means the server should be sending the data to the client, even if it didn't change server-side. To - force this, we tell the server the data has always changed. - */ - @Override - public boolean c() { - return true; - } - }); - - levelCost.set(AnvilInventoryImpl.super.cost); - - setTitle(title); - - Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - - Slot newSlot = new Slot(originalSlot.inventory, originalSlot.index, originalSlot.e, originalSlot.f) { - @Override - public boolean isAllowed(ItemStack itemStack) { - return true; - } - - @Override - public boolean isAllowed(EntityHuman entityHuman) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return originalSlot.a(entityHuman, itemStack); - } - }; - - this.slots.set(RESULT_SLOT_INDEX, newSlot); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - @Override - public void a(@Nullable String name) { - name = name == null ? "" : name; - - /* Only update if the name is actually different. This may be called even if the name is not different, - particularly when putting an item in the first slot. */ - if (!name.equals(AnvilInventoryImpl.super.observableText.get())) { - AnvilInventoryImpl.super.observableText.set(name); - } - - //the client predicts the output result, so we broadcast the state again to override it - forceUpdate(); - } - - @Override - public void e() {} - - @Override - public void b(EntityHuman entityHuman) {} - - @Override - protected void a(EntityHuman entityHuman, World world, @NotNull IInventory inventory) {} - - @Override - protected ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return itemStack; - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - public int getContainerId() { - return this.windowId; - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - c(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/BeaconInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/BeaconInventoryImpl.java deleted file mode 100644 index 80e5b9a93..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/BeaconInventoryImpl.java +++ /dev/null @@ -1,178 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.*; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal beacon inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class BeaconInventoryImpl extends BeaconInventory { - - public BeaconInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(entityPlayer, item); - - entityPlayer.activeContainer = containerBeacon; - - int id = containerBeacon.windowId; - ChatMessage message = new ChatMessage("Beacon"); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.BEACON, message)); - - sendItem(player, item); - } - - @Override - public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - NonNullList items = NonNullList.a( - ItemStack.b, //the first item doesn't count for some reason, so send a dummy item - CraftItemStack.asNMSCopy(item) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), items)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container beacon - * - * @since 0.8.0 - */ - private class ContainerBeaconImpl extends ContainerBeacon { - - /** - * The player for this beacon container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container beacon - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the beacon field - */ - @NotNull - private final Field beaconField; - - public ContainerBeaconImpl(@NotNull EntityPlayer entityPlayer, @Nullable org.bukkit.inventory.ItemStack item) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.beaconField = ContainerBeacon.class.getDeclaredField("beacon"); - this.beaconField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - ItemStack itemStack = CraftItemStack.asNMSCopy(item); - - ((IInventory) beaconField.get(this)).setItem(0, itemStack); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryBeacon((IInventory) beaconField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/CartographyTableInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/CartographyTableInventoryImpl.java deleted file mode 100644 index bf6d8ba59..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/CartographyTableInventoryImpl.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.util.TextHolderUtil; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.*; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal cartography table inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class CartographyTableInventoryImpl extends CartographyTableInventory { - - public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a cartography table should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( - entityPlayer, items - ); - - entityPlayer.activeContainer = containerCartographyTable; - - int id = containerCartographyTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container cartography table - * - * @since 0.8.0 - */ - private class ContainerCartographyTableImpl extends ContainerCartography { - - /** - * The player for this cartography table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container cartography table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerCartographyTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerCartography.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryCartography(super.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/EnchantingTableInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/EnchantingTableInventoryImpl.java deleted file mode 100644 index abf9e5393..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/EnchantingTableInventoryImpl.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.util.TextHolderUtil; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.*; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal enchanting table inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class EnchantingTableInventoryImpl extends EnchantingTableInventory { - - public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for an enchanting table should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerEnchantingTableImpl extends ContainerEnchantTable { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the enchant slots field - */ - @NotNull - private final Field enchantSlotsField; - - public ContainerEnchantingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.enchantSlotsField = ContainerEnchantTable.class.getDeclaredField("enchantSlots"); - this.enchantSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - IInventory input = (IInventory) enchantSlotsField.get(this); - - input.setItem(0, CraftItemStack.asNMSCopy(items[0])); - input.setItem(1, CraftItemStack.asNMSCopy(items[1])); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryEnchanting((IInventory) enchantSlotsField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - exception.printStackTrace(); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java deleted file mode 100644 index 0950c0553..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java +++ /dev/null @@ -1,271 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.util.TextHolderUtil; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_16_R2.inventory.*; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal grindstone inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); - - Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int windowId = containerGrindstone.getWindowId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, Containers.GRINDSTONE, message)); - entityPlayer.activeContainer = containerGrindstone; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container grindstone - * - * @since 0.8.0 - */ - private static class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new grindstone container - * - * @param entityPlayer the player for whom this container should be opened - * @since 0.10.8 - */ - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - Slot firstSlot = this.slots.get(0); - Slot secondSlot = this.slots.get(1); - Slot thirdSlot = this.slots.get(2); - - this.slots.set(0, new Slot(firstSlot.inventory, firstSlot.rawSlotIndex, firstSlot.e, firstSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(1, new Slot(secondSlot.inventory, secondSlot.rawSlotIndex, secondSlot.e, secondSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(2, new Slot(thirdSlot.inventory, thirdSlot.rawSlotIndex, thirdSlot.e, thirdSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, ItemStack itemStack) { - return itemStack; - } - }); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - notifyListeners(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityHuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityHuman) {} - - public int getWindowId() { - return this.windowId; - } - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/MerchantInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/MerchantInventoryImpl.java deleted file mode 100644 index 9401a94d1..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/MerchantInventoryImpl.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; -import net.minecraft.server.v1_16_R2.EntityPlayer; -import net.minecraft.server.v1_16_R2.MerchantRecipeList; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Map; - -/** - * Internal merchant inventory for 1.16.2 - 1.16.3 - * - * @since 0.10.1 - */ -public class MerchantInventoryImpl extends MerchantInventory { - - @Override - public void sendMerchantOffers(@NotNull Player player, - @NotNull List> trades, - int level, int experience) { - MerchantRecipeList offers = new MerchantRecipeList(); - - for (Map.Entry entry : trades) { - MerchantRecipe recipe = entry.getKey(); - List ingredients = recipe.getIngredients(); - - if (ingredients.size() < 1) { - throw new IllegalStateException("Merchant recipe has no ingredients"); - } - - ItemStack itemA = ingredients.get(0); - ItemStack itemB = null; - - if (ingredients.size() >= 2) { - itemB = ingredients.get(1); - } - - net.minecraft.server.v1_16_R2.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); - net.minecraft.server.v1_16_R2.ItemStack nmsItemB = net.minecraft.server.v1_16_R2.ItemStack.b; - net.minecraft.server.v1_16_R2.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); - - if (itemB != null) { - nmsItemB = CraftItemStack.asNMSCopy(itemB); - } - - int uses = recipe.getUses(); - int maxUses = recipe.getMaxUses(); - int exp = recipe.getVillagerExperience(); - float multiplier = recipe.getPriceMultiplier(); - - net.minecraft.server.v1_16_R2.MerchantRecipe merchantOffer = new net.minecraft.server.v1_16_R2.MerchantRecipe( - nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier - ); - merchantOffer.setSpecialPrice(entry.getValue()); - - offers.add(merchantOffer); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - entityPlayer.openTrade(getWindowId(entityPlayer), offers, level, experience, true, false); - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.10.1 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.10.1 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/SmithingTableInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/SmithingTableInventoryImpl.java deleted file mode 100644 index 18dad0415..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/SmithingTableInventoryImpl.java +++ /dev/null @@ -1,231 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.util.TextHolderUtil; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.*; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Internal smithing table inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class SmithingTableInventoryImpl extends SmithingTableInventory { - - public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Nullable - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a stonecutter should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerSmithingTable; - - int id = containerSmithingTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items, null); - - return null; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.b); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - */ - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - */ - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container smithing table - * - * @since 0.8.0 - */ - private class ContainerSmithingTableImpl extends ContainerSmithing { - - /** - * The player for this smithing table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container smithing table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - public ContainerSmithingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.player = entityPlayer.getBukkitEntity(); - - repairInventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - repairInventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultInventory.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventorySmithing(containerAccess.getLocation(), repairInventory, - resultInventory) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/StonecutterInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/StonecutterInventoryImpl.java deleted file mode 100644 index 05f40294e..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/StonecutterInventoryImpl.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.util.TextHolderUtil; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.*; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal stonecutter inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class StonecutterInventoryImpl extends StonecutterInventory { - - public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for a stonecutter should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerStonecutterImpl extends ContainerStonecutter { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerStonecutterImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerStonecutter.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[1])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryStonecutter(this.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - public IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} diff --git a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/util/TextHolderUtil.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/util/TextHolderUtil.java deleted file mode 100644 index 42b2c9036..000000000 --- a/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/util/TextHolderUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.util; - -import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import net.minecraft.server.v1_16_R2.ChatComponentText; -import net.minecraft.server.v1_16_R2.IChatBaseComponent; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -/** - * A utility class for adding {@link TextHolder} support. - * - * @since 0.10.0 - */ -public final class TextHolderUtil { - - private TextHolderUtil() { - //private constructor to prevent construction - } - - /** - * Converts the specified value to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { - if (holder instanceof StringHolder) { - return toComponent((StringHolder) holder); - } else { - return toComponent((ComponentHolder) holder); - } - } - - /** - * Converts the specified legacy string holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { - return new ChatComponentText(holder.asLegacyString()); - } - - /** - * Converts the specified Adventure component holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { - return Objects.requireNonNull(IChatBaseComponent.ChatSerializer.a(holder.asJson())); - } -} diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml deleted file mode 100644 index 74e96e538..000000000 --- a/nms/1_16_4-5/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 - ../../pom.xml - - 4.0.0 - - 1_16_4-5 - - - true - - - - - io.papermc - paper - 1.16.4-R0.1-SNAPSHOT - provided - - - com.github.stefvanschie.inventoryframework - abstraction - ${project.version} - compile - - - - \ No newline at end of file diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java deleted file mode 100644 index 99f65b47e..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java +++ /dev/null @@ -1,386 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.util.TextHolderUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal anvil inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class AnvilInventoryImpl extends AnvilInventory { - - public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, message); - - Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int containerId = containerAnvil.getContainerId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); - entityPlayer.activeContainer = containerAnvil; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.b); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Deprecated - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - * @deprecated no longer used internally - */ - @Contract(pure = true) - @Deprecated - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - * @deprecated no longer used internally - */ - @NotNull - @Contract(pure = true) - @Deprecated - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The index of the result slot - */ - private static final int RESULT_SLOT_INDEX = 2; - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for whom this anvil container is - * @param title the title of the inventory - * @since 0.10.8 - */ - public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.checkReachable = false; - - try { - //stores all the registered container properties - Field dField = Container.class.getDeclaredField("d"); - dField.setAccessible(true); - - //get rid of the level cost property - ((List) dField.get(this)).clear(); - } catch (NoSuchFieldException | IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'd'", exception); - } - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - //register a new property for the level cost - ContainerProperty levelCost = a(new ContainerProperty() { - private int value; - - @Override - public int get() { - return value; - } - - @Override - public void set(int value) { - this.value = value; - } - - /* - This checks whether there have been any changes, but we want to override the client prediction. This - means the server should be sending the data to the client, even if it didn't change server-side. To - force this, we tell the server the data has always changed. - */ - @Override - public boolean c() { - return true; - } - }); - - levelCost.set(AnvilInventoryImpl.super.cost); - - setTitle(title); - - Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - - Slot newSlot = new Slot(originalSlot.inventory, originalSlot.index, originalSlot.e, originalSlot.f) { - @Override - public boolean isAllowed(ItemStack itemStack) { - return true; - } - - @Override - public boolean isAllowed(EntityHuman entityHuman) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return originalSlot.a(entityHuman, itemStack); - } - }; - - this.slots.set(RESULT_SLOT_INDEX, newSlot); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - @Override - public void a(@Nullable String name) { - name = name == null ? "" : name; - - /* Only update if the name is actually different. This may be called even if the name is not different, - particularly when putting an item in the first slot. */ - if (!name.equals(AnvilInventoryImpl.super.observableText.get())) { - AnvilInventoryImpl.super.observableText.set(name); - } - - //the client predicts the output result, so we broadcast the state again to override it - forceUpdate(); - } - - @Override - public void e() {} - - @Override - public void b(EntityHuman entityHuman) {} - - @Override - protected void a(EntityHuman entityHuman, World world, @NotNull IInventory inventory) {} - - @Override - protected ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { - return itemStack; - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - public int getContainerId() { - return this.windowId; - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - c(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/BeaconInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/BeaconInventoryImpl.java deleted file mode 100644 index eaed00847..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/BeaconInventoryImpl.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryBeacon; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal beacon inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class BeaconInventoryImpl extends BeaconInventory { - - public BeaconInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(entityPlayer, item); - - entityPlayer.activeContainer = containerBeacon; - - int id = containerBeacon.windowId; - ChatMessage message = new ChatMessage("Beacon"); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.BEACON, message)); - - sendItem(player, item); - } - - @Override - public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - NonNullList items = NonNullList.a( - ItemStack.b, //the first item doesn't count for some reason, so send a dummy item - CraftItemStack.asNMSCopy(item) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), items)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container beacon - * - * @since 0.8.0 - */ - private class ContainerBeaconImpl extends ContainerBeacon { - - /** - * The player for this beacon container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container beacon - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the beacon field - */ - @NotNull - private final Field beaconField; - - public ContainerBeaconImpl(@NotNull EntityPlayer entityPlayer, @Nullable org.bukkit.inventory.ItemStack item) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.beaconField = ContainerBeacon.class.getDeclaredField("beacon"); - this.beaconField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - ItemStack itemStack = CraftItemStack.asNMSCopy(item); - - ((IInventory) beaconField.get(this)).setItem(0, itemStack); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryBeacon((IInventory) beaconField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/CartographyTableInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/CartographyTableInventoryImpl.java deleted file mode 100644 index fef838730..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/CartographyTableInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.util.TextHolderUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryCartography; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal cartography table inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class CartographyTableInventoryImpl extends CartographyTableInventory { - - public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a cartography table should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( - entityPlayer, items - ); - - entityPlayer.activeContainer = containerCartographyTable; - - int id = containerCartographyTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container cartography table - * - * @since 0.8.0 - */ - private class ContainerCartographyTableImpl extends ContainerCartography { - - /** - * The player for this cartography table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container cartography table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerCartographyTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerCartography.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryCartography(super.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/EnchantingTableInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/EnchantingTableInventoryImpl.java deleted file mode 100644 index 611a64ab5..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/EnchantingTableInventoryImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.util.TextHolderUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryEnchanting; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal enchanting table inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class EnchantingTableInventoryImpl extends EnchantingTableInventory { - - public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for an enchanting table should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerEnchantingTableImpl extends ContainerEnchantTable { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the enchant slots field - */ - @NotNull - private final Field enchantSlotsField; - - public ContainerEnchantingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.enchantSlotsField = ContainerEnchantTable.class.getDeclaredField("enchantSlots"); - this.enchantSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - try { - IInventory input = (IInventory) enchantSlotsField.get(this); - - input.setItem(0, CraftItemStack.asNMSCopy(items[0])); - input.setItem(1, CraftItemStack.asNMSCopy(items[1])); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - try { - CraftInventory inventory = new CraftInventoryEnchanting((IInventory) enchantSlotsField.get(this)) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } catch (IllegalAccessException exception) { - exception.printStackTrace(); - } - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java deleted file mode 100644 index 0ce518a25..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.util.TextHolderUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Internal grindstone inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - //ignore deprecation: superseding method is only available on Paper - //noinspection deprecation - CraftEventFactory.handleInventoryCloseEvent(entityPlayer); - - entityPlayer.activeContainer = entityPlayer.defaultContainer; - - IChatBaseComponent message = TextHolderUtil.toComponent(title); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); - - Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - - inventory.setItem(0, items[0]); - inventory.setItem(1, items[1]); - inventory.setItem(2, items[2]); - - int windowId = containerGrindstone.getWindowId(); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, Containers.GRINDSTONE, message)); - entityPlayer.activeContainer = containerGrindstone; - entityPlayer.syncInventory(); - - return inventory; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container grindstone - * - * @since 0.8.0 - */ - private static class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * A unique item - */ - @NotNull - private final ItemStack uniqueItem; - - /** - * The field containing the listeners for this container - */ - @NotNull - private final Field listenersField; - - /** - * Creates a new grindstone container - * - * @param entityPlayer the player for whom this container should be opened - * @since 0.10.8 - */ - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - try { - this.listenersField = Container.class.getDeclaredField("listeners"); - this.listenersField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - Slot firstSlot = this.slots.get(0); - Slot secondSlot = this.slots.get(1); - Slot thirdSlot = this.slots.get(2); - - this.slots.set(0, new Slot(firstSlot.inventory, firstSlot.rawSlotIndex, firstSlot.e, firstSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(1, new Slot(secondSlot.inventory, secondSlot.rawSlotIndex, secondSlot.e, secondSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - }); - - this.slots.set(2, new Slot(thirdSlot.inventory, thirdSlot.rawSlotIndex, thirdSlot.e, thirdSlot.f) { - @Override - public boolean isAllowed(ItemStack stack) { - return true; - } - - @Override - public ItemStack a(EntityHuman entityHuman, ItemStack itemStack) { - return itemStack; - } - }); - - this.uniqueItem = new ItemStack(Items.COOKIE); - - //to make the item unique, we add a random uuid as nbt to it - UUID uuid = UUID.randomUUID(); - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - - nbtTagCompound.set("uuid", new NBTTagLongArray(new long [] { - uuid.getLeastSignificantBits(), - uuid.getMostSignificantBits() - })); - - this.uniqueItem.setTag(nbtTagCompound); - } - - /** - * Forcefully updates the client state, sending all items, container properties and the held item. - * - * @since 0.10.8 - */ - public void forceUpdate() { - /* - The server will not send the items when they haven't changed, so we will overwrite every item with a unique - item first to ensure the server is going to send our items. - */ - Collections.fill(this.items, this.uniqueItem); - - notifyListeners(); - - List listeners; - - try { - //noinspection unchecked - listeners = (List) listenersField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException("Unable to access field 'listeners'", exception); - } - - for (ICrafting listener : listeners) { - if (!(listener instanceof EntityPlayer)) { - continue; - } - - EntityPlayer player = (EntityPlayer) listener; - - player.e = false; - player.broadcastCarriedItem(); - } - } - - @Override - public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { - ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - - //the client predicts the allowed movement of the item, so we broadcast the state again to override it - forceUpdate(); - - return itemStack; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityHuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityHuman) {} - - public int getWindowId() { - return this.windowId; - } - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/MerchantInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/MerchantInventoryImpl.java deleted file mode 100644 index 1f48e76d2..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/MerchantInventoryImpl.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; -import net.minecraft.server.v1_16_R3.EntityPlayer; -import net.minecraft.server.v1_16_R3.MerchantRecipeList; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Map; - -/** - * Internal merchant inventory for 1.16.4 - 1.16.5 - * - * @since 0.10.1 - */ -public class MerchantInventoryImpl extends MerchantInventory { - - @Override - public void sendMerchantOffers(@NotNull Player player, - @NotNull List> trades, - int level, int experience) { - MerchantRecipeList offers = new MerchantRecipeList(); - - for (Map.Entry entry : trades) { - MerchantRecipe recipe = entry.getKey(); - List ingredients = recipe.getIngredients(); - - if (ingredients.size() < 1) { - throw new IllegalStateException("Merchant recipe has no ingredients"); - } - - ItemStack itemA = ingredients.get(0); - ItemStack itemB = null; - - if (ingredients.size() >= 2) { - itemB = ingredients.get(1); - } - - net.minecraft.server.v1_16_R3.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); - net.minecraft.server.v1_16_R3.ItemStack nmsItemB = net.minecraft.server.v1_16_R3.ItemStack.b; - net.minecraft.server.v1_16_R3.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); - - if (itemB != null) { - nmsItemB = CraftItemStack.asNMSCopy(itemB); - } - - int uses = recipe.getUses(); - int maxUses = recipe.getMaxUses(); - int exp = recipe.getVillagerExperience(); - float multiplier = recipe.getPriceMultiplier(); - - net.minecraft.server.v1_16_R3.MerchantRecipe merchantOffer = new net.minecraft.server.v1_16_R3.MerchantRecipe( - nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier - ); - merchantOffer.setSpecialPrice(entry.getValue()); - - offers.add(merchantOffer); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - - entityPlayer.openTrade(getWindowId(entityPlayer), offers, level, experience, true, false); - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.10.1 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.10.1 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/SmithingTableInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/SmithingTableInventoryImpl.java deleted file mode 100644 index a1d178405..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/SmithingTableInventoryImpl.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.util.TextHolderUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventorySmithing; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Internal smithing table inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class SmithingTableInventoryImpl extends SmithingTableInventory { - - public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Nullable - @Override - public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 3) { - throw new IllegalArgumentException( - "The amount of items for a smithing table should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerSmithingTable; - - int id = containerSmithingTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items, null); - - return null; - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, - @Nullable org.bukkit.inventory.ItemStack cursor) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]), - CraftItemStack.asNMSCopy(items[2]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 0, nmsItem)); - } - - @Override - public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - ItemStack nmsItem = CraftItemStack.asNMSCopy(item); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 1, nmsItem)); - } - - @Override - public void sendResultItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { - sendResultItem(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearResultItem(@NotNull Player player) { - sendResultItem(player, ItemStack.b); - } - - @Override - public void setCursor(@NotNull Player player, @NotNull org.bukkit.inventory.ItemStack item) { - setCursor(player, CraftItemStack.asNMSCopy(item)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Sets the cursor of the given player - * - * @param player the player to set the cursor - * @param item the item to set the cursor to - * @since 0.8.0 - */ - private void setCursor(@NotNull Player player, @NotNull ItemStack item) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, item)); - } - - /** - * Sends the result item to the specified player with the given item - * - * @param player the player to send the result item to - * @param item the result item - * @since 0.8.0 - */ - private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutSetSlot(getWindowId(entityPlayer), 2, item)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container smithing table - * - * @since 0.8.0 - */ - private class ContainerSmithingTableImpl extends ContainerSmithing { - - /** - * The player for this smithing table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container smithing table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - public ContainerSmithingTableImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - - this.player = entityPlayer.getBukkitEntity(); - - repairInventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - repairInventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultInventory.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventorySmithing(containerAccess.getLocation(), repairInventory, - resultInventory) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/StonecutterInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/StonecutterInventoryImpl.java deleted file mode 100644 index 0d44d97c9..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/StonecutterInventoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.util.TextHolderUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryStonecutter; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -/** - * Internal stonecutter inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class StonecutterInventoryImpl extends StonecutterInventory { - - public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { - super(inventoryHolder); - } - - @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { - int itemAmount = items.length; - - if (itemAmount != 2) { - throw new IllegalArgumentException( - "The amount of items for a stonecutter should be 2, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerEnchantmentTable; - - int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); - - entityPlayer.playerConnection.sendPacket(packet); - - sendItems(player, items); - } - - @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { - NonNullList nmsItems = NonNullList.a( - ItemStack.b, - CraftItemStack.asNMSCopy(items[0]), - CraftItemStack.asNMSCopy(items[1]) - ); - - EntityPlayer entityPlayer = getEntityPlayer(player); - - getPlayerConnection(entityPlayer).sendPacket(new PacketPlayOutWindowItems(getWindowId(entityPlayer), nmsItems)); - } - - @Override - public void clearCursor(@NotNull Player player) { - getPlayerConnection(getEntityPlayer(player)).sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.b)); - } - - /** - * Gets the window id for the inventory view the player currently has open - * - * @param entityPlayer the player to get the window id for - * @return the window id - * @since 0.8.0 - */ - @Contract(pure = true) - private int getWindowId(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.activeContainer.windowId; - } - - /** - * Gets the player connection for the specified player - * - * @param entityPlayer the player to get the player connection from - * @return the player connection - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private PlayerConnection getPlayerConnection(@NotNull EntityPlayer entityPlayer) { - return entityPlayer.playerConnection; - } - - /** - * Gets the entity player associated to this player - * - * @param player the player to get the entity player from - * @return the entity player - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } - - /** - * A custom container enchanting table - * - * @since 0.8.0 - */ - private class ContainerStonecutterImpl extends ContainerStonecutter { - - /** - * The player for this enchanting table container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container enchanting table - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerStonecutterImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.resultInventoryField = ContainerStonecutter.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - inventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[1])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryStonecutter(this.inventory, getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Contract(pure = true, value = "_ -> true") - @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } - - @Override - public void a(IInventory inventory) {} - - @Override - public void b(EntityHuman entityhuman) {} - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - public IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} diff --git a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/util/TextHolderUtil.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/util/TextHolderUtil.java deleted file mode 100644 index 506d10d9b..000000000 --- a/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/util/TextHolderUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.util; - -import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import net.minecraft.server.v1_16_R3.ChatComponentText; -import net.minecraft.server.v1_16_R3.IChatBaseComponent; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -/** - * A utility class for adding {@link TextHolder} support. - * - * @since 0.10.0 - */ -public final class TextHolderUtil { - - private TextHolderUtil() { - //private constructor to prevent construction - } - - /** - * Converts the specified value to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { - if (holder instanceof StringHolder) { - return toComponent((StringHolder) holder); - } else { - return toComponent((ComponentHolder) holder); - } - } - - /** - * Converts the specified legacy string holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { - return new ChatComponentText(holder.asLegacyString()); - } - - /** - * Converts the specified Adventure component holder to a vanilla component. - * - * @param holder the value to convert - * @return the value as a vanilla component - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { - return Objects.requireNonNull(IChatBaseComponent.ChatSerializer.a(holder.asJson())); - } -} diff --git a/pom.xml b/pom.xml index bb812af0e..8a88e9721 100644 --- a/pom.xml +++ b/pom.xml @@ -27,11 +27,6 @@ nms/1_18_0 nms/1_17_1 nms/1_17_0 - nms/1_16_4-5 - nms/1_16_2-3 - nms/1_16_1 - nms/1_15 - nms/1_14 adventure-support inventory-view/iv-abstract-class inventory-view/iv-abstraction @@ -39,8 +34,8 @@ - 1.8 - 1.8 + 17 + 17 true UTF-8 4.18.0 From 44e492481c5409ace2cb56428f22f5b156b71604 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 16:56:29 +0100 Subject: [PATCH 15/20] add github packages deployment --- .github/deployment/settings.xml | 5 +++++ .github/workflows/github-packages.yml | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/deployment/settings.xml b/.github/deployment/settings.xml index 6f1a37206..09f7a17fe 100644 --- a/.github/deployment/settings.xml +++ b/.github/deployment/settings.xml @@ -5,5 +5,10 @@ ${deploy.username} ${deploy.password} + + github + ${env.GITHUB_ACTOR} + ${env.GITHUB_TOKEN} + \ No newline at end of file diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml index 0e9ecdcf4..ccf1cdc80 100644 --- a/.github/workflows/github-packages.yml +++ b/.github/workflows/github-packages.yml @@ -103,6 +103,6 @@ jobs: java -jar BuildTools.jar --rev 1.21.4 --remapped --disable-java-check cd ../ - - name: Install package + - name: Deploy to GitHub Packages run: | - mvn install \ No newline at end of file + mvn deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/$GITHUB_REPOSITORY \ No newline at end of file From 1e5fd9b5c00a9ad90a454e5e5a01eff2547a602c Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 17:08:32 +0100 Subject: [PATCH 16/20] add github packages deployment --- .github/workflows/github-packages.yml | 2 +- pom.xml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-packages.yml b/.github/workflows/github-packages.yml index ccf1cdc80..857515704 100644 --- a/.github/workflows/github-packages.yml +++ b/.github/workflows/github-packages.yml @@ -105,4 +105,4 @@ jobs: cd ../ - name: Deploy to GitHub Packages run: | - mvn deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/$GITHUB_REPOSITORY \ No newline at end of file + mvn deploy -P github-deploy -DgithubDeploy=true -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/$GITHUB_REPOSITORY \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8a88e9721..84878346e 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,21 @@ + + github-deploy + + + githubDeploy + true + + + + + github + https://maven.pkg.github.com/${env.GITHUB_REPOSITORY} + + + From ae1cbd352538b561acb9084b79d11d67d63ae6cd Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 17:12:13 +0100 Subject: [PATCH 17/20] fix deploy --- pom.xml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 84878346e..cef296c3a 100644 --- a/pom.xml +++ b/pom.xml @@ -78,17 +78,6 @@ - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - deploy @@ -110,6 +99,16 @@
+ + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + github-deploy From 03ab962720e1ab864adbf0bb5d67d203bdd657c9 Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 17:14:58 +0100 Subject: [PATCH 18/20] fix deploy --- IF/pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index f4e67e135..46e5e567c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -277,17 +277,6 @@
- - org.sonatype.plugins - nexus-staging-maven-plugin - 1.7.0 - true - - ossrh - https://oss.sonatype.org/ - true - - org.apache.maven.plugins maven-source-plugin From 104a18741501ab634bfe7088c64d45a225e53beb Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Wed, 5 Mar 2025 17:17:53 +0100 Subject: [PATCH 19/20] fix deploy --- pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pom.xml b/pom.xml index cef296c3a..9e41e0fb6 100644 --- a/pom.xml +++ b/pom.xml @@ -146,17 +146,6 @@ - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.7.0 - true - - ossrh - https://oss.sonatype.org/ - true - - org.apache.maven.plugins maven-source-plugin From 5d2c9becc3eb8a9e0b6473458e1015ec573c9f1f Mon Sep 17 00:00:00 2001 From: Alberto Migliorato Date: Tue, 8 Apr 2025 00:57:44 +0200 Subject: [PATCH 20/20] fix --- IF/pom.xml | 96 +++++++++---------- .../inventoryframework/util/SkullUtil.java | 71 +++++++++----- README.md | 8 +- adventure-support/pom.xml | 6 +- inventory-view/iv-abstract-class/pom.xml | 8 +- inventory-view/iv-abstraction/pom.xml | 6 +- inventory-view/iv-interface/pom.xml | 8 +- nms/1_17_0/pom.xml | 8 +- nms/1_17_1/pom.xml | 8 +- nms/1_18_0/pom.xml | 8 +- nms/1_18_1/pom.xml | 8 +- nms/1_18_2/pom.xml | 8 +- nms/1_19_0/pom.xml | 8 +- nms/1_19_1/pom.xml | 8 +- nms/1_19_2/pom.xml | 8 +- nms/1_19_3/pom.xml | 8 +- nms/1_19_4/pom.xml | 8 +- nms/1_20_0/pom.xml | 8 +- nms/1_20_1/pom.xml | 8 +- nms/1_20_2/pom.xml | 8 +- nms/1_20_3-4/pom.xml | 8 +- nms/1_20_5/pom.xml | 8 +- nms/1_20_6/pom.xml | 8 +- nms/1_21_0/pom.xml | 8 +- nms/1_21_1/pom.xml | 8 +- nms/1_21_2-3/pom.xml | 8 +- nms/1_21_4/pom.xml | 8 +- nms/abstraction/pom.xml | 8 +- pom.xml | 14 +-- 29 files changed, 201 insertions(+), 184 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 46e5e567c..e394a5ceb 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -3,14 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../pom.xml 4.0.0 - IF + if jar @@ -36,162 +36,149 @@ provided - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_17_0 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_17_1 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_18_0 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_18_1 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_18_2 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_19_0 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_19_1 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_19_2 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_19_3 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_19_4 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_20_0 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_20_1 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_20_2 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_20_3-4 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_20_5 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_20_6 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_21_0 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_21_1 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_21_2-3 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio 1_21_4 ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio iv-abstraction ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio iv-abstract-class ${project.version} compile - com.github.stefvanschie.inventoryframework + com.github.albemiglio iv-interface ${project.version} compile - - org.spigotmc - spigot-api - 1.20.3-R0.1-SNAPSHOT - provided - - - - org.apache.commons - commons-lang3 - - - com.mojang authlib @@ -211,19 +198,14 @@ 5.11.4 test + + org.spigotmc + spigot-api + 1.21.4-R0.1-SNAPSHOT + compile + - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - deploy @@ -245,6 +227,16 @@ + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/SkullUtil.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/SkullUtil.java index 1537767dc..c62d2b8be 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/SkullUtil.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/SkullUtil.java @@ -1,16 +1,18 @@ package com.github.stefvanschie.inventoryframework.util; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; +import com.github.stefvanschie.inventoryframework.util.version.Version; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.profile.PlayerProfile; +import org.bukkit.profile.PlayerTextures; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Base64; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Objects; import java.util.UUID; @@ -21,6 +23,9 @@ */ public final class SkullUtil { + private static Field cachedProfileField; + private static Method cachedSetProfileMethod; + /** * A private constructor to ensure this class isn't instantiated * @@ -53,27 +58,47 @@ public static ItemStack getSkull(@NotNull String id) { * @param id the skull id */ public static void setSkull(@NotNull ItemMeta meta, @NotNull String id) { - GameProfile profile = new GameProfile(UUID.randomUUID(), ""); - byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", - "http://textures.minecraft.net/texture/" + id).getBytes()); - profile.getProperties().put("textures", new Property("textures", new String(encodedData))); - String itemDisplayName = meta.getDisplayName(); + Version ver = Version.getVersion(); + if (!(meta instanceof org.bukkit.inventory.meta.SkullMeta skullMeta)) { + throw new IllegalArgumentException("ItemMeta is not an instance of SkullMeta"); + } + if (ver.name().contains("1_20") || ver.name().contains("1_21")) { + final UUID uuid = UUID.randomUUID(); + final PlayerProfile playerProfile = Bukkit.getServer().createPlayerProfile(uuid, uuid.toString().substring(0, 16)); + PlayerTextures playerTextures = playerProfile.getTextures(); + try { + playerTextures.setSkin(new URL("http://textures.minecraft.net/texture/" + id)); + } + catch (MalformedURLException e) { + throw new IllegalArgumentException("Invalid URL for skin texture", e); + } + playerProfile.setTextures(playerTextures); + skullMeta.setOwnerProfile(playerProfile); + } + else { + com.mojang.authlib.GameProfile profile = new com.mojang.authlib.GameProfile(UUID.randomUUID(), ""); + byte[] encodedData = java.util.Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", + "http://textures.minecraft.net/texture/" + id).getBytes()); + profile.getProperties().put("textures", new com.mojang.authlib.properties.Property("textures", new String(encodedData))); + String itemDisplayName = skullMeta.getDisplayName(); - try { - Field profileField = meta.getClass().getDeclaredField("profile"); - profileField.setAccessible(true); - profileField.set(meta, profile); + try { + if (cachedProfileField == null) { + cachedProfileField = skullMeta.getClass().getDeclaredField("profile"); + cachedProfileField.setAccessible(true); + } + cachedProfileField.set(skullMeta, profile); - meta.setDisplayName(itemDisplayName); + meta.setDisplayName(itemDisplayName); - // Sets serializedProfile field on meta - // If it does throw NoSuchMethodException this stops, and meta is correct. - // Else it has profile and will set the field. - Method setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class); - setProfile.setAccessible(true); - setProfile.invoke(meta, profile); - } catch (NoSuchFieldException | SecurityException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } catch (NoSuchMethodException ignored) {} + if (cachedSetProfileMethod == null) { + cachedSetProfileMethod = skullMeta.getClass().getDeclaredMethod("setProfile", com.mojang.authlib.GameProfile.class); + cachedSetProfileMethod.setAccessible(true); + } + cachedSetProfileMethod.invoke(skullMeta, profile); + } catch (NoSuchFieldException | SecurityException | IllegalAccessException | java.lang.reflect.InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException ignored) {} + } } } diff --git a/README.md b/README.md index 8afee5596..e8f36c746 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ Next to those panes, GUIs can also be created from XML files by simple loading t To add this project as a dependency to your pom.xml, add the following to your pom.xml: ```XML - com.github.stefvanschie.inventoryframework - IF - 0.10.19 + com.github.albemiglio + if + 0.10.19-SNAPSHOT ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -29,7 +29,7 @@ Now in order to shade the project into your project, add the following to your p ${project.build.directory}/dependency-reduced-pom.xml - com.github.stefvanschie.inventoryframework + com.github.albemiglio [YOUR PACKAGE].inventoryframework diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index ae7464066..3ba6bb398 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT 4.0.0 diff --git a/inventory-view/iv-abstract-class/pom.xml b/inventory-view/iv-abstract-class/pom.xml index 5c511c882..a4e929ad3 100644 --- a/inventory-view/iv-abstract-class/pom.xml +++ b/inventory-view/iv-abstract-class/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -25,7 +25,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio iv-abstraction ${project.version} diff --git a/inventory-view/iv-abstraction/pom.xml b/inventory-view/iv-abstraction/pom.xml index d91f87dba..3dcf78520 100644 --- a/inventory-view/iv-abstraction/pom.xml +++ b/inventory-view/iv-abstraction/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml diff --git a/inventory-view/iv-interface/pom.xml b/inventory-view/iv-interface/pom.xml index a9dd991b9..0a5dda995 100644 --- a/inventory-view/iv-interface/pom.xml +++ b/inventory-view/iv-interface/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -25,7 +25,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio iv-abstraction ${project.version} diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index e9dd146e7..3cf576e1f 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 976547ad3..d09e4c056 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 499898fd2..87831e9e2 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index c90d01e94..38196577b 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 1c900e61a..9d30d662e 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 98d7e93c4..988ca319d 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index d2b0378d2..bbf31c9ef 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 18c701d5f..a6a36eac9 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index c5358b10d..cec28ddab 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index fbf4d9c6d..5405081f0 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index ed3988abd..580c66785 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 74bf47f8b..f4ff1c0f1 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index cdc56995f..f759e7c99 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 24bda8dd8..11d3ad597 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 2312420bf..0895b4d7e 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index aad5a6759..86efdd9e9 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_21_0/pom.xml b/nms/1_21_0/pom.xml index 3d41fff12..f647d89de 100644 --- a/nms/1_21_0/pom.xml +++ b/nms/1_21_0/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_21_1/pom.xml b/nms/1_21_1/pom.xml index 3143338e1..5ab81c91c 100644 --- a/nms/1_21_1/pom.xml +++ b/nms/1_21_1/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_21_2-3/pom.xml b/nms/1_21_2-3/pom.xml index 037a7fc18..da7378eb9 100644 --- a/nms/1_21_2-3/pom.xml +++ b/nms/1_21_2-3/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/1_21_4/pom.xml b/nms/1_21_4/pom.xml index 1faa7e5d7..2a658f43d 100644 --- a/nms/1_21_4/pom.xml +++ b/nms/1_21_4/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT ../../pom.xml @@ -18,7 +18,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio abstraction ${project.version} compile diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index bc169a5fe..c1bcd3b27 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - IF-parent - com.github.stefvanschie.inventoryframework - 0.10.19 + if-parent + com.github.albemiglio + 0.10.19-SNAPSHOT ../../pom.xml 4.0.0 @@ -25,7 +25,7 @@ - com.github.stefvanschie.inventoryframework + com.github.albemiglio adventure-support ${project.version} compile diff --git a/pom.xml b/pom.xml index 9e41e0fb6..65f759c0a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 - IF + if nms/abstraction nms/1_21_4 nms/1_21_2-3 @@ -41,14 +41,14 @@ 4.18.0 - com.github.stefvanschie.inventoryframework - IF-parent - 0.10.19 + com.github.albemiglio + if-parent + 0.10.19-SNAPSHOT pom - IF + if An inventory framework for managing GUIs - https://github.com/stefvanschie/IF + https://github.com/albemiglio/IF @@ -59,7 +59,7 @@ - https://github.com/stefvanschie/IF.git + https://github.com/albemiglio/IF.git