From c579c47d049cd50545ccfa483856db619d38e3f5 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 17 Jun 2021 20:53:03 +0200 Subject: [PATCH 001/382] Add 1.17 R1 support --- .github/workflows/maven.yml | 1 + IF/pom.xml | 6 + .../util/version/Version.java | 11 +- .../util/version/VersionMatcher.java | 14 + nms/1_17_R1/pom.xml | 72 +++++ .../nms/v1_17_R1/AnvilInventoryImpl.java | 254 ++++++++++++++++++ .../nms/v1_17_R1/BeaconInventoryImpl.java | 195 ++++++++++++++ .../CartographyTableInventoryImpl.java | 207 ++++++++++++++ .../EnchantingTableInventoryImpl.java | 207 ++++++++++++++ .../nms/v1_17_R1/GrindstoneInventoryImpl.java | 236 ++++++++++++++++ .../v1_17_R1/SmithingTableInventoryImpl.java | 238 ++++++++++++++++ .../v1_17_R1/StonecutterInventoryImpl.java | 213 +++++++++++++++ .../v1_17_R1/util/CustomInventoryUtil.java | 41 +++ pom.xml | 1 + 14 files changed, 1695 insertions(+), 1 deletion(-) create mode 100644 nms/1_17_R1/pom.xml create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/BeaconInventoryImpl.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/CustomInventoryUtil.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9df069e74..44f0a0d59 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,6 +23,7 @@ jobs: java -jar BuildTools.jar --rev 1.16.1 java -jar BuildTools.jar --rev 1.16.3 java -jar BuildTools.jar --rev 1.16.4 + java -jar BuildTools.jar --rev 1.17 --remapped - uses: actions/checkout@v2 - name: Set up JDK 1.8 uses: actions/setup-java@v1 diff --git a/IF/pom.xml b/IF/pom.xml index 90d71667b..836007380 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -64,6 +64,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_17_R1 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index aa2a2edca..8b6dc2e89 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -45,7 +45,14 @@ public enum Version { * * @since 0.8.0 */ - V1_16_R3; + V1_16_R3, + + /** + * Version 1.17 R1 + * + * @since 0.9.9 + */ + V1_17_R1; /** * Gets the version currently being used. If the used version is not supported, an @@ -70,6 +77,8 @@ public static Version getVersion() { return V1_16_R2; case "v1_16_R3": return V1_16_R3; + case "v1_17_R1": + return V1_17_R1; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 c4f108e10..3e73d81d0 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 @@ -219,6 +219,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_16_R2.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_16_R3, com.github.stefvanschie.inventoryframework.nms.v1_16_R3.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_17_R1, + com.github.stefvanschie.inventoryframework.nms.v1_17_R1.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14_R1, @@ -231,6 +233,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_16_R2.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_16_R3, com.github.stefvanschie.inventoryframework.nms.v1_16_R3.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_17_R1, + com.github.stefvanschie.inventoryframework.nms.v1_17_R1.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14_R1, @@ -243,6 +247,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_16_R2.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_16_R3, com.github.stefvanschie.inventoryframework.nms.v1_16_R3.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_17_R1, + com.github.stefvanschie.inventoryframework.nms.v1_17_R1.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14_R1, @@ -255,6 +261,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_16_R2.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_16_R3, com.github.stefvanschie.inventoryframework.nms.v1_16_R3.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_17_R1, + com.github.stefvanschie.inventoryframework.nms.v1_17_R1.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14_R1, @@ -267,6 +275,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_16_R2.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_16_R3, com.github.stefvanschie.inventoryframework.nms.v1_16_R3.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_17_R1, + com.github.stefvanschie.inventoryframework.nms.v1_17_R1.GrindstoneInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_R1, @@ -275,6 +285,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_16_R2.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_R3, com.github.stefvanschie.inventoryframework.nms.v1_16_R3.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_17_R1, + com.github.stefvanschie.inventoryframework.nms.v1_17_R1.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14_R1, @@ -287,5 +299,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_16_R2.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_16_R3, com.github.stefvanschie.inventoryframework.nms.v1_16_R3.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_17_R1, + com.github.stefvanschie.inventoryframework.nms.v1_17_R1.StonecutterInventoryImpl.class); } } diff --git a/nms/1_17_R1/pom.xml b/nms/1_17_R1/pom.xml new file mode 100644 index 000000000..04aa027b1 --- /dev/null +++ b/nms/1_17_R1/pom.xml @@ -0,0 +1,72 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.9.8 + ../../pom.xml + + 4.0.0 + + 1_17_R1 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.17-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + \ No newline at end of file diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java new file mode 100644 index 000000000..3a34dd4aa --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java @@ -0,0 +1,254 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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; + +/** + * Internal anvil inventory for 1.17 R1 + * + * @since 0.9.9 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @Override + public void openInventory(@NotNull Player player, @NotNull String 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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + TranslatableComponent message = new TranslatableComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetContentPacket(containerId, nmsItems)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, 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.EMPTY); + } + + @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) { + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY); + + getPlayerConnection(getServerPlayer(player)).send(packet); + } + + /** + * 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.9.9 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + getPlayerConnection(getServerPlayer(player)).send(new ClientboundContainerSetSlotPacket(-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.9.9 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.9.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.9.9 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.9.9 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/BeaconInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/BeaconInventoryImpl.java new file mode 100644 index 000000000..c27673e21 --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/BeaconInventoryImpl.java @@ -0,0 +1,195 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.9.9 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + TranslatableComponent message = new TranslatableComponent("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, message)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetContentPacket(containerId, items)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY); + + getPlayerConnection(getServerPlayer(player)).send(packet); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.9.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.9.9 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..7b4d02f81 --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java @@ -0,0 +1,207 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.9.9 + */ +public class CartographyTableInventoryImpl extends CartographyTableInventory { + + public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @Override + public void openInventory(@NotNull Player player, @NotNull String 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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + TranslatableComponent message = new TranslatableComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetContentPacket(containerId, nmsItems)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY); + + getPlayerConnection(getServerPlayer(player)).send(packet); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.9.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.9.9 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..af442d93f --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java @@ -0,0 +1,207 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.9.9 + */ +public class EnchantingTableInventoryImpl extends EnchantingTableInventory { + + public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @Override + public void openInventory(@NotNull Player player, @NotNull String 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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + TranslatableComponent message = new TranslatableComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetContentPacket(containerId, nmsItems)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY); + + getPlayerConnection(getServerPlayer(player)).send(packet); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.9.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.9.9 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..2291d9621 --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java @@ -0,0 +1,236 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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 grindstone inventory for 1.17 R1 + * + * @since 0.9.9 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @Override + public void openInventory(@NotNull Player player, @NotNull String 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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + TranslatableComponent message = new TranslatableComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetContentPacket(containerId, nmsItems)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY); + + getPlayerConnection(getServerPlayer(player)).send(packet); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.9.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.9.9 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..4836fc3bd --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java @@ -0,0 +1,238 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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; + +/** + * Internal smithing table inventory for 1.17 R1 + * + * @since 0.9.9 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @Override + public void openInventory(@NotNull Player player, @NotNull String 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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + TranslatableComponent message = new TranslatableComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetContentPacket(containerId, nmsItems)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, 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.EMPTY); + } + + @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) { + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY); + + getPlayerConnection(getServerPlayer(player)).send(packet); + } + + /** + * 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.9.9 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + getPlayerConnection(getServerPlayer(player)).send(new ClientboundContainerSetSlotPacket(-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.9.9 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.9.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.9.9 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java new file mode 100644 index 000000000..c3823e4dc --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.9.9 + */ +public class StonecutterInventoryImpl extends StonecutterInventory { + + public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @Override + public void openInventory(@NotNull Player player, @NotNull String 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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + TranslatableComponent message = new TranslatableComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetContentPacket(containerId, nmsItems)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ClientboundContainerSetSlotPacket packet = new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY); + + getPlayerConnection(getServerPlayer(player)).send(packet); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.9.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.9.9 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/CustomInventoryUtil.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/CustomInventoryUtil.java new file mode 100644 index 000000000..989764a67 --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.9.9 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.9.9 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/pom.xml b/pom.xml index 37b63b40e..9674a7b07 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_17_R1 nms/1_16_R3 nms/1_16_R2 nms/1_16_R1 From cf4ebbfa4bfe4e2b757cf5e5b95989c10aa65480 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 17 Jun 2021 21:13:03 +0200 Subject: [PATCH 002/382] Update GitHub actions to Java 16 --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 44f0a0d59..7c3ab5146 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,9 +25,9 @@ jobs: java -jar BuildTools.jar --rev 1.16.4 java -jar BuildTools.jar --rev 1.17 --remapped - uses: actions/checkout@v2 - - name: Set up JDK 1.8 + - name: Set up JDK 16 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 16 - name: Build with Maven run: mvn -B package --file pom.xml From 91c3c6b8622747d9b3dd787af7bc1e129ce99d6f Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 17 Jun 2021 21:30:55 +0200 Subject: [PATCH 003/382] Use Java 16 for everything --- .github/workflows/maven.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7c3ab5146..dda61dd1a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,6 +16,10 @@ jobs: runs-on: ubuntu-latest name: 'Build' steps: + - name: Set up JDK 16 + uses: actions/setup-java@v1 + with: + java-version: 16 - run: | wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar java -jar BuildTools.jar --rev 1.14.4 @@ -24,10 +28,8 @@ jobs: java -jar BuildTools.jar --rev 1.16.3 java -jar BuildTools.jar --rev 1.16.4 java -jar BuildTools.jar --rev 1.17 --remapped + name: Run BuildTools - uses: actions/checkout@v2 - - name: Set up JDK 16 - uses: actions/setup-java@v1 - with: - java-version: 16 + name: Checkout code - name: Build with Maven run: mvn -B package --file pom.xml From 4bdc80cf60faa8b1d5c4050e7a25ecf103214333 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 18 Jun 2021 20:30:20 +0200 Subject: [PATCH 004/382] Disable Java check for BuildTools Blame this if some future Java version breaks old BuildTools versions and this all breaks. --- .github/workflows/maven.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index dda61dd1a..4e25f3e28 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -22,12 +22,12 @@ jobs: java-version: 16 - run: | wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar - java -jar BuildTools.jar --rev 1.14.4 - java -jar BuildTools.jar --rev 1.15.2 - java -jar BuildTools.jar --rev 1.16.1 - java -jar BuildTools.jar --rev 1.16.3 - java -jar BuildTools.jar --rev 1.16.4 - java -jar BuildTools.jar --rev 1.17 --remapped + java -jar BuildTools.jar --rev 1.14.4 --disable-java-check + java -jar BuildTools.jar --rev 1.15.2 --disable-java-check + java -jar BuildTools.jar --rev 1.16.1 --disable-java-check + java -jar BuildTools.jar --rev 1.16.3 --disable-java-check + java -jar BuildTools.jar --rev 1.16.4 --disable-java-check + java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check name: Run BuildTools - uses: actions/checkout@v2 name: Checkout code From 4bdd09b29d9eb3775b8ef2fc7e61c8dfa2e33657 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 18 Jun 2021 20:35:30 +0200 Subject: [PATCH 005/382] Only use Java 16 for 1.17 Now I can blame the previous commit. --- .github/workflows/maven.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4e25f3e28..650debaa3 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,10 +16,10 @@ jobs: runs-on: ubuntu-latest name: 'Build' steps: - - name: Set up JDK 16 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 16 + java-version: 11 - run: | wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar java -jar BuildTools.jar --rev 1.14.4 --disable-java-check @@ -27,8 +27,15 @@ jobs: java -jar BuildTools.jar --rev 1.16.1 --disable-java-check java -jar BuildTools.jar --rev 1.16.3 --disable-java-check java -jar BuildTools.jar --rev 1.16.4 --disable-java-check + name: Run BuildTools 1.14 - 1.16 + - name: Set up JDK 16 + uses: actions/setup-java@v1 + with: + java-version: 16 + - run: | + wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check - name: Run BuildTools + name: Run BuildTools 1.17 - uses: actions/checkout@v2 name: Checkout code - name: Build with Maven From c28014c3843e80c448e5efc0b2fcec49b15149b9 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 22 Jun 2021 20:22:12 +0200 Subject: [PATCH 006/382] Retain cursor between updates --- .../inventoryframework/gui/type/util/Gui.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 028857291..23e3c9333 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 @@ -9,6 +9,7 @@ import com.github.stefvanschie.inventoryframework.util.XMLUtil; import org.apache.commons.lang3.reflect.MethodUtils; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; @@ -16,6 +17,7 @@ import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; @@ -227,7 +229,14 @@ public List getViewers() { public void update() { updating = true; - getViewers().forEach(this::show); + for (HumanEntity viewer : getViewers()) { + ItemStack cursor = viewer.getItemOnCursor(); + viewer.setItemOnCursor(new ItemStack(Material.AIR)); + + show(viewer); + + viewer.setItemOnCursor(cursor); + } if (!updating) throw new AssertionError("Gui#isUpdating became false before Gui#update finished"); From 9b18dcbecb14130067f24c7dcef1635ed473c968 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 22 Jun 2021 20:31:31 +0200 Subject: [PATCH 007/382] V 0.9.9 --- IF/pom.xml | 2 +- README.md | 13 ++++++++++--- nms/1_14_R1/pom.xml | 2 +- nms/1_15_R1/pom.xml | 2 +- nms/1_16_R1/pom.xml | 2 +- nms/1_16_R2/pom.xml | 2 +- nms/1_16_R3/pom.xml | 2 +- nms/1_17_R1/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 19 insertions(+), 12 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 836007380..8b1a5fc41 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 4.0.0 diff --git a/README.md b/README.md index a6d6353e1..f07c855c5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IF Discord guild -*This framework works for Minecraft versions 1.14-1.16* +*This framework works for Minecraft versions 1.14-1.17* An inventory framework for managing GUIs @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.9.8 + 0.9.9 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.9.8' + compile 'com.github.stefvanschie.inventoryframework:IF:0.9.9' // ... } ``` @@ -72,6 +72,13 @@ shadowJar { } ``` +## Dependency via plugin.yml +You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. +```yaml +libraries: + - com.github.stefvanschie.inventoryframework:IF:0.9.9 +``` + ## Building from source If you want to build this project from source, run the following from Git Bash: diff --git a/nms/1_14_R1/pom.xml b/nms/1_14_R1/pom.xml index 6dbcde799..39052d32a 100644 --- a/nms/1_14_R1/pom.xml +++ b/nms/1_14_R1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 ../../pom.xml 4.0.0 diff --git a/nms/1_15_R1/pom.xml b/nms/1_15_R1/pom.xml index 8cbdc5417..cf07729fa 100644 --- a/nms/1_15_R1/pom.xml +++ b/nms/1_15_R1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 ../../pom.xml 4.0.0 diff --git a/nms/1_16_R1/pom.xml b/nms/1_16_R1/pom.xml index 47e02eab6..5b1cb1019 100644 --- a/nms/1_16_R1/pom.xml +++ b/nms/1_16_R1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 ../../pom.xml 4.0.0 diff --git a/nms/1_16_R2/pom.xml b/nms/1_16_R2/pom.xml index f630a7f1e..3735b0c25 100644 --- a/nms/1_16_R2/pom.xml +++ b/nms/1_16_R2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 ../../pom.xml 4.0.0 diff --git a/nms/1_16_R3/pom.xml b/nms/1_16_R3/pom.xml index 5ddb316fd..323764041 100644 --- a/nms/1_16_R3/pom.xml +++ b/nms/1_16_R3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 ../../pom.xml 4.0.0 diff --git a/nms/1_17_R1/pom.xml b/nms/1_17_R1/pom.xml index 04aa027b1..3b81a46fe 100644 --- a/nms/1_17_R1/pom.xml +++ b/nms/1_17_R1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index e0566382b..68d709a80 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.8 + 0.9.9 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 9674a7b07..85ad9693d 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.9.8 + 0.9.9 pom IF From 7ae366f67e90c81db7e08622ef984ef2133f3b8e Mon Sep 17 00:00:00 2001 From: Trigary Date: Thu, 24 Jun 2021 12:27:34 +0200 Subject: [PATCH 008/382] adventure support (initial attempt) --- .editorconfig | 2 + IF/pom.xml | 6 + .../inventoryframework/gui/type/AnvilGui.java | 10 +- .../gui/type/BarrelGui.java | 10 +- .../gui/type/BeaconGui.java | 2 +- .../gui/type/BlastFurnaceGui.java | 10 +- .../gui/type/BrewingStandGui.java | 10 +- .../gui/type/CartographyTableGui.java | 9 +- .../inventoryframework/gui/type/ChestGui.java | 19 ++- .../gui/type/CraftingTableGui.java | 10 +- .../gui/type/DispenserGui.java | 10 +- .../gui/type/DropperGui.java | 10 +- .../gui/type/EnchantingTableGui.java | 10 +- .../gui/type/EnderChestGui.java | 10 +- .../gui/type/FurnaceGui.java | 10 +- .../gui/type/GrindstoneGui.java | 10 +- .../gui/type/HopperGui.java | 10 +- .../gui/type/ShulkerBoxGui.java | 10 +- .../gui/type/SmithingTableGui.java | 10 +- .../gui/type/SmokerGui.java | 10 +- .../gui/type/StonecutterGui.java | 10 +- .../inventoryframework/gui/type/util/Gui.java | 4 +- .../gui/type/util/NamedGui.java | 64 +++++----- .../inventoryframework/pane/Pane.java | 12 +- README.md | 8 ++ adventure-support/pom.xml | 39 +++++++ .../adventuresupport/ComponentHolder.java | 99 ++++++++++++++++ .../adventuresupport/StringHolder.java | 110 ++++++++++++++++++ .../adventuresupport/TextHolder.java | 90 ++++++++++++++ .../nms/v1_14_R1/AnvilInventoryImpl.java | 6 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 6 +- .../nms/v1_14_R1/GrindstoneInventoryImpl.java | 6 +- .../v1_14_R1/StonecutterInventoryImpl.java | 6 +- .../v1_14_R1/util/AdventureSupportUtil.java | 40 +++++++ .../nms/v1_15_R1/AnvilInventoryImpl.java | 6 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 6 +- .../nms/v1_15_R1/GrindstoneInventoryImpl.java | 6 +- .../v1_15_R1/StonecutterInventoryImpl.java | 6 +- .../v1_15_R1/util/AdventureSupportUtil.java | 40 +++++++ .../nms/v1_16_R1/AnvilInventoryImpl.java | 6 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 6 +- .../nms/v1_16_R1/GrindstoneInventoryImpl.java | 6 +- .../v1_16_R1/SmithingTableInventoryImpl.java | 6 +- .../v1_16_R1/StonecutterInventoryImpl.java | 6 +- .../v1_16_R1/util/AdventureSupportUtil.java | 40 +++++++ .../nms/v1_16_R2/AnvilInventoryImpl.java | 6 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 6 +- .../nms/v1_16_R2/GrindstoneInventoryImpl.java | 6 +- .../v1_16_R2/SmithingTableInventoryImpl.java | 6 +- .../v1_16_R2/StonecutterInventoryImpl.java | 6 +- .../v1_16_R2/util/AdventureSupportUtil.java | 40 +++++++ .../nms/v1_16_R3/AnvilInventoryImpl.java | 6 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 6 +- .../nms/v1_16_R3/GrindstoneInventoryImpl.java | 6 +- .../v1_16_R3/SmithingTableInventoryImpl.java | 6 +- .../v1_16_R3/StonecutterInventoryImpl.java | 6 +- .../v1_16_R3/util/AdventureSupportUtil.java | 40 +++++++ .../nms/v1_17_R1/AnvilInventoryImpl.java | 8 +- .../CartographyTableInventoryImpl.java | 8 +- .../EnchantingTableInventoryImpl.java | 8 +- .../nms/v1_17_R1/GrindstoneInventoryImpl.java | 8 +- .../v1_17_R1/SmithingTableInventoryImpl.java | 8 +- .../v1_17_R1/StonecutterInventoryImpl.java | 8 +- .../v1_17_R1/util/AdventureSupportUtil.java | 40 +++++++ nms/abstraction/pom.xml | 6 + .../abstraction/AnvilInventory.java | 8 +- .../CartographyTableInventory.java | 8 +- .../abstraction/EnchantingTableInventory.java | 8 +- .../abstraction/GrindstoneInventory.java | 8 +- .../abstraction/SmithingTableInventory.java | 8 +- .../abstraction/StonecutterInventory.java | 8 +- pom.xml | 2 + 77 files changed, 959 insertions(+), 177 deletions(-) create mode 100644 adventure-support/pom.xml create mode 100644 adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java create mode 100644 adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java create mode 100644 adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java create mode 100644 nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/AdventureSupportUtil.java create mode 100644 nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/AdventureSupportUtil.java create mode 100644 nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/AdventureSupportUtil.java create mode 100644 nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/AdventureSupportUtil.java create mode 100644 nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/AdventureSupportUtil.java create mode 100644 nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/AdventureSupportUtil.java diff --git a/.editorconfig b/.editorconfig index 21392b2d0..938058287 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,4 +2,6 @@ root = true # Indentation override for all java files [**.java] +indent_style = space indent_size = 4 +insert_final_newline = true diff --git a/IF/pom.xml b/IF/pom.xml index 8b1a5fc41..d54432c58 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -28,6 +28,12 @@ + + net.kyori + adventure-api + ${adventure.version} + provided + com.github.stefvanschie.inventoryframework abstraction 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 2bec9e2d6..ce1f8933d 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 @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -74,6 +74,10 @@ public class AnvilGui extends NamedGui { public AnvilGui(@NotNull String title) { super(title); } + + public AnvilGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -140,8 +144,8 @@ public void click(@NotNull InventoryClickEvent event) { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.ANVIL, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.ANVIL); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index 10815fedb..a922dc39a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,6 +50,10 @@ public class BarrelGui extends NamedGui implements MergedGui { public BarrelGui(@NotNull String title) { super(title); } + + public BarrelGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -128,8 +132,8 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.BARREL, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.BARREL); } @NotNull diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java index d88ae7419..c0f68d4a3 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java @@ -114,7 +114,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory() { + protected Inventory createInventory() { return Bukkit.createInventory(this, InventoryType.BEACON); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index dc24e3e0d..9d9e74782 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -62,6 +62,10 @@ public class BlastFurnaceGui extends NamedGui { public BlastFurnaceGui(@NotNull String title) { super(title); } + + public BlastFurnaceGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -129,8 +133,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.BLAST_FURNACE, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.BLAST_FURNACE); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 2d9960f26..9c1f5f3a4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -74,6 +74,10 @@ public class BrewingStandGui extends NamedGui { public BrewingStandGui(@NotNull String title) { super(title); } + + public BrewingStandGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -149,8 +153,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - Inventory inventory = Bukkit.createInventory(this, InventoryType.BREWING, title); + protected Inventory createInventory() { + Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.BREWING); addInventory(inventory, this); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 14e2d9e0f..40b494457 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -6,6 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; +import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; @@ -76,6 +77,10 @@ public class CartographyTableGui extends NamedGui { public CartographyTableGui(@NotNull String title) { super(title); } + + public CartographyTableGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -147,8 +152,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.CARTOGRAPHY, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.CARTOGRAPHY); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 64930e34f..92a3bd42b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -1,12 +1,15 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; @@ -54,6 +57,14 @@ public class ChestGui extends NamedGui implements MergedGui { * @since 0.8.0 */ public ChestGui(int rows, @NotNull String title) { + this(rows, StringHolder.of(title)); + } + + public ChestGui(int rows, @NotNull Component title) { + this(rows, ComponentHolder.of(title)); + } + + public ChestGui(int rows, @NotNull TextHolder title) { super(title); if (!(rows >= 1 && rows <= 6)) { @@ -135,7 +146,7 @@ public void setRows(int rows) { //copy the viewers List viewers = getViewers(); - this.inventory = Bukkit.createInventory(this, rows * 9, getTitle()); + this.inventory = createInventory(); viewers.forEach(humanEntity -> humanEntity.openInventory(inventory)); } @@ -162,8 +173,8 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, getRows() * 9, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, getRows() * 9); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index 735260584..b4a681d98 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -56,6 +56,10 @@ public class CraftingTableGui extends NamedGui { public CraftingTableGui(@NotNull String title) { super(title); } + + public CraftingTableGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -119,8 +123,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.WORKBENCH, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.WORKBENCH); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index dafdd3262..bde40e6b6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,6 +50,10 @@ public class DispenserGui extends NamedGui { public DispenserGui(@NotNull String title) { super(title); } + + public DispenserGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -109,8 +113,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - Inventory inventory = Bukkit.createInventory(this, InventoryType.DISPENSER, title); + protected Inventory createInventory() { + Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.DISPENSER); addInventory(inventory, this); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index 2cbf45cd1..efc47c4ad 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,6 +50,10 @@ public class DropperGui extends NamedGui { public DropperGui(@NotNull String title) { super(title); } + + public DropperGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -109,8 +113,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - Inventory inventory = Bukkit.createInventory(this, InventoryType.DROPPER, title); + protected Inventory createInventory() { + Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.DROPPER); addInventory(inventory, this); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index d4e771b4d..7cc5ee90a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -62,6 +62,10 @@ public class EnchantingTableGui extends NamedGui { public EnchantingTableGui(@NotNull String title) { super(title); } + + public EnchantingTableGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -125,8 +129,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.ENCHANTING, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.ENCHANTING); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index db47c007e..488de478e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,6 +50,10 @@ public class EnderChestGui extends NamedGui implements MergedGui { public EnderChestGui(@NotNull String title) { super(title); } + + public EnderChestGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -128,8 +132,8 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.ENDER_CHEST, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.ENDER_CHEST); } @NotNull diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index 674aa2dae..374e37a12 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -62,6 +62,10 @@ public class FurnaceGui extends NamedGui { public FurnaceGui(@NotNull String title) { super(title); } + + public FurnaceGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -129,8 +133,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - Inventory inventory = Bukkit.createInventory(this, InventoryType.FURNACE, title); + protected Inventory createInventory() { + Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.FURNACE); addInventory(inventory, this); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index a7c665c6e..ca7a164e5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -68,6 +68,10 @@ public class GrindstoneGui extends NamedGui { public GrindstoneGui(@NotNull String title) { super(title); } + + public GrindstoneGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -135,8 +139,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.GRINDSTONE, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.GRINDSTONE); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index b33be09b7..48408c1b1 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,6 +50,10 @@ public class HopperGui extends NamedGui { public HopperGui(@NotNull String title) { super(title); } + + public HopperGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -109,8 +113,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - Inventory inventory = Bukkit.createInventory(this, InventoryType.HOPPER, title); + protected Inventory createInventory() { + Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.HOPPER); addInventory(inventory, this); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index f84ee3f6a..2e482e815 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,6 +50,10 @@ public class ShulkerBoxGui extends NamedGui implements MergedGui { public ShulkerBoxGui(@NotNull String title) { super(title); } + + public ShulkerBoxGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -128,8 +132,8 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.SHULKER_BOX, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.SHULKER_BOX); } @NotNull diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index bb058e527..bb56371b3 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -75,6 +75,10 @@ public class SmithingTableGui extends NamedGui { public SmithingTableGui(@NotNull String title) { super(title); } + + public SmithingTableGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -146,8 +150,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.SMITHING, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.SMITHING); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index c65fd42b1..519deb15a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -3,7 +3,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -62,6 +62,10 @@ public class SmokerGui extends NamedGui { public SmokerGui(@NotNull String title) { super(title); } + + public SmokerGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -129,8 +133,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.SMOKER, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.SMOKER); } /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 89d219181..9e3dec479 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import org.bukkit.Bukkit; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -69,6 +69,10 @@ public class StonecutterGui extends NamedGui { public StonecutterGui(@NotNull String title) { super(title); } + + public StonecutterGui(@NotNull Component title) { + super(title); + } @Override public void show(@NotNull HumanEntity humanEntity) { @@ -136,8 +140,8 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - public Inventory createInventory(@NotNull String title) { - return Bukkit.createInventory(this, InventoryType.STONECUTTER, title); + protected Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.STONECUTTER); } /** 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 23e3c9333..b0191214a 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 @@ -151,14 +151,14 @@ public Gui() { } /** - * Creates a new inventory of the type of the implementing class with the provided title. + * Creates a new inventory of the type of the implementing class. * * @return the new inventory * @since 0.8.0 */ @NotNull @Contract(pure = true) - public abstract Inventory createInventory(); + protected abstract Inventory createInventory(); /** * Shows a gui to a player diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java index 1ac7127f5..79b75ca2b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java @@ -1,9 +1,10 @@ package com.github.stefvanschie.inventoryframework.gui.type.util; -import org.bukkit.Bukkit; +import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; -import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -15,7 +16,7 @@ public abstract class NamedGui extends Gui { * The title of this gui */ @NotNull - private String title; + private TextHolder title; /** * Constructs a new gui with a title @@ -24,34 +25,15 @@ public abstract class NamedGui extends Gui { * @since 0.8.0 */ public NamedGui(@NotNull String title) { - this.title = title; + this(StringHolder.of(title)); } - - /** - * Creates a new inventory of the type of the implementing class with the provided title. - * - * @param title the title for the new inventory - * @return the new inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - public abstract Inventory createInventory(@NotNull String title); - - @NotNull - @Override - public Inventory getInventory() { - if (this.inventory == null) { - this.inventory = createInventory(getTitle()); - } - - return inventory; + + public NamedGui(@NotNull Component title) { + this(ComponentHolder.of(title)); } - - @NotNull - @Override - public Inventory createInventory() { - return createInventory(title); + + protected NamedGui(@NotNull TextHolder title) { + this.title = title; } /** @@ -61,11 +43,19 @@ public Inventory createInventory() { * @param title the title */ public void setTitle(@NotNull String title) { + setTitle(StringHolder.of(title)); + } + + public void setTitle(@NotNull Component title) { + setTitle(ComponentHolder.of(title)); + } + + private void setTitle(@NotNull TextHolder title) { //copy the viewers List viewers = getViewers(); - this.inventory = createInventory(title); this.title = title; + this.inventory = createInventory(); updating = true; @@ -85,6 +75,18 @@ public void setTitle(@NotNull String title) { @NotNull @Contract(pure = true) public String getTitle() { + return title.asLegacyString(); + } + + @NotNull + @Contract(pure = true) + public Component title() { + return title.asComponent(); + } + + @NotNull + @Contract(pure = true) + protected TextHolder getTitleHolder() { return title; } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 79a7afed8..755e12e41 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.pane; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.GuiItem; @@ -10,7 +11,6 @@ import com.github.stefvanschie.inventoryframework.util.XMLUtil; import com.google.common.primitives.Primitives; import org.apache.commons.lang3.reflect.MethodUtils; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; @@ -358,12 +358,7 @@ public static GuiItem loadItem(@NotNull Object instance, @NotNull Element elemen if (!innerNode.getNodeName().equals("line")) continue; - boolean hasLore = itemMeta.hasLore(); - List lore = hasLore ? Objects.requireNonNull(itemMeta.getLore()) : new ArrayList<>(); - - lore.add(ChatColor.translateAlternateColorCodes('&', innerNode - .getTextContent())); - itemMeta.setLore(lore); + TextHolder.fromNodeTextContent(innerNode).asItemLoreAtEnd(itemMeta); itemStack.setItemMeta(itemMeta); break; case "enchantments": @@ -388,8 +383,7 @@ public static GuiItem loadItem(@NotNull Object instance, @NotNull Element elemen } else if (nodeName.equals("displayname")) { ItemMeta itemMeta = Objects.requireNonNull(itemStack.getItemMeta()); - itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', item - .getTextContent())); + TextHolder.fromNodeTextContent(item).asItemDisplayName(itemMeta); itemStack.setItemMeta(itemMeta); } else if (nodeName.equals("skull") && itemStack.getItemMeta() instanceof SkullMeta) { diff --git a/README.md b/README.md index f07c855c5..85f13d187 100644 --- a/README.md +++ b/README.md @@ -87,3 +87,11 @@ If you want to build this project from source, run the following from Git Bash: mvn clean package The build can then be found in /IF/target/. + +TODO adventure support notes +- proper adventure support is only achieved if you run paper: + we can only create adventure inventory titles on paper + +TODO actual TODO for me: + - which adventure versions to use? same one in all places? + even in 1.14 NMS? \ No newline at end of file diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml new file mode 100644 index 000000000..ebffc0a69 --- /dev/null +++ b/adventure-support/pom.xml @@ -0,0 +1,39 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.9.9 + + 4.0.0 + + adventure-support + + + true + + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + + + com.destroystokyo.paper + paper-api + 1.16.5-R0.1-SNAPSHOT + provided + + + net.kyori + adventure-api + ${adventure.version} + provided + + + \ No newline at end of file diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java new file mode 100644 index 000000000..895032d9d --- /dev/null +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -0,0 +1,99 @@ +package com.github.stefvanschie.inventoryframework.adventuresupport; + +import com.google.gson.JsonElement; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public final class ComponentHolder extends TextHolder { + + @NotNull + @Contract(pure = true) + public static ComponentHolder of(@NotNull Component value) { + Validate.notNull(value, "value mustn't be null"); + return new ComponentHolder(value); + } + + @NotNull + private final Component value; + + private ComponentHolder(@NotNull Component value) { + this.value = value; + } + + @NotNull + @Contract(pure = true) + public JsonElement asJson() { + return GsonComponentSerializer.gson().serializeToTree(value); + } + + @NotNull + @Contract(pure = true) + @Override + public String toString() { + return getClass().getSimpleName() + "{" + value + "}"; + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object other) { + return other != null && getClass() == other.getClass() + && Objects.equals(value, ((ComponentHolder) other).value); + } + + @NotNull + @Contract(pure = true) + public String asLegacyString() { + return LegacyComponentSerializer.legacySection().serialize(value); + } + + @NotNull + @Contract(pure = true) + public Component asComponent() { + return value; + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, InventoryType type) { + return Bukkit.createInventory(holder, type, value); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, int size) { + return Bukkit.createInventory(holder, size, value); + } + + @Override + public void asItemDisplayName(ItemMeta meta) { + meta.displayName(value); + } + + @Override + public void asItemLoreAtEnd(ItemMeta meta) { + List lore = meta.hasLore() + ? Objects.requireNonNull(meta.lore()) + : new ArrayList<>(); + lore.add(value); + meta.lore(lore); + } +} diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java new file mode 100644 index 000000000..1db42b016 --- /dev/null +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java @@ -0,0 +1,110 @@ +package com.github.stefvanschie.inventoryframework.adventuresupport; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public final class StringHolder extends TextHolder { + + @NotNull + private static final StringHolder EMPTY = StringHolder.of(""); + + @NotNull + @Contract(pure = true) + public static StringHolder of(@NotNull String value) { + Validate.notNull(value, "value mustn't be null"); + return new StringHolder(value); + } + + /** + * Gets an instance that contains no characters. + * + * @return an instance without any characters + */ + @NotNull + @Contract(pure = true) + public static StringHolder empty() { + return EMPTY; + } + + @NotNull + private final String value; + + private StringHolder(@NotNull String value) { + this.value = value; + } + + @NotNull + @Contract(pure = true) + @Override + public String toString() { + return getClass().getSimpleName() + "{" + value + "}"; + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object other) { + return other != null && getClass() == other.getClass() + && Objects.equals(value, ((StringHolder) other).value); + } + + @NotNull + @Contract(pure = true) + public String asLegacyString() { + return value; + } + + @NotNull + @Contract(pure = true) + public Component asComponent() { + return LegacyComponentSerializer.legacySection().deserialize(value); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, InventoryType type) { + //noinspection deprecation + return Bukkit.createInventory(holder, type, value); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, int size) { + //noinspection deprecation + return Bukkit.createInventory(holder, size, value); + } + + @Override + public void asItemDisplayName(ItemMeta meta) { + //noinspection deprecation + meta.setDisplayName(value); + } + + @Override + public void asItemLoreAtEnd(ItemMeta meta) { + //noinspection deprecation + List lore = meta.hasLore() + ? Objects.requireNonNull(meta.getLore()) + : new ArrayList<>(); + lore.add(value); + //noinspection deprecation + meta.setLore(lore); + } +} diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java new file mode 100644 index 000000000..ec8ea549d --- /dev/null +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java @@ -0,0 +1,90 @@ +package com.github.stefvanschie.inventoryframework.adventuresupport; + +import net.kyori.adventure.text.Component; +import org.bukkit.ChatColor; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.Node; + +/** + * Immutable wrapper of a text-like value. + * Support for both Adventure-based Paper + * and non-Adventure Spigot is achieved through this class. + *

+ * This class is an implementation detail. + * It must not be exposed to the users of the IF library. + *

+ */ +public abstract class TextHolder { + + /** + * Gets an instance that contains no characters. + * + * @return an instance without any characters + */ + @NotNull + @Contract(pure = true) + public static TextHolder empty() { + return StringHolder.empty(); + } + + /** + * Deserializes the specified node's {@link Node#getTextContent()} + * as a {@link TextHolder}. + * This method is still WIP and may change drastically in the future: + *
    + *
  • Should it take a {@link Node} or a {@link String} as parameter?
  • + *
  • Are we ever gonna use anything other than {@link Node#getTextContent()}?
  • + *
  • Are we going to use minimessage if it's present?
  • + *
  • Is minimessage going to be opt-in? If yes, how do we opt-in?
  • + *
+ * + * @param node the node whose text content to deserialize + * @return an instance containing the text from the node + */ + @NotNull + @Contract(pure = true) + public static TextHolder fromNodeTextContent(@NotNull Node node) { + String legacy = ChatColor.translateAlternateColorCodes('&', node.getTextContent()); + return StringHolder.of(legacy); + } + + TextHolder() { + //package-private constructor to "seal" the class + } + + @NotNull + @Contract(pure = true) + @Override + public abstract String toString(); + + @Override + public abstract int hashCode(); + + @Override + public abstract boolean equals(Object other); + + @NotNull + @Contract(pure = true) + public abstract String asLegacyString(); + + @NotNull + @Contract(pure = true) + public abstract Component asComponent(); + + @NotNull + @Contract(pure = true) + public abstract Inventory asInventoryTitle(InventoryHolder holder, InventoryType type); + + @NotNull + @Contract(pure = true) + public abstract Inventory asInventoryTitle(InventoryHolder holder, int size); + + public abstract void asItemDisplayName(ItemMeta meta); + + public abstract void asItemLoreAtEnd(ItemMeta meta); +} diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java index a17945e39..dbaa54f32 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; import net.minecraft.server.v1_14_R1.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; @@ -28,7 +30,7 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -44,7 +46,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java index 75766664d..48870003b 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -45,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java index 0acb73900..53f88f68e 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java index c93769a78..12418f526 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java index a193a995d..2a46f07a5 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/AdventureSupportUtil.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/AdventureSupportUtil.java new file mode 100644 index 000000000..0fb17bd00 --- /dev/null +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/AdventureSupportUtil.java @@ -0,0 +1,40 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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; + +public final class AdventureSupportUtil { + + private AdventureSupportUtil() { + //private constructor to prevent construction + } + + @NotNull + @Contract(pure = true) + public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { + if (holder instanceof StringHolder) { + return toComponent((StringHolder) holder); + } else { + return toComponent((ComponentHolder) holder); + } + } + + @NotNull + @Contract(pure = true) + private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { + return new ChatComponentText(holder.asLegacyString()); + } + + @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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java index 2cbfc8c58..2820b588e 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; @@ -28,7 +30,7 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -44,7 +46,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java index 9748a472a..fdcbc74a9 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -45,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java index 42018e6c9..48fbaf98d 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java index d582f5fcc..8e8efe4fd 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java index ded6bb0d1..5cbbc7d9f 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/AdventureSupportUtil.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/AdventureSupportUtil.java new file mode 100644 index 000000000..cde9096ae --- /dev/null +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/AdventureSupportUtil.java @@ -0,0 +1,40 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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; + +public final class AdventureSupportUtil { + + private AdventureSupportUtil() { + //private constructor to prevent construction + } + + @NotNull + @Contract(pure = true) + public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { + if (holder instanceof StringHolder) { + return toComponent((StringHolder) holder); + } else { + return toComponent((ComponentHolder) holder); + } + } + + @NotNull + @Contract(pure = true) + private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { + return new ChatComponentText(holder.asLegacyString()); + } + + @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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java index 5da3e3f29..baa98976a 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R1.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; @@ -26,7 +28,7 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -42,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java index e4d3895a0..a55263007 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -45,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java index 901cceb5e..f8cc6cd29 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java index 291db39c1..71e31b3cd 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java index c9e30f97c..c0b1c8778 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; 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; @@ -25,7 +27,7 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -41,7 +43,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerSmithingTable; int id = containerSmithingTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java index 8c76fb843..f2a090720 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/AdventureSupportUtil.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/AdventureSupportUtil.java new file mode 100644 index 000000000..cbaa7d735 --- /dev/null +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/AdventureSupportUtil.java @@ -0,0 +1,40 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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; + +public final class AdventureSupportUtil { + + private AdventureSupportUtil() { + //private constructor to prevent construction + } + + @NotNull + @Contract(pure = true) + public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { + if (holder instanceof StringHolder) { + return toComponent((StringHolder) holder); + } else { + return toComponent((ComponentHolder) holder); + } + } + + @NotNull + @Contract(pure = true) + private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { + return new ChatComponentText(holder.asLegacyString()); + } + + @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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java index b0fc4bd74..dd1ab839e 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R2.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; @@ -26,7 +28,7 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -42,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java index b11ac0f23..edd791e57 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R2.*; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_16_R2.inventory.*; @@ -24,7 +26,7 @@ public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -42,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java index 89145689c..3573a7a05 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R2.*; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_16_R2.inventory.*; @@ -24,7 +26,7 @@ public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -40,7 +42,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java index 48bf2f02e..5b8e11ac3 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R2.*; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_16_R2.inventory.*; @@ -24,7 +26,7 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -40,7 +42,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java index 82779d966..bbf3bd329 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R2.*; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_16_R2.inventory.*; @@ -22,7 +24,7 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -38,7 +40,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerSmithingTable; int id = containerSmithingTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java index 83d8d88d4..e56d7e05e 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R2.*; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_16_R2.inventory.*; @@ -24,7 +26,7 @@ public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -40,7 +42,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/AdventureSupportUtil.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/AdventureSupportUtil.java new file mode 100644 index 000000000..5f7ffcf88 --- /dev/null +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/AdventureSupportUtil.java @@ -0,0 +1,40 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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; + +public final class AdventureSupportUtil { + + private AdventureSupportUtil() { + //private constructor to prevent construction + } + + @NotNull + @Contract(pure = true) + public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { + if (holder instanceof StringHolder) { + return toComponent((StringHolder) holder); + } else { + return toComponent((ComponentHolder) holder); + } + } + + @NotNull + @Contract(pure = true) + private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { + return new ChatComponentText(holder.asLegacyString()); + } + + @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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java index 636d6ce51..f347a7576 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; import net.minecraft.server.v1_16_R3.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; @@ -26,7 +28,7 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -42,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java index e63aba2f3..1f2077e1c 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -45,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java index 7c3584325..512b7e440 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java index 140cf4d7b..6c10cdc9c 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java index a9e9e5d60..4fd5ca708 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; 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; @@ -25,7 +27,7 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -41,7 +43,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerSmithingTable; int id = containerSmithingTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java index 2e9db691e..3150315df 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java @@ -1,6 +1,8 @@ package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; 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; @@ -27,7 +29,7 @@ public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -43,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - ChatMessage message = new ChatMessage(title); + IChatBaseComponent message = AdventureSupportUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/AdventureSupportUtil.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/AdventureSupportUtil.java new file mode 100644 index 000000000..39b4f2d3e --- /dev/null +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/AdventureSupportUtil.java @@ -0,0 +1,40 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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; + +public final class AdventureSupportUtil { + + private AdventureSupportUtil() { + //private constructor to prevent construction + } + + @NotNull + @Contract(pure = true) + public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { + if (holder instanceof StringHolder) { + return toComponent((StringHolder) holder); + } else { + return toComponent((ComponentHolder) holder); + } + } + + @NotNull + @Contract(pure = true) + private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { + return new ChatComponentText(holder.asLegacyString()); + } + + @NotNull + @Contract(pure = true) + private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(IChatBaseComponent.ChatSerializer.a(holder.asJson())); + } +} diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java index 3a34dd4aa..89ac428f6 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java @@ -1,10 +1,12 @@ package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; @@ -39,7 +41,7 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -55,7 +57,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, serverPlayer.containerMenu = containerAnvil; int id = containerAnvil.containerId; - TranslatableComponent message = new TranslatableComponent(title); + Component message = AdventureSupportUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java index 7b4d02f81..d614a3585 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java @@ -1,9 +1,11 @@ package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; @@ -38,7 +40,7 @@ public CartographyTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -56,7 +58,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, serverPlayer.containerMenu = containerCartographyTable; int id = containerCartographyTable.containerId; - TranslatableComponent message = new TranslatableComponent(title); + Component message = AdventureSupportUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java index af442d93f..ed6035272 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java @@ -1,8 +1,10 @@ package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; @@ -37,7 +39,7 @@ public EnchantingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -53,7 +55,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, serverPlayer.containerMenu = containerEnchantmentTable; int id = containerEnchantmentTable.containerId; - TranslatableComponent message = new TranslatableComponent(title); + Component message = AdventureSupportUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java index 2291d9621..0e35ee7e5 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java @@ -1,9 +1,11 @@ package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; @@ -38,7 +40,7 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -54,7 +56,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, serverPlayer.containerMenu = containerGrindstone; int id = containerGrindstone.containerId; - TranslatableComponent message = new TranslatableComponent(title); + Component message = AdventureSupportUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java index 4836fc3bd..8a16aa8c1 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java @@ -1,10 +1,12 @@ package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; @@ -38,7 +40,7 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -54,7 +56,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, serverPlayer.containerMenu = containerSmithingTable; int id = containerSmithingTable.containerId; - TranslatableComponent message = new TranslatableComponent(title); + Component message = AdventureSupportUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java index c3823e4dc..fa59ffe0c 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java @@ -1,8 +1,10 @@ package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; @@ -37,7 +39,7 @@ public StonecutterInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull String title, + public void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -53,7 +55,7 @@ public void openInventory(@NotNull Player player, @NotNull String title, serverPlayer.containerMenu = containerEnchantmentTable; int id = containerEnchantmentTable.containerId; - TranslatableComponent message = new TranslatableComponent(title); + Component message = AdventureSupportUtil.toComponent(title); ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); serverPlayer.connection.send(packet); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/AdventureSupportUtil.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/AdventureSupportUtil.java new file mode 100644 index 000000000..de520e73a --- /dev/null +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/AdventureSupportUtil.java @@ -0,0 +1,40 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_R1.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.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +public final class AdventureSupportUtil { + + private AdventureSupportUtil() { + //private constructor to prevent construction + } + + @NotNull + @Contract(pure = true) + public static Component toComponent(@NotNull TextHolder holder) { + if (holder instanceof StringHolder) { + return toComponent((StringHolder) holder); + } else { + return toComponent((ComponentHolder) holder); + } + } + + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return new TextComponent(holder.asLegacyString()); + } + + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 68d709a80..fbdee3848 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -24,6 +24,12 @@ + + com.github.stefvanschie.inventoryframework + adventure-support + ${project.version} + compile + org.spigotmc spigot-api 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 e70fdf48e..f5762d4cf 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 @@ -1,5 +1,7 @@ package com.github.stefvanschie.inventoryframework.abstraction; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -44,7 +46,11 @@ public AnvilInventory(@NotNull InventoryHolder inventoryHolder) { * @param items the items to show * @since 0.8.0 */ - public abstract void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items); + public final void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { + openInventory(player, StringHolder.of(title), items); + } + + public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/CartographyTableInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/CartographyTableInventory.java index da4f1db58..586ecc61a 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/CartographyTableInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/CartographyTableInventory.java @@ -1,5 +1,7 @@ package com.github.stefvanschie.inventoryframework.abstraction; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -37,7 +39,11 @@ public CartographyTableInventory(@NotNull InventoryHolder inventoryHolder) { * @param items the top items of the inventory * @since 0.8.0 */ - public abstract void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items); + public final void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { + openInventory(player, StringHolder.of(title), items); + } + + public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/EnchantingTableInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/EnchantingTableInventory.java index dc8b97bf0..d60093350 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/EnchantingTableInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/EnchantingTableInventory.java @@ -1,5 +1,7 @@ package com.github.stefvanschie.inventoryframework.abstraction; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -37,7 +39,11 @@ public EnchantingTableInventory(@NotNull InventoryHolder inventoryHolder) { * @param items the top items * @since 0.8.0 */ - public abstract void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items); + public final void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { + openInventory(player, StringHolder.of(title), items); + } + + public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java index 314eb1996..ce1dda004 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java @@ -1,5 +1,7 @@ package com.github.stefvanschie.inventoryframework.abstraction; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -37,7 +39,11 @@ public GrindstoneInventory(@NotNull InventoryHolder inventoryHolder) { * @param items the top items * @since 0.8.0 */ - public abstract void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items); + public final void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { + openInventory(player, StringHolder.of(title), items); + } + + public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java index e34f65ea0..5b0dc3cb3 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java @@ -1,5 +1,7 @@ package com.github.stefvanschie.inventoryframework.abstraction; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -37,7 +39,11 @@ public SmithingTableInventory(@NotNull InventoryHolder inventoryHolder) { * @param items the top items * @since 0.8.0 */ - public abstract void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items); + public final void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { + openInventory(player, StringHolder.of(title), items); + } + + public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/StonecutterInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/StonecutterInventory.java index 7481979d8..5e2450c12 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/StonecutterInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/StonecutterInventory.java @@ -1,5 +1,7 @@ package com.github.stefvanschie.inventoryframework.abstraction; +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -37,7 +39,11 @@ public StonecutterInventory(@NotNull InventoryHolder inventoryHolder) { * @param items the top items * @since 0.8.0 */ - public abstract void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items); + public final void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { + openInventory(player, StringHolder.of(title), items); + } + + public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. diff --git a/pom.xml b/pom.xml index 85ad9693d..f1be32c7c 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ nms/1_16_R1 nms/1_15_R1 nms/1_14_R1 + adventure-support
@@ -20,6 +21,7 @@ 1.8 true UTF-8 + 4.8.1 com.github.stefvanschie.inventoryframework From fc7487a9739535aa3685d18ba18dd4b3f4d8221a Mon Sep 17 00:00:00 2001 From: Trigary Date: Thu, 24 Jun 2021 18:01:15 +0200 Subject: [PATCH 009/382] differentiate native and non-native Adventure --- README.md | 16 ++-- .../adventuresupport/ComponentHolder.java | 75 ++++++++++--------- .../ForeignComponentHolder.java | 43 +++++++++++ .../NativeComponentHolder.java | 49 ++++++++++++ 4 files changed, 139 insertions(+), 44 deletions(-) create mode 100644 adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java create mode 100644 adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java diff --git a/README.md b/README.md index 85f13d187..e8e04464b 100644 --- a/README.md +++ b/README.md @@ -88,10 +88,12 @@ If you want to build this project from source, run the following from Git Bash: The build can then be found in /IF/target/. -TODO adventure support notes -- proper adventure support is only achieved if you run paper: - we can only create adventure inventory titles on paper - -TODO actual TODO for me: - - which adventure versions to use? same one in all places? - even in 1.14 NMS? \ No newline at end of file +## Adventure support + +TODO actually write this part of the readme + +https://docs.adventure.kyori.net/platform/index.html + +full support is obviously only achieved when your platform +(spigot/Paper) natively supports adventure... +but adventure also works on spigot: stuff get converted to legacy diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java index 895032d9d..8a8b59e96 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -5,31 +5,58 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; -public final class ComponentHolder extends TextHolder { +public abstract class ComponentHolder extends TextHolder { + + private static Boolean nativeAdventureSupport; @NotNull @Contract(pure = true) public static ComponentHolder of(@NotNull Component value) { Validate.notNull(value, "value mustn't be null"); - return new ComponentHolder(value); + return isNativeAdventureSupport() + ? new NativeComponentHolder(value) + : new ForeignComponentHolder(value); + } + + private static boolean isNativeAdventureSupport() { + if (nativeAdventureSupport == null) { + try { + Component component = Component.text("test"); + NativeComponentHolder holder = new NativeComponentHolder(component); + + //If NoSuchMethodError or something is thrown we can assume that + //Adventure components are not natively supported by the server platform + + //noinspection unused + Object ignored1 = holder.asInventoryTitle(null, 9); + //noinspection unused + Object ignored2 = holder.asInventoryTitle(null, InventoryType.HOPPER); + + ItemMeta meta = new ItemStack(Material.STONE).getItemMeta(); + holder.asItemDisplayName(meta); + holder.asItemLoreAtEnd(meta); + + nativeAdventureSupport = true; + } catch (Throwable t) { + nativeAdventureSupport = false; + } + } + return nativeAdventureSupport; } @NotNull - private final Component value; + protected final Component value; - private ComponentHolder(@NotNull Component value) { + ComponentHolder(@NotNull Component value) { this.value = value; } @@ -60,6 +87,8 @@ public boolean equals(Object other) { @NotNull @Contract(pure = true) public String asLegacyString() { + //TODO this down samples colors to the nearest ChatColor + // is this a bug or a feature? return LegacyComponentSerializer.legacySection().serialize(value); } @@ -68,32 +97,4 @@ public String asLegacyString() { public Component asComponent() { return value; } - - @NotNull - @Contract(pure = true) - @Override - public Inventory asInventoryTitle(InventoryHolder holder, InventoryType type) { - return Bukkit.createInventory(holder, type, value); - } - - @NotNull - @Contract(pure = true) - @Override - public Inventory asInventoryTitle(InventoryHolder holder, int size) { - return Bukkit.createInventory(holder, size, value); - } - - @Override - public void asItemDisplayName(ItemMeta meta) { - meta.displayName(value); - } - - @Override - public void asItemLoreAtEnd(ItemMeta meta) { - List lore = meta.hasLore() - ? Objects.requireNonNull(meta.lore()) - : new ArrayList<>(); - lore.add(value); - meta.lore(lore); - } } diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java new file mode 100644 index 000000000..9985a3291 --- /dev/null +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java @@ -0,0 +1,43 @@ +package com.github.stefvanschie.inventoryframework.adventuresupport; + +import net.kyori.adventure.text.Component; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +class ForeignComponentHolder extends ComponentHolder { + + private final StringHolder legacy; + + ForeignComponentHolder(@NotNull Component value) { + super(value); + legacy = StringHolder.of(asLegacyString()); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, InventoryType type) { + return legacy.asInventoryTitle(holder, type); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, int size) { + return legacy.asInventoryTitle(holder, size); + } + + @Override + public void asItemDisplayName(ItemMeta meta) { + legacy.asItemDisplayName(meta); + } + + @Override + public void asItemLoreAtEnd(ItemMeta meta) { + legacy.asItemLoreAtEnd(meta); + } +} diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java new file mode 100644 index 000000000..96b49f8cb --- /dev/null +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java @@ -0,0 +1,49 @@ +package com.github.stefvanschie.inventoryframework.adventuresupport; + +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +class NativeComponentHolder extends ComponentHolder { + + NativeComponentHolder(@NotNull Component value) { + super(value); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, InventoryType type) { + return Bukkit.createInventory(holder, type, value); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory asInventoryTitle(InventoryHolder holder, int size) { + return Bukkit.createInventory(holder, size, value); + } + + @Override + public void asItemDisplayName(ItemMeta meta) { + meta.displayName(value); + } + + @Override + public void asItemLoreAtEnd(ItemMeta meta) { + List lore = meta.hasLore() + ? Objects.requireNonNull(meta.lore()) + : new ArrayList<>(); + lore.add(value); + meta.lore(lore); + } +} From da7937cfb6359056abe0d44106afcdf0b96c36de Mon Sep 17 00:00:00 2001 From: Trigary Date: Thu, 24 Jun 2021 19:11:07 +0200 Subject: [PATCH 010/382] fix issues when Adventure isn't present --- .editorconfig | 1 + .../inventoryframework/gui/type/AnvilGui.java | 6 ++-- .../gui/type/BarrelGui.java | 6 ++-- .../gui/type/BlastFurnaceGui.java | 6 ++-- .../gui/type/BrewingStandGui.java | 6 ++-- .../gui/type/CartographyTableGui.java | 6 ++-- .../inventoryframework/gui/type/ChestGui.java | 6 ---- .../gui/type/CraftingTableGui.java | 6 ++-- .../gui/type/DispenserGui.java | 6 ++-- .../gui/type/DropperGui.java | 6 ++-- .../gui/type/EnchantingTableGui.java | 6 ++-- .../gui/type/EnderChestGui.java | 6 ++-- .../gui/type/FurnaceGui.java | 6 ++-- .../gui/type/GrindstoneGui.java | 6 ++-- .../gui/type/HopperGui.java | 6 ++-- .../gui/type/ShulkerBoxGui.java | 6 ++-- .../gui/type/SmithingTableGui.java | 6 ++-- .../gui/type/SmokerGui.java | 6 ++-- .../gui/type/StonecutterGui.java | 6 ++-- .../gui/type/util/NamedGui.java | 28 ++++----------- .../inventoryframework/pane/Pane.java | 6 ++-- .../adventuresupport/ComponentHolder.java | 7 +--- .../adventuresupport/StringHolder.java | 9 +---- .../adventuresupport/TextHolder.java | 34 ++++++------------- 24 files changed, 75 insertions(+), 118 deletions(-) diff --git a/.editorconfig b/.editorconfig index 938058287..2dc9cc093 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,3 +5,4 @@ root = true indent_style = space indent_size = 4 insert_final_newline = true +ij_continuation_indent_size = 8 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 ce1f8933d..84cec646d 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 @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -74,8 +74,8 @@ public class AnvilGui extends NamedGui { public AnvilGui(@NotNull String title) { super(title); } - - public AnvilGui(@NotNull Component title) { + + public AnvilGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index a922dc39a..1626f408b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,8 +50,8 @@ public class BarrelGui extends NamedGui implements MergedGui { public BarrelGui(@NotNull String title) { super(title); } - - public BarrelGui(@NotNull Component title) { + + public BarrelGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index 9d9e74782..012723ecf 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -62,8 +62,8 @@ public class BlastFurnaceGui extends NamedGui { public BlastFurnaceGui(@NotNull String title) { super(title); } - - public BlastFurnaceGui(@NotNull Component title) { + + public BlastFurnaceGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 9c1f5f3a4..9081a94a4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -74,8 +74,8 @@ public class BrewingStandGui extends NamedGui { public BrewingStandGui(@NotNull String title) { super(title); } - - public BrewingStandGui(@NotNull Component title) { + + public BrewingStandGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 40b494457..d4dc388c1 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; @@ -77,8 +77,8 @@ public class CartographyTableGui extends NamedGui { public CartographyTableGui(@NotNull String title) { super(title); } - - public CartographyTableGui(@NotNull Component title) { + + public CartographyTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 92a3bd42b..643bfb9fd 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -1,6 +1,5 @@ package com.github.stefvanschie.inventoryframework.gui.type; -import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -9,7 +8,6 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; @@ -60,10 +58,6 @@ public ChestGui(int rows, @NotNull String title) { this(rows, StringHolder.of(title)); } - public ChestGui(int rows, @NotNull Component title) { - this(rows, ComponentHolder.of(title)); - } - public ChestGui(int rows, @NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index b4a681d98..966f4d4b5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -56,8 +56,8 @@ public class CraftingTableGui extends NamedGui { public CraftingTableGui(@NotNull String title) { super(title); } - - public CraftingTableGui(@NotNull Component title) { + + public CraftingTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index bde40e6b6..c99837f70 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,8 +50,8 @@ public class DispenserGui extends NamedGui { public DispenserGui(@NotNull String title) { super(title); } - - public DispenserGui(@NotNull Component title) { + + public DispenserGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index efc47c4ad..70f6d8bce 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,8 +50,8 @@ public class DropperGui extends NamedGui { public DropperGui(@NotNull String title) { super(title); } - - public DropperGui(@NotNull Component title) { + + public DropperGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 7cc5ee90a..1e3c8757a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -62,8 +62,8 @@ public class EnchantingTableGui extends NamedGui { public EnchantingTableGui(@NotNull String title) { super(title); } - - public EnchantingTableGui(@NotNull Component title) { + + public EnchantingTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index 488de478e..ec0a8e757 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,8 +50,8 @@ public class EnderChestGui extends NamedGui implements MergedGui { public EnderChestGui(@NotNull String title) { super(title); } - - public EnderChestGui(@NotNull Component title) { + + public EnderChestGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index 374e37a12..efbbf5b9e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -62,8 +62,8 @@ public class FurnaceGui extends NamedGui { public FurnaceGui(@NotNull String title) { super(title); } - - public FurnaceGui(@NotNull Component title) { + + public FurnaceGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index ca7a164e5..afe8809cf 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -68,8 +68,8 @@ public class GrindstoneGui extends NamedGui { public GrindstoneGui(@NotNull String title) { super(title); } - - public GrindstoneGui(@NotNull Component title) { + + public GrindstoneGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index 48408c1b1..bae830f61 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,8 +50,8 @@ public class HopperGui extends NamedGui { public HopperGui(@NotNull String title) { super(title); } - - public HopperGui(@NotNull Component title) { + + public HopperGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index 2e482e815..9a4deff03 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -50,8 +50,8 @@ public class ShulkerBoxGui extends NamedGui implements MergedGui { public ShulkerBoxGui(@NotNull String title) { super(title); } - - public ShulkerBoxGui(@NotNull Component title) { + + public ShulkerBoxGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index bb56371b3..771fbb326 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -75,8 +75,8 @@ public class SmithingTableGui extends NamedGui { public SmithingTableGui(@NotNull String title) { super(title); } - - public SmithingTableGui(@NotNull Component title) { + + public SmithingTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index 519deb15a..a0d5b68b0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -1,9 +1,9 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -62,8 +62,8 @@ public class SmokerGui extends NamedGui { public SmokerGui(@NotNull String title) { super(title); } - - public SmokerGui(@NotNull Component title) { + + public SmokerGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 9e3dec479..e52a62f84 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -1,12 +1,12 @@ package com.github.stefvanschie.inventoryframework.gui.type; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -69,8 +69,8 @@ public class StonecutterGui extends NamedGui { public StonecutterGui(@NotNull String title) { super(title); } - - public StonecutterGui(@NotNull Component title) { + + public StonecutterGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java index 79b75ca2b..8888b3799 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java @@ -1,9 +1,7 @@ package com.github.stefvanschie.inventoryframework.gui.type.util; -import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import net.kyori.adventure.text.Component; import org.bukkit.entity.HumanEntity; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -27,12 +25,8 @@ public abstract class NamedGui extends Gui { public NamedGui(@NotNull String title) { this(StringHolder.of(title)); } - - public NamedGui(@NotNull Component title) { - this(ComponentHolder.of(title)); - } - - protected NamedGui(@NotNull TextHolder title) { + + public NamedGui(@NotNull TextHolder title) { this.title = title; } @@ -45,12 +39,8 @@ protected NamedGui(@NotNull TextHolder title) { public void setTitle(@NotNull String title) { setTitle(StringHolder.of(title)); } - - public void setTitle(@NotNull Component title) { - setTitle(ComponentHolder.of(title)); - } - - private void setTitle(@NotNull TextHolder title) { + + public void setTitle(@NotNull TextHolder title) { //copy the viewers List viewers = getViewers(); @@ -77,16 +67,10 @@ private void setTitle(@NotNull TextHolder title) { public String getTitle() { return title.asLegacyString(); } - - @NotNull - @Contract(pure = true) - public Component title() { - return title.asComponent(); - } - + @NotNull @Contract(pure = true) - protected TextHolder getTitleHolder() { + public TextHolder getTitleHolder() { return title; } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 755e12e41..e80321d8a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -358,7 +358,8 @@ public static GuiItem loadItem(@NotNull Object instance, @NotNull Element elemen if (!innerNode.getNodeName().equals("line")) continue; - TextHolder.fromNodeTextContent(innerNode).asItemLoreAtEnd(itemMeta); + TextHolder.deserialize(innerNode.getTextContent()) + .asItemLoreAtEnd(itemMeta); itemStack.setItemMeta(itemMeta); break; case "enchantments": @@ -383,7 +384,8 @@ public static GuiItem loadItem(@NotNull Object instance, @NotNull Element elemen } else if (nodeName.equals("displayname")) { ItemMeta itemMeta = Objects.requireNonNull(itemStack.getItemMeta()); - TextHolder.fromNodeTextContent(item).asItemDisplayName(itemMeta); + TextHolder.deserialize(item.getTextContent()) + .asItemDisplayName(itemMeta); itemStack.setItemMeta(itemMeta); } else if (nodeName.equals("skull") && itemStack.getItemMeta() instanceof SkullMeta) { diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java index 8a8b59e96..6799ddc82 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -86,15 +86,10 @@ public boolean equals(Object other) { @NotNull @Contract(pure = true) + @Override public String asLegacyString() { //TODO this down samples colors to the nearest ChatColor // is this a bug or a feature? return LegacyComponentSerializer.legacySection().serialize(value); } - - @NotNull - @Contract(pure = true) - public Component asComponent() { - return value; - } } diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java index 1db42b016..9b9997597 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java @@ -1,7 +1,5 @@ package com.github.stefvanschie.inventoryframework.adventuresupport; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryType; @@ -65,16 +63,11 @@ public boolean equals(Object other) { @NotNull @Contract(pure = true) + @Override public String asLegacyString() { return value; } - @NotNull - @Contract(pure = true) - public Component asComponent() { - return LegacyComponentSerializer.legacySection().deserialize(value); - } - @NotNull @Contract(pure = true) @Override diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java index ec8ea549d..cabfe282a 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java @@ -1,6 +1,5 @@ package com.github.stefvanschie.inventoryframework.adventuresupport; -import net.kyori.adventure.text.Component; import org.bukkit.ChatColor; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; @@ -8,16 +7,13 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Node; /** * Immutable wrapper of a text-like value. - * Support for both Adventure-based Paper - * and non-Adventure Spigot is achieved through this class. - *

- * This class is an implementation detail. - * It must not be exposed to the users of the IF library. - *

+ * Support for both Adventure and legacy strings is achieved through this class. + * + * @see StringHolder + * @see ComponentHolder */ public abstract class TextHolder { @@ -33,24 +29,20 @@ public static TextHolder empty() { } /** - * Deserializes the specified node's {@link Node#getTextContent()} - * as a {@link TextHolder}. + * Deserializes the specified {@link String} as a {@link TextHolder}. * This method is still WIP and may change drastically in the future: *
    - *
  • Should it take a {@link Node} or a {@link String} as parameter?
  • - *
  • Are we ever gonna use anything other than {@link Node#getTextContent()}?
  • - *
  • Are we going to use minimessage if it's present?
  • - *
  • Is minimessage going to be opt-in? If yes, how do we opt-in?
  • + *
  • Are we going to use MiniMessage if it's present?
  • + *
  • Is MiniMessage going to be opt-in? If yes, how do we opt-in?
  • *
* - * @param node the node whose text content to deserialize - * @return an instance containing the text from the node + * @param string the raw data to deserialize + * @return an instance containing the text from the string */ @NotNull @Contract(pure = true) - public static TextHolder fromNodeTextContent(@NotNull Node node) { - String legacy = ChatColor.translateAlternateColorCodes('&', node.getTextContent()); - return StringHolder.of(legacy); + public static TextHolder deserialize(@NotNull String string) { + return StringHolder.of(ChatColor.translateAlternateColorCodes('&', string)); } TextHolder() { @@ -72,10 +64,6 @@ public static TextHolder fromNodeTextContent(@NotNull Node node) { @Contract(pure = true) public abstract String asLegacyString(); - @NotNull - @Contract(pure = true) - public abstract Component asComponent(); - @NotNull @Contract(pure = true) public abstract Inventory asInventoryTitle(InventoryHolder holder, InventoryType type); From 255d3765491afa33f1d290023b0b75e3eef3a09f Mon Sep 17 00:00:00 2001 From: Trigary Date: Sat, 26 Jun 2021 01:22:51 +0200 Subject: [PATCH 011/382] add Adventure README section, Component getter --- README.md | 39 ++++++++++++++++--- .../adventuresupport/ComponentHolder.java | 6 +++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e8e04464b..deff6b242 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,39 @@ The build can then be found in /IF/target/. ## Adventure support -TODO actually write this part of the readme +IF supports [Adventure](https://github.com/KyoriPowered/adventure), but does not shade it in itself. +The use of Adventure `Component`s instead of legacy `String`s completely optional. +If you do not wish to use Adventure you can safely ignore all `TextHolder` related methods. -https://docs.adventure.kyori.net/platform/index.html +### What is Adventure? -full support is obviously only achieved when your platform -(spigot/Paper) natively supports adventure... -but adventure also works on spigot: stuff get converted to legacy +Adventure is a library that adds proper modern text support to Minecraft. +Modern text is represented using bungee-chat and `BaseComponent` instances in Spigot. +Adventure is an alternative to bungee-chat and offers more features. + +### Using Adventure on 1.16.5+ Paper + +You don't need to import/shade anything for Adventure support in this case! + +*Note: Paper only supports Adventure on build 473 and above. If you aren't running months old builds, then you are fine.* + +### Using Adventure on Spigot and older Paper + +On Spigot Adventure isn't included in the server, therefore you have to shade and relocate it yourself. +The following dependencies need to be imported and shaded: +- adventure-api +- adventure-platform-bukkit + +Please consult the [Adventure documentation](https://docs.adventure.kyori.net/) for more information. + +### How to use Adventure `Component`s + +Example of migration from legacy `String` to Adventure `Component`: + - legacy: `namedGui.setTitle("My Title!");` + - Adventure: `namedGui.setTitle(ComponentHolder.of(Component.text("My Title!")));` + +We apologize for the boilerplate (the `ComponentHolder.of(...)` call), but that was the only way to not make IF hard-depend on Adventure. + +Full Adventure support is only achieved when your server natively supports Adventure. +In other words, you won't benefit from Adventure as much if you use Spigot instead of Paper. +This is because for Spigot we have to convert everything back to legacy `String`s before passing them to the Bukkit API. diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java index 6799ddc82..d21a1f24a 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -60,6 +60,12 @@ private static boolean isNativeAdventureSupport() { this.value = value; } + @NotNull + @Contract(pure = true) + public Component getComponent() { + return value; + } + @NotNull @Contract(pure = true) public JsonElement asJson() { From 5074e5b1170f026df71bf6bb761e1222b426e3ba Mon Sep 17 00:00:00 2001 From: Trigary Date: Sat, 26 Jun 2021 01:41:15 +0200 Subject: [PATCH 012/382] don't use tabs for new code in PR --- .editorconfig | 7 ++ .../inventoryframework/pane/Pane.java | 2 +- adventure-support/pom.xml | 72 +++++++++---------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2dc9cc093..89050be96 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,10 @@ indent_style = space indent_size = 4 insert_final_newline = true ij_continuation_indent_size = 8 + +# Indentation override for all +[pom.xml] +indent_style = space +indent_size = 4 +insert_final_newline = false +ij_continuation_indent_size = 8 diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index e80321d8a..597627298 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -358,7 +358,7 @@ public static GuiItem loadItem(@NotNull Object instance, @NotNull Element elemen if (!innerNode.getNodeName().equals("line")) continue; - TextHolder.deserialize(innerNode.getTextContent()) + TextHolder.deserialize(innerNode.getTextContent()) .asItemLoreAtEnd(itemMeta); itemStack.setItemMeta(itemMeta); break; diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index ebffc0a69..1a4d04ab9 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -1,39 +1,39 @@ - - IF-parent - com.github.stefvanschie.inventoryframework - 0.9.9 - - 4.0.0 - - adventure-support - - - true - - - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - - - - com.destroystokyo.paper - paper-api - 1.16.5-R0.1-SNAPSHOT - provided - - - net.kyori - adventure-api - ${adventure.version} - provided - - + 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.9.9 + + 4.0.0 + + adventure-support + + + true + + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + + + com.destroystokyo.paper + paper-api + 1.16.5-R0.1-SNAPSHOT + provided + + + net.kyori + adventure-api + ${adventure.version} + provided + + \ No newline at end of file From 6323da14033af40628435eb70d9b31af6115fb1a Mon Sep 17 00:00:00 2001 From: Trigary Date: Sun, 27 Jun 2021 12:34:20 +0200 Subject: [PATCH 013/382] only downsample colors when necessary --- README.md | 4 ++-- .../adventuresupport/ComponentHolder.java | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index deff6b242..468db8f07 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,6 @@ Example of migration from legacy `String` to Adventure `Component`: We apologize for the boilerplate (the `ComponentHolder.of(...)` call), but that was the only way to not make IF hard-depend on Adventure. -Full Adventure support is only achieved when your server natively supports Adventure. +Full Adventure support is only achieved when your server natively supports Adventure (it is running Paper) and your plugin depends on Paper (instead of Spigot). In other words, you won't benefit from Adventure as much if you use Spigot instead of Paper. -This is because for Spigot we have to convert everything back to legacy `String`s before passing them to the Bukkit API. +This is because when Adventure is relocated we have to convert everything back to legacy `String`s before passing them to the Bukkit API. diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java index d21a1f24a..a4c93a69f 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -18,6 +18,8 @@ public abstract class ComponentHolder extends TextHolder { private static Boolean nativeAdventureSupport; + private static LegacyComponentSerializer legacySerializer; + @NotNull @Contract(pure = true) public static ComponentHolder of(@NotNull Component value) { @@ -53,6 +55,20 @@ private static boolean isNativeAdventureSupport() { return nativeAdventureSupport; } + private static LegacyComponentSerializer getLegacySerializer() { + if (legacySerializer == null) { + LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder() + .character(LegacyComponentSerializer.SECTION_CHAR); + if (!net.md_5.bungee.api.ChatColor.class.isEnum()) { + //1.16+ Spigot (or Paper), hex colors are supported, no need to down sample them + builder.hexColors() + .useUnusualXRepeatedCharacterHexFormat(); + } + legacySerializer = builder.build(); + } + return legacySerializer; + } + @NotNull protected final Component value; @@ -94,8 +110,6 @@ public boolean equals(Object other) { @Contract(pure = true) @Override public String asLegacyString() { - //TODO this down samples colors to the nearest ChatColor - // is this a bug or a feature? - return LegacyComponentSerializer.legacySection().serialize(value); + return getLegacySerializer().serialize(value); } } From 549670d40947f261655c0b5613f083bd244b6d27 Mon Sep 17 00:00:00 2001 From: Trigary Date: Sun, 27 Jun 2021 17:27:32 +0200 Subject: [PATCH 014/382] add JavaDocs --- .../inventoryframework/gui/type/AnvilGui.java | 6 ++ .../gui/type/BarrelGui.java | 6 ++ .../gui/type/BlastFurnaceGui.java | 6 ++ .../gui/type/BrewingStandGui.java | 6 ++ .../gui/type/CartographyTableGui.java | 6 ++ .../inventoryframework/gui/type/ChestGui.java | 14 +++-- .../gui/type/CraftingTableGui.java | 6 ++ .../gui/type/DispenserGui.java | 6 ++ .../gui/type/DropperGui.java | 6 ++ .../gui/type/EnchantingTableGui.java | 6 ++ .../gui/type/EnderChestGui.java | 6 ++ .../gui/type/FurnaceGui.java | 6 ++ .../gui/type/GrindstoneGui.java | 6 ++ .../gui/type/HopperGui.java | 6 ++ .../gui/type/ShulkerBoxGui.java | 6 ++ .../gui/type/SmithingTableGui.java | 6 ++ .../gui/type/SmokerGui.java | 6 ++ .../gui/type/StonecutterGui.java | 6 ++ .../gui/type/util/NamedGui.java | 21 ++++++- .../adventuresupport/ComponentHolder.java | 60 ++++++++++++++++++- .../ForeignComponentHolder.java | 16 +++++ .../NativeComponentHolder.java | 15 ++++- .../adventuresupport/StringHolder.java | 31 +++++++++- .../adventuresupport/TextHolder.java | 47 ++++++++++++++- .../nms/v1_14_R1/AnvilInventoryImpl.java | 4 +- .../CartographyTableInventoryImpl.java | 4 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_14_R1/GrindstoneInventoryImpl.java | 4 +- .../v1_14_R1/StonecutterInventoryImpl.java | 4 +- ...reSupportUtil.java => TextHolderUtil.java} | 30 +++++++++- .../nms/v1_15_R1/AnvilInventoryImpl.java | 4 +- .../CartographyTableInventoryImpl.java | 4 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_15_R1/GrindstoneInventoryImpl.java | 4 +- .../v1_15_R1/StonecutterInventoryImpl.java | 4 +- ...reSupportUtil.java => TextHolderUtil.java} | 30 +++++++++- .../nms/v1_16_R1/AnvilInventoryImpl.java | 4 +- .../CartographyTableInventoryImpl.java | 4 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_16_R1/GrindstoneInventoryImpl.java | 4 +- .../v1_16_R1/SmithingTableInventoryImpl.java | 4 +- .../v1_16_R1/StonecutterInventoryImpl.java | 4 +- ...reSupportUtil.java => TextHolderUtil.java} | 30 +++++++++- .../nms/v1_16_R2/AnvilInventoryImpl.java | 4 +- .../CartographyTableInventoryImpl.java | 4 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_16_R2/GrindstoneInventoryImpl.java | 4 +- .../v1_16_R2/SmithingTableInventoryImpl.java | 4 +- .../v1_16_R2/StonecutterInventoryImpl.java | 4 +- ...reSupportUtil.java => TextHolderUtil.java} | 30 +++++++++- .../nms/v1_16_R3/AnvilInventoryImpl.java | 4 +- .../CartographyTableInventoryImpl.java | 4 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_16_R3/GrindstoneInventoryImpl.java | 4 +- .../v1_16_R3/SmithingTableInventoryImpl.java | 4 +- .../v1_16_R3/StonecutterInventoryImpl.java | 4 +- ...reSupportUtil.java => TextHolderUtil.java} | 30 +++++++++- .../nms/v1_17_R1/AnvilInventoryImpl.java | 4 +- .../CartographyTableInventoryImpl.java | 4 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_17_R1/GrindstoneInventoryImpl.java | 4 +- .../v1_17_R1/SmithingTableInventoryImpl.java | 4 +- .../v1_17_R1/StonecutterInventoryImpl.java | 4 +- ...reSupportUtil.java => TextHolderUtil.java} | 30 +++++++++- 64 files changed, 525 insertions(+), 97 deletions(-) rename nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/{AdventureSupportUtil.java => TextHolderUtil.java} (61%) rename nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/{AdventureSupportUtil.java => TextHolderUtil.java} (61%) rename nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/{AdventureSupportUtil.java => TextHolderUtil.java} (61%) rename nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/{AdventureSupportUtil.java => TextHolderUtil.java} (61%) rename nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/{AdventureSupportUtil.java => TextHolderUtil.java} (61%) rename nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/{AdventureSupportUtil.java => TextHolderUtil.java} (60%) 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 84cec646d..c92e2fae2 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 @@ -75,6 +75,12 @@ public AnvilGui(@NotNull String title) { super(title); } + /** + * Constructs a new anvil gui + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public AnvilGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index 1626f408b..35308cd9c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -51,6 +51,12 @@ public BarrelGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public BarrelGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index 012723ecf..32aa9f615 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -63,6 +63,12 @@ public BlastFurnaceGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public BlastFurnaceGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 9081a94a4..956bddc01 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -75,6 +75,12 @@ public BrewingStandGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public BrewingStandGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index d4dc388c1..3d4538c20 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -78,6 +78,12 @@ public CartographyTableGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public CartographyTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 643bfb9fd..0e88312e5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -42,11 +42,6 @@ public class ChestGui extends NamedGui implements MergedGui { @NotNull private InventoryComponent inventoryComponent; - /** - * The amount of rows this gui has - */ - private int rows; - /** * Constructs a new chest GUI * @@ -57,7 +52,14 @@ public class ChestGui extends NamedGui implements MergedGui { public ChestGui(int rows, @NotNull String title) { this(rows, StringHolder.of(title)); } - + + /** + * Constructs a new chest GUI + * + * @param rows the amount of rows this gui should contain, in range 1..6. + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public ChestGui(int rows, @NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index 966f4d4b5..6eb007ef6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -57,6 +57,12 @@ public CraftingTableGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public CraftingTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index c99837f70..deec09c3a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -51,6 +51,12 @@ public DispenserGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public DispenserGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index 70f6d8bce..fc7e421bd 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -51,6 +51,12 @@ public DropperGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public DropperGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 1e3c8757a..f579fddd2 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -63,6 +63,12 @@ public EnchantingTableGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public EnchantingTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index ec0a8e757..bf292887f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -51,6 +51,12 @@ public EnderChestGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public EnderChestGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index efbbf5b9e..dfab9a7fd 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -63,6 +63,12 @@ public FurnaceGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public FurnaceGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index afe8809cf..2c7e6ff9f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -69,6 +69,12 @@ public GrindstoneGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public GrindstoneGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index bae830f61..31f452145 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -51,6 +51,12 @@ public HopperGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public HopperGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index 9a4deff03..dc6a6cbbd 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -51,6 +51,12 @@ public ShulkerBoxGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public ShulkerBoxGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 771fbb326..48765b105 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -76,6 +76,12 @@ public SmithingTableGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public SmithingTableGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index a0d5b68b0..3a4e8063f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -63,6 +63,12 @@ public SmokerGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public SmokerGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index e52a62f84..005a55beb 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -70,6 +70,12 @@ public StonecutterGui(@NotNull String title) { super(title); } + /** + * Constructs a new GUI + * + * @param title the title/name of this gui. + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public StonecutterGui(@NotNull TextHolder title) { super(title); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java index 8888b3799..2203c2798 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java @@ -26,6 +26,12 @@ public NamedGui(@NotNull String title) { this(StringHolder.of(title)); } + /** + * Constructs a new gui with a title + * + * @param title the title/name of this gui + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public NamedGui(@NotNull TextHolder title) { this.title = title; } @@ -40,6 +46,13 @@ public void setTitle(@NotNull String title) { setTitle(StringHolder.of(title)); } + /** + * Sets the title for this inventory. This will (unlike most other methods) directly update itself in order + * to ensure all viewers will still be viewing the new inventory as well. + * + * @param title the title + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public void setTitle(@NotNull TextHolder title) { //copy the viewers List viewers = getViewers(); @@ -57,7 +70,7 @@ public void setTitle(@NotNull TextHolder title) { } /** - * Returns the title of this gui + * Returns the title of this gui as a legacy string. * * @return the title * @since 0.8.0 @@ -68,6 +81,12 @@ public String getTitle() { return title.asLegacyString(); } + /** + * Returns the title of this GUI in a wrapped form. + * + * @return the title + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public TextHolder getTitleHolder() { diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java index a4c93a69f..a3e96b8f7 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -11,24 +11,54 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Objects; +/** + * Wrapper of an Adventure {@link Component}. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public abstract class ComponentHolder extends TextHolder { + /** + * Whether the server platform natively supports Adventure. + * A null value indicates that we don't yet know this: it hasn't been determined yet. + * This field should not be used directly, use {@link #isNativeAdventureSupport()} instead. + */ + @Nullable private static Boolean nativeAdventureSupport; + /** + * The serializer to use when converting wrapped values to legacy strings. + * A null value indicates that we haven't created the serializer yet. + * This field should not be used directly, use {@link #getLegacySerializer()} instead. + */ + @Nullable private static LegacyComponentSerializer legacySerializer; + /** + * Wraps the specified Adventure component. + * + * @param value the value to wrap + * @return an instance that wraps the specified value + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static ComponentHolder of(@NotNull Component value) { Validate.notNull(value, "value mustn't be null"); return isNativeAdventureSupport() - ? new NativeComponentHolder(value) - : new ForeignComponentHolder(value); + ? new NativeComponentHolder(value) + : new ForeignComponentHolder(value); } + /** + * Gets whether the server platform natively supports Adventure. + * Native Adventure support means that eg. {@link ItemMeta#displayName(Component)} + * is a valid method. + */ private static boolean isNativeAdventureSupport() { if (nativeAdventureSupport == null) { try { @@ -55,6 +85,10 @@ private static boolean isNativeAdventureSupport() { return nativeAdventureSupport; } + /** + * Gets the serializer to use when converting wrapped values to legacy strings. + * Main use case being the implementation of {@link #asLegacyString()}. + */ private static LegacyComponentSerializer getLegacySerializer() { if (legacySerializer == null) { LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder() @@ -69,19 +103,39 @@ private static LegacyComponentSerializer getLegacySerializer() { return legacySerializer; } + /** + * The Adventure component this instance wraps. + */ @NotNull protected final Component value; + /** + * Creates and initializes a new instance. + * + * @param value the Adventure component this instance should wrap + */ ComponentHolder(@NotNull Component value) { this.value = value; } + /** + * Gets the Adventure component this instance wraps. + * + * @return the contained Adventure component + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public Component getComponent() { return value; } + /** + * Gets the wrapped Adventure component in a JSON representation. + * + * @return the contained Adventure component as JSON + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public JsonElement asJson() { @@ -103,7 +157,7 @@ public int hashCode() { @Override public boolean equals(Object other) { return other != null && getClass() == other.getClass() - && Objects.equals(value, ((ComponentHolder) other).value); + && Objects.equals(value, ((ComponentHolder) other).value); } @NotNull diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java index 9985a3291..3b68f4289 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java @@ -8,10 +8,26 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +/** + * A {@link ComponentHolder} implementation for platforms where Adventure isn't natively supported. + * Adventure components are converted to legacy Strings before passed to the Bukkit API. + * + * @see NativeComponentHolder + */ class ForeignComponentHolder extends ComponentHolder { + /** + * A {@link StringHolder} wrapping {@link #asLegacyString()}. + * This class depends on {@link StringHolder} to reduce code duplication. + */ + @NotNull private final StringHolder legacy; + /** + * Creates and initializes a new instance. + * + * @param value the Adventure component this instance should wrap + */ ForeignComponentHolder(@NotNull Component value) { super(value); legacy = StringHolder.of(asLegacyString()); diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java index 96b49f8cb..cbe804538 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java @@ -13,8 +13,19 @@ import java.util.List; import java.util.Objects; +/** + * A {@link ComponentHolder} implementation for platforms where Adventure is natively supported. + * Adventure components are directly passed to the Bukkit (Paper) API. + * + * @see ForeignComponentHolder + */ class NativeComponentHolder extends ComponentHolder { + /** + * Creates and initializes a new instance. + * + * @param value the Adventure component this instance should wrap + */ NativeComponentHolder(@NotNull Component value) { super(value); } @@ -41,8 +52,8 @@ public void asItemDisplayName(ItemMeta meta) { @Override public void asItemLoreAtEnd(ItemMeta meta) { List lore = meta.hasLore() - ? Objects.requireNonNull(meta.lore()) - : new ArrayList<>(); + ? Objects.requireNonNull(meta.lore()) + : new ArrayList<>(); lore.add(value); meta.lore(lore); } diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java index 9b9997597..05dc6dda4 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java @@ -13,11 +13,27 @@ import java.util.List; import java.util.Objects; +/** + * Wrapper of a legacy string value. + * {@link org.bukkit.ChatColor} based formatting is used. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public final class StringHolder extends TextHolder { + /** + * Cached instance which wraps an empty {@link String}. + */ @NotNull private static final StringHolder EMPTY = StringHolder.of(""); + /** + * Wraps the specified legacy string. + * + * @param value the value to wrap + * @return an instance that wraps the specified value + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static StringHolder of(@NotNull String value) { @@ -29,6 +45,7 @@ public static StringHolder of(@NotNull String value) { * Gets an instance that contains no characters. * * @return an instance without any characters + * @since $ADVENTURE-SUPPORT-SINCE$ */ @NotNull @Contract(pure = true) @@ -36,9 +53,17 @@ public static StringHolder empty() { return EMPTY; } + /** + * The legacy string this instance wraps. + */ @NotNull private final String value; + /** + * Creates and initializes a new instance. + * + * @param value the legacy string this instance should wrap + */ private StringHolder(@NotNull String value) { this.value = value; } @@ -58,7 +83,7 @@ public int hashCode() { @Override public boolean equals(Object other) { return other != null && getClass() == other.getClass() - && Objects.equals(value, ((StringHolder) other).value); + && Objects.equals(value, ((StringHolder) other).value); } @NotNull @@ -94,8 +119,8 @@ public void asItemDisplayName(ItemMeta meta) { public void asItemLoreAtEnd(ItemMeta meta) { //noinspection deprecation List lore = meta.hasLore() - ? Objects.requireNonNull(meta.getLore()) - : new ArrayList<>(); + ? Objects.requireNonNull(meta.getLore()) + : new ArrayList<>(); lore.add(value); //noinspection deprecation meta.setLore(lore); diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java index cabfe282a..f7eb5eb51 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.adventuresupport; +import net.kyori.adventure.text.Component; import org.bukkit.ChatColor; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; @@ -11,16 +12,22 @@ /** * Immutable wrapper of a text-like value. * Support for both Adventure and legacy strings is achieved through this class. + * To get an instance of this class please refer to either {@link StringHolder#of(String)} + * or {@link ComponentHolder#of(Component)}. + * Other methods like {@link #empty()} and {@link #deserialize(String)} + * also exist, but their use cases are very limited. * * @see StringHolder * @see ComponentHolder + * @since $ADVENTURE-SUPPORT-SINCE$ */ public abstract class TextHolder { /** - * Gets an instance that contains no characters. + * Gets an instance that contains no characters and no formatting. * - * @return an instance without any characters + * @return an instance without any characters or formatting + * @since $ADVENTURE-SUPPORT-SINCE$ */ @NotNull @Contract(pure = true) @@ -38,6 +45,7 @@ public static TextHolder empty() { * * @param string the raw data to deserialize * @return an instance containing the text from the string + * @since $ADVENTURE-SUPPORT-SINCE$ */ @NotNull @Contract(pure = true) @@ -60,19 +68,54 @@ public static TextHolder deserialize(@NotNull String string) { @Override public abstract boolean equals(Object other); + /** + * Converts the text wrapped by this class instance to a legacy string, + * keeping the original formatting. + * + * @return the wrapped value represented as a legacy string + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public abstract String asLegacyString(); + /** + * Creates a new inventory with the wrapped value as the inventory's title. + * + * @param holder the holder to use for the new inventory + * @param type the type of inventory to create + * @return a newly created inventory with the wrapped value as its title + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public abstract Inventory asInventoryTitle(InventoryHolder holder, InventoryType type); + /** + * Creates a new inventory with the wrapped value as the inventory's title. + * + * @param holder the holder to use for the new inventory + * @param size the count of slots the inventory should have (normal size restrictions apply) + * @return a newly created inventory with the wrapped value as its title + * @since $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public abstract Inventory asInventoryTitle(InventoryHolder holder, int size); + /** + * Modifies the specified meta: sets the display name to the wrapped value. + * + * @param meta the meta whose display name to set + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public abstract void asItemDisplayName(ItemMeta meta); + /** + * Modifies the specified meta: adds the wrapped value as a new lore line at the end + * + * @param meta the meta whose lore to append to + * @since $ADVENTURE-SUPPORT-SINCE$ + */ public abstract void asItemLoreAtEnd(ItemMeta meta); } diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java index dbaa54f32..e7b7bf10b 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.TextHolderUtil; import net.minecraft.server.v1_14_R1.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; @@ -46,7 +46,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java index 48870003b..7722d72e5 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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; @@ -47,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java index 53f88f68e..669259a13 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java index 12418f526..57f33a193 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java index 2a46f07a5..fc4513817 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/AdventureSupportUtil.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java similarity index 61% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/AdventureSupportUtil.java rename to nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java index 0fb17bd00..a6b9fb441 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/AdventureSupportUtil.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java @@ -10,12 +10,24 @@ import java.util.Objects; -public final class AdventureSupportUtil { +/** + * A utility class for adding {@link TextHolder} support. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ +public final class TextHolderUtil { - private AdventureSupportUtil() { + 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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { @@ -26,12 +38,26 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder 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 $ADVENTURE-SUPPORT-SINCE$ + */ @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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java index 2820b588e..4ee7d368c 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.TextHolderUtil; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; @@ -46,7 +46,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java index fdcbc74a9..e7120b77e 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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; @@ -47,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java index 48fbaf98d..280905787 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java index 8e8efe4fd..eef5dd4c9 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java index 5cbbc7d9f..0750b8db4 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/AdventureSupportUtil.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java similarity index 61% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/AdventureSupportUtil.java rename to nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java index cde9096ae..d1ffc4fc2 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/AdventureSupportUtil.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java @@ -10,12 +10,24 @@ import java.util.Objects; -public final class AdventureSupportUtil { +/** + * A utility class for adding {@link TextHolder} support. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ +public final class TextHolderUtil { - private AdventureSupportUtil() { + 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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { @@ -26,12 +38,26 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder 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 $ADVENTURE-SUPPORT-SINCE$ + */ @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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java index baa98976a..5c1865554 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.TextHolderUtil; import net.minecraft.server.v1_16_R1.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; @@ -44,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java index a55263007..a4e723886 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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; @@ -47,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java index f8cc6cd29..817393c7d 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java index 71e31b3cd..58945ae1d 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java index c0b1c8778..1c5607dfd 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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; @@ -43,7 +43,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerSmithingTable; int id = containerSmithingTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java index f2a090720..eb961f3fe 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/AdventureSupportUtil.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java similarity index 61% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/AdventureSupportUtil.java rename to nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java index cbaa7d735..2c36b77c3 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/AdventureSupportUtil.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java @@ -10,12 +10,24 @@ import java.util.Objects; -public final class AdventureSupportUtil { +/** + * A utility class for adding {@link TextHolder} support. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ +public final class TextHolderUtil { - private AdventureSupportUtil() { + 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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { @@ -26,12 +38,26 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder 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 $ADVENTURE-SUPPORT-SINCE$ + */ @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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java index dd1ab839e..fb0a879c8 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.TextHolderUtil; import net.minecraft.server.v1_16_R2.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; @@ -44,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java index edd791e57..454deb361 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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.*; @@ -44,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java index 3573a7a05..e98bc58ed 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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.*; @@ -42,7 +42,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java index 5b8e11ac3..78153d189 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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.*; @@ -42,7 +42,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java index bbf3bd329..448985a38 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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.*; @@ -40,7 +40,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerSmithingTable; int id = containerSmithingTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java index e56d7e05e..1e0f0d2f7 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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.*; @@ -42,7 +42,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/AdventureSupportUtil.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java similarity index 61% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/AdventureSupportUtil.java rename to nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java index 5f7ffcf88..2a12c452d 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/AdventureSupportUtil.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java @@ -10,12 +10,24 @@ import java.util.Objects; -public final class AdventureSupportUtil { +/** + * A utility class for adding {@link TextHolder} support. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ +public final class TextHolderUtil { - private AdventureSupportUtil() { + 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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { @@ -26,12 +38,26 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder 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 $ADVENTURE-SUPPORT-SINCE$ + */ @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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java index f347a7576..2fc09ac52 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.TextHolderUtil; import net.minecraft.server.v1_16_R3.*; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; @@ -44,7 +44,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerAnvil; int id = containerAnvil.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java index 1f2077e1c..90dcbb098 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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; @@ -47,7 +47,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerCartographyTable; int id = containerCartographyTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.CARTOGRAPHY_TABLE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java index 512b7e440..e557206fc 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.ENCHANTMENT, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java index 6c10cdc9c..be26bbf08 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerGrindstone; int id = containerGrindstone.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java index 4fd5ca708..20bd19ac3 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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; @@ -43,7 +43,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerSmithingTable; int id = containerSmithingTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.SMITHING, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java index 3150315df..701e46e93 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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; @@ -45,7 +45,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.activeContainer = containerEnchantmentTable; int id = containerEnchantmentTable.windowId; - IChatBaseComponent message = AdventureSupportUtil.toComponent(title); + IChatBaseComponent message = TextHolderUtil.toComponent(title); PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.STONECUTTER, message); entityPlayer.playerConnection.sendPacket(packet); diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/AdventureSupportUtil.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java similarity index 61% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/AdventureSupportUtil.java rename to nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java index 39b4f2d3e..275585611 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/AdventureSupportUtil.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java @@ -10,12 +10,24 @@ import java.util.Objects; -public final class AdventureSupportUtil { +/** + * A utility class for adding {@link TextHolder} support. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ +public final class TextHolderUtil { - private AdventureSupportUtil() { + 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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { @@ -26,12 +38,26 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder 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 $ADVENTURE-SUPPORT-SINCE$ + */ @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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) private static IChatBaseComponent toComponent(@NotNull ComponentHolder holder) { diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java index 89ac428f6..6b17f777e 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; @@ -57,7 +57,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.containerMenu = containerAnvil; int id = containerAnvil.containerId; - Component message = AdventureSupportUtil.toComponent(title); + Component message = TextHolderUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java index d614a3585..cd9b6ee34 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -58,7 +58,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.containerMenu = containerCartographyTable; int id = containerCartographyTable.containerId; - Component message = AdventureSupportUtil.toComponent(title); + Component message = TextHolderUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java index ed6035272..419f25b1c 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -55,7 +55,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.containerMenu = containerEnchantmentTable; int id = containerEnchantmentTable.containerId; - Component message = AdventureSupportUtil.toComponent(title); + Component message = TextHolderUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java index 0e35ee7e5..3828c60a4 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -56,7 +56,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.containerMenu = containerGrindstone; int id = containerGrindstone.containerId; - Component message = AdventureSupportUtil.toComponent(title); + Component message = TextHolderUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java index 8a16aa8c1..d143e879e 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; @@ -56,7 +56,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.containerMenu = containerSmithingTable; int id = containerSmithingTable.containerId; - Component message = AdventureSupportUtil.toComponent(title); + Component message = TextHolderUtil.toComponent(title); serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java index fa59ffe0c..fc858f5ca 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java @@ -2,7 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.AdventureSupportUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -55,7 +55,7 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.containerMenu = containerEnchantmentTable; int id = containerEnchantmentTable.containerId; - Component message = AdventureSupportUtil.toComponent(title); + Component message = TextHolderUtil.toComponent(title); ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); serverPlayer.connection.send(packet); diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/AdventureSupportUtil.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java similarity index 60% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/AdventureSupportUtil.java rename to nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java index de520e73a..397f5d4c5 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/AdventureSupportUtil.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java @@ -10,12 +10,24 @@ import java.util.Objects; -public final class AdventureSupportUtil { +/** + * A utility class for adding {@link TextHolder} support. + * + * @since $ADVENTURE-SUPPORT-SINCE$ + */ +public final class TextHolderUtil { - private AdventureSupportUtil() { + 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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) public static Component toComponent(@NotNull TextHolder holder) { @@ -26,12 +38,26 @@ public static Component toComponent(@NotNull TextHolder 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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) private static Component toComponent(@NotNull StringHolder holder) { return new TextComponent(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 $ADVENTURE-SUPPORT-SINCE$ + */ @NotNull @Contract(pure = true) private static Component toComponent(@NotNull ComponentHolder holder) { From f9e30bf3bb314be6834a004fa4b8963d6df56f38 Mon Sep 17 00:00:00 2001 From: Trigary Date: Mon, 5 Jul 2021 23:04:41 +0200 Subject: [PATCH 015/382] fix typo, add missing @return tags --- README.md | 2 +- .../inventoryframework/adventuresupport/ComponentHolder.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 468db8f07..7e949b2a9 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ The build can then be found in /IF/target/. ## Adventure support IF supports [Adventure](https://github.com/KyoriPowered/adventure), but does not shade it in itself. -The use of Adventure `Component`s instead of legacy `String`s completely optional. +The use of Adventure `Component`s instead of legacy `String`s is completely optional. If you do not wish to use Adventure you can safely ignore all `TextHolder` related methods. ### What is Adventure? diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java index a3e96b8f7..7554d2841 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -58,6 +58,8 @@ public static ComponentHolder of(@NotNull Component value) { * Gets whether the server platform natively supports Adventure. * Native Adventure support means that eg. {@link ItemMeta#displayName(Component)} * is a valid method. + * + * @return whether the server platform natively supports Adventure */ private static boolean isNativeAdventureSupport() { if (nativeAdventureSupport == null) { @@ -88,6 +90,8 @@ private static boolean isNativeAdventureSupport() { /** * Gets the serializer to use when converting wrapped values to legacy strings. * Main use case being the implementation of {@link #asLegacyString()}. + * + * @return a serializer for converting wrapped values to legacy strings */ private static LegacyComponentSerializer getLegacySerializer() { if (legacySerializer == null) { From f3e7b114444e01ac3dce077759d0b26bd991970a Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 6 Jul 2021 16:21:58 +0200 Subject: [PATCH 016/382] Change since tags --- .../inventoryframework/gui/type/AnvilGui.java | 2 +- .../inventoryframework/gui/type/BarrelGui.java | 2 +- .../gui/type/BlastFurnaceGui.java | 2 +- .../gui/type/BrewingStandGui.java | 2 +- .../gui/type/CartographyTableGui.java | 2 +- .../inventoryframework/gui/type/ChestGui.java | 2 +- .../gui/type/CraftingTableGui.java | 2 +- .../gui/type/DispenserGui.java | 2 +- .../inventoryframework/gui/type/DropperGui.java | 2 +- .../gui/type/EnchantingTableGui.java | 2 +- .../gui/type/EnderChestGui.java | 2 +- .../inventoryframework/gui/type/FurnaceGui.java | 2 +- .../gui/type/GrindstoneGui.java | 2 +- .../inventoryframework/gui/type/HopperGui.java | 2 +- .../gui/type/ShulkerBoxGui.java | 2 +- .../gui/type/SmithingTableGui.java | 2 +- .../inventoryframework/gui/type/SmokerGui.java | 2 +- .../gui/type/StonecutterGui.java | 2 +- .../gui/type/util/NamedGui.java | 6 +++--- .../adventuresupport/ComponentHolder.java | 11 +++++++---- .../adventuresupport/ForeignComponentHolder.java | 2 ++ .../adventuresupport/NativeComponentHolder.java | 2 ++ .../adventuresupport/StringHolder.java | 7 ++++--- .../adventuresupport/TextHolder.java | 16 ++++++++-------- .../nms/v1_14_R1/util/TextHolderUtil.java | 8 ++++---- .../nms/v1_15_R1/util/TextHolderUtil.java | 8 ++++---- .../nms/v1_16_R1/util/TextHolderUtil.java | 8 ++++---- .../nms/v1_16_R2/util/TextHolderUtil.java | 8 ++++---- .../nms/v1_16_R3/util/TextHolderUtil.java | 8 ++++---- .../nms/v1_17_R1/util/TextHolderUtil.java | 8 ++++---- 30 files changed, 68 insertions(+), 60 deletions(-) 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 c92e2fae2..e021518af 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 @@ -79,7 +79,7 @@ public AnvilGui(@NotNull String title) { * Constructs a new anvil gui * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public AnvilGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index 35308cd9c..cf2ff8d3d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -55,7 +55,7 @@ public BarrelGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public BarrelGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index 32aa9f615..9fced8054 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -67,7 +67,7 @@ public BlastFurnaceGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public BlastFurnaceGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 956bddc01..38ee28cbb 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -79,7 +79,7 @@ public BrewingStandGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public BrewingStandGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 3d4538c20..274c36b0d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -82,7 +82,7 @@ public CartographyTableGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public CartographyTableGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 0e88312e5..44ac14c83 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -58,7 +58,7 @@ public ChestGui(int rows, @NotNull String title) { * * @param rows the amount of rows this gui should contain, in range 1..6. * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public ChestGui(int rows, @NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index 6eb007ef6..f1728903d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -61,7 +61,7 @@ public CraftingTableGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public CraftingTableGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index deec09c3a..ab96fa5eb 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -55,7 +55,7 @@ public DispenserGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public DispenserGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index fc7e421bd..6eb970563 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -55,7 +55,7 @@ public DropperGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public DropperGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index f579fddd2..6d2111ce9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -67,7 +67,7 @@ public EnchantingTableGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public EnchantingTableGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index bf292887f..71478adb6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -55,7 +55,7 @@ public EnderChestGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public EnderChestGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index dfab9a7fd..6552b5d5f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -67,7 +67,7 @@ public FurnaceGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public FurnaceGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index 2c7e6ff9f..0534be860 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -73,7 +73,7 @@ public GrindstoneGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public GrindstoneGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index 31f452145..7afa6b97f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -55,7 +55,7 @@ public HopperGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public HopperGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index dc6a6cbbd..5fcd82cc8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -55,7 +55,7 @@ public ShulkerBoxGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public ShulkerBoxGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 48765b105..43cfb2d7a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -80,7 +80,7 @@ public SmithingTableGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public SmithingTableGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index 3a4e8063f..5fd263519 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -67,7 +67,7 @@ public SmokerGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public SmokerGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 005a55beb..c1ee199a7 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -74,7 +74,7 @@ public StonecutterGui(@NotNull String title) { * Constructs a new GUI * * @param title the title/name of this gui. - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public StonecutterGui(@NotNull TextHolder title) { super(title); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java index 2203c2798..8465763c5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java @@ -30,7 +30,7 @@ public NamedGui(@NotNull String title) { * Constructs a new gui with a title * * @param title the title/name of this gui - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public NamedGui(@NotNull TextHolder title) { this.title = title; @@ -51,7 +51,7 @@ public void setTitle(@NotNull String title) { * to ensure all viewers will still be viewing the new inventory as well. * * @param title the title - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public void setTitle(@NotNull TextHolder title) { //copy the viewers @@ -85,7 +85,7 @@ public String getTitle() { * Returns the title of this GUI in a wrapped form. * * @return the title - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java index 7554d2841..3d6a4b587 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ComponentHolder.java @@ -18,7 +18,7 @@ /** * Wrapper of an Adventure {@link Component}. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public abstract class ComponentHolder extends TextHolder { @@ -43,7 +43,7 @@ public abstract class ComponentHolder extends TextHolder { * * @param value the value to wrap * @return an instance that wraps the specified value - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -60,6 +60,7 @@ public static ComponentHolder of(@NotNull Component value) { * is a valid method. * * @return whether the server platform natively supports Adventure + * @since 0.10.0 */ private static boolean isNativeAdventureSupport() { if (nativeAdventureSupport == null) { @@ -92,6 +93,7 @@ private static boolean isNativeAdventureSupport() { * Main use case being the implementation of {@link #asLegacyString()}. * * @return a serializer for converting wrapped values to legacy strings + * @since 0.10.0 */ private static LegacyComponentSerializer getLegacySerializer() { if (legacySerializer == null) { @@ -117,6 +119,7 @@ private static LegacyComponentSerializer getLegacySerializer() { * Creates and initializes a new instance. * * @param value the Adventure component this instance should wrap + * @since 0.10.0 */ ComponentHolder(@NotNull Component value) { this.value = value; @@ -126,7 +129,7 @@ private static LegacyComponentSerializer getLegacySerializer() { * Gets the Adventure component this instance wraps. * * @return the contained Adventure component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -138,7 +141,7 @@ public Component getComponent() { * Gets the wrapped Adventure component in a JSON representation. * * @return the contained Adventure component as JSON - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java index 3b68f4289..f4d5ce578 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java @@ -13,6 +13,7 @@ * Adventure components are converted to legacy Strings before passed to the Bukkit API. * * @see NativeComponentHolder + * @since 0.10.0 */ class ForeignComponentHolder extends ComponentHolder { @@ -27,6 +28,7 @@ class ForeignComponentHolder extends ComponentHolder { * Creates and initializes a new instance. * * @param value the Adventure component this instance should wrap + * @since 0.10.0 */ ForeignComponentHolder(@NotNull Component value) { super(value); diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java index cbe804538..f3698382a 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java @@ -18,6 +18,7 @@ * Adventure components are directly passed to the Bukkit (Paper) API. * * @see ForeignComponentHolder + * @since 0.10.0 */ class NativeComponentHolder extends ComponentHolder { @@ -25,6 +26,7 @@ class NativeComponentHolder extends ComponentHolder { * Creates and initializes a new instance. * * @param value the Adventure component this instance should wrap + * @since 0.10.0 */ NativeComponentHolder(@NotNull Component value) { super(value); diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java index 05dc6dda4..e9b264eff 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java @@ -17,7 +17,7 @@ * Wrapper of a legacy string value. * {@link org.bukkit.ChatColor} based formatting is used. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public final class StringHolder extends TextHolder { @@ -32,7 +32,7 @@ public final class StringHolder extends TextHolder { * * @param value the value to wrap * @return an instance that wraps the specified value - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -45,7 +45,7 @@ public static StringHolder of(@NotNull String value) { * Gets an instance that contains no characters. * * @return an instance without any characters - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -63,6 +63,7 @@ public static StringHolder empty() { * Creates and initializes a new instance. * * @param value the legacy string this instance should wrap + * @since 0.10.0 */ private StringHolder(@NotNull String value) { this.value = value; diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java index f7eb5eb51..7de003b12 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java @@ -19,7 +19,7 @@ * * @see StringHolder * @see ComponentHolder - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public abstract class TextHolder { @@ -27,7 +27,7 @@ public abstract class TextHolder { * Gets an instance that contains no characters and no formatting. * * @return an instance without any characters or formatting - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -45,7 +45,7 @@ public static TextHolder empty() { * * @param string the raw data to deserialize * @return an instance containing the text from the string - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -73,7 +73,7 @@ public static TextHolder deserialize(@NotNull String string) { * keeping the original formatting. * * @return the wrapped value represented as a legacy string - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -85,7 +85,7 @@ public static TextHolder deserialize(@NotNull String string) { * @param holder the holder to use for the new inventory * @param type the type of inventory to create * @return a newly created inventory with the wrapped value as its title - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -97,7 +97,7 @@ public static TextHolder deserialize(@NotNull String string) { * @param holder the holder to use for the new inventory * @param size the count of slots the inventory should have (normal size restrictions apply) * @return a newly created inventory with the wrapped value as its title - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -107,7 +107,7 @@ public static TextHolder deserialize(@NotNull String string) { * Modifies the specified meta: sets the display name to the wrapped value. * * @param meta the meta whose display name to set - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public abstract void asItemDisplayName(ItemMeta meta); @@ -115,7 +115,7 @@ public static TextHolder deserialize(@NotNull String string) { * Modifies the specified meta: adds the wrapped value as a new lore line at the end * * @param meta the meta whose lore to append to - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public abstract void asItemLoreAtEnd(ItemMeta meta); } diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java index a6b9fb441..4b7a1f58c 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java +++ b/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java index d1ffc4fc2..e2888af2d 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java +++ b/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java index 2c36b77c3..97bea8a28 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java +++ b/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java index 2a12c452d..8462e9ece 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java +++ b/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java index 275585611..397723c95 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java +++ b/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static IChatBaseComponent toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static IChatBaseComponent toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java index 397f5d4c5..a9d9b7710 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java +++ b/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static Component toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static Component toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since $ADVENTURE-SUPPORT-SINCE$ + * @since 0.10.0 */ @NotNull @Contract(pure = true) From 31415a4e86fd5adac669a7bb7f7f5645c329d6a8 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 8 Jul 2021 17:29:22 +0200 Subject: [PATCH 017/382] Add merchant gui --- .../inventoryframework/gui/GuiListener.java | 21 +- .../gui/InventoryComponent.java | 9 +- .../inventoryframework/gui/type/AnvilGui.java | 35 +- .../gui/type/BarrelGui.java | 34 +- .../gui/type/BeaconGui.java | 30 +- .../gui/type/BlastFurnaceGui.java | 35 +- .../gui/type/BrewingStandGui.java | 35 +- .../gui/type/CartographyTableGui.java | 35 +- .../inventoryframework/gui/type/ChestGui.java | 45 ++- .../gui/type/CraftingTableGui.java | 35 +- .../gui/type/DispenserGui.java | 35 +- .../gui/type/DropperGui.java | 35 +- .../gui/type/EnchantingTableGui.java | 35 +- .../gui/type/EnderChestGui.java | 34 +- .../gui/type/FurnaceGui.java | 35 +- .../gui/type/GrindstoneGui.java | 35 +- .../gui/type/HopperGui.java | 35 +- .../gui/type/MerchantGui.java | 364 ++++++++++++++++++ .../gui/type/ShulkerBoxGui.java | 34 +- .../gui/type/SmithingTableGui.java | 35 +- .../gui/type/SmokerGui.java | 35 +- .../gui/type/StonecutterGui.java | 35 +- .../inventoryframework/gui/type/util/Gui.java | 32 +- .../gui/type/util/InventoryBased.java | 20 + .../gui/type/util/NamedGui.java | 48 ++- .../inventoryframework/pane/Pane.java | 7 +- .../ForeignComponentHolder.java | 9 + .../NativeComponentHolder.java | 11 +- .../adventuresupport/StringHolder.java | 11 +- .../adventuresupport/TextHolder.java | 11 + 30 files changed, 1106 insertions(+), 104 deletions(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/InventoryBased.java diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index 0703a5e0b..a5cbfcc14 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -300,13 +300,7 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { //due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly client-side playerInventory.setItemInOffHand(playerInventory.getItemInOffHand()); - if (gui.isUpdating()) { - gui.getHumanEntityCache().restoreAndForget(humanEntity); - - if (gui.getViewerCount() == 1) { - activeGuiInstances.remove(gui); - } - } else { + if (!gui.isUpdating()) { gui.callOnClose(event); //this is a hack to remove items correctly when players press the x button in a beacon @@ -316,6 +310,19 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { } }); } + + //delay because merchants put items in slots back in the player inventory + Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { + gui.getHumanEntityCache().restoreAndForget(humanEntity); + + if (gui.getViewerCount() == 1) { + activeGuiInstances.remove(gui); + } + + if (gui instanceof MerchantGui) { + ((MerchantGui) gui).handleClose(humanEntity); + } + }); } /** 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 9dd4d6d12..83c846f00 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 @@ -1,6 +1,7 @@ package com.github.stefvanschie.inventoryframework.gui; 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.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; @@ -122,10 +123,10 @@ public void display(@NotNull Inventory inventory, int offset) { * This will make each pane in this component render their items in this inventory component. The panes are * 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. The items displayed in this - * inventory component will be put into the inventory found in {@link Gui#getInventory()}. The slots will be placed - * from the top-right to the bottom-left, continuing from left-to-right, top-to-bottom plus the specified offset. - * This ordering is different from the normal ordering of the indices of a {@link PlayerInventory}. See for the - * normal ordering of a {@link PlayerInventory}'s slots its documentation. + * inventory component will be put into the inventory found in {@link InventoryBased#getInventory()}. The slots will + * be placed from the top-right to the bottom-left, continuing from left-to-right, top-to-bottom plus the specified + * offset. This ordering is different from the normal ordering of the indices of a {@link PlayerInventory}. See for + * 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 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 e021518af..7e9e967c2 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 @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; @@ -26,13 +27,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of an anvil * * @since 0.8.0 */ -public class AnvilGui extends NamedGui { +public class AnvilGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the first item @@ -91,6 +94,11 @@ public void show(@NotNull HumanEntity humanEntity) { throw new IllegalArgumentException("Anvils can only be opened by players"); } + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -147,10 +155,20 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.ANVIL); } @@ -173,6 +191,19 @@ public boolean isPlayerInventoryUsed() { return getPlayerInventoryComponent().hasItem(); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Handles an incoming inventory click event * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index cf2ff8d3d..568c749c6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; @@ -24,6 +25,7 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -33,7 +35,7 @@ * * @since 0.8.0 */ -public class BarrelGui extends NamedGui implements MergedGui { +public class BarrelGui extends NamedGui implements MergedGui, InventoryBased { /** * Represents the inventory component for the entire gui @@ -63,6 +65,11 @@ public BarrelGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -105,6 +112,16 @@ public BarrelGui copy() { return gui; } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Override public void click(@NotNull InventoryClickEvent event) { getInventoryComponent().click(this, event, event.getRawSlot()); @@ -138,10 +155,23 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.BARREL); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + @NotNull @Contract(pure = true) @Override diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java index c0f68d4a3..1925bbec4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; import org.bukkit.Bukkit; @@ -25,13 +26,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a beacon * * @since 0.8.0 */ -public class BeaconGui extends Gui { +public class BeaconGui extends Gui implements InventoryBased { /** * Represents the payment item inventory component @@ -105,6 +108,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -114,10 +127,23 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return Bukkit.createInventory(this, InventoryType.BEACON); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Handles an incoming inventory click event * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index 9fced8054..f95e5ba6b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a blast furnace * * @since 0.8.0 */ -public class BlastFurnaceGui extends NamedGui { +public class BlastFurnaceGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the ingredient @@ -75,6 +78,11 @@ public BlastFurnaceGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -130,6 +138,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -139,10 +157,23 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.BLAST_FURNACE); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the ingredient * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 38ee28cbb..5820c8efe 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a brewing stand * * @since 0.8.0 */ -public class BrewingStandGui extends NamedGui { +public class BrewingStandGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the first bottle @@ -87,6 +90,11 @@ public BrewingStandGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -156,10 +164,20 @@ public boolean isPlayerInventoryUsed() { return getPlayerInventoryComponent().hasItem(); } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.BREWING); addInventory(inventory, this); @@ -167,6 +185,19 @@ protected Inventory createInventory() { return inventory; } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the first bottle * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 274c36b0d..f230a5eee 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; @@ -28,13 +29,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a cartography table * * @since 0.8.0 */ -public class CartographyTableGui extends NamedGui { +public class CartographyTableGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the map @@ -94,6 +97,11 @@ public void show(@NotNull HumanEntity humanEntity) { throw new IllegalArgumentException("Cartography tables can only be opened by players"); } + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -149,6 +157,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -158,10 +176,23 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.CARTOGRAPHY); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Handles an incoming inventory click event * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 44ac14c83..36a2069ba 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -5,6 +5,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; @@ -24,6 +25,7 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -34,7 +36,7 @@ * * @since 0.8.0 */ -public class ChestGui extends NamedGui implements MergedGui { +public class ChestGui extends NamedGui implements MergedGui, InventoryBased { /** * Represents the inventory component for the entire gui @@ -42,6 +44,11 @@ public class ChestGui extends NamedGui implements MergedGui { @NotNull private InventoryComponent inventoryComponent; + /** + * Whether the amount of rows are dirty i.e. has been changed + */ + private boolean dirtyRows = false; + /** * Constructs a new chest GUI * @@ -72,6 +79,13 @@ public ChestGui(int rows, @NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty() || dirtyRows) { + this.inventory = createInventory(); + this.dirtyRows = true; + + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -138,13 +152,17 @@ public void setRows(int rows) { } this.inventoryComponent = new InventoryComponent(9, rows + 4); + this.dirtyRows = true; + } - //copy the viewers - List viewers = getViewers(); - - this.inventory = createInventory(); + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } - viewers.forEach(humanEntity -> humanEntity.openInventory(inventory)); + return inventory; } @Override @@ -169,7 +187,7 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, getRows() * 9); } @@ -184,6 +202,19 @@ public int getRows() { return getInventoryComponent().getHeight() - 4; } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + @NotNull @Contract(pure = true) @Override diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index f1728903d..61eda8a86 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a crafting table * * @since 0.8.0 */ -public class CraftingTableGui extends NamedGui { +public class CraftingTableGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the input @@ -69,6 +72,11 @@ public CraftingTableGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -120,6 +128,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -129,10 +147,23 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.WORKBENCH); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the input * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index ab96fa5eb..8aeabe5a4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a dispenser * * @since 0.8.0 */ -public class DispenserGui extends NamedGui { +public class DispenserGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the contents @@ -63,6 +66,11 @@ public DispenserGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -110,6 +118,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -119,7 +137,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.DISPENSER); addInventory(inventory, this); @@ -127,6 +145,19 @@ protected Inventory createInventory() { return inventory; } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the contents * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index 6eb970563..8a91a70a8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a dropper * * @since 0.8.0 */ -public class DropperGui extends NamedGui { +public class DropperGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the contents @@ -63,6 +66,11 @@ public DropperGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -110,6 +118,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -119,7 +137,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.DROPPER); addInventory(inventory, this); @@ -127,6 +145,19 @@ protected Inventory createInventory() { return inventory; } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the contents * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 6d2111ce9..664a8a857 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; @@ -26,13 +27,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of an enchanting table * * @since 0.8.0 */ -public class EnchantingTableGui extends NamedGui { +public class EnchantingTableGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the input @@ -79,6 +82,11 @@ public void show(@NotNull HumanEntity humanEntity) { throw new IllegalArgumentException("Enchanting tables can only be opened by players"); } + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -126,6 +134,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -135,7 +153,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.ENCHANTING); } @@ -158,6 +176,19 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { } } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the input * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index 71478adb6..c202d49c9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; @@ -24,6 +25,7 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -33,7 +35,7 @@ * * @since 0.8.0 */ -public class EnderChestGui extends NamedGui implements MergedGui { +public class EnderChestGui extends NamedGui implements MergedGui, InventoryBased { /** * Represents the inventory component for the entire gui @@ -63,6 +65,11 @@ public EnderChestGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -105,6 +112,16 @@ public EnderChestGui copy() { return gui; } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -138,10 +155,23 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.ENDER_CHEST); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + @NotNull @Contract(pure = true) @Override diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index 6552b5d5f..980420af4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a furnace * * @since 0.8.0 */ -public class FurnaceGui extends NamedGui { +public class FurnaceGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the ingredient @@ -75,6 +78,11 @@ public FurnaceGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -130,6 +138,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -139,7 +157,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.FURNACE); addInventory(inventory, this); @@ -147,6 +165,19 @@ protected Inventory createInventory() { return inventory; } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the ingredient * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index 0534be860..309c194ad 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; @@ -26,13 +27,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a grindstone * * @since 0.8.0 */ -public class GrindstoneGui extends NamedGui { +public class GrindstoneGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the items @@ -85,6 +88,11 @@ public void show(@NotNull HumanEntity humanEntity) { throw new IllegalArgumentException("Grindstones can only be opened by players"); } + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -136,6 +144,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -145,7 +163,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.GRINDSTONE); } @@ -170,6 +188,19 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { } } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the items * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index 7afa6b97f..3b6fc3979 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a hopper * * @since 0.8.0 */ -public class HopperGui extends NamedGui { +public class HopperGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the slots @@ -63,6 +66,11 @@ public HopperGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -110,6 +118,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -119,7 +137,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.HOPPER); addInventory(inventory, this); @@ -127,6 +145,19 @@ protected Inventory createInventory() { return inventory; } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component for the slots * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java new file mode 100644 index 000000000..4f4c05e6f --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -0,0 +1,364 @@ +package com.github.stefvanschie.inventoryframework.gui.type; + +import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; +import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; +import com.github.stefvanschie.inventoryframework.pane.Pane; +import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Merchant; +import org.bukkit.inventory.MerchantRecipe; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * Represents a gui in the form of a merchant. + * + * @since 0.10.0 + */ +public class MerchantGui extends NamedGui { + + /** + * Represents the inventory component for the input + */ + @NotNull + private InventoryComponent inputComponent = new InventoryComponent(2, 1); + + /** + * Represents the inventory component for the player inventory + */ + @NotNull + private InventoryComponent playerInventoryComponent = new InventoryComponent(9, 4); + + /** + * The merchant holding the trades and inventory + */ + @NotNull + private Merchant merchant; + + /** + * The human entities viewing this gui + */ + @NotNull + private final List viewers = new ArrayList<>(); + + /** + * Creates a merchant gui with the given title. + * + * @param title the title + * @since 0.10.0 + */ + public MerchantGui(@NotNull String title) { + this(StringHolder.of(title)); + } + + /** + * Creates a merchant gui with the given title. + * + * @param title the title + * @since 0.10.0 + */ + public MerchantGui(@NotNull TextHolder title) { + super(title); + + this.merchant = getTitleHolder().asMerchantTitle(); + } + + @Override + public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.merchant = getTitleHolder().asMerchantTitle(); + markChanges(); + } + + InventoryView view = humanEntity.openMerchant(merchant, true); + + if (view == null) { + throw new IllegalStateException("Merchant could not be opened"); + } + + Inventory inventory = view.getTopInventory(); + + addInventory(inventory, this); + + inventory.clear(); + + getHumanEntityCache().store(humanEntity); + + getInputComponent().display(inventory, 0); + getPlayerInventoryComponent().display(); + + if (getPlayerInventoryComponent().hasItem()) { + humanEntity.getInventory().clear(); + + getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); + } else { + getHumanEntityCache().clearCache(humanEntity); + } + + this.viewers.add(humanEntity); + } + + @NotNull + @Override + public Gui copy() { + MerchantGui gui = new MerchantGui(getTitle()); + + gui.inputComponent = inputComponent.copy(); + gui.playerInventoryComponent = playerInventoryComponent.copy(); + + gui.setOnTopClick(this.onTopClick); + gui.setOnBottomClick(this.onBottomClick); + gui.setOnGlobalClick(this.onGlobalClick); + gui.setOnOutsideClick(this.onOutsideClick); + gui.setOnClose(this.onClose); + + return gui; + } + + @Override + public void click(@NotNull InventoryClickEvent event) { + int rawSlot = event.getRawSlot(); + + if (rawSlot >= 0 && rawSlot <= 1) { + getInputComponent().click(this, event, rawSlot); + } else if (rawSlot != 2) { + getPlayerInventoryComponent().click(this, event, rawSlot - 3); + } + } + + /** + * Adds a trade to this gui. + * + * @param recipe the recipe to add + * @since 0.10.0 + */ + public void addTrade(@NotNull MerchantRecipe recipe) { + List recipes = new ArrayList<>(this.merchant.getRecipes()); + + recipes.add(recipe); + + this.merchant.setRecipes(recipes); + } + + /** + * Handles a human entity closing this gui. + * + * @param humanEntity the human entity who's closing this gui + * @since 0.10.0 + */ + public void handleClose(@NotNull HumanEntity humanEntity) { + this.viewers.remove(humanEntity); + } + + @Override + public boolean isPlayerInventoryUsed() { + return getPlayerInventoryComponent().hasItem(); + } + + @Contract(pure = true) + @Override + public int getViewerCount() { + return this.viewers.size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(this.viewers); + } + + /** + * Gets the inventory component representing the input + * + * @return the input component + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public InventoryComponent getInputComponent() { + return inputComponent; + } + + /** + * Gets the inventory component representing the player inventory + * + * @return the player inventory component + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public InventoryComponent getPlayerInventoryComponent() { + return playerInventoryComponent; + } + + /** + * Loads a merchant gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded merchant gui + * @since 0.10.0 + */ + @Nullable + @Contract(pure = true) + public static MerchantGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + try { + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); + Element documentElement = document.getDocumentElement(); + + documentElement.normalize(); + + return load(instance, documentElement); + } catch (SAXException | ParserConfigurationException | IOException e) { + e.printStackTrace(); + return null; + } + } + + /** + * Loads a merchant gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded merchant gui + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public static MerchantGui load(@NotNull Object instance, @NotNull Element element) { + if (!element.hasAttribute("title")) { + throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); + } + + MerchantGui merchantGui = new MerchantGui(element.getAttribute("title")); + merchantGui.initializeOrThrow(instance, element); + + if (element.hasAttribute("populate")) { + return merchantGui; + } + + NodeList childNodes = element.getChildNodes(); + + for (int index = 0; index < childNodes.getLength(); index++) { + Node item = childNodes.item(index); + + if (item.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + Element nestedElement = (Element) item; + String tagName = nestedElement.getTagName(); + + if (tagName.equalsIgnoreCase("component")) { + if (!nestedElement.hasAttribute("name")) { + throw new XMLLoadException("Component tag does not have a name specified"); + } + + InventoryComponent component; + + switch (nestedElement.getAttribute("name")) { + case "input": + component = merchantGui.getInputComponent(); + break; + case "player-inventory": + component = merchantGui.getPlayerInventoryComponent(); + break; + default: + throw new XMLLoadException("Unknown component name"); + } + + component.load(instance, nestedElement); + } else if (tagName.equalsIgnoreCase("trade")) { + NodeList tradeNodes = nestedElement.getChildNodes(); + + List ingredients = new ArrayList<>(2); + ItemStack result = null; + + for (int tradeIndex = 0; tradeIndex < tradeNodes.getLength(); tradeIndex++) { + Node tradeNode = tradeNodes.item(tradeIndex); + + if (tradeNode.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + Element tradeElement = (Element) tradeNode; + + if (tradeElement.getTagName().equalsIgnoreCase("ingredient")) { + if (ingredients.size() >= 2) { + throw new XMLLoadException("Too many ingredients specified, must be no more than two"); + } + + NodeList ingredientNodes = tradeElement.getChildNodes(); + + for (int ingredientIndex = 0; ingredientIndex < ingredientNodes.getLength(); ingredientIndex++) { + Node ingredientNode = ingredientNodes.item(ingredientIndex); + + if (ingredientNode.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + ingredients.add(Pane.loadItem(instance, (Element) ingredientNode).getItem()); + } + } else if (tradeElement.getTagName().equalsIgnoreCase("result")) { + NodeList resultNodes = tradeElement.getChildNodes(); + + for (int resultIndex = 0; resultIndex < resultNodes.getLength(); resultIndex++) { + Node resultNode = resultNodes.item(resultIndex); + + if (resultNode.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + if (result != null) { + throw new XMLLoadException("Multiple results specified for the same trade"); + } + + result = Pane.loadItem(instance, (Element) resultNode).getItem(); + } + } else { + throw new XMLLoadException("Trade element is neither an ingredient nor a result"); + } + } + + if (result == null) { + throw new XMLLoadException("Trade must have a result specified"); + } + + if (ingredients.size() < 1) { + throw new XMLLoadException("Trade must have at least one ingredient"); + } + + MerchantRecipe recipe = new MerchantRecipe(result, Integer.MAX_VALUE); + + recipe.setIngredients(ingredients); + + merchantGui.addTrade(recipe); + } else { + throw new XMLLoadException("Nested element is neither a component nor a trade"); + } + } + + return merchantGui; + } +} diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index 5fcd82cc8..77981169e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.MergedGui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; @@ -24,6 +25,7 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -33,7 +35,7 @@ * * @since 0.8.0 */ -public class ShulkerBoxGui extends NamedGui implements MergedGui { +public class ShulkerBoxGui extends NamedGui implements MergedGui, InventoryBased { /** * Represents the inventory component for the entire gui @@ -63,6 +65,11 @@ public ShulkerBoxGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -105,6 +112,16 @@ public ShulkerBoxGui copy() { return gui; } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -138,10 +155,23 @@ public Collection getItems() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.SHULKER_BOX); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + @NotNull @Contract(pure = true) @Override diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 43cfb2d7a..41a8ac6f1 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; @@ -26,13 +27,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a smithing table * * @since 0.8.0 */ -public class SmithingTableGui extends NamedGui { +public class SmithingTableGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the first item @@ -92,6 +95,11 @@ public void show(@NotNull HumanEntity humanEntity) { throw new IllegalArgumentException("Smithing tables can only be opened by players"); } + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -147,6 +155,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -156,7 +174,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.SMITHING); } @@ -195,6 +213,19 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { } } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the first item * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index 5fd263519..b0d2c6c30 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -21,13 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a smoker * * @since 0.8.0 */ -public class SmokerGui extends NamedGui { +public class SmokerGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the ingredient @@ -75,6 +78,11 @@ public SmokerGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -130,6 +138,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -139,10 +157,23 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.SMOKER); } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the ingredient * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index c1ee199a7..d76bc7d97 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; @@ -26,13 +27,15 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** * Represents a gui in the form of a stonecutter * * @since 0.8.0 */ -public class StonecutterGui extends NamedGui { +public class StonecutterGui extends NamedGui implements InventoryBased { /** * Represents the inventory component for the input @@ -86,6 +89,11 @@ public void show(@NotNull HumanEntity humanEntity) { throw new IllegalArgumentException("Enchanting tables can only be opened by players"); } + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + getInventory().clear(); getHumanEntityCache().store(humanEntity); @@ -137,6 +145,16 @@ public void click(@NotNull InventoryClickEvent event) { } } + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + @Contract(pure = true) @Override public boolean isPlayerInventoryUsed() { @@ -146,7 +164,7 @@ public boolean isPlayerInventoryUsed() { @NotNull @Contract(pure = true) @Override - protected Inventory createInventory() { + public Inventory createInventory() { return getTitleHolder().asInventoryTitle(this, InventoryType.STONECUTTER); } @@ -171,6 +189,19 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { } } + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + /** * Gets the inventory component representing the input * 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 b0191214a..aacbbce8a 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 @@ -16,7 +16,6 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -43,7 +42,7 @@ /** * The base class of all GUIs */ -public abstract class Gui implements InventoryHolder { +public abstract class Gui { /** * The inventory of this gui @@ -150,16 +149,6 @@ public Gui() { } } - /** - * Creates a new inventory of the type of the implementing class. - * - * @return the new inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - protected abstract Inventory createInventory(); - /** * Shows a gui to a player * @@ -205,9 +194,7 @@ public Gui() { * @since 0.5.19 */ @Contract(pure = true) - public int getViewerCount() { - return getInventory().getViewers().size(); - } + public abstract int getViewerCount(); /** * Gets a mutable snapshot of the current {@link HumanEntity} viewers of this GUI. @@ -219,9 +206,7 @@ public int getViewerCount() { */ @NotNull @Contract(pure = true) - public List getViewers() { - return new ArrayList<>(getInventory().getViewers()); - } + public abstract List getViewers(); /** * Update the gui for everyone @@ -573,16 +558,6 @@ private void callCallback(@Nullable Consumer callb } } - @NotNull - @Override - public Inventory getInventory() { - if (this.inventory == null) { - this.inventory = createInventory(); - } - - return inventory; - } - /** * Gets whether this gui is being updated, as invoked by {@link #update()}. This returns true if this is the case * and false otherwise. @@ -678,6 +653,7 @@ public static Pane loadPane(@NotNull Object instance, @NotNull Node node) { registerGui("furnace", FurnaceGui::load); registerGui("grindstone", GrindstoneGui::load); registerGui("hopper", HopperGui::load); + registerGui("merchant", MerchantGui::load); registerGui("shulker-box", ShulkerBoxGui::load); registerGui("smithing-table", SmithingTableGui::load); registerGui("smoker", SmokerGui::load); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/InventoryBased.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/InventoryBased.java new file mode 100644 index 000000000..8aaa21c29 --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/InventoryBased.java @@ -0,0 +1,20 @@ +package com.github.stefvanschie.inventoryframework.gui.type.util; + +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public interface InventoryBased extends InventoryHolder { + + /** + * Creates a new inventory of the type of the implementing class. + * + * @return the new inventory + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + Inventory createInventory(); + +} diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java index 8465763c5..95d07b360 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java @@ -2,12 +2,9 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import org.bukkit.entity.HumanEntity; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.List; - public abstract class NamedGui extends Gui { /** @@ -16,6 +13,11 @@ public abstract class NamedGui extends Gui { @NotNull private TextHolder title; + /** + * Whether the title is dirty i.e., has changed + */ + private boolean dirty = false; + /** * Constructs a new gui with a title * @@ -37,8 +39,7 @@ public NamedGui(@NotNull TextHolder title) { } /** - * Sets the title for this inventory. This will (unlike most other methods) directly update itself in order - * to ensure all viewers will still be viewing the new inventory as well. + * Sets the title for this inventory. * * @param title the title */ @@ -47,26 +48,14 @@ public void setTitle(@NotNull String title) { } /** - * Sets the title for this inventory. This will (unlike most other methods) directly update itself in order - * to ensure all viewers will still be viewing the new inventory as well. + * Sets the title for this inventory. * * @param title the title * @since 0.10.0 */ public void setTitle(@NotNull TextHolder title) { - //copy the viewers - List viewers = getViewers(); - this.title = title; - this.inventory = createInventory(); - - updating = true; - - for (HumanEntity viewer : viewers) { - show(viewer); - } - - updating = false; + this.dirty = true; } /** @@ -92,4 +81,25 @@ public String getTitle() { public TextHolder getTitleHolder() { return title; } + + /** + * Gets whether this title is dirty or not i.e. whether the title has changed. + * + * @return whether the title is dirty + * @since 0.10.0 + */ + @Contract(pure = true) + public boolean isDirty() { + return dirty; + } + + /** + * Marks that the changes present here have been accepted. This sets dirty to false. If dirty was already false, + * this will do nothing. + * + * @since 0.10.0 + */ + public void markChanges() { + this.dirty = false; + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 597627298..f7d33c38f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -305,7 +305,12 @@ public void setPriority(@NotNull Priority priority) { @Contract(pure = true) public static GuiItem loadItem(@NotNull Object instance, @NotNull Element element) { String id = element.getAttribute("id"); - Material material = Objects.requireNonNull(Material.matchMaterial(id.toUpperCase(Locale.getDefault()))); + Material material = Material.matchMaterial(id.toUpperCase(Locale.getDefault())); + + if (material == null) { + throw new XMLLoadException("Can't find material for '" + id + "'"); + } + boolean hasAmount = element.hasAttribute("amount"); boolean hasDamage = element.hasAttribute("damage"); int amount = hasAmount ? Integer.parseInt(element.getAttribute("amount")) : 1; diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java index f4d5ce578..ddc7955e9 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/ForeignComponentHolder.java @@ -1,9 +1,11 @@ package com.github.stefvanschie.inventoryframework.adventuresupport; import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.Merchant; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -48,6 +50,13 @@ public Inventory asInventoryTitle(InventoryHolder holder, InventoryType type) { public Inventory asInventoryTitle(InventoryHolder holder, int size) { return legacy.asInventoryTitle(holder, size); } + + @NotNull + @Contract(pure = true) + @Override + public Merchant asMerchantTitle() { + return legacy.asMerchantTitle(); + } @Override public void asItemDisplayName(ItemMeta meta) { diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java index f3698382a..6cfde4d5d 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java @@ -5,7 +5,9 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.Merchant; import org.bukkit.inventory.meta.ItemMeta; +import org.checkerframework.checker.units.qual.C; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -45,7 +47,14 @@ public Inventory asInventoryTitle(InventoryHolder holder, InventoryType type) { public Inventory asInventoryTitle(InventoryHolder holder, int size) { return Bukkit.createInventory(holder, size, value); } - + + @NotNull + @Contract(pure = true) + @Override + public Merchant asMerchantTitle() { + return Bukkit.createMerchant(value); + } + @Override public void asItemDisplayName(ItemMeta meta) { meta.displayName(value); diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java index e9b264eff..cfbbb7aa6 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/StringHolder.java @@ -5,6 +5,7 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.Merchant; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -109,7 +110,15 @@ public Inventory asInventoryTitle(InventoryHolder holder, int size) { //noinspection deprecation return Bukkit.createInventory(holder, size, value); } - + + @NotNull + @Contract(pure = true) + @Override + public Merchant asMerchantTitle() { + //noinspection deprecation + return Bukkit.createMerchant(value); + } + @Override public void asItemDisplayName(ItemMeta meta) { //noinspection deprecation diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java index 7de003b12..dea4b8d72 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/TextHolder.java @@ -5,6 +5,7 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.Merchant; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -102,6 +103,16 @@ public static TextHolder deserialize(@NotNull String string) { @NotNull @Contract(pure = true) public abstract Inventory asInventoryTitle(InventoryHolder holder, int size); + + /** + * Creates a new merchant with the wrapped value as the merchant's title. + * + * @return a newly created inventory with the wrapped value as its title + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public abstract Merchant asMerchantTitle(); /** * Modifies the specified meta: sets the display name to the wrapped value. From 4d3ba8f7893aa84bae60329cd9164600a1299786 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 8 Jul 2021 17:32:29 +0200 Subject: [PATCH 018/382] Fix copy methods not using components --- .../stefvanschie/inventoryframework/gui/type/AnvilGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/BarrelGui.java | 2 +- .../inventoryframework/gui/type/BlastFurnaceGui.java | 2 +- .../inventoryframework/gui/type/BrewingStandGui.java | 2 +- .../inventoryframework/gui/type/CartographyTableGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/ChestGui.java | 2 +- .../inventoryframework/gui/type/CraftingTableGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/DispenserGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/DropperGui.java | 2 +- .../inventoryframework/gui/type/EnchantingTableGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/EnderChestGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/FurnaceGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/GrindstoneGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/HopperGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/MerchantGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java | 2 +- .../inventoryframework/gui/type/SmithingTableGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/SmokerGui.java | 2 +- .../inventoryframework/gui/type/StonecutterGui.java | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) 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 7e9e967c2..b2ed5e860 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 @@ -124,7 +124,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public AnvilGui copy() { - AnvilGui gui = new AnvilGui(getTitle()); + AnvilGui gui = new AnvilGui(getTitleHolder()); gui.firstItemComponent = firstItemComponent.copy(); gui.secondItemComponent = secondItemComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index 568c749c6..777c17d10 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -99,7 +99,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public BarrelGui copy() { - BarrelGui gui = new BarrelGui(getTitle()); + BarrelGui gui = new BarrelGui(getTitleHolder()); gui.inventoryComponent = inventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index f95e5ba6b..a61a53bbd 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -107,7 +107,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public BlastFurnaceGui copy() { - BlastFurnaceGui gui = new BlastFurnaceGui(getTitle()); + BlastFurnaceGui gui = new BlastFurnaceGui(getTitleHolder()); gui.ingredientComponent = ingredientComponent.copy(); gui.fuelComponent = fuelComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 5820c8efe..618196903 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -121,7 +121,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public BrewingStandGui copy() { - BrewingStandGui gui = new BrewingStandGui(getTitle()); + BrewingStandGui gui = new BrewingStandGui(getTitleHolder()); gui.firstBottleComponent = firstBottleComponent.copy(); gui.secondBottleComponent = secondBottleComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index f230a5eee..876b680b6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -126,7 +126,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public CartographyTableGui copy() { - CartographyTableGui gui = new CartographyTableGui(getTitle()); + CartographyTableGui gui = new CartographyTableGui(getTitleHolder()); gui.mapComponent = mapComponent.copy(); gui.paperComponent = paperComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 36a2069ba..041ab2c71 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -114,7 +114,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public ChestGui copy() { - ChestGui gui = new ChestGui(getRows(), getTitle()); + ChestGui gui = new ChestGui(getRows(), getTitleHolder()); gui.inventoryComponent = inventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index 61eda8a86..4dc76c92c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -100,7 +100,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public CraftingTableGui copy() { - CraftingTableGui gui = new CraftingTableGui(getTitle()); + CraftingTableGui gui = new CraftingTableGui(getTitleHolder()); gui.inputComponent = inputComponent.copy(); gui.outputComponent = outputComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index 8aeabe5a4..4ab3898a5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -93,7 +93,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public DispenserGui copy() { - DispenserGui gui = new DispenserGui(getTitle()); + DispenserGui gui = new DispenserGui(getTitleHolder()); gui.contentsComponent = contentsComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index 8a91a70a8..6e6b1443b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -93,7 +93,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public DropperGui copy() { - DropperGui gui = new DropperGui(getTitle()); + DropperGui gui = new DropperGui(getTitleHolder()); gui.contentsComponent = contentsComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 664a8a857..695c45060 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -109,7 +109,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public EnchantingTableGui copy() { - EnchantingTableGui gui = new EnchantingTableGui(getTitle()); + EnchantingTableGui gui = new EnchantingTableGui(getTitleHolder()); gui.inputComponent = inputComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index c202d49c9..783258b49 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -99,7 +99,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public EnderChestGui copy() { - EnderChestGui gui = new EnderChestGui(getTitle()); + EnderChestGui gui = new EnderChestGui(getTitleHolder()); gui.inventoryComponent = inventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index 980420af4..0b01fa8f8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -107,7 +107,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public FurnaceGui copy() { - FurnaceGui gui = new FurnaceGui(getTitle()); + FurnaceGui gui = new FurnaceGui(getTitleHolder()); gui.ingredientComponent = ingredientComponent.copy(); gui.fuelComponent = fuelComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index 309c194ad..aeaab0251 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -116,7 +116,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public GrindstoneGui copy() { - GrindstoneGui gui = new GrindstoneGui(getTitle()); + GrindstoneGui gui = new GrindstoneGui(getTitleHolder()); gui.itemsComponent = itemsComponent.copy(); gui.resultComponent = resultComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index 3b6fc3979..a8e5ee8de 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -93,7 +93,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public HopperGui copy() { - HopperGui gui = new HopperGui(getTitle()); + HopperGui gui = new HopperGui(getTitleHolder()); gui.slotsComponent = slotsComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index 4f4c05e6f..31466cff1 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -121,7 +121,7 @@ public void show(@NotNull HumanEntity humanEntity) { @NotNull @Override public Gui copy() { - MerchantGui gui = new MerchantGui(getTitle()); + MerchantGui gui = new MerchantGui(getTitleHolder()); gui.inputComponent = inputComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index 77981169e..e896cddc5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -99,7 +99,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public ShulkerBoxGui copy() { - ShulkerBoxGui gui = new ShulkerBoxGui(getTitle()); + ShulkerBoxGui gui = new ShulkerBoxGui(getTitleHolder()); gui.inventoryComponent = inventoryComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 41a8ac6f1..38e4dd02b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -124,7 +124,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public SmithingTableGui copy() { - SmithingTableGui gui = new SmithingTableGui(getTitle()); + SmithingTableGui gui = new SmithingTableGui(getTitleHolder()); gui.firstItemComponent = firstItemComponent.copy(); gui.secondItemComponent = secondItemComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index b0d2c6c30..67a2c3654 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -107,7 +107,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public SmokerGui copy() { - SmokerGui gui = new SmokerGui(getTitle()); + SmokerGui gui = new SmokerGui(getTitleHolder()); gui.ingredientComponent = ingredientComponent.copy(); gui.fuelComponent = fuelComponent.copy(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index d76bc7d97..939c5b374 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -117,7 +117,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public StonecutterGui copy() { - StonecutterGui gui = new StonecutterGui(getTitle()); + StonecutterGui gui = new StonecutterGui(getTitleHolder()); gui.inputComponent = inputComponent.copy(); gui.resultComponent = resultComponent.copy(); From 9c3f541b712b44338716f6a79bdb612808f356ed Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jul 2021 16:24:15 +0200 Subject: [PATCH 019/382] Add 1.17.1 support --- IF/pom.xml | 18 +- .../util/version/Version.java | 81 ++- .../util/version/VersionMatcher.java | 176 ++--- nms/{1_14_R1 => 1_14}/pom.xml | 2 +- .../nms/v1_14}/AnvilInventoryImpl.java | 612 +++++++++--------- .../nms/v1_14}/BeaconInventoryImpl.java | 362 +++++------ .../v1_14}/CartographyTableInventoryImpl.java | 402 ++++++------ .../v1_14}/EnchantingTableInventoryImpl.java | 392 +++++------ .../nms/v1_14}/GrindstoneInventoryImpl.java | 458 ++++++------- .../nms/v1_14}/StonecutterInventoryImpl.java | 402 ++++++------ .../nms/v1_14}/util/TextHolderUtil.java | 2 +- nms/{1_15_R1 => 1_15}/pom.xml | 2 +- .../nms/v1_15}/AnvilInventoryImpl.java | 612 +++++++++--------- .../nms/v1_15}/BeaconInventoryImpl.java | 362 +++++------ .../v1_15}/CartographyTableInventoryImpl.java | 402 ++++++------ .../v1_15}/EnchantingTableInventoryImpl.java | 392 +++++------ .../nms/v1_15}/GrindstoneInventoryImpl.java | 458 ++++++------- .../nms/v1_15}/StonecutterInventoryImpl.java | 402 ++++++------ .../nms/v1_15}/util/TextHolderUtil.java | 2 +- nms/{1_16_R1 => 1_16_1}/pom.xml | 2 +- .../nms/v1_16_1}/AnvilInventoryImpl.java | 486 +++++++------- .../nms/v1_16_1}/BeaconInventoryImpl.java | 362 +++++------ .../CartographyTableInventoryImpl.java | 402 ++++++------ .../EnchantingTableInventoryImpl.java | 392 +++++------ .../nms/v1_16_1}/GrindstoneInventoryImpl.java | 458 ++++++------- .../v1_16_1}/SmithingTableInventoryImpl.java | 456 ++++++------- .../v1_16_1}/StonecutterInventoryImpl.java | 402 ++++++------ .../nms/v1_16_1}/util/TextHolderUtil.java | 2 +- nms/{1_16_R2 => 1_16_2-3}/pom.xml | 2 +- .../nms/v1_16_2_3}/AnvilInventoryImpl.java | 486 +++++++------- .../nms/v1_16_2_3}/BeaconInventoryImpl.java | 356 +++++----- .../CartographyTableInventoryImpl.java | 396 ++++++------ .../EnchantingTableInventoryImpl.java | 386 +++++------ .../v1_16_2_3}/GrindstoneInventoryImpl.java | 452 ++++++------- .../SmithingTableInventoryImpl.java | 452 ++++++------- .../v1_16_2_3}/StonecutterInventoryImpl.java | 396 ++++++------ .../nms/v1_16_2_3}/util/TextHolderUtil.java | 2 +- nms/{1_16_R3 => 1_16_4-5}/pom.xml | 2 +- .../nms/v1_16_4_5}/AnvilInventoryImpl.java | 486 +++++++------- .../nms/v1_16_4_5}/BeaconInventoryImpl.java | 362 +++++------ .../CartographyTableInventoryImpl.java | 402 ++++++------ .../EnchantingTableInventoryImpl.java | 392 +++++------ .../v1_16_4_5}/GrindstoneInventoryImpl.java | 458 ++++++------- .../SmithingTableInventoryImpl.java | 458 ++++++------- .../v1_16_4_5}/StonecutterInventoryImpl.java | 402 ++++++------ .../nms/v1_16_4_5}/util/TextHolderUtil.java | 2 +- nms/{1_17_R1 => 1_17_0}/pom.xml | 2 +- .../nms/v1_17_0}/AnvilInventoryImpl.java | 6 +- .../nms/v1_17_0}/BeaconInventoryImpl.java | 2 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_17_0}/GrindstoneInventoryImpl.java | 6 +- .../v1_17_0}/SmithingTableInventoryImpl.java | 6 +- .../v1_17_0}/StonecutterInventoryImpl.java | 4 +- .../v1_17_0}/util/CustomInventoryUtil.java | 2 +- .../nms/v1_17_0}/util/TextHolderUtil.java | 2 +- nms/1_17_1/pom.xml | 73 +++ .../nms/v1_17_1/AnvilInventoryImpl.java | 266 ++++++++ .../nms/v1_17_1/BeaconInventoryImpl.java | 199 ++++++ .../CartographyTableInventoryImpl.java | 213 ++++++ .../v1_17_1/EnchantingTableInventoryImpl.java | 213 ++++++ .../nms/v1_17_1/GrindstoneInventoryImpl.java | 242 +++++++ .../v1_17_1/SmithingTableInventoryImpl.java | 250 +++++++ .../nms/v1_17_1/StonecutterInventoryImpl.java | 219 +++++++ .../nms/v1_17_1/util/CustomInventoryUtil.java | 41 ++ .../nms/v1_17_1/util/TextHolderUtil.java | 66 ++ pom.xml | 13 +- 67 files changed, 9024 insertions(+), 7204 deletions(-) rename nms/{1_14_R1 => 1_14}/pom.xml (96%) rename nms/{1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1 => 1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14}/AnvilInventoryImpl.java (95%) rename nms/{1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1 => 1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14}/BeaconInventoryImpl.java (95%) rename nms/{1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1 => 1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14}/CartographyTableInventoryImpl.java (95%) rename nms/{1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1 => 1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14}/EnchantingTableInventoryImpl.java (95%) rename nms/{1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1 => 1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14}/GrindstoneInventoryImpl.java (95%) rename nms/{1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1 => 1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14}/StonecutterInventoryImpl.java (94%) rename nms/{1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1 => 1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14}/util/TextHolderUtil.java (96%) rename nms/{1_15_R1 => 1_15}/pom.xml (96%) rename nms/{1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1 => 1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15}/AnvilInventoryImpl.java (95%) rename nms/{1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1 => 1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15}/BeaconInventoryImpl.java (95%) rename nms/{1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1 => 1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15}/CartographyTableInventoryImpl.java (95%) rename nms/{1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1 => 1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15}/EnchantingTableInventoryImpl.java (95%) rename nms/{1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1 => 1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15}/GrindstoneInventoryImpl.java (95%) rename nms/{1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1 => 1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15}/StonecutterInventoryImpl.java (94%) rename nms/{1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1 => 1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15}/util/TextHolderUtil.java (96%) rename nms/{1_16_R1 => 1_16_1}/pom.xml (96%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/AnvilInventoryImpl.java (95%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/BeaconInventoryImpl.java (95%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/CartographyTableInventoryImpl.java (95%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/EnchantingTableInventoryImpl.java (95%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/GrindstoneInventoryImpl.java (95%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/SmithingTableInventoryImpl.java (95%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/StonecutterInventoryImpl.java (94%) rename nms/{1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1 => 1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1}/util/TextHolderUtil.java (96%) rename nms/{1_16_R2 => 1_16_2-3}/pom.xml (96%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/AnvilInventoryImpl.java (95%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/BeaconInventoryImpl.java (95%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/CartographyTableInventoryImpl.java (94%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/EnchantingTableInventoryImpl.java (94%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/GrindstoneInventoryImpl.java (95%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/SmithingTableInventoryImpl.java (95%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/StonecutterInventoryImpl.java (94%) rename nms/{1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2 => 1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3}/util/TextHolderUtil.java (96%) rename nms/{1_16_R3 => 1_16_4-5}/pom.xml (96%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/AnvilInventoryImpl.java (95%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/BeaconInventoryImpl.java (95%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/CartographyTableInventoryImpl.java (95%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/EnchantingTableInventoryImpl.java (95%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/GrindstoneInventoryImpl.java (95%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/SmithingTableInventoryImpl.java (95%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/StonecutterInventoryImpl.java (94%) rename nms/{1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3 => 1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5}/util/TextHolderUtil.java (96%) rename nms/{1_17_R1 => 1_17_0}/pom.xml (98%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/AnvilInventoryImpl.java (97%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/BeaconInventoryImpl.java (99%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/CartographyTableInventoryImpl.java (96%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/EnchantingTableInventoryImpl.java (98%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/GrindstoneInventoryImpl.java (97%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/SmithingTableInventoryImpl.java (97%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/StonecutterInventoryImpl.java (98%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/util/CustomInventoryUtil.java (94%) rename nms/{1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1 => 1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0}/util/TextHolderUtil.java (96%) create mode 100644 nms/1_17_1/pom.xml create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/BeaconInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/CartographyTableInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/EnchantingTableInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/StonecutterInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/CustomInventoryUtil.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index d54432c58..169837159 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -42,37 +42,43 @@
com.github.stefvanschie.inventoryframework - 1_14_R1 + 1_14 ${project.version} compile com.github.stefvanschie.inventoryframework - 1_15_R1 + 1_15 ${project.version} compile com.github.stefvanschie.inventoryframework - 1_16_R1 + 1_16_1 ${project.version} compile com.github.stefvanschie.inventoryframework - 1_16_R2 + 1_16_2-3 ${project.version} compile com.github.stefvanschie.inventoryframework - 1_16_R3 + 1_16_4-5 ${project.version} compile com.github.stefvanschie.inventoryframework - 1_17_R1 + 1_17_0 + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + 1_17_1 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 8b6dc2e89..af46bcd50 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -13,46 +13,53 @@ public enum Version { /** - * Version 1.14 R1 + * Version 1.14 * - * @since 0.8.0 + * @since 0.10.0 */ - V1_14_R1, + V1_14, /** - * Version 1.15 R1 + * Version 1.15 * - * @since 0.8.0 + * @since 0.10.0 */ - V1_15_R1, + V1_15, /** - * Version 1.16 R1 + * Version 1.16.1 * - * @since 0.8.0 + * @since 0.10.0 */ - V1_16_R1, + V1_16_1, /** - * Version 1.16 R2 + * Version 1.16.2 - 1.16.3 * - * @since 0.8.0 + * @since 0.10.0 */ - V1_16_R2, + V1_16_2_3, /** - * Version 1.16 R3 + * Version 1.16.4 - 1.16.5 * - * @since 0.8.0 + * @since 0.10.0 + */ + V1_16_4_5, + + /** + * Version 1.17 + * + * @since 0.10.0 */ - V1_16_R3, + V1_17_0, /** - * Version 1.17 R1 + * Version 1.17.1 * - * @since 0.9.9 + * @since 0.10.0 */ - V1_17_R1; + V1_17_1; /** * Gets the version currently being used. If the used version is not supported, an @@ -64,21 +71,31 @@ public enum Version { @NotNull @Contract(pure = true) public static Version getVersion() { - String version = Bukkit.getServer().getClass().getPackage().getName(); + String version = Bukkit.getBukkitVersion().split("-")[0]; - switch (version.substring(version.lastIndexOf('.') + 1)) { - case "v1_14_R1": - return V1_14_R1; - case "v1_15_R1": - return V1_15_R1; - case "v1_16_R1": - return V1_16_R1; - case "v1_16_R2": - return V1_16_R2; - case "v1_16_R3": - return V1_16_R3; - case "v1_17_R1": - return V1_17_R1; + switch (version) { + case "1.14": + case "1.14.1": + case "1.14.2": + case "1.14.3": + case "1.14.4": + return V1_14; + case "1.15": + case "1.15.1": + case "1.15.2": + return V1_15; + case "1.16.1": + return V1_16_1; + case "1.16.2": + case "1.16.3": + return V1_16_2_3; + case "1.16.4": + case "1.16.5": + return V1_16_4_5; + case "1.17": + return V1_17_0; + case "1.17.1": + return V1_17_1; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 3e73d81d0..8a4cffa67 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 @@ -171,7 +171,7 @@ public static GrindstoneInventory newGrindstoneInventory(@NotNull Version versio @Contract(pure = true) public static SmithingTableInventory newSmithingTableInventory(@NotNull Version version, @NotNull InventoryHolder inventoryHolder) { - if (version == Version.V1_14_R1 || version == Version.V1_15_R1) { + if (version == Version.V1_14 || version == Version.V1_15) { throw new UnsupportedVersionException("Smithing tables didn't exist in version " + version); } @@ -209,97 +209,111 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers static { ANVIL_INVENTORIES = new EnumMap<>(Version.class); - ANVIL_INVENTORIES.put(Version.V1_14_R1, - com.github.stefvanschie.inventoryframework.nms.v1_14_R1.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_15_R1, - com.github.stefvanschie.inventoryframework.nms.v1_15_R1.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_16_R1, - com.github.stefvanschie.inventoryframework.nms.v1_16_R1.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_16_R2, - com.github.stefvanschie.inventoryframework.nms.v1_16_R2.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_16_R3, - com.github.stefvanschie.inventoryframework.nms.v1_16_R3.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_17_R1, - com.github.stefvanschie.inventoryframework.nms.v1_17_R1.AnvilInventoryImpl.class); + 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); + ANVIL_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.AnvilInventoryImpl.class); + 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); + ANVIL_INVENTORIES.put(Version.V1_17_0, + com.github.stefvanschie.inventoryframework.nms.v1_17_0.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_17_1, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); - BEACON_INVENTORIES.put(Version.V1_14_R1, - com.github.stefvanschie.inventoryframework.nms.v1_14_R1.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_15_R1, - com.github.stefvanschie.inventoryframework.nms.v1_15_R1.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_16_R1, - com.github.stefvanschie.inventoryframework.nms.v1_16_R1.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_16_R2, - com.github.stefvanschie.inventoryframework.nms.v1_16_R2.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_16_R3, - com.github.stefvanschie.inventoryframework.nms.v1_16_R3.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_17_R1, - com.github.stefvanschie.inventoryframework.nms.v1_17_R1.BeaconInventoryImpl.class); + 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); + BEACON_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.BeaconInventoryImpl.class); + 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); + BEACON_INVENTORIES.put(Version.V1_17_0, + com.github.stefvanschie.inventoryframework.nms.v1_17_0.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_17_1, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14_R1, - com.github.stefvanschie.inventoryframework.nms.v1_14_R1.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_15_R1, - com.github.stefvanschie.inventoryframework.nms.v1_15_R1.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_16_R1, - com.github.stefvanschie.inventoryframework.nms.v1_16_R1.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_16_R2, - com.github.stefvanschie.inventoryframework.nms.v1_16_R2.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_16_R3, - com.github.stefvanschie.inventoryframework.nms.v1_16_R3.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_17_R1, - com.github.stefvanschie.inventoryframework.nms.v1_17_R1.CartographyTableInventoryImpl.class); + 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); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.CartographyTableInventoryImpl.class); + 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); + 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, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14_R1, - com.github.stefvanschie.inventoryframework.nms.v1_14_R1.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_15_R1, - com.github.stefvanschie.inventoryframework.nms.v1_15_R1.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_16_R1, - com.github.stefvanschie.inventoryframework.nms.v1_16_R1.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_16_R2, - com.github.stefvanschie.inventoryframework.nms.v1_16_R2.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_16_R3, - com.github.stefvanschie.inventoryframework.nms.v1_16_R3.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_17_R1, - com.github.stefvanschie.inventoryframework.nms.v1_17_R1.EnchantingTableInventoryImpl.class); + 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); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.EnchantingTableInventoryImpl.class); + 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); + 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, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); - GRINDSTONE_INVENTORIES.put(Version.V1_14_R1, - com.github.stefvanschie.inventoryframework.nms.v1_14_R1.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_15_R1, - com.github.stefvanschie.inventoryframework.nms.v1_15_R1.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_16_R1, - com.github.stefvanschie.inventoryframework.nms.v1_16_R1.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_16_R2, - com.github.stefvanschie.inventoryframework.nms.v1_16_R2.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_16_R3, - com.github.stefvanschie.inventoryframework.nms.v1_16_R3.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_17_R1, - com.github.stefvanschie.inventoryframework.nms.v1_17_R1.GrindstoneInventoryImpl.class); + 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); + GRINDSTONE_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.GrindstoneInventoryImpl.class); + 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); + GRINDSTONE_INVENTORIES.put(Version.V1_17_0, + com.github.stefvanschie.inventoryframework.nms.v1_17_0.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_17_1, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.GrindstoneInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_16_R1, - com.github.stefvanschie.inventoryframework.nms.v1_16_R1.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_16_R2, - com.github.stefvanschie.inventoryframework.nms.v1_16_R2.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_16_R3, - com.github.stefvanschie.inventoryframework.nms.v1_16_R3.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_17_R1, - com.github.stefvanschie.inventoryframework.nms.v1_17_R1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_16_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_16_4_5, + com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_17_0, + com.github.stefvanschie.inventoryframework.nms.v1_17_0.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_17_1, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); - STONECUTTER_INVENTORIES.put(Version.V1_14_R1, - com.github.stefvanschie.inventoryframework.nms.v1_14_R1.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_15_R1, - com.github.stefvanschie.inventoryframework.nms.v1_15_R1.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_16_R1, - com.github.stefvanschie.inventoryframework.nms.v1_16_R1.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_16_R2, - com.github.stefvanschie.inventoryframework.nms.v1_16_R2.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_16_R3, - com.github.stefvanschie.inventoryframework.nms.v1_16_R3.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_17_R1, - com.github.stefvanschie.inventoryframework.nms.v1_17_R1.StonecutterInventoryImpl.class); + 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); + STONECUTTER_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.StonecutterInventoryImpl.class); + 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); + STONECUTTER_INVENTORIES.put(Version.V1_17_0, + com.github.stefvanschie.inventoryframework.nms.v1_17_0.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_17_1, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.StonecutterInventoryImpl.class); } } diff --git a/nms/1_14_R1/pom.xml b/nms/1_14/pom.xml similarity index 96% rename from nms/1_14_R1/pom.xml rename to nms/1_14/pom.xml index 39052d32a..9b97fcf99 100644 --- a/nms/1_14_R1/pom.xml +++ b/nms/1_14/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_14_R1 + 1_14 true diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/AnvilInventoryImpl.java similarity index 95% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java rename to nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/AnvilInventoryImpl.java index e7b7bf10b..e2bdfe0f6 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/AnvilInventoryImpl.java +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/AnvilInventoryImpl.java @@ -1,306 +1,306 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util.TextHolderUtil; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.Location; -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.CraftInventoryAnvil; -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 anvil inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class AnvilInventoryImpl extends AnvilInventory { - - public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerAnvil; - - int id = containerAnvil.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); - - 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 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 - */ - 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 anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the repair inventory field - */ - @NotNull - private final Field repairInventoryField; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - /** - * Field for accessing the container access field - */ - @NotNull - private final Field containerAccessField; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 - */ - public ContainerAnvilImpl(@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(); - - try { - repairInventoryField = ContainerAnvil.class.getDeclaredField("repairInventory"); - repairInventoryField.setAccessible(true); - - resultInventoryField = ContainerAnvil.class.getDeclaredField("resultInventory"); - resultInventoryField.setAccessible(true); - - containerAccessField = ContainerAnvil.class.getDeclaredField("containerAccess"); - containerAccessField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getRepairInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getRepairInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = getContainerAccess().getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, getRepairInventory(), getResultInventory(), - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Override - public void a(@Nullable String name) { - text = name == null ? "" : name; - - sendResultItem(player, getResultInventory().getItem(0)); - } - - @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 getRepairInventory() { - try { - return (IInventory) repairInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Contract(pure = true) - private ContainerAccess getContainerAccess() { - try { - return (ContainerAccess) containerAccessField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} +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.Location; +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.CraftInventoryAnvil; +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 anvil inventory for 1.14 R1 + * + * @since 0.8.0 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerAnvil; + + int id = containerAnvil.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + + 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 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 + */ + 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 anvil for responding to item renaming + * + * @since 0.8.0 + */ + private class ContainerAnvilImpl extends ContainerAnvil { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the repair inventory field + */ + @NotNull + private final Field repairInventoryField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultInventoryField; + + /** + * Field for accessing the container access field + */ + @NotNull + private final Field containerAccessField; + + /** + * Creates a new custom anvil container for the specified player + * + * @param entityPlayer the player for who this anvil container is + * @since 0.8.0 + */ + public ContainerAnvilImpl(@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(); + + try { + repairInventoryField = ContainerAnvil.class.getDeclaredField("repairInventory"); + repairInventoryField.setAccessible(true); + + resultInventoryField = ContainerAnvil.class.getDeclaredField("resultInventory"); + resultInventoryField.setAccessible(true); + + containerAccessField = ContainerAnvil.class.getDeclaredField("containerAccess"); + containerAccessField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getRepairInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getRepairInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = getContainerAccess().getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, getRepairInventory(), getResultInventory(), + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void a(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, getResultInventory().getItem(0)); + } + + @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 getRepairInventory() { + try { + return (IInventory) repairInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + @NotNull + @Contract(pure = true) + private IInventory getResultInventory() { + try { + return (IInventory) resultInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + @NotNull + @Contract(pure = true) + private ContainerAccess getContainerAccess() { + try { + return (ContainerAccess) containerAccessField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/BeaconInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/BeaconInventoryImpl.java similarity index 95% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/BeaconInventoryImpl.java rename to nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/BeaconInventoryImpl.java index e6fb366da..407358326 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/BeaconInventoryImpl.java +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/BeaconInventoryImpl.java @@ -1,181 +1,181 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; - -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) {} - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/CartographyTableInventoryImpl.java similarity index 95% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java rename to nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/CartographyTableInventoryImpl.java index 7722d72e5..fe2798387 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/CartographyTableInventoryImpl.java +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/CartographyTableInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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); - } - } - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/EnchantingTableInventoryImpl.java similarity index 95% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java rename to nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/EnchantingTableInventoryImpl.java index 669259a13..ae6bb4e44 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/EnchantingTableInventoryImpl.java @@ -1,196 +1,196 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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) {} - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/GrindstoneInventoryImpl.java similarity index 95% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java rename to nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/GrindstoneInventoryImpl.java index 57f33a193..ac83d4fc0 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/GrindstoneInventoryImpl.java +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/GrindstoneInventoryImpl.java @@ -1,229 +1,229 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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.CraftInventoryGrindstone; -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 grindstone inventory for 1.14 R1 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerGrindstone; - - int id = containerGrindstone.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone - * - * @since 0.8.0 - */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field craftInventoryField; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} +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.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryGrindstone; +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 grindstone inventory for 1.14 R1 + * + * @since 0.8.0 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerGrindstone; + + int id = containerGrindstone.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone + * + * @since 0.8.0 + */ + private class ContainerGrindstoneImpl extends ContainerGrindstone { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field craftInventoryField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultInventoryField; + + public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + + this.player = entityPlayer.getBukkitEntity(); + + try { + this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); + this.craftInventoryField.setAccessible(true); + + this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); + this.resultInventoryField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory + * + * @return the craft inventory + * @since 0.8.0 + */ + @NotNull + @Contract(pure = true) + private IInventory getCraftInventory() { + try { + return (IInventory) craftInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.8.0 + */ + @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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/StonecutterInventoryImpl.java similarity index 94% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java rename to nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/StonecutterInventoryImpl.java index fc4513817..877624db6 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/StonecutterInventoryImpl.java +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/StonecutterInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_14_R1.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); - } - } - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/util/TextHolderUtil.java similarity index 96% rename from nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java rename to nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/util/TextHolderUtil.java index 4b7a1f58c..5f628de0d 100644 --- a/nms/1_14_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14_R1/util/TextHolderUtil.java +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_14_R1.util; +package com.github.stefvanschie.inventoryframework.nms.v1_14.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/nms/1_15_R1/pom.xml b/nms/1_15/pom.xml similarity index 96% rename from nms/1_15_R1/pom.xml rename to nms/1_15/pom.xml index cf07729fa..736cfc936 100644 --- a/nms/1_15_R1/pom.xml +++ b/nms/1_15/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_15_R1 + 1_15 true diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java similarity index 95% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java rename to nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java index 4ee7d368c..4addd1d7d 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/AnvilInventoryImpl.java +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java @@ -1,306 +1,306 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util.TextHolderUtil; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Location; -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.CraftInventoryAnvil; -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 anvil inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class AnvilInventoryImpl extends AnvilInventory { - - public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerAnvil; - - int id = containerAnvil.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); - - 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 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 - */ - 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 anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the repair inventory field - */ - @NotNull - private final Field repairInventoryField; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - /** - * Field for accessing the container access field - */ - @NotNull - private final Field containerAccessField; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 - */ - public ContainerAnvilImpl(@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(); - - try { - repairInventoryField = ContainerAnvil.class.getDeclaredField("repairInventory"); - repairInventoryField.setAccessible(true); - - resultInventoryField = ContainerAnvil.class.getDeclaredField("resultInventory"); - resultInventoryField.setAccessible(true); - - containerAccessField = ContainerAnvil.class.getDeclaredField("containerAccess"); - containerAccessField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getRepairInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getRepairInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = getContainerAccess().getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, getRepairInventory(), getResultInventory(), - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Override - public void a(@Nullable String name) { - text = name == null ? "" : name; - - sendResultItem(player, getResultInventory().getItem(0)); - } - - @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 getRepairInventory() { - try { - return (IInventory) repairInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - @NotNull - @Contract(pure = true) - private ContainerAccess getContainerAccess() { - try { - return (ContainerAccess) containerAccessField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} +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.Location; +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.CraftInventoryAnvil; +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 anvil inventory for 1.15 R1 + * + * @since 0.8.0 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerAnvil; + + int id = containerAnvil.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + + 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 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 + */ + 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 anvil for responding to item renaming + * + * @since 0.8.0 + */ + private class ContainerAnvilImpl extends ContainerAnvil { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the repair inventory field + */ + @NotNull + private final Field repairInventoryField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultInventoryField; + + /** + * Field for accessing the container access field + */ + @NotNull + private final Field containerAccessField; + + /** + * Creates a new custom anvil container for the specified player + * + * @param entityPlayer the player for who this anvil container is + * @since 0.8.0 + */ + public ContainerAnvilImpl(@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(); + + try { + repairInventoryField = ContainerAnvil.class.getDeclaredField("repairInventory"); + repairInventoryField.setAccessible(true); + + resultInventoryField = ContainerAnvil.class.getDeclaredField("resultInventory"); + resultInventoryField.setAccessible(true); + + containerAccessField = ContainerAnvil.class.getDeclaredField("containerAccess"); + containerAccessField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getRepairInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getRepairInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = getContainerAccess().getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, getRepairInventory(), getResultInventory(), + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void a(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, getResultInventory().getItem(0)); + } + + @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 getRepairInventory() { + try { + return (IInventory) repairInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + @NotNull + @Contract(pure = true) + private IInventory getResultInventory() { + try { + return (IInventory) resultInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + @NotNull + @Contract(pure = true) + private ContainerAccess getContainerAccess() { + try { + return (ContainerAccess) containerAccessField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/BeaconInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/BeaconInventoryImpl.java similarity index 95% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/BeaconInventoryImpl.java rename to nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/BeaconInventoryImpl.java index 38d7d21df..f6cc4814a 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/BeaconInventoryImpl.java +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/BeaconInventoryImpl.java @@ -1,181 +1,181 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; - -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) {} - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/CartographyTableInventoryImpl.java similarity index 95% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java rename to nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/CartographyTableInventoryImpl.java index e7120b77e..bc6ada39f 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/CartographyTableInventoryImpl.java +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/CartographyTableInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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); - } - } - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/EnchantingTableInventoryImpl.java similarity index 95% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java rename to nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/EnchantingTableInventoryImpl.java index 280905787..280f3e242 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/EnchantingTableInventoryImpl.java @@ -1,196 +1,196 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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) {} - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/GrindstoneInventoryImpl.java similarity index 95% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java rename to nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/GrindstoneInventoryImpl.java index eef5dd4c9..148d160d5 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/GrindstoneInventoryImpl.java +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/GrindstoneInventoryImpl.java @@ -1,229 +1,229 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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.CraftInventoryGrindstone; -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 grindstone inventory for 1.15 R1 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerGrindstone; - - int id = containerGrindstone.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone - * - * @since 0.8.0 - */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field craftInventoryField; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} +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.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryGrindstone; +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 grindstone inventory for 1.15 R1 + * + * @since 0.8.0 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerGrindstone; + + int id = containerGrindstone.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone + * + * @since 0.8.0 + */ + private class ContainerGrindstoneImpl extends ContainerGrindstone { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field craftInventoryField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultInventoryField; + + public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + + this.player = entityPlayer.getBukkitEntity(); + + try { + this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); + this.craftInventoryField.setAccessible(true); + + this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); + this.resultInventoryField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory + * + * @return the craft inventory + * @since 0.8.0 + */ + @NotNull + @Contract(pure = true) + private IInventory getCraftInventory() { + try { + return (IInventory) craftInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.8.0 + */ + @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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/StonecutterInventoryImpl.java similarity index 94% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java rename to nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/StonecutterInventoryImpl.java index 0750b8db4..88118970e 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/StonecutterInventoryImpl.java +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/StonecutterInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_15_R1.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); - } - } - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/util/TextHolderUtil.java similarity index 96% rename from nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java rename to nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/util/TextHolderUtil.java index e2888af2d..7554a5bc6 100644 --- a/nms/1_15_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15_R1/util/TextHolderUtil.java +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_15_R1.util; +package com.github.stefvanschie.inventoryframework.nms.v1_15.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/nms/1_16_R1/pom.xml b/nms/1_16_1/pom.xml similarity index 96% rename from nms/1_16_R1/pom.xml rename to nms/1_16_1/pom.xml index 5b1cb1019..ff3961860 100644 --- a/nms/1_16_R1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_16_R1 + 1_16_1 true diff --git a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java similarity index 95% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java index 5c1865554..aab6c707d 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/AnvilInventoryImpl.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java @@ -1,243 +1,243 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util.TextHolderUtil; -import net.minecraft.server.v1_16_R1.*; -import org.bukkit.Location; -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.CraftInventoryAnvil; -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; - -/** - * 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 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 an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerAnvil; - - int id = containerAnvil.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); - - 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 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 anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 - */ - public ContainerAnvilImpl(@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) { - Location location = containerAccess.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Override - public void a(@Nullable String name) { - text = name == null ? "" : name; - - sendResultItem(player, resultInventory.getItem(0)); - } - - @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) {} - } -} +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.Location; +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.CraftInventoryAnvil; +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; + +/** + * 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 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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerAnvil; + + int id = containerAnvil.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + + 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 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 anvil for responding to item renaming + * + * @since 0.8.0 + */ + private class ContainerAnvilImpl extends ContainerAnvil { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param entityPlayer the player for who this anvil container is + * @since 0.8.0 + */ + public ContainerAnvilImpl(@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) { + Location location = containerAccess.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void a(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultInventory.getItem(0)); + } + + @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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/BeaconInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/BeaconInventoryImpl.java similarity index 95% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/BeaconInventoryImpl.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/BeaconInventoryImpl.java index 3bfc1f68b..68183b72b 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/BeaconInventoryImpl.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/BeaconInventoryImpl.java @@ -1,181 +1,181 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; - -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) {} - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/CartographyTableInventoryImpl.java similarity index 95% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/CartographyTableInventoryImpl.java index a4e723886..b80f7bafb 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/CartographyTableInventoryImpl.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/CartographyTableInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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); - } - } - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/EnchantingTableInventoryImpl.java similarity index 95% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/EnchantingTableInventoryImpl.java index 817393c7d..73a9c5f62 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/EnchantingTableInventoryImpl.java @@ -1,196 +1,196 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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) {} - - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/GrindstoneInventoryImpl.java similarity index 95% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/GrindstoneInventoryImpl.java index 58945ae1d..9178d98ef 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/GrindstoneInventoryImpl.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/GrindstoneInventoryImpl.java @@ -1,229 +1,229 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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.CraftInventoryGrindstone; -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 grindstone inventory for 1.16 R1 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerGrindstone; - - int id = containerGrindstone.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone - * - * @since 0.8.0 - */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field craftInventoryField; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} +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.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryGrindstone; +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 grindstone inventory for 1.16 R1 + * + * @since 0.8.0 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerGrindstone; + + int id = containerGrindstone.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone + * + * @since 0.8.0 + */ + private class ContainerGrindstoneImpl extends ContainerGrindstone { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field craftInventoryField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultInventoryField; + + public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + + this.player = entityPlayer.getBukkitEntity(); + + try { + this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); + this.craftInventoryField.setAccessible(true); + + this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); + this.resultInventoryField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory + * + * @return the craft inventory + * @since 0.8.0 + */ + @NotNull + @Contract(pure = true) + private IInventory getCraftInventory() { + try { + return (IInventory) craftInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.8.0 + */ + @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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/SmithingTableInventoryImpl.java similarity index 95% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/SmithingTableInventoryImpl.java index 1c5607dfd..70e06cb20 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/SmithingTableInventoryImpl.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/SmithingTableInventoryImpl.java @@ -1,228 +1,228 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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.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); - } - - @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 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); - } - - @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 - */ - 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) {} - } -} +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.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); + } + + @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 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); + } + + @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 + */ + 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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/StonecutterInventoryImpl.java similarity index 94% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/StonecutterInventoryImpl.java index eb961f3fe..aa9889fcd 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/StonecutterInventoryImpl.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/StonecutterInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R1.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); - } - } - } -} +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_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/util/TextHolderUtil.java similarity index 96% rename from nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java rename to nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/util/TextHolderUtil.java index 97bea8a28..1e805f59b 100644 --- a/nms/1_16_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R1/util/TextHolderUtil.java +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R1.util; +package com.github.stefvanschie.inventoryframework.nms.v1_16_1.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/nms/1_16_R2/pom.xml b/nms/1_16_2-3/pom.xml similarity index 96% rename from nms/1_16_R2/pom.xml rename to nms/1_16_2-3/pom.xml index 3735b0c25..38b555a5a 100644 --- a/nms/1_16_R2/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_16_R2 + 1_16_2-3 true diff --git a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java similarity index 95% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java index fb0a879c8..60ce9be2c 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/AnvilInventoryImpl.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java @@ -1,243 +1,243 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util.TextHolderUtil; -import net.minecraft.server.v1_16_R2.*; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_16_R2.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; - -/** - * 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 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 an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerAnvil; - - int id = containerAnvil.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); - - 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 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 anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 - */ - public ContainerAnvilImpl(@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) { - Location location = containerAccess.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Override - public void a(@Nullable String name) { - text = name == null ? "" : name; - - sendResultItem(player, resultInventory.getItem(0)); - } - - @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) {} - } -} +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.Location; +import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_16_R2.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; + +/** + * 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 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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerAnvil; + + int id = containerAnvil.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + + 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 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 anvil for responding to item renaming + * + * @since 0.8.0 + */ + private class ContainerAnvilImpl extends ContainerAnvil { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param entityPlayer the player for who this anvil container is + * @since 0.8.0 + */ + public ContainerAnvilImpl(@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) { + Location location = containerAccess.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void a(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultInventory.getItem(0)); + } + + @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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/BeaconInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/BeaconInventoryImpl.java similarity index 95% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/BeaconInventoryImpl.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/BeaconInventoryImpl.java index 2a8d3cc64..80e5b9a93 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/BeaconInventoryImpl.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/BeaconInventoryImpl.java @@ -1,178 +1,178 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; - -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) {} - - } -} +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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/CartographyTableInventoryImpl.java similarity index 94% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/CartographyTableInventoryImpl.java index 454deb361..bf6d8ba59 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/CartographyTableInventoryImpl.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/CartographyTableInventoryImpl.java @@ -1,198 +1,198 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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); - } - } - - } -} +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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/EnchantingTableInventoryImpl.java similarity index 94% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/EnchantingTableInventoryImpl.java index e98bc58ed..abf9e5393 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/EnchantingTableInventoryImpl.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/EnchantingTableInventoryImpl.java @@ -1,193 +1,193 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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) {} - - } -} +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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java similarity index 95% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java index 78153d189..244349403 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/GrindstoneInventoryImpl.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java @@ -1,226 +1,226 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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 grindstone inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerGrindstone; - - int id = containerGrindstone.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone - * - * @since 0.8.0 - */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field craftInventoryField; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} +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.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 grindstone inventory for 1.16 R2 + * + * @since 0.8.0 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerGrindstone; + + int id = containerGrindstone.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone + * + * @since 0.8.0 + */ + private class ContainerGrindstoneImpl extends ContainerGrindstone { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field craftInventoryField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultInventoryField; + + public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + + this.player = entityPlayer.getBukkitEntity(); + + try { + this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); + this.craftInventoryField.setAccessible(true); + + this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); + this.resultInventoryField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory + * + * @return the craft inventory + * @since 0.8.0 + */ + @NotNull + @Contract(pure = true) + private IInventory getCraftInventory() { + try { + return (IInventory) craftInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.8.0 + */ + @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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/SmithingTableInventoryImpl.java similarity index 95% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/SmithingTableInventoryImpl.java index 448985a38..053398e26 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/SmithingTableInventoryImpl.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/SmithingTableInventoryImpl.java @@ -1,226 +1,226 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; - -import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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; - -/** - * Internal smithing table inventory for 1.16 R2 - * - * @since 0.8.0 - */ -public class SmithingTableInventoryImpl extends SmithingTableInventory { - - public SmithingTableInventoryImpl(@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 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); - } - - @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 - */ - 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) {} - } -} +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.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); + } + + @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 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); + } + + @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 + */ + 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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/StonecutterInventoryImpl.java similarity index 94% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/StonecutterInventoryImpl.java index 1e0f0d2f7..05f40294e 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/StonecutterInventoryImpl.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/StonecutterInventoryImpl.java @@ -1,198 +1,198 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R2.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); - } - } - } -} +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_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/util/TextHolderUtil.java similarity index 96% rename from nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java rename to nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/util/TextHolderUtil.java index 8462e9ece..42b2c9036 100644 --- a/nms/1_16_R2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R2/util/TextHolderUtil.java +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R2.util; +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; diff --git a/nms/1_16_R3/pom.xml b/nms/1_16_4-5/pom.xml similarity index 96% rename from nms/1_16_R3/pom.xml rename to nms/1_16_4-5/pom.xml index 323764041..db8936675 100644 --- a/nms/1_16_R3/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_16_R3 + 1_16_4-5 true diff --git a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java similarity index 95% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java index 2fc09ac52..257de5d3a 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/AnvilInventoryImpl.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java @@ -1,243 +1,243 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; - -import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util.TextHolderUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.Location; -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.CraftInventoryAnvil; -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; - -/** - * 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 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 an anvil should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerAnvil; - - int id = containerAnvil.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); - - 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 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 anvil for responding to item renaming - * - * @since 0.8.0 - */ - private class ContainerAnvilImpl extends ContainerAnvil { - - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Creates a new custom anvil container for the specified player - * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 - */ - public ContainerAnvilImpl(@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) { - Location location = containerAccess.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; - } - - @Override - public void a(@Nullable String name) { - text = name == null ? "" : name; - - sendResultItem(player, resultInventory.getItem(0)); - } - - @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) {} - } -} +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.Location; +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.CraftInventoryAnvil; +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; + +/** + * 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 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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerAnvil; + + int id = containerAnvil.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + + 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 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 anvil for responding to item renaming + * + * @since 0.8.0 + */ + private class ContainerAnvilImpl extends ContainerAnvil { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param entityPlayer the player for who this anvil container is + * @since 0.8.0 + */ + public ContainerAnvilImpl(@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) { + Location location = containerAccess.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void a(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultInventory.getItem(0)); + } + + @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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/BeaconInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/BeaconInventoryImpl.java similarity index 95% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/BeaconInventoryImpl.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/BeaconInventoryImpl.java index b1a433ab3..eaed00847 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/BeaconInventoryImpl.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/BeaconInventoryImpl.java @@ -1,181 +1,181 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; - -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) {} - - } -} +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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/CartographyTableInventoryImpl.java similarity index 95% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/CartographyTableInventoryImpl.java index 90dcbb098..fef838730 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/CartographyTableInventoryImpl.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/CartographyTableInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; - -import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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); - } - } - - } -} +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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/EnchantingTableInventoryImpl.java similarity index 95% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/EnchantingTableInventoryImpl.java index e557206fc..611a64ab5 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/EnchantingTableInventoryImpl.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/EnchantingTableInventoryImpl.java @@ -1,196 +1,196 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; - -import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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) {} - - } -} +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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java similarity index 95% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java index be26bbf08..01227e3ca 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/GrindstoneInventoryImpl.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java @@ -1,229 +1,229 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; - -import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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.CraftInventoryGrindstone; -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 grindstone inventory for 1.16 R3 - * - * @since 0.8.0 - */ -public class GrindstoneInventoryImpl extends GrindstoneInventory { - - public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" - ); - } - - EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - - entityPlayer.activeContainer = containerGrindstone; - - int id = containerGrindstone.windowId; - IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone - * - * @since 0.8.0 - */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { - - /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field craftInventoryField; - - /** - * Field for accessing the result inventory field - */ - @NotNull - private final Field resultInventoryField; - - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); - - this.player = entityPlayer.getBukkitEntity(); - - try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - } -} +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.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryGrindstone; +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 grindstone inventory for 1.16 R3 + * + * @since 0.8.0 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + EntityPlayer entityPlayer = getEntityPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); + + entityPlayer.activeContainer = containerGrindstone; + + int id = containerGrindstone.windowId; + IChatBaseComponent message = TextHolderUtil.toComponent(title); + PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, 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 grindstone + * + * @since 0.8.0 + */ + private class ContainerGrindstoneImpl extends ContainerGrindstone { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field craftInventoryField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultInventoryField; + + public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + + this.player = entityPlayer.getBukkitEntity(); + + try { + this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); + this.craftInventoryField.setAccessible(true); + + this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); + this.resultInventoryField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 craft inventory + * + * @return the craft inventory + * @since 0.8.0 + */ + @NotNull + @Contract(pure = true) + private IInventory getCraftInventory() { + try { + return (IInventory) craftInventoryField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.8.0 + */ + @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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/SmithingTableInventoryImpl.java similarity index 95% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/SmithingTableInventoryImpl.java index 20bd19ac3..87c8f74a8 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/SmithingTableInventoryImpl.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/SmithingTableInventoryImpl.java @@ -1,229 +1,229 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; - -import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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.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); - } - - @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 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); - } - - @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 - */ - 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) {} - } -} +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.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); + } + + @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 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); + } + + @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 + */ + 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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/StonecutterInventoryImpl.java similarity index 94% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/StonecutterInventoryImpl.java index 701e46e93..0d44d97c9 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/StonecutterInventoryImpl.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/StonecutterInventoryImpl.java @@ -1,201 +1,201 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3; - -import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; -import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_16_R3.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); - } - } - } -} +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_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/util/TextHolderUtil.java similarity index 96% rename from nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java rename to nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/util/TextHolderUtil.java index 397723c95..506d10d9b 100644 --- a/nms/1_16_R3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_R3/util/TextHolderUtil.java +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_16_R3.util; +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; diff --git a/nms/1_17_R1/pom.xml b/nms/1_17_0/pom.xml similarity index 98% rename from nms/1_17_R1/pom.xml rename to nms/1_17_0/pom.xml index 3b81a46fe..21e7886a3 100644 --- a/nms/1_17_R1/pom.xml +++ b/nms/1_17_0/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_17_R1 + 1_17_0 true diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java similarity index 97% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java index 6b17f777e..900524ac2 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/AnvilInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.CustomInventoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/BeaconInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/BeaconInventoryImpl.java similarity index 99% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/BeaconInventoryImpl.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/BeaconInventoryImpl.java index c27673e21..38d644489 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/BeaconInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/BeaconInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import net.minecraft.core.NonNullList; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/CartographyTableInventoryImpl.java similarity index 96% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/CartographyTableInventoryImpl.java index cd9b6ee34..aa3d0c3fa 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/CartographyTableInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/CartographyTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.CustomInventoryUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/EnchantingTableInventoryImpl.java similarity index 98% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/EnchantingTableInventoryImpl.java index 419f25b1c..891ee33b5 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/EnchantingTableInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/EnchantingTableInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java similarity index 97% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java index 3828c60a4..d38721555 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/GrindstoneInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.CustomInventoryUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java similarity index 97% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java index d143e879e..ba7b3def0 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/SmithingTableInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.CustomInventoryUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/StonecutterInventoryImpl.java similarity index 98% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/StonecutterInventoryImpl.java index fc858f5ca..7525c3764 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/StonecutterInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/StonecutterInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/CustomInventoryUtil.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/util/CustomInventoryUtil.java similarity index 94% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/CustomInventoryUtil.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/util/CustomInventoryUtil.java index 989764a67..6b5366b62 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/CustomInventoryUtil.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/util/CustomInventoryUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; diff --git a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/util/TextHolderUtil.java similarity index 96% rename from nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java rename to nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/util/TextHolderUtil.java index a9d9b7710..30dd41d1e 100644 --- a/nms/1_17_R1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_R1/util/TextHolderUtil.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_17_R1.util; +package com.github.stefvanschie.inventoryframework.nms.v1_17_0.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml new file mode 100644 index 000000000..8542d49f8 --- /dev/null +++ b/nms/1_17_1/pom.xml @@ -0,0 +1,73 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.9.9 + ../../pom.xml + + 4.0.0 + + 1_17_1 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.17.1-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java new file mode 100644 index 000000000..d92d52f9e --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java @@ -0,0 +1,266 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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; + +/** + * Internal anvil inventory for 1.17 R1 + * + * @since 0.10.0 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.0 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.0 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.0 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.10.0 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/BeaconInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/BeaconInventoryImpl.java new file mode 100644 index 000000000..fa1022b40 --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.10.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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + TranslatableComponent message = new TranslatableComponent("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, message)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.0 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/CartographyTableInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..7a57a64e1 --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.10.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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.0 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/EnchantingTableInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..e1cc97b5f --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.10.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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.0 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..26ebd808e --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java @@ -0,0 +1,242 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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 grindstone inventory for 1.17 R1 + * + * @since 0.10.0 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.0 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..b8268690b --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java @@ -0,0 +1,250 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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; + +/** + * Internal smithing table inventory for 1.17 R1 + * + * @since 0.10.0 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.0 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.0 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.0 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/StonecutterInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/StonecutterInventoryImpl.java new file mode 100644 index 000000000..564cb736f --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_17_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_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.17 R1 + * + * @since 0.10.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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.0 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/CustomInventoryUtil.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/CustomInventoryUtil.java new file mode 100644 index 000000000..4959cb8b6 --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.0 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/TextHolderUtil.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/TextHolderUtil.java new file mode 100644 index 000000000..9615b0b52 --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/util/TextHolderUtil.java @@ -0,0 +1,66 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_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.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +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 Component 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 Component toComponent(@NotNull StringHolder holder) { + return new TextComponent(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 Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index f1be32c7c..4f2eebd19 100644 --- a/pom.xml +++ b/pom.xml @@ -7,12 +7,13 @@ IF nms/abstraction - nms/1_17_R1 - nms/1_16_R3 - nms/1_16_R2 - nms/1_16_R1 - nms/1_15_R1 - nms/1_14_R1 + 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 From cdc8fbc58cb581e0da36b17adaa469c5a47a23f4 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jul 2021 16:29:40 +0200 Subject: [PATCH 020/382] Add overloaded constructor for gui with plugin --- .../inventoryframework/gui/type/util/Gui.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 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 aacbbce8a..53ee5cc99 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 @@ -141,9 +141,19 @@ public abstract class Gui { * @since 0.8.0 */ public Gui() { + this(JavaPlugin.getProvidingPlugin(Gui.class)); + } + + /** + * Constructs a new gui with the provided plugin. + * + * @param plugin the plugin + * @see Gui#Gui() for a constructor that automatically detects the wanted plugin + * @since 0.10.0 + */ + public Gui(@NotNull JavaPlugin plugin) { if (!hasRegisteredListeners) { - Bukkit.getPluginManager().registerEvents(new GuiListener(), - JavaPlugin.getProvidingPlugin(getClass())); + Bukkit.getPluginManager().registerEvents(new GuiListener(), plugin); hasRegisteredListeners = true; } From 9261d057e53bf1cd1bbe0ec60e4285770be52228 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jul 2021 16:38:08 +0200 Subject: [PATCH 021/382] Add way to remove items from static pane based on location --- .../inventoryframework/pane/StaticPane.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 b77249f35..9c395e056 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 @@ -113,6 +113,17 @@ public void removeItem(@NotNull GuiItem item) { items.values().removeIf(guiItem -> guiItem.equals(item)); } + /** + * Removes the specified item from the pane + * + * @param x the x coordinate of the item to remove + * @param y the y coordinate of the item to remove + * @since 0.10.0 + */ + public void removeItem(int x, int y) { + items.remove(new AbstractMap.SimpleEntry<>(x, y)); + } + @Override public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComponent, @NotNull InventoryClickEvent event, int slot, int paneOffsetX, int paneOffsetY, int maxLength, From 34dca3a815f35a5ab66bb4ab763fe99e3cb9728b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jul 2021 16:50:01 +0200 Subject: [PATCH 022/382] Fix anvils not showing result item properly --- .../inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java | 2 +- .../inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java index 900524ac2..9df96142f 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java @@ -210,7 +210,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); } @NotNull diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java index d92d52f9e..85c734b01 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java @@ -220,7 +220,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); } @NotNull From b5be3e8efc7dcb3784d2c27b2888aa04850096cc Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jul 2021 21:02:10 +0200 Subject: [PATCH 023/382] Add 1.17.1 to workflow --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 650debaa3..192a6c982 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,6 +35,7 @@ jobs: - run: | wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check + java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check name: Run BuildTools 1.17 - uses: actions/checkout@v2 name: Checkout code From cce8ee5982c5678951eb815f5ca90e75f685129c Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jul 2021 21:24:06 +0200 Subject: [PATCH 024/382] Fix events not working when opening gui on close --- .../stefvanschie/inventoryframework/gui/GuiListener.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index a5cbfcc14..3b9be3377 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -300,11 +300,10 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { //due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly client-side playerInventory.setItemInOffHand(playerInventory.getItemInOffHand()); - if (!gui.isUpdating()) { - gui.callOnClose(event); - - //this is a hack to remove items correctly when players press the x button in a beacon + if (!gui.isUpdating()) {//this is a hack to remove items correctly when players press the x button in a beacon Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { + gui.callOnClose(event); + if (humanEntity.getOpenInventory().getTopInventory() instanceof PlayerInventory) { humanEntity.closeInventory(); } From 6d8d7867e963192d9a7a328cb0d28a9ca9aefba1 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jul 2021 21:36:49 +0200 Subject: [PATCH 025/382] V 0.10.0 --- IF/pom.xml | 2 +- README.md | 6 +++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 2 +- nms/1_17_0/pom.xml | 2 +- nms/1_17_1/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 169837159..63dd6edf9 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 4.0.0 diff --git a/README.md b/README.md index 7e949b2a9..6b47d7644 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.9.9 + 0.10.0 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.9.9' + compile 'com.github.stefvanschie.inventoryframework:IF:0.10.0' // ... } ``` @@ -76,7 +76,7 @@ shadowJar { You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. ```yaml libraries: - - com.github.stefvanschie.inventoryframework:IF:0.9.9 + - com.github.stefvanschie.inventoryframework:IF:0.10.0 ``` ## Building from source diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 1a4d04ab9..7b37d2ad1 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 9b97fcf99..46784b358 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 736cfc936..67ed8de04 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index ff3961860..1d70147eb 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 38b555a5a..fe06b02ee 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index db8936675..5b3041116 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 21e7886a3..f255f086b 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 8542d49f8..97f5ca427 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index fbdee3848..cc53b1c45 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.9.9 + 0.10.0 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 4f2eebd19..15400a581 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.9.9 + 0.10.0 pom IF From 76691131607961e3e60603c86ab10094a26359c6 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 11 Aug 2021 17:40:50 +0200 Subject: [PATCH 026/382] Allow setting level and experience on merchant gui --- .../gui/type/MerchantGui.java | 67 +++++++++++++ .../util/version/VersionMatcher.java | 39 ++++++++ .../nms/v1_14/MerchantInventoryImpl.java | 91 ++++++++++++++++++ .../nms/v1_15/MerchantInventoryImpl.java | 91 ++++++++++++++++++ .../nms/v1_16_1/MerchantInventoryImpl.java | 91 ++++++++++++++++++ .../nms/v1_16_2_3/MerchantInventoryImpl.java | 91 ++++++++++++++++++ .../nms/v1_16_4_5/MerchantInventoryImpl.java | 91 ++++++++++++++++++ .../nms/v1_17_0/MerchantInventoryImpl.java | 93 +++++++++++++++++++ .../nms/v1_17_1/MerchantInventoryImpl.java | 93 +++++++++++++++++++ .../abstraction/MerchantInventory.java | 27 ++++++ 10 files changed, 774 insertions(+) create mode 100644 nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/MerchantInventoryImpl.java create mode 100644 nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/MerchantInventoryImpl.java create mode 100644 nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/MerchantInventoryImpl.java create mode 100644 nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/MerchantInventoryImpl.java create mode 100644 nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/MerchantInventoryImpl.java create mode 100644 nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/MerchantInventoryImpl.java create mode 100644 nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/MerchantInventoryImpl.java create mode 100644 nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/MerchantInventory.java diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index 31466cff1..0d1cad9d6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -7,7 +8,10 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.util.version.Version; +import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; @@ -61,6 +65,22 @@ public class MerchantGui extends NamedGui { @NotNull private final List viewers = new ArrayList<>(); + /** + * The experience of this merchant. Values below zero indicate that the experience should be hidden. + */ + private int experience = -1; + + /** + * The level of this merchant. A value of zero indicates this villager doesn't have a level. + */ + private int level = 0; + + /** + * The internal merchant inventory + */ + @NotNull + private final MerchantInventory merchantInventory = VersionMatcher.newMerchantInventory(Version.getVersion()); + /** * Creates a merchant gui with the given title. * @@ -85,6 +105,10 @@ public MerchantGui(@NotNull TextHolder title) { @Override public void show(@NotNull HumanEntity humanEntity) { + if (!(humanEntity instanceof Player)) { + throw new IllegalArgumentException("Merchants can only be opened by players"); + } + if (isDirty()) { this.merchant = getTitleHolder().asMerchantTitle(); markChanges(); @@ -116,6 +140,12 @@ public void show(@NotNull HumanEntity humanEntity) { } this.viewers.add(humanEntity); + + if (this.experience >= 0 || this.level > 0) { + Player player = (Player) humanEntity; + + this.merchantInventory.sendMerchantOffers(player, merchant.getRecipes(), this.level, this.experience); + } } @NotNull @@ -160,6 +190,43 @@ public void addTrade(@NotNull MerchantRecipe recipe) { this.merchant.setRecipes(recipes); } + /** + * Sets the experience of this merchant gui. Setting the experience will make the experience bar visible, even if + * the amount of experience is zero. Note that if the level of this merchant gui has not been set via + * {@link #setLevel(int)} that the experience will always show as zero even when set to something else. Experience + * must be greater than or equal to zero. Attempting to set the experience to below zero will throw an + * {@link IllegalArgumentException}. + * + * @param experience the experience to set + * @since 0.10.1 + * @throws IllegalArgumentException when the experience is below zero + */ + public void setExperience(int experience) { + if (experience < 0) { + throw new IllegalArgumentException("Experience must be greater than or equal to zero"); + } + + this.experience = experience; + } + + /** + * Sets the level of this merchant gui. This is a value between one and five and will visibly change the gui by + * appending the level of the villager to the title. These are displayed as "Novice", "Apprentice", "Journeyman", + * "Expert" and "Master" respectively (when the player's locale is set to English). When an argument is supplied + * that is not within one and five, an {@link IllegalArgumentException} will be thrown. + * + * @param level the numeric level + * @since 0.10.1 + * @throws IllegalArgumentException when the level is not between one and five + */ + public void setLevel(int level) { + if (level < 0 || level > 5) { + throw new IllegalArgumentException("Level must be between one and five"); + } + + this.level = level; + } + /** * Handles a human entity closing this gui. * 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 8a4cffa67..d69bc261f 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 @@ -41,6 +41,11 @@ public class VersionMatcher { */ private static final EnumMap> GRINDSTONE_INVENTORIES; + /** + * The different merchant inventories for different versions + */ + private static final EnumMap> MERCHANT_INVENTORIES; + /** * The different smithing table inventories for different versions */ @@ -156,6 +161,24 @@ public static GrindstoneInventory newGrindstoneInventory(@NotNull Version versio } } + /** + * Gets a new merchant inventory for the specified version. + * + * @param version the version to get the inventory of + * @return the merchant inventory + * @since 0.10.1 + */ + @NotNull + @Contract(pure = true) + public static MerchantInventory newMerchantInventory(@NotNull Version version) { + try { + return MERCHANT_INVENTORIES.get(version).getConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException exception) { + throw new IllegalStateException(exception); + } + } + /** * Gets a new smithing table inventory for the specified version of the specified inventory holder. If a smithing * table is requested for a version that does not have smithing tables, an {@link UnsupportedVersionException} is @@ -288,6 +311,22 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers GRINDSTONE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.GrindstoneInventoryImpl.class); + MERCHANT_INVENTORIES = new EnumMap<>(Version.class); + 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); + MERCHANT_INVENTORIES.put(Version.V1_16_1, + com.github.stefvanschie.inventoryframework.nms.v1_16_1.MerchantInventoryImpl.class); + 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); + MERCHANT_INVENTORIES.put(Version.V1_17_0, + com.github.stefvanschie.inventoryframework.nms.v1_17_0.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_17_1, + com.github.stefvanschie.inventoryframework.nms.v1_17_1.MerchantInventoryImpl.class); + SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, com.github.stefvanschie.inventoryframework.nms.v1_16_1.SmithingTableInventoryImpl.class); 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 new file mode 100644 index 000000000..03f9655e7 --- /dev/null +++ b/nms/1_14/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_14/MerchantInventoryImpl.java @@ -0,0 +1,91 @@ +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; + +/** + * 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 (MerchantRecipe recipe : trades) { + 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 + ); + + 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/MerchantInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/MerchantInventoryImpl.java new file mode 100644 index 000000000..673956c60 --- /dev/null +++ b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/MerchantInventoryImpl.java @@ -0,0 +1,91 @@ +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; + +/** + * 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 (MerchantRecipe recipe : trades) { + 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 + ); + + 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/MerchantInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/MerchantInventoryImpl.java new file mode 100644 index 000000000..a66250510 --- /dev/null +++ b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/MerchantInventoryImpl.java @@ -0,0 +1,91 @@ +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; + +/** + * 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 (MerchantRecipe recipe : trades) { + 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 + ); + + 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/MerchantInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/MerchantInventoryImpl.java new file mode 100644 index 000000000..545ddc40b --- /dev/null +++ b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/MerchantInventoryImpl.java @@ -0,0 +1,91 @@ +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; + +/** + * 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 (MerchantRecipe recipe : trades) { + 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 + ); + + 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/MerchantInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/MerchantInventoryImpl.java new file mode 100644 index 000000000..22cdd67b0 --- /dev/null +++ b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/MerchantInventoryImpl.java @@ -0,0 +1,91 @@ +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; + +/** + * 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 (MerchantRecipe recipe : trades) { + 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 + ); + + 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_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/MerchantInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/MerchantInventoryImpl.java new file mode 100644 index 000000000..b42fc5004 --- /dev/null +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/MerchantInventoryImpl.java @@ -0,0 +1,93 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_0; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_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; + +/** + * Internal merchant inventory for 1.17.0 + * + * @since 0.10.1 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + for (MerchantRecipe recipe : trades) { + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.1 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.1 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/MerchantInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/MerchantInventoryImpl.java new file mode 100644 index 000000000..0efc7da88 --- /dev/null +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/MerchantInventoryImpl.java @@ -0,0 +1,93 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_17_1; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_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; + +/** + * Internal merchant inventory for 1.17.1 + * + * @since 0.10.1 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + for (MerchantRecipe recipe : trades) { + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.1 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.1 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/MerchantInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/MerchantInventory.java new file mode 100644 index 000000000..8ab07ed21 --- /dev/null +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/MerchantInventory.java @@ -0,0 +1,27 @@ +package com.github.stefvanschie.inventoryframework.abstraction; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.MerchantRecipe; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * A merchant inventory + * + * @since 0.10.1 + */ +public abstract class MerchantInventory { + + /** + * Sends the merchant offers to the player, combined with the merchants level and experience. + * + * @param player the player to send this to + * @param trades the trades to send + * @param level the level of the merchant + * @param experience the experience of the merchant + * @since 0.10.1 + */ + public abstract void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + int level, int experience); +} From 5a43a3f590d74c41011262c0b5f4cea9be42ef1a Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 11 Aug 2021 19:46:44 +0200 Subject: [PATCH 027/382] Allow for setting discounts on trades --- .../gui/type/MerchantGui.java | 46 +++++++++++++++++-- .../nms/v1_14/MerchantInventoryImpl.java | 8 +++- .../nms/v1_15/MerchantInventoryImpl.java | 8 +++- .../nms/v1_16_1/MerchantInventoryImpl.java | 8 +++- .../nms/v1_16_2_3/MerchantInventoryImpl.java | 8 +++- .../nms/v1_16_4_5/MerchantInventoryImpl.java | 8 +++- .../nms/v1_17_0/MerchantInventoryImpl.java | 8 +++- .../nms/v1_17_1/MerchantInventoryImpl.java | 8 +++- .../abstraction/MerchantInventory.java | 4 +- 9 files changed, 86 insertions(+), 20 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index 0d1cad9d6..bad7df2a2 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -31,8 +31,10 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * Represents a gui in the form of a merchant. @@ -65,6 +67,13 @@ public class MerchantGui extends NamedGui { @NotNull private final List viewers = new ArrayList<>(); + /** + * The trades of this merchant with their price differences. The differences are the difference between the new + * price and the original price. + */ + @NotNull + private final List> trades = new ArrayList<>(); + /** * The experience of this merchant. Values below zero indicate that the experience should be hidden. */ @@ -141,10 +150,22 @@ public void show(@NotNull HumanEntity humanEntity) { this.viewers.add(humanEntity); + Player player = (Player) humanEntity; + if (this.experience >= 0 || this.level > 0) { - Player player = (Player) humanEntity; + this.merchantInventory.sendMerchantOffers(player, this.trades, this.level, this.experience); - this.merchantInventory.sendMerchantOffers(player, merchant.getRecipes(), this.level, this.experience); + return; + } + + boolean discount = false; + + for (Map.Entry trade : this.trades) { + if (trade.getValue() != 0) { + this.merchantInventory.sendMerchantOffers(player, this.trades, this.level, this.experience); + + break; + } } } @@ -177,12 +198,16 @@ public void click(@NotNull InventoryClickEvent event) { } /** - * Adds a trade to this gui. + * Adds a trade to this gui. The specified discount is the difference between the old price and the new price. For + * example, if a price was decreased from five to two, the discount would be three. * * @param recipe the recipe to add - * @since 0.10.0 + * @param discount the discount + * @since 0.10.1 */ - public void addTrade(@NotNull MerchantRecipe recipe) { + public void addTrade(@NotNull MerchantRecipe recipe, int discount) { + this.trades.add(new AbstractMap.SimpleImmutableEntry<>(recipe, -discount)); + List recipes = new ArrayList<>(this.merchant.getRecipes()); recipes.add(recipe); @@ -227,6 +252,17 @@ public void setLevel(int level) { this.level = level; } + /** + * Adds a trade to this gui. This will not set a discount on the trade. For specifiying discounts, see + * {@link #addTrade(MerchantRecipe, int)}. + * + * @param recipe the recipe to add + * @since 0.10.0 + */ + public void addTrade(@NotNull MerchantRecipe recipe) { + addTrade(recipe, 0); + } + /** * Handles a human entity closing this gui. * 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 index 03f9655e7..326c2ed8d 100644 --- 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 @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Map; /** * Internal merchant inventory for 1.14 @@ -21,11 +22,13 @@ public class MerchantInventoryImpl extends MerchantInventory { @Override - public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience) { MerchantRecipeList offers = new MerchantRecipeList(); - for (MerchantRecipe recipe : trades) { + for (Map.Entry entry : trades) { + MerchantRecipe recipe = entry.getKey(); List ingredients = recipe.getIngredients(); if (ingredients.size() < 1) { @@ -55,6 +58,7 @@ public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience) { MerchantRecipeList offers = new MerchantRecipeList(); - for (MerchantRecipe recipe : trades) { + for (Map.Entry entry : trades) { + MerchantRecipe recipe = entry.getKey(); List ingredients = recipe.getIngredients(); if (ingredients.size() < 1) { @@ -55,6 +58,7 @@ public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience) { MerchantRecipeList offers = new MerchantRecipeList(); - for (MerchantRecipe recipe : trades) { + for (Map.Entry entry : trades) { + MerchantRecipe recipe = entry.getKey(); List ingredients = recipe.getIngredients(); if (ingredients.size() < 1) { @@ -55,6 +58,7 @@ public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience) { MerchantRecipeList offers = new MerchantRecipeList(); - for (MerchantRecipe recipe : trades) { + for (Map.Entry entry : trades) { + MerchantRecipe recipe = entry.getKey(); List ingredients = recipe.getIngredients(); if (ingredients.size() < 1) { @@ -55,6 +58,7 @@ public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience) { MerchantRecipeList offers = new MerchantRecipeList(); - for (MerchantRecipe recipe : trades) { + for (Map.Entry entry : trades) { + MerchantRecipe recipe = entry.getKey(); List ingredients = recipe.getIngredients(); if (ingredients.size() < 1) { @@ -55,6 +58,7 @@ public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience) { MerchantOffers offers = new MerchantOffers(); - for (MerchantRecipe recipe : trades) { + for (Map.Entry entry : trades) { + MerchantRecipe recipe = entry.getKey(); List ingredients = recipe.getIngredients(); if (ingredients.size() < 1) { @@ -56,6 +59,7 @@ public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience) { MerchantOffers offers = new MerchantOffers(); - for (MerchantRecipe recipe : trades) { + for (Map.Entry entry : trades) { + MerchantRecipe recipe = entry.getKey(); List ingredients = recipe.getIngredients(); if (ingredients.size() < 1) { @@ -56,6 +59,7 @@ public void sendMerchantOffers(@NotNull Player player, @NotNull List trades, + public abstract void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, int level, int experience); } From 82e9b7a47091720dff952f19603a2f21d9290fd0 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 14 Aug 2021 21:24:27 +0200 Subject: [PATCH 028/382] Add alignments to outline pane --- .../inventoryframework/pane/OutlinePane.java | 216 ++++++++++++------ .../pane/OutlinePaneTest.java | 2 + 2 files changed, 147 insertions(+), 71 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java index fdda3e95d..623972e6a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java @@ -54,6 +54,12 @@ public class OutlinePane extends Pane implements Flippable, Orientable, Rotatabl */ private boolean flipHorizontally, flipVertically; + /** + * The alignment of this pane + */ + @NotNull + private Alignment alignment = Alignment.BEGIN; + /** * The mask for this pane */ @@ -92,98 +98,116 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int x = 0, y = 0; + int itemIndex = 0; + int gapCount = 0; - if (orientation == Orientation.HORIZONTAL) { - outerloop: - for (int rowIndex = 0; rowIndex < inventoryComponent.getHeight(); rowIndex++) { - boolean[] row = mask.getRow(rowIndex); + int size; - for (int columnIndex = 0; columnIndex < inventoryComponent.getLength(); columnIndex++) { - if (!row[columnIndex]) { - continue; - } + if (getOrientation() == Orientation.HORIZONTAL) { + size = height; + } else if (getOrientation() == Orientation.VERTICAL) { + size = length; + } else { + throw new IllegalStateException("Unknown orientation '" + getOrientation() + "'"); + } - x = columnIndex; - y = rowIndex; - break outerloop; - } - } - } else if (orientation == Orientation.VERTICAL) { - outerloop: - for (int columnIndex = 0; columnIndex < inventoryComponent.getLength(); columnIndex++) { - boolean[] column = mask.getColumn(columnIndex); - - for (int rowIndex = 0; rowIndex < inventoryComponent.getHeight(); rowIndex++) { - if (!column[rowIndex]) { - continue; - } + for (int vectorIndex = 0; vectorIndex < size && getItems().size() > itemIndex; vectorIndex++) { + boolean[] maskLine; - x = columnIndex; - y = rowIndex; - break outerloop; - } + if (getOrientation() == Orientation.HORIZONTAL) { + maskLine = mask.getRow(vectorIndex); + } else if (getOrientation() == Orientation.VERTICAL) { + maskLine = mask.getColumn(vectorIndex); + } else { + throw new IllegalStateException("Unknown orientation '" + getOrientation() + "'"); } - } - int itemAmount = items.size(); + int enabled = 0; - outerloop: - for (int i = 0; i < (doesRepeat() ? Math.max(mask.amountOfEnabledSlots(), inventoryComponent.getSize()) : itemAmount); i++) { - GuiItem item = items.get(i % itemAmount); + for (boolean bool : maskLine) { + if (bool) { + enabled++; + } + } - if (!item.isVisible()) - continue; + GuiItem[] items; - int newX = x, newY = y; + if (doesRepeat()) { + items = new GuiItem[enabled]; + } else { + int remainingPositions = gapCount + (getItems().size() - itemIndex - 1) * (getGap() + 1) + 1; - if (flipHorizontally) - newX = length - x - 1; + items = new GuiItem[Math.min(enabled, remainingPositions)]; + } - if (flipVertically) - newY = height - y - 1; + for (int index = 0; index < items.length; index++) { + if (gapCount == 0) { + items[index] = getItems().get(itemIndex); - Map.Entry coordinates = GeometryUtil.processClockwiseRotation(newX, newY, length, height, - rotation); + itemIndex++; - newX = coordinates.getKey(); - newY = coordinates.getValue(); + if (doesRepeat() && itemIndex >= getItems().size()) { + itemIndex = 0; + } - if (newX >= 0 && newX < length && newY >= 0 && newY < height) { - int finalRow = getY() + newY + paneOffsetY; - int finalColumn = getX() + newX + paneOffsetX; + gapCount = getGap(); + } else { + items[index] = null; - inventoryComponent.setItem(item, finalColumn, finalRow); + gapCount--; + } } - int gapCount = gap; + int index; - do { - if (orientation == Orientation.HORIZONTAL) { - x++; - - if (x >= length) { - y++; - x = 0; - } - } else if (orientation == Orientation.VERTICAL) { - y++; + if (getAlignment() == Alignment.BEGIN) { + index = 0; + } else if (getAlignment() == Alignment.CENTER) { + index = -((enabled - items.length) / 2); + } else { + throw new IllegalStateException("Unknown alignment '" + getAlignment() + "'"); + } - if (y >= height) { - x++; - y = 0; + for (int opposingVectorIndex = 0; opposingVectorIndex < maskLine.length; opposingVectorIndex++) { + if (maskLine[opposingVectorIndex]) { + if (index >= 0 && index < items.length && items[index] != null) { + int x, y; + + if (getOrientation() == Orientation.HORIZONTAL) { + x = opposingVectorIndex; + y = vectorIndex; + } else if (getOrientation() == Orientation.VERTICAL) { + x = vectorIndex; + y = opposingVectorIndex; + } else { + throw new IllegalStateException("Unknown orientation '" + getOrientation() + "'"); + } + + if (flipHorizontally) { + x = length - x - 1; + } + + if (flipVertically) { + y = height - y - 1; + } + + Map.Entry coordinates = GeometryUtil.processClockwiseRotation(x, y, + length, height, rotation); + + x = coordinates.getKey(); + y = coordinates.getValue(); + + if (x >= 0 && x < length && y >= 0 && y < height) { + int finalRow = getY() + y + paneOffsetY; + int finalColumn = getX() + x + paneOffsetX; + + inventoryComponent.setItem(items[index], finalColumn, finalRow); + } } - } - - //stop the loop when there is no more space in the pane - if (x >= length || y >= height) { - break outerloop; - } - if (mask.isEnabled(x, y)) { - gapCount--; + index++; } - } while (gapCount >= 0); + } } } @@ -245,6 +269,7 @@ public OutlinePane copy() { outlinePane.flipHorizontally = flipHorizontally; outlinePane.flipVertically = flipVertically; outlinePane.mask = mask; + outlinePane.alignment = alignment; return outlinePane; } @@ -326,6 +351,16 @@ public void setHeight(int height) { applyMask(getMask().setHeight(height)); } + /** + * Aligns the pane in the way specified by the provided alignment. + * + * @param alignment the new alignment + * @since 0.10.1 + */ + public void align(@NotNull Alignment alignment) { + this.alignment = alignment; + } + @Override public void flipHorizontally(boolean flipHorizontally) { this.flipHorizontally = flipHorizontally; @@ -366,6 +401,18 @@ public Collection getPanes() { return new HashSet<>(); } + /** + * Gets the alignment set on this pane. + * + * @return the alignment + * @since 0.10.1 + */ + @NotNull + @Contract(pure = true) + public Alignment getAlignment() { + return this.alignment; + } + /** * Gets whether this outline pane repeats itself * @@ -455,6 +502,10 @@ public static OutlinePane load(@NotNull Object instance, @NotNull Element elemen if (element.hasAttribute("repeat")) outlinePane.setRepeat(Boolean.parseBoolean(element.getAttribute("repeat"))); + if (element.hasAttribute("alignment")) { + outlinePane.align(Alignment.valueOf(element.getAttribute("alignment").toUpperCase())); + } + Pane.load(outlinePane, instance, element); Flippable.load(outlinePane, element); Orientable.load(outlinePane, element); @@ -482,4 +533,27 @@ public static OutlinePane load(@NotNull Object instance, @NotNull Element elemen throw new XMLLoadException(exception); } } -} \ No newline at end of file + + /** + * An enum containing different alignments that can be used on the outline pane. + * + * @since 0.10.1 + */ + public enum Alignment { + + /** + * Aligns the items at the start of the pane. + * + * @since 0.10.1 + */ + BEGIN, + + /** + * Aligns the items in the center of the pane. If there is no exact center, this will preference the left (for a + * horizontal orientation) or the top (for a vertical orientation). + * + * @since 0.10.1 + */ + CENTER + } +} diff --git a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/OutlinePaneTest.java b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/OutlinePaneTest.java index 3522c1185..29f0a4411 100644 --- a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/OutlinePaneTest.java +++ b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/OutlinePaneTest.java @@ -24,6 +24,7 @@ void testCopy() { original.flipHorizontally(true); original.flipVertically(true); original.applyMask(new Mask("0")); + original.align(OutlinePane.Alignment.CENTER); OutlinePane copy = original.copy(); @@ -42,6 +43,7 @@ void testCopy() { assertEquals(original.isFlippedHorizontally(), copy.isFlippedHorizontally()); assertEquals(original.isFlippedVertically(), copy.isFlippedVertically()); assertEquals(original.getMask(), copy.getMask()); + assertEquals(original.getAlignment(), copy.getAlignment()); assertEquals(original.getUUID(), copy.getUUID()); } } From 2a370c955c20d3fedc25b8085562f747ebd5255c Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 17 Aug 2021 17:05:56 +0200 Subject: [PATCH 029/382] Fix armor disappearing when opening a gui Opening a gui with an item in the player inventory would delete any armor the player was wearing. --- .../inventoryframework/gui/type/AnvilGui.java | 6 +----- .../inventoryframework/gui/type/BarrelGui.java | 7 +------ .../inventoryframework/gui/type/BeaconGui.java | 8 ++------ .../inventoryframework/gui/type/BlastFurnaceGui.java | 6 +----- .../inventoryframework/gui/type/BrewingStandGui.java | 6 +----- .../inventoryframework/gui/type/CartographyTableGui.java | 6 +----- .../inventoryframework/gui/type/ChestGui.java | 6 +----- .../inventoryframework/gui/type/CraftingTableGui.java | 6 +----- .../inventoryframework/gui/type/DispenserGui.java | 6 +----- .../inventoryframework/gui/type/DropperGui.java | 6 +----- .../inventoryframework/gui/type/EnchantingTableGui.java | 6 +----- .../inventoryframework/gui/type/EnderChestGui.java | 7 +------ .../inventoryframework/gui/type/FurnaceGui.java | 6 +----- .../inventoryframework/gui/type/GrindstoneGui.java | 6 +----- .../inventoryframework/gui/type/HopperGui.java | 6 +----- .../inventoryframework/gui/type/MerchantGui.java | 6 +----- .../inventoryframework/gui/type/ShulkerBoxGui.java | 8 +------- .../inventoryframework/gui/type/SmithingTableGui.java | 6 +----- .../inventoryframework/gui/type/SmokerGui.java | 6 +----- .../inventoryframework/gui/type/StonecutterGui.java | 6 +----- 20 files changed, 21 insertions(+), 105 deletions(-) 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 b2ed5e860..40ec3dabc 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 @@ -101,8 +101,6 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getFirstItemComponent().display(getInventory(), 0); getSecondItemComponent().display(getInventory(), 1); getResultComponent().display(getInventory(), 2); @@ -110,11 +108,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } anvilInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index 777c17d10..445c2aa0c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -72,8 +72,6 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - int height = getInventoryComponent().getHeight(); getInventoryComponent().display(); @@ -82,14 +80,11 @@ public void show(@NotNull HumanEntity humanEntity) { InventoryComponent bottomComponent = getInventoryComponent().excludeRows(0, height - 5); topComponent.placeItems(getInventory(), 0); - bottomComponent.placeItems(humanEntity.getInventory(), 0); if (bottomComponent.hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); bottomComponent.placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java index 1925bbec4..e27beebb0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java @@ -63,17 +63,13 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().storeAndClear(humanEntity); - getPaymentItemComponent().display(getInventory(), 0); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); - getPlayerInventoryComponent().display(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); + getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } beaconInventory.openInventory((Player) humanEntity, getPaymentItemComponent().getItem(0, 0)); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index a61a53bbd..69d7a8f85 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -85,19 +85,15 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getIngredientComponent().display(getInventory(), 0); getFuelComponent().display(getInventory(), 1); getOutputComponent().display(getInventory(), 2); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 618196903..85f06e468 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -97,8 +97,6 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getFirstBottleComponent().display(getInventory(), 0); getSecondBottleComponent().display(getInventory(), 1); getThirdBottleComponent().display(getInventory(), 2); @@ -107,11 +105,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 876b680b6..803cca05e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -104,19 +104,15 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getMapComponent().display(getInventory(), 0); getPaperComponent().display(getInventory(), 1); getOutputComponent().display(getInventory(), 2); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } cartographyTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 041ab2c71..fd2c46bce 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -88,8 +88,6 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - int height = getInventoryComponent().getHeight(); getInventoryComponent().display(); @@ -100,11 +98,9 @@ public void show(@NotNull HumanEntity humanEntity) { topComponent.placeItems(getInventory(), 0); if (bottomComponent.hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); bottomComponent.placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index 4dc76c92c..cfd08cce5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -79,18 +79,14 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getOutputComponent().display(getInventory(), 0); getInputComponent().display(getInventory(), 1); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index 4ab3898a5..39d244599 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -73,17 +73,13 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getContentsComponent().display(getInventory(), 0); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index 6e6b1443b..df50567fe 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -73,17 +73,13 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getContentsComponent().display(getInventory(), 0); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 695c45060..79a288f53 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -89,17 +89,13 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getInputComponent().display(getInventory(), 0); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } enchantingTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index 783258b49..aaf65daad 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -72,8 +72,6 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - int height = getInventoryComponent().getHeight(); getInventoryComponent().display(); @@ -82,14 +80,11 @@ public void show(@NotNull HumanEntity humanEntity) { InventoryComponent bottomComponent = getInventoryComponent().excludeRows(0, height - 5); topComponent.placeItems(getInventory(), 0); - bottomComponent.placeItems(humanEntity.getInventory(), 0); if (bottomComponent.hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); bottomComponent.placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index 0b01fa8f8..ce19331a6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -85,19 +85,15 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getIngredientComponent().display(getInventory(), 0); getFuelComponent().display(getInventory(), 1); getOutputComponent().display(getInventory(), 2); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index aeaab0251..d40b1183a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -95,18 +95,14 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getItemsComponent().display(getInventory(), 0); getResultComponent().display(getInventory(), 2); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } grindstoneInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index a8e5ee8de..9d19c941f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -73,17 +73,13 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getSlotsComponent().display(getInventory(), 0); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index bad7df2a2..c8c926940 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -135,17 +135,13 @@ public void show(@NotNull HumanEntity humanEntity) { inventory.clear(); - getHumanEntityCache().store(humanEntity); - getInputComponent().display(inventory, 0); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } this.viewers.add(humanEntity); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index e896cddc5..0dd753324 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -71,9 +71,6 @@ public void show(@NotNull HumanEntity humanEntity) { } getInventory().clear(); - - getHumanEntityCache().store(humanEntity); - int height = getInventoryComponent().getHeight(); getInventoryComponent().display(); @@ -82,14 +79,11 @@ public void show(@NotNull HumanEntity humanEntity) { InventoryComponent bottomComponent = getInventoryComponent().excludeRows(0, height - 5); topComponent.placeItems(getInventory(), 0); - bottomComponent.placeItems(humanEntity.getInventory(), 0); if (bottomComponent.hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); bottomComponent.placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 38e4dd02b..40eac7c77 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -102,19 +102,15 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getFirstItemComponent().display(getInventory(), 0); getSecondItemComponent().display(getInventory(), 1); getResultComponent().display(getInventory(), 2); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } smithingTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index 67a2c3654..3b4bad105 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -85,19 +85,15 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getIngredientComponent().display(getInventory(), 0); getFuelComponent().display(getInventory(), 1); getOutputComponent().display(getInventory(), 2); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } humanEntity.openInventory(getInventory()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 939c5b374..280c6e418 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -96,18 +96,14 @@ public void show(@NotNull HumanEntity humanEntity) { getInventory().clear(); - getHumanEntityCache().store(humanEntity); - getInputComponent().display(getInventory(), 0); getResultComponent().display(getInventory(), 1); getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - humanEntity.getInventory().clear(); + getHumanEntityCache().storeAndClear(humanEntity); getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); - } else { - getHumanEntityCache().clearCache(humanEntity); } stonecutterInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); From 663fbd9fee810d3f8e972c6fcabbc91f9995d97a Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 17 Aug 2021 17:45:13 +0200 Subject: [PATCH 030/382] Fix items not being moved properly in grindstone gui --- .../inventoryframework/gui/type/GrindstoneGui.java | 4 ++-- .../nms/v1_14/GrindstoneInventoryImpl.java | 5 +++-- .../nms/v1_15/GrindstoneInventoryImpl.java | 5 +++-- .../nms/v1_16_1/GrindstoneInventoryImpl.java | 5 +++-- .../nms/v1_16_2_3/GrindstoneInventoryImpl.java | 5 +++-- .../nms/v1_16_4_5/GrindstoneInventoryImpl.java | 5 +++-- .../nms/v1_17_0/GrindstoneInventoryImpl.java | 5 +++-- .../nms/v1_17_1/GrindstoneInventoryImpl.java | 13 +++++++++---- .../abstraction/GrindstoneInventory.java | 3 ++- 9 files changed, 31 insertions(+), 19 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index d40b1183a..e361a658b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -174,9 +174,9 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); if (slot >= 3 && slot <= 38) { - grindstoneInventory.sendItems(player, getTopItems()); + grindstoneInventory.sendItems(player, getTopItems(), event.getCurrentItem()); } else if (slot >= 0 && slot <= 2) { - grindstoneInventory.sendItems(player, getTopItems()); + grindstoneInventory.sendItems(player, getTopItems(), event.getCurrentItem()); if (event.isCancelled()) { grindstoneInventory.clearCursor(player); 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 index ac83d4fc0..72a292f87 100644 --- 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 @@ -50,11 +50,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), 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 index 148d160d5..1847edbed 100644 --- 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 @@ -50,11 +50,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), 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 index 9178d98ef..fdbbb801a 100644 --- 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 @@ -50,11 +50,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), 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 index 244349403..4ba21f41d 100644 --- 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 @@ -47,11 +47,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), 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 index 01227e3ca..c10bb72bd 100644 --- 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 @@ -50,11 +50,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java index d38721555..2636ccc6f 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java @@ -60,11 +60,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java index 26ebd808e..1ba46fc2f 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java @@ -60,19 +60,24 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); - sendItems(player, items); + sendItems(player, items, player.getItemOnCursor()); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.17.1"); + } + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); int state = serverPlayer.containerMenu.incrementStateId(); - ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); - playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); } @Override diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java index ce1dda004..98c5bcfc5 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java @@ -50,9 +50,10 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * * @param player the player for which to open the grindstone * @param items the items to send + * @param cursor the cursor item, this may be null on versions prior to 1.17.1 * @since 0.8.0 */ - public abstract void sendItems(@NotNull Player player, @Nullable ItemStack[] items); + public abstract void sendItems(@NotNull Player player, @Nullable ItemStack[] items, @Nullable ItemStack cursor); /** * Clears the cursor of the specified player From d86c9bc71952d360391df762689db9cdf8e88257 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 17 Aug 2021 20:49:19 +0200 Subject: [PATCH 031/382] Fix viewers being empty for anvils --- .../inventoryframework/gui/GuiListener.java | 4 +++- .../inventoryframework/gui/type/AnvilGui.java | 24 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index 3b9be3377..d5a266ea0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -318,7 +318,9 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { activeGuiInstances.remove(gui); } - if (gui instanceof MerchantGui) { + if (gui instanceof AnvilGui) { + ((AnvilGui) gui).handleClose(humanEntity); + } else if (gui instanceof MerchantGui) { ((MerchantGui) gui).handleClose(humanEntity); } }); 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 40ec3dabc..32c949062 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 @@ -28,6 +28,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; /** @@ -68,6 +70,12 @@ public class AnvilGui extends NamedGui implements InventoryBased { private final AnvilInventory anvilInventory = VersionMatcher.newAnvilInventory(Version.getVersion(), this); + /** + * The viewers of this gui + */ + @NotNull + private final Collection viewers = new HashSet<>(); + /** * Constructs a new anvil gui * @@ -114,6 +122,8 @@ public void show(@NotNull HumanEntity humanEntity) { } anvilInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); + + this.viewers.add(humanEntity); } @NotNull @@ -190,14 +200,14 @@ public boolean isPlayerInventoryUsed() { @Contract(pure = true) @Override public int getViewerCount() { - return getInventory().getViewers().size(); + return this.viewers.size(); } @NotNull @Contract(pure = true) @Override public List getViewers() { - return new ArrayList<>(getInventory().getViewers()); + return new ArrayList<>(this.viewers); } /** @@ -235,6 +245,16 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { } } + /** + * Handles a human entity closing this gui. + * + * @param humanEntity the human entity closing the gui + * @since 0.10.1 + */ + public void handleClose(@NotNull HumanEntity humanEntity) { + this.viewers.remove(humanEntity); + } + /** * Gets the inventory component representing the first item * From e72a7fa6275bb7e3c0d5d62984cf22073d488a96 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 17 Aug 2021 20:52:22 +0200 Subject: [PATCH 032/382] V 0.10.1 --- IF/pom.xml | 2 +- README.md | 6 +++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 2 +- nms/1_17_0/pom.xml | 2 +- nms/1_17_1/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 63dd6edf9..67acab56c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 4.0.0 diff --git a/README.md b/README.md index 6b47d7644..d0e3f1ef8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.0 + 0.10.1 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.10.0' + compile 'com.github.stefvanschie.inventoryframework:IF:0.10.1' // ... } ``` @@ -76,7 +76,7 @@ shadowJar { You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. ```yaml libraries: - - com.github.stefvanschie.inventoryframework:IF:0.10.0 + - com.github.stefvanschie.inventoryframework:IF:0.10.1 ``` ## Building from source diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 7b37d2ad1..96e27228f 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 46784b358..144f5fa66 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 67ed8de04..4d7d27847 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 1d70147eb..fad5fa89f 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index fe06b02ee..3662ed310 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 5b3041116..4878a4fbf 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index f255f086b..864ce5ce6 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 97f5ca427..7461dd802 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index cc53b1c45..63504e7ef 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.0 + 0.10.1 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 15400a581..83d2e56f6 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.0 + 0.10.1 pom IF From 4ebb4fe879328a643a90f8d0ba7e34ba9d1e91ed Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 4 Sep 2021 16:47:27 +0200 Subject: [PATCH 033/382] Fix deploy plugin not working on Java 16 --- IF/pom.xml | 7 +++++++ pom.xml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/IF/pom.xml b/IF/pom.xml index 67acab56c..c7ee42037 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -181,6 +181,13 @@ https://oss.sonatype.org/ true + + + com.thoughtworks.xstream + xstream + 1.4.13 + + org.apache.maven.plugins diff --git a/pom.xml b/pom.xml index 83d2e56f6..138ea026b 100644 --- a/pom.xml +++ b/pom.xml @@ -126,6 +126,13 @@ https://oss.sonatype.org/ true + + + com.thoughtworks.xstream + xstream + 1.4.13 + + org.apache.maven.plugins From acec2ae942a261260188eb097e575098a1be2e46 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 3 Sep 2021 20:50:26 +0200 Subject: [PATCH 034/382] Fix smithing table item movement Moving an item would make it disappear, this is now fixed. --- .../inventoryframework/gui/type/SmithingTableGui.java | 2 +- .../nms/v1_16_1/SmithingTableInventoryImpl.java | 5 +++-- .../nms/v1_16_2_3/SmithingTableInventoryImpl.java | 5 +++-- .../nms/v1_16_4_5/SmithingTableInventoryImpl.java | 5 +++-- .../nms/v1_17_0/SmithingTableInventoryImpl.java | 5 +++-- .../nms/v1_17_1/SmithingTableInventoryImpl.java | 9 +++++---- .../abstraction/SmithingTableInventory.java | 3 ++- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 40eac7c77..19350c5a7 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -185,7 +185,7 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); if (slot >= 3 && slot <= 38) { - smithingTableInventory.sendItems(player, getTopItems()); + smithingTableInventory.sendItems(player, getTopItems(), event.getCurrentItem()); } else if (slot == 0 || slot == 1) { if (event.isCancelled()) { if (slot == 0) { 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 index 70e06cb20..a8a5df0da 100644 --- 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 @@ -48,11 +48,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), 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 index 053398e26..f89ee345d 100644 --- 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 @@ -45,11 +45,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), 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 index 87c8f74a8..2fb7fe694 100644 --- 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 @@ -48,11 +48,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + 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]), diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java index ba7b3def0..e51b8dde3 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java @@ -60,11 +60,12 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); - sendItems(player, items); + sendItems(player, items, null); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack item) { NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java index b8268690b..4ada319ad 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java @@ -60,19 +60,20 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); - sendItems(player, items); + sendItems(player, items, player.getItemOnCursor()); } @Override - public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); int state = serverPlayer.containerMenu.incrementStateId(); - ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); - playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); } @Override diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java index 5b0dc3cb3..8490598b7 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java @@ -50,9 +50,10 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * * @param player the player for which to open the smithing table * @param items the items to send + * @param cursor the cursor item, this may be null on versions prior to 1.17.1 * @since 0.8.0 */ - public abstract void sendItems(@NotNull Player player, @Nullable ItemStack[] items); + public abstract void sendItems(@NotNull Player player, @Nullable ItemStack[] items, @Nullable ItemStack cursor); /** * Sends the result item to the specified player From dd47188fa8df7ecddfa9e8b5e6a66293c6127309 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 4 Sep 2021 14:31:52 +0200 Subject: [PATCH 035/382] V 0.10.2 --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 2 +- nms/1_17_0/pom.xml | 2 +- nms/1_17_1/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 67acab56c..8b4f339c1 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 96e27228f..a7c930416 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 144f5fa66..c4f756f5a 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 4d7d27847..bea20888f 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index fad5fa89f..7bb086d4d 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 3662ed310..82fa6c642 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 4878a4fbf..cc16b1b93 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 864ce5ce6..c5f8f5c97 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 7461dd802..afae4f804 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 63504e7ef..6f1ed8ffb 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.1 + 0.10.2 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 83d2e56f6..d7f0ef9b8 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.1 + 0.10.2 pom IF From 07f2fc4c3644a1aac024f4b2a262fa04c10f5aad Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 4 Sep 2021 14:39:50 +0200 Subject: [PATCH 036/382] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0e3f1ef8..7fcdd2d56 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.1 + 0.10.2 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.10.1' + compile 'com.github.stefvanschie.inventoryframework:IF:0.10.2' // ... } ``` From 68449280ee1cf7ea93bb064d10f06eaf39b76de4 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 4 Sep 2021 14:58:38 +0200 Subject: [PATCH 037/382] Update plugin.yml dependency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7fcdd2d56..b98efe794 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ shadowJar { You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. ```yaml libraries: - - com.github.stefvanschie.inventoryframework:IF:0.10.1 + - com.github.stefvanschie.inventoryframework:IF:0.10.2 ``` ## Building from source From 567d58a92c871b0d3d64239b6d48ccf8b27eed3f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 4 Sep 2021 14:52:24 +0000 Subject: [PATCH 038/382] Bump xstream from 1.4.13 to 1.4.18 in /IF Bumps [xstream](https://github.com/x-stream/xstream) from 1.4.13 to 1.4.18. - [Release notes](https://github.com/x-stream/xstream/releases) - [Commits](https://github.com/x-stream/xstream/commits) --- updated-dependencies: - dependency-name: com.thoughtworks.xstream:xstream dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 8d1fd3d27..73981da92 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -185,7 +185,7 @@ com.thoughtworks.xstream xstream - 1.4.13 + 1.4.18 From ae6f1c23334f675d0a83e20f6f0f18f6e7e4429d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 4 Sep 2021 15:16:34 +0000 Subject: [PATCH 039/382] Bump xstream from 1.4.13 to 1.4.18 Bumps [xstream](https://github.com/x-stream/xstream) from 1.4.13 to 1.4.18. - [Release notes](https://github.com/x-stream/xstream/releases) - [Commits](https://github.com/x-stream/xstream/commits) --- updated-dependencies: - dependency-name: com.thoughtworks.xstream:xstream dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a2e688645..736efb96a 100644 --- a/pom.xml +++ b/pom.xml @@ -130,7 +130,7 @@ com.thoughtworks.xstream xstream - 1.4.13 + 1.4.18 From a7ac330aa6e963d684c33c83bb228f91adf0f352 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 16 Sep 2021 21:12:40 +0200 Subject: [PATCH 040/382] Fix populate method calls not working --- IF/pom.xml | 18 ++++++++++++-- .../inventoryframework/gui/type/util/Gui.java | 12 +--------- .../inventoryframework/pane/Pane.java | 7 +----- .../inventoryframework/util/XMLUtil.java | 24 +++++++++++++++++++ 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 73981da92..5c794cb8a 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -85,14 +85,28 @@ org.spigotmc spigot-api - 1.16.4-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT provided + + + + org.apache.commons + commons-lang3 + + com.mojang authlib - 1.5.21 + 1.5.26 provided + + + + org.apache.commons + commons-lang3 + + org.junit.jupiter 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 53ee5cc99..74fa560b5 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 @@ -7,7 +7,6 @@ import com.github.stefvanschie.inventoryframework.pane.*; import com.github.stefvanschie.inventoryframework.pane.component.*; import com.github.stefvanschie.inventoryframework.util.XMLUtil; -import org.apache.commons.lang3.reflect.MethodUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; @@ -17,7 +16,6 @@ import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -31,7 +29,6 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -357,14 +354,7 @@ protected void initializeOrThrow(@NotNull Object instance, @NotNull Element elem } if (element.hasAttribute("populate")) { - try { - MethodUtils.invokeExactMethod(instance, "populate", this, Gui.class); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - Plugin plugin = JavaPlugin.getProvidingPlugin(Gui.class); - - throw new XMLLoadException("Error loading " + plugin.getName() + "'s gui with associated class: " - + instance.getClass().getSimpleName(), e); - } + XMLUtil.invokeMethod(instance, element.getAttribute("populate"), this, Gui.class); } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index f7d33c38f..8b9cf15fc 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -10,7 +10,6 @@ import com.github.stefvanschie.inventoryframework.util.UUIDTagType; import com.github.stefvanschie.inventoryframework.util.XMLUtil; import com.google.common.primitives.Primitives; -import org.apache.commons.lang3.reflect.MethodUtils; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; @@ -482,11 +481,7 @@ else if (parameterCount == properties.size() + 1) { XMLUtil.loadFieldAttribute(instance, element, item); if (element.hasAttribute("populate")) { - try { - MethodUtils.invokeExactMethod(instance, "populate", item, GuiItem.class); - } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException exception) { - throw new XMLLoadException(exception); - } + XMLUtil.invokeMethod(instance, element.getAttribute("populate"), item, GuiItem.class); } item.setProperties(properties); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/XMLUtil.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/XMLUtil.java index ede880dbc..1f3586bc9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/XMLUtil.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/XMLUtil.java @@ -62,6 +62,30 @@ public static Consumer loadOnEventAttribute(@NotNull Object return null; } + /** + * Invokes the method by the given name on the given instance with the provided argument. The method should have + * the exact name specified and the exact parameter as specified. If the method cannot be accessed or found, this + * will throw an {@link XMLLoadException}. + * + * @param instance the instance on which to call the method + * @param methodName the name of the method to invoke + * @param argument the argument to provide for the invocation + * @param parameter the parameter of the method + * @since 0.10.3 + * @throws XMLLoadException if the method cannot be accessed or found + */ + public static void invokeMethod(@NotNull Object instance, @NotNull String methodName, @NotNull Object argument, + @NotNull Class parameter) { + try { + Method method = instance.getClass().getMethod(methodName, parameter); + + method.setAccessible(true); + method.invoke(instance, argument); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException exception) { + throw new XMLLoadException(exception); + } + } + /** * Sets a field from the given instance and element to the specified value * From bf402934821662e05a745aff76fd3ed06e1013f4 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 16 Sep 2021 21:17:36 +0200 Subject: [PATCH 041/382] V 0.10.3 --- IF/pom.xml | 2 +- README.md | 6 +++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 2 +- nms/1_17_0/pom.xml | 2 +- nms/1_17_1/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 5c794cb8a..900dddb22 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 4.0.0 diff --git a/README.md b/README.md index b98efe794..28a9a25de 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.2 + 0.10.3 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.10.2' + compile 'com.github.stefvanschie.inventoryframework:IF:0.10.3' // ... } ``` @@ -76,7 +76,7 @@ shadowJar { You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. ```yaml libraries: - - com.github.stefvanschie.inventoryframework:IF:0.10.2 + - com.github.stefvanschie.inventoryframework:IF:0.10.3 ``` ## Building from source diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index a7c930416..8783e70ee 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index c4f756f5a..d90042c3d 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index bea20888f..28a80cbb2 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 7bb086d4d..76de02c53 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 82fa6c642..84c54d02a 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index cc16b1b93..127a1425a 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index c5f8f5c97..fd3950ee4 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index afae4f804..bf7bcea6f 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 6f1ed8ffb..56a7d61ce 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.2 + 0.10.3 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 736efb96a..abbb13d0a 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.2 + 0.10.3 pom IF From ed6960b823d0d340824af9a89c355f8bb8363e1b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 20 Sep 2021 19:49:34 +0200 Subject: [PATCH 042/382] Set up dependabot --- .github/dependabot.yml | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..d2f8803b0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,46 @@ +version: 2 +updates: + - package-ecosystem: "maven" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/IF" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/adventure-support" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_14" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_15" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_16_1" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_16_2-3" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_16_4-5" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_17_0" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_17_1" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/abstraction" + schedule: + interval: "daily" From 9f438a898a9ef5414418c4b4ceaacbeeab0d724e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:49:53 +0000 Subject: [PATCH 043/382] Bump maven-gpg-plugin from 1.6 to 3.0.1 Bumps [maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 1.6 to 3.0.1. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-1.6...maven-gpg-plugin-3.0.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 900dddb22..3d92b1cbd 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -135,7 +135,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + 3.0.1 sign-artifacts diff --git a/pom.xml b/pom.xml index abbb13d0a..f5472de75 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + 3.0.1 sign-artifacts From 2402adbb7899fce655424805d0d4fa64de8449d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:49:54 +0000 Subject: [PATCH 044/382] Bump junit-jupiter-engine from 5.2.0 to 5.8.0 in /IF Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.2.0 to 5.8.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.2.0...r5.8.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 3d92b1cbd..e1af4f08b 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -168,7 +168,7 @@ org.junit.jupiter junit-jupiter-engine - 5.2.0 + 5.8.0 From c7458d9c4855e7a9c71527be635dc132b9043886 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:49:57 +0000 Subject: [PATCH 045/382] Bump junit-jupiter-api from 5.3.1 to 5.8.0 Bumps [junit-jupiter-api](https://github.com/junit-team/junit5) from 5.3.1 to 5.8.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.3.1...r5.8.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index e1af4f08b..8b834f9e8 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -111,7 +111,7 @@ org.junit.jupiter junit-jupiter-api - 5.3.1 + 5.8.0 test From 1e206cdc6ad6cec6e7b6de779ab0891babb6d560 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:49:58 +0000 Subject: [PATCH 046/382] Bump maven-surefire-plugin from 2.22.0 to 2.22.2 in /IF Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 2.22.0 to 2.22.2. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-2.22.0...surefire-2.22.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 8b834f9e8..69f600f2c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -158,7 +158,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.0 + 2.22.2 org.junit.platform From 74dcadcee0e82b06789863c3e50a06b5d72203b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:50:04 +0000 Subject: [PATCH 047/382] Bump junit-platform-surefire-provider from 1.2.0-M1 to 1.3.2 in /IF Bumps [junit-platform-surefire-provider](https://github.com/junit-team/junit5) from 1.2.0-M1 to 1.3.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/commits) --- updated-dependencies: - dependency-name: org.junit.platform:junit-platform-surefire-provider dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 69f600f2c..86735fa5b 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -163,7 +163,7 @@ org.junit.platform junit-platform-surefire-provider - 1.2.0-M1 + 1.3.2 org.junit.jupiter From e045e0f045ecabfdd1d8f37407b8c7ce6c4a988f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:50:15 +0000 Subject: [PATCH 048/382] Bump maven-surefire-plugin from 2.22.0 to 2.22.2 Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 2.22.0 to 2.22.2. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-2.22.0...surefire-2.22.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f5472de75..50c700e4d 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.0 + 2.22.2 org.junit.platform From 149cdc98e5afc3251966663f7af9b3d348c409c3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:50:17 +0000 Subject: [PATCH 049/382] Bump junit-platform-surefire-provider from 1.2.0-M1 to 1.3.2 Bumps [junit-platform-surefire-provider](https://github.com/junit-team/junit5) from 1.2.0-M1 to 1.3.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/commits) --- updated-dependencies: - dependency-name: org.junit.platform:junit-platform-surefire-provider dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 50c700e4d..b37b7f96e 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ org.junit.platform junit-platform-surefire-provider - 1.2.0-M1 + 1.3.2 org.junit.jupiter From 65be28745121bb591e35d501cc0814b56bfd3555 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:50:20 +0000 Subject: [PATCH 050/382] Bump annotations from 19.0.0 to 22.0.0 Bumps [annotations](https://github.com/JetBrains/java-annotations) from 19.0.0 to 22.0.0. - [Release notes](https://github.com/JetBrains/java-annotations/releases) - [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md) - [Commits](https://github.com/JetBrains/java-annotations/compare/19.0.0...22.0.0) --- updated-dependencies: - dependency-name: org.jetbrains:annotations dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b37b7f96e..7fb1b3695 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ org.jetbrains annotations - 19.0.0 + 22.0.0 provided From 2ae735daa1d860e3febf5c9a18cd0219e218688d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:50:27 +0000 Subject: [PATCH 051/382] Bump maven-shade-plugin from 3.2.1 to 3.2.4 in /IF Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.1 to 3.2.4. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.1...maven-shade-plugin-3.2.4) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 86735fa5b..56dc0c6b9 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -175,7 +175,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.1 + 3.2.4 package From 94eb2f5757965af68dead8b423748c54e4e87768 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:22:53 +0000 Subject: [PATCH 052/382] Bump maven-javadoc-plugin from 3.1.1 to 3.3.1 in /IF Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.1.1 to 3.3.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.1.1...maven-javadoc-plugin-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 56dc0c6b9..31914bafa 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -219,7 +219,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.3.1 attach-javadocs From b310f7603129daa1ab4dbad64bc49a297fe64726 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:22:55 +0000 Subject: [PATCH 053/382] Bump maven-javadoc-plugin from 3.1.1 to 3.3.1 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.1.1 to 3.3.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.1.1...maven-javadoc-plugin-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7fb1b3695..9c0b1c74a 100644 --- a/pom.xml +++ b/pom.xml @@ -150,7 +150,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.3.1 attach-javadocs From 4645e1970536677fb72920baf1c0a88630ff78d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:25:03 +0000 Subject: [PATCH 054/382] Bump maven-source-plugin from 3.2.0 to 3.2.1 in /IF Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.0 to 3.2.1. - [Release notes](https://github.com/apache/maven-source-plugin/releases) - [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.0...maven-source-plugin-3.2.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-source-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 31914bafa..1782117ea 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -206,7 +206,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.0 + 3.2.1 attach-sources From dfc8154e22511cfcf700a6368db3ec3cecfb0ab6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:25:20 +0000 Subject: [PATCH 055/382] Bump junit-jupiter-engine from 5.2.0 to 5.8.0 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.2.0 to 5.8.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.2.0...r5.8.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9c0b1c74a..5d10c039b 100644 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ org.junit.jupiter junit-jupiter-engine - 5.2.0 + 5.8.0 From 569abcd4aa77fa68686c5e83a37e8b174fdf2ed0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:26:46 +0000 Subject: [PATCH 056/382] Bump maven-source-plugin from 3.2.0 to 3.2.1 Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.0 to 3.2.1. - [Release notes](https://github.com/apache/maven-source-plugin/releases) - [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.0...maven-source-plugin-3.2.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-source-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5d10c039b..af5c8136b 100644 --- a/pom.xml +++ b/pom.xml @@ -137,7 +137,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.0 + 3.2.1 attach-sources From 97563ab031ece3898450a95723ba033129e560fa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Sep 2021 05:16:04 +0000 Subject: [PATCH 057/382] Bump junit-jupiter-engine from 5.8.0 to 5.8.1 in /IF Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.8.0 to 5.8.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.0...r5.8.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 1782117ea..07feeef57 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -168,7 +168,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.0 + 5.8.1 From e80139d0ed98011aa896cb19e532847c6cc5a553 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Sep 2021 05:16:04 +0000 Subject: [PATCH 058/382] Bump junit-jupiter-api from 5.8.0 to 5.8.1 Bumps [junit-jupiter-api](https://github.com/junit-team/junit5) from 5.8.0 to 5.8.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.0...r5.8.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 07feeef57..79f7cfdf2 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -111,7 +111,7 @@ org.junit.jupiter junit-jupiter-api - 5.8.0 + 5.8.1 test From 3369eb05523357b61a863522fb13a585817c8d49 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Sep 2021 05:16:20 +0000 Subject: [PATCH 059/382] Bump junit-jupiter-engine from 5.8.0 to 5.8.1 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.8.0 to 5.8.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.0...r5.8.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index af5c8136b..c6f373b2a 100644 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.0 + 5.8.1 From 2a6895fd1328ac733462a28b9e6f76c498d4cf4f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:25:18 +0000 Subject: [PATCH 060/382] Bump adventure-api from 4.8.1 to 4.9.1 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.8.1 to 4.9.1. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.8.1...v4.9.1) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c6f373b2a..5c3c4efdc 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 1.8 true UTF-8 - 4.8.1 + 4.9.1 com.github.stefvanschie.inventoryframework From 6a77b5a141ab545eec91704a576377dfe9124d26 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 28 Sep 2021 20:53:13 +0200 Subject: [PATCH 061/382] Remove unused import --- .../adventuresupport/NativeComponentHolder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java index 6cfde4d5d..eaea94d11 100644 --- a/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java +++ b/adventure-support/src/main/java/com/github/stefvanschie/inventoryframework/adventuresupport/NativeComponentHolder.java @@ -7,7 +7,6 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.Merchant; import org.bukkit.inventory.meta.ItemMeta; -import org.checkerframework.checker.units.qual.C; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; From 18da58ee9f90c4422caa6f3a6f89d6f472874d6e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Oct 2021 05:18:45 +0000 Subject: [PATCH 062/382] Bump adventure-api from 4.9.1 to 4.9.2 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.9.1 to 4.9.2. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.9.1...v4.9.2) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5c3c4efdc..637cf533b 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 1.8 true UTF-8 - 4.9.1 + 4.9.2 com.github.stefvanschie.inventoryframework From 965e46d604376cdde6ce4a6c24d25318c965d11b Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Tue, 12 Oct 2021 21:48:56 +0200 Subject: [PATCH 063/382] Add enabled parameter to constructor --- .../pane/component/ToggleButton.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index da25e0435..b0e426a97 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -40,6 +40,12 @@ public ToggleButton(int x, int y, int length, int height, @NotNull Priority prio setPriority(priority); } + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled) { + this(x, y, length, height, priority); + + this.enabled = enabled; + } + public ToggleButton(int length, int height) { super(length, height); @@ -52,6 +58,12 @@ public ToggleButton(int length, int height) { this.disabledPane.setRepeat(true); } + public ToggleButton(int length, int height, boolean enabled) { + this(length, height); + + this.enabled = enabled; + } + public ToggleButton(int x, int y, int length, int height) { this(length, height); @@ -59,6 +71,12 @@ public ToggleButton(int x, int y, int length, int height) { setY(y); } + public ToggleButton(int x, int y, int length, int height, boolean enabled) { + this(x, y, length, height); + + this.enabled = enabled; + } + @Override public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { @@ -114,7 +132,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Contract(pure = true) @Override public ToggleButton copy() { - ToggleButton toggleButton = new ToggleButton(x, y, length, height, getPriority()); + ToggleButton toggleButton = new ToggleButton(x, y, length, height, getPriority(), enabled); toggleButton.setVisible(isVisible()); toggleButton.onClick = onClick; @@ -124,8 +142,6 @@ public ToggleButton copy() { toggleButton.setEnabledItem(enabledPane.getItems().get(0).copy()); toggleButton.setDisabledItem(disabledPane.getItems().get(0).copy()); - toggleButton.enabled = enabled; - return toggleButton; } @@ -208,14 +224,11 @@ public static ToggleButton load(@NotNull Object instance, @NotNull Element eleme throw new XMLLoadException(exception); } - ToggleButton toggleButton = new ToggleButton(length, height); + boolean enabled = element.hasAttribute("enabled") && Boolean.parseBoolean(element.getAttribute("enabled")); + ToggleButton toggleButton = new ToggleButton(length, height, enabled); Pane.load(toggleButton, instance, element); - if (element.hasAttribute("enabled") && Boolean.parseBoolean(element.getAttribute("enabled"))) { - toggleButton.toggle(); - } - return toggleButton; } } From b3b85e5e8ab932097a926eb855f656d1fd44b8e5 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Thu, 14 Oct 2021 17:11:37 +0200 Subject: [PATCH 064/382] Faster builds --- .github/workflows/maven.yml | 57 ++++++++++++++++++++++++++++++------- nms/1_14/pom.xml | 4 +-- nms/1_15/pom.xml | 4 +-- nms/1_16_1/pom.xml | 4 +-- nms/1_16_2-3/pom.xml | 4 +-- nms/1_16_4-5/pom.xml | 12 ++++---- 6 files changed, 61 insertions(+), 24 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 192a6c982..bec082650 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,27 +16,64 @@ jobs: runs-on: ubuntu-latest name: 'Build' steps: + - name: Cache Paperclip Jars + id: cache-paperclip-jars + uses: actions/cache@v2 + with: + path: | + build + paperclip + ~/.m2/repository/io/papermc/paper + ~/.m2/repository/org/spigotmc + key: ${{ runner.os }}-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 + wget https://papermc.io/api/v2/projects/paper/versions/1.17/builds/79/downloads/paper-1.17-79.jar -O paperclip/paper-1.17.jar + wget https://papermc.io/api/v2/projects/paper/versions/1.17.1/builds/327/downloads/paper-1.17.1-327.jar -O paperclip/paper-1.17.1.jar - name: Set up JDK 11 uses: actions/setup-java@v1 with: java-version: 11 - - run: | - wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar - java -jar BuildTools.jar --rev 1.14.4 --disable-java-check - java -jar BuildTools.jar --rev 1.15.2 --disable-java-check - java -jar BuildTools.jar --rev 1.16.1 --disable-java-check - java -jar BuildTools.jar --rev 1.16.3 --disable-java-check - java -jar BuildTools.jar --rev 1.16.4 --disable-java-check - name: Run BuildTools 1.14 - 1.16 + - name: Generate 1.14 - 1.16 Paper Jars + if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + run: | + cd paperclip/ + 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 + cd ../ + - name: Install 1.14 - 1.16 Paper Jars + if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + run: | + cd paperclip/ + 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" + cd ../ - name: Set up JDK 16 uses: actions/setup-java@v1 with: java-version: 16 - - run: | + - name: Run BuildTools 1.17 + 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 java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check - name: Run BuildTools 1.17 + cd ../ - uses: actions/checkout@v2 name: Checkout code - name: Build with Maven diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index d90042c3d..76093d58b 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.14.4-R0.1-SNAPSHOT provided diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 28a80cbb2..c7fb2ae3a 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.15.2-R0.1-SNAPSHOT provided diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 76de02c53..cf423cb74 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.16.1-R0.1-SNAPSHOT provided diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 84c54d02a..729f82cb9 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.16.3-R0.1-SNAPSHOT provided diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 127a1425a..500f411cc 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -17,18 +17,18 @@ + + io.papermc + paper + 1.16.4-R0.1-SNAPSHOT + provided + com.github.stefvanschie.inventoryframework abstraction ${project.version} compile - - org.spigotmc - spigot - 1.16.4-R0.1-SNAPSHOT - provided - \ No newline at end of file From 9eeb6a4f82b20f639a1fa9fdf30fcf55a7422c1c Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Thu, 14 Oct 2021 18:47:47 +0200 Subject: [PATCH 065/382] No need for >1.17 paperclip --- .github/workflows/maven.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index bec082650..e4c073052 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,8 +35,6 @@ jobs: 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://papermc.io/api/v2/projects/paper/versions/1.17/builds/79/downloads/paper-1.17-79.jar -O paperclip/paper-1.17.jar - wget https://papermc.io/api/v2/projects/paper/versions/1.17.1/builds/327/downloads/paper-1.17.1-327.jar -O paperclip/paper-1.17.1.jar - name: Set up JDK 11 uses: actions/setup-java@v1 with: From 79b61fc30e4001a5c4c16443f4de4ca02a2b3573 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 28 Oct 2021 21:02:13 +0200 Subject: [PATCH 066/382] Fix open virtual inventories crashing upon server shutdown --- .../stefvanschie/inventoryframework/gui/type/AnvilGui.java | 3 +++ .../stefvanschie/inventoryframework/gui/type/BeaconGui.java | 3 +++ .../inventoryframework/gui/type/CartographyTableGui.java | 3 +++ .../inventoryframework/gui/type/CraftingTableGui.java | 3 +++ .../inventoryframework/gui/type/EnchantingTableGui.java | 3 +++ .../inventoryframework/gui/type/GrindstoneGui.java | 3 +++ .../inventoryframework/gui/type/SmithingTableGui.java | 3 +++ .../inventoryframework/gui/type/StonecutterGui.java | 3 +++ 8 files changed, 24 insertions(+) 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 32c949062..93109f647 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 @@ -121,6 +121,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + anvilInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); this.viewers.add(humanEntity); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java index e27beebb0..4bdb08cd2 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java @@ -72,6 +72,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + beaconInventory.openInventory((Player) humanEntity, getPaymentItemComponent().getItem(0, 0)); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 803cca05e..3f8f1bed6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -115,6 +115,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + cartographyTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index cfd08cce5..a992c9b93 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -89,6 +89,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + humanEntity.openInventory(getInventory()); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 79a288f53..79548aaff 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -98,6 +98,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + enchantingTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index e361a658b..ef3b9ba6f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -105,6 +105,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + grindstoneInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 19350c5a7..542e0e6a6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -113,6 +113,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + smithingTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 280c6e418..04be02e41 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -106,6 +106,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } + //also let Bukkit know that we opened an inventory + humanEntity.openInventory(getInventory()); + stonecutterInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); } From 0ef1ac4b7cc2cdfce90d760ae6258c3fa5225bd7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 05:18:09 +0000 Subject: [PATCH 067/382] Bump adventure-api from 4.9.2 to 4.9.3 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.9.2 to 4.9.3. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.9.2...v4.9.3) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 637cf533b..f968911c9 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 1.8 true UTF-8 - 4.9.2 + 4.9.3 com.github.stefvanschie.inventoryframework From b4db6988efffa24f0f39cda9a3c4cc522bb47732 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Nov 2021 05:16:21 +0000 Subject: [PATCH 068/382] Bump annotations from 22.0.0 to 23.0.0 Bumps [annotations](https://github.com/JetBrains/java-annotations) from 22.0.0 to 23.0.0. - [Release notes](https://github.com/JetBrains/java-annotations/releases) - [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md) - [Commits](https://github.com/JetBrains/java-annotations/compare/22.0.0...23.0.0) --- updated-dependencies: - dependency-name: org.jetbrains:annotations dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f968911c9..5005f9735 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ org.jetbrains annotations - 22.0.0 + 23.0.0 provided From fad07defcdeb8a4e98e24845cc3db5ccf32d7397 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Nov 2021 05:20:18 +0000 Subject: [PATCH 069/382] Bump specialsource-maven-plugin from 1.2.2 to 1.2.3 Bumps [specialsource-maven-plugin](https://github.com/agaricusb/SpecialSourceMP) from 1.2.2 to 1.2.3. - [Release notes](https://github.com/agaricusb/SpecialSourceMP/releases) - [Commits](https://github.com/agaricusb/SpecialSourceMP/commits) --- updated-dependencies: - dependency-name: net.md-5:specialsource-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_17_0/pom.xml | 2 +- nms/1_17_1/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index fd3950ee4..b0f267c2f 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -37,7 +37,7 @@ net.md-5 specialsource-maven-plugin - 1.2.2 + 1.2.3 package diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index bf7bcea6f..f998d62fa 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -37,7 +37,7 @@ net.md-5 specialsource-maven-plugin - 1.2.2 + 1.2.3 package From 0d9ac2be6d4bd7ae1760ce0334d03436f179a788 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Thu, 14 Oct 2021 17:11:37 +0200 Subject: [PATCH 070/382] Faster builds --- .github/workflows/maven.yml | 57 ++++++++++++++++++++++++++++++------- nms/1_14/pom.xml | 4 +-- nms/1_15/pom.xml | 4 +-- nms/1_16_1/pom.xml | 4 +-- nms/1_16_2-3/pom.xml | 4 +-- nms/1_16_4-5/pom.xml | 12 ++++---- 6 files changed, 61 insertions(+), 24 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 192a6c982..bec082650 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,27 +16,64 @@ jobs: runs-on: ubuntu-latest name: 'Build' steps: + - name: Cache Paperclip Jars + id: cache-paperclip-jars + uses: actions/cache@v2 + with: + path: | + build + paperclip + ~/.m2/repository/io/papermc/paper + ~/.m2/repository/org/spigotmc + key: ${{ runner.os }}-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 + wget https://papermc.io/api/v2/projects/paper/versions/1.17/builds/79/downloads/paper-1.17-79.jar -O paperclip/paper-1.17.jar + wget https://papermc.io/api/v2/projects/paper/versions/1.17.1/builds/327/downloads/paper-1.17.1-327.jar -O paperclip/paper-1.17.1.jar - name: Set up JDK 11 uses: actions/setup-java@v1 with: java-version: 11 - - run: | - wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar - java -jar BuildTools.jar --rev 1.14.4 --disable-java-check - java -jar BuildTools.jar --rev 1.15.2 --disable-java-check - java -jar BuildTools.jar --rev 1.16.1 --disable-java-check - java -jar BuildTools.jar --rev 1.16.3 --disable-java-check - java -jar BuildTools.jar --rev 1.16.4 --disable-java-check - name: Run BuildTools 1.14 - 1.16 + - name: Generate 1.14 - 1.16 Paper Jars + if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + run: | + cd paperclip/ + 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 + cd ../ + - name: Install 1.14 - 1.16 Paper Jars + if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + run: | + cd paperclip/ + 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" + cd ../ - name: Set up JDK 16 uses: actions/setup-java@v1 with: java-version: 16 - - run: | + - name: Run BuildTools 1.17 + 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 java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check - name: Run BuildTools 1.17 + cd ../ - uses: actions/checkout@v2 name: Checkout code - name: Build with Maven diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index d90042c3d..76093d58b 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.14.4-R0.1-SNAPSHOT provided diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 28a80cbb2..c7fb2ae3a 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.15.2-R0.1-SNAPSHOT provided diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 76de02c53..cf423cb74 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.16.1-R0.1-SNAPSHOT provided diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 84c54d02a..729f82cb9 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -18,8 +18,8 @@ - org.spigotmc - spigot + io.papermc + paper 1.16.3-R0.1-SNAPSHOT provided diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 127a1425a..500f411cc 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -17,18 +17,18 @@ + + io.papermc + paper + 1.16.4-R0.1-SNAPSHOT + provided + com.github.stefvanschie.inventoryframework abstraction ${project.version} compile - - org.spigotmc - spigot - 1.16.4-R0.1-SNAPSHOT - provided - \ No newline at end of file From 7980c8b7027d1ae8cadaf2bb120402b90693010d Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Thu, 14 Oct 2021 18:47:47 +0200 Subject: [PATCH 071/382] No need for >1.17 paperclip --- .github/workflows/maven.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index bec082650..e4c073052 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,8 +35,6 @@ jobs: 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://papermc.io/api/v2/projects/paper/versions/1.17/builds/79/downloads/paper-1.17-79.jar -O paperclip/paper-1.17.jar - wget https://papermc.io/api/v2/projects/paper/versions/1.17.1/builds/327/downloads/paper-1.17.1-327.jar -O paperclip/paper-1.17.1.jar - name: Set up JDK 11 uses: actions/setup-java@v1 with: From 1550845830f2d5a12357e974d7b414cf42596cdc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 05:18:09 +0000 Subject: [PATCH 072/382] Bump adventure-api from 4.9.2 to 4.9.3 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.9.2 to 4.9.3. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.9.2...v4.9.3) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 637cf533b..f968911c9 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 1.8 true UTF-8 - 4.9.2 + 4.9.3 com.github.stefvanschie.inventoryframework From ba2b210fe9c76e257f86efdcdf90d282d534c436 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Nov 2021 05:16:21 +0000 Subject: [PATCH 073/382] Bump annotations from 22.0.0 to 23.0.0 Bumps [annotations](https://github.com/JetBrains/java-annotations) from 22.0.0 to 23.0.0. - [Release notes](https://github.com/JetBrains/java-annotations/releases) - [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md) - [Commits](https://github.com/JetBrains/java-annotations/compare/22.0.0...23.0.0) --- updated-dependencies: - dependency-name: org.jetbrains:annotations dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f968911c9..5005f9735 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ org.jetbrains annotations - 22.0.0 + 23.0.0 provided From 900a247bfa4b423fd7c7d9b4e2d1d4a0d5ac0224 Mon Sep 17 00:00:00 2001 From: cdfn Date: Sun, 28 Nov 2021 10:41:01 +0100 Subject: [PATCH 074/382] Allow lowercase priorities in xml --- .../com/github/stefvanschie/inventoryframework/pane/Pane.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 8b9cf15fc..381993fc7 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -499,7 +499,7 @@ public static void load(@NotNull Pane pane, @NotNull Object instance, @NotNull E } if (element.hasAttribute("priority")) - pane.setPriority(Priority.valueOf(element.getAttribute("priority"))); + pane.setPriority(Priority.valueOf(element.getAttribute("priority").toUpperCase())); if (element.hasAttribute("visible")) pane.setVisible(Boolean.parseBoolean(element.getAttribute("visible"))); From d3099a07200b1d84743b1bf7c23883b0ad2e2116 Mon Sep 17 00:00:00 2001 From: CDFN Date: Wed, 1 Dec 2021 00:43:43 +0100 Subject: [PATCH 075/382] Check for panes outside page tag in PaginatedPane --- .../stefvanschie/inventoryframework/pane/PaginatedPane.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index 2237e0a61..bdb269fb4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -326,6 +326,9 @@ public static PaginatedPane load(@NotNull Object instance, @NotNull Element elem NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); + if(!item.getNodeName().equals("page")) { + throw new XMLLoadException("Panes have to be inside page tag"); + } if (item.getNodeType() != Node.ELEMENT_NODE) continue; From 41b3fc166bc2773888fb7cbcc0dd0700f6a5108b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 05:19:30 +0000 Subject: [PATCH 076/382] Bump junit-jupiter-engine from 5.8.1 to 5.8.2 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.8.1 to 5.8.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.1...r5.8.2) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 79f7cfdf2..58095f18f 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -168,7 +168,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.1 + 5.8.2 diff --git a/pom.xml b/pom.xml index 5005f9735..b5eb14c99 100644 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.1 + 5.8.2 From ac9d4f247f12718b3f96a0c1c066c18f0f295c43 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 05:19:33 +0000 Subject: [PATCH 077/382] Bump junit-jupiter-api from 5.8.1 to 5.8.2 Bumps [junit-jupiter-api](https://github.com/junit-team/junit5) from 5.8.1 to 5.8.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.1...r5.8.2) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 58095f18f..b6a8e198e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -111,7 +111,7 @@ org.junit.jupiter junit-jupiter-api - 5.8.1 + 5.8.2 test From 9c9774740dce334083ae69a350041662b0d54fb9 Mon Sep 17 00:00:00 2001 From: CDFN Date: Wed, 1 Dec 2021 21:21:21 +0100 Subject: [PATCH 078/382] Move page tag check further so comments won't break anything --- .../inventoryframework/pane/PaginatedPane.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index bdb269fb4..4e9cc6fe4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -326,13 +326,12 @@ public static PaginatedPane load(@NotNull Object instance, @NotNull Element elem NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); - if(!item.getNodeName().equals("page")) { - throw new XMLLoadException("Panes have to be inside page tag"); - } - if (item.getNodeType() != Node.ELEMENT_NODE) continue; + if(!item.getNodeName().equals("page")) + throw new XMLLoadException("Panes have to be inside page tag"); + NodeList innerNodes = item.getChildNodes(); for (int j = 0; j < innerNodes.getLength(); j++) { From 1bc11c9d276340938666696af74c8a8de41992e0 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 13 Dec 2021 22:04:28 +0100 Subject: [PATCH 079/382] Add 1.18 support --- IF/pom.xml | 6 + .../util/version/Version.java | 11 +- .../util/version/VersionMatcher.java | 30 +- nms/1_18/pom.xml | 73 +++++ .../nms/v1_18/AnvilInventoryImpl.java | 266 ++++++++++++++++++ .../nms/v1_18/BeaconInventoryImpl.java | 199 +++++++++++++ .../v1_18/CartographyTableInventoryImpl.java | 213 ++++++++++++++ .../v1_18/EnchantingTableInventoryImpl.java | 213 ++++++++++++++ .../nms/v1_18/GrindstoneInventoryImpl.java | 247 ++++++++++++++++ .../nms/v1_18/MerchantInventoryImpl.java | 97 +++++++ .../nms/v1_18/SmithingTableInventoryImpl.java | 251 +++++++++++++++++ .../nms/v1_18/StonecutterInventoryImpl.java | 219 ++++++++++++++ .../nms/v1_18/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_18/util/TextHolderUtil.java | 66 +++++ pom.xml | 1 + 15 files changed, 1925 insertions(+), 8 deletions(-) create mode 100644 nms/1_18/pom.xml create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java create mode 100644 nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index 79f7cfdf2..35610cf83 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -82,6 +82,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_18 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index af46bcd50..47f76cb36 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -59,7 +59,14 @@ public enum Version { * * @since 0.10.0 */ - V1_17_1; + V1_17_1, + + /** + * Version 1.18 + * + * @since 0.10.4 + */ + V1_18; /** * Gets the version currently being used. If the used version is not supported, an @@ -96,6 +103,8 @@ public static Version getVersion() { return V1_17_0; case "1.17.1": return V1_17_1; + case "1.18": + return V1_18; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 d69bc261f..026abc2bd 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 @@ -246,6 +246,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -262,6 +264,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -278,6 +282,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -294,6 +300,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -310,22 +318,26 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, - com.github.stefvanschie.inventoryframework.nms.v1_14.MerchantInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_14.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_15, - com.github.stefvanschie.inventoryframework.nms.v1_15.MerchantInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_15.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_16_1, - com.github.stefvanschie.inventoryframework.nms.v1_16_1.MerchantInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_16_1.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_16_2_3, - com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.MerchantInventoryImpl.class); + 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); + com.github.stefvanschie.inventoryframework.nms.v1_17_0.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_17_1, - com.github.stefvanschie.inventoryframework.nms.v1_17_1.MerchantInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_17_1.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -338,6 +350,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -354,5 +368,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_18, + com.github.stefvanschie.inventoryframework.nms.v1_18.StonecutterInventoryImpl.class); } } diff --git a/nms/1_18/pom.xml b/nms/1_18/pom.xml new file mode 100644 index 000000000..1f9e9812e --- /dev/null +++ b/nms/1_18/pom.xml @@ -0,0 +1,73 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.3 + ../../pom.xml + + 4.0.0 + + 1_18 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.18-rc3-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.18-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.18-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.18-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.18-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java new file mode 100644 index 000000000..2f0ef2e03 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java @@ -0,0 +1,266 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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; + +/** + * Internal anvil inventory for 1.17 R1 + * + * @since 0.10.0 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.0 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.0 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.0 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.10.0 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java new file mode 100644 index 000000000..dac276164 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.17 R1 + * + * @since 0.10.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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + TranslatableComponent message = new TranslatableComponent("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, message)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.0 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..dee9baf63 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.17 R1 + * + * @since 0.10.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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.0 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..16c188881 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.17 R1 + * + * @since 0.10.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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.0 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..c9e9d0d8a --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java @@ -0,0 +1,247 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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 grindstone inventory for 1.17 R1 + * + * @since 0.10.0 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.17.1"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.0 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java new file mode 100644 index 000000000..bab3caf77 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_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.17.1 + * + * @since 0.10.1 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.1 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.1 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..bd4db9ea6 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java @@ -0,0 +1,251 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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; + +/** + * Internal smithing table inventory for 1.17 R1 + * + * @since 0.10.0 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.0 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.0 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.0 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java new file mode 100644 index 000000000..a92adbc41 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.17 R1 + * + * @since 0.10.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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.0 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.0 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java new file mode 100644 index 000000000..2be71c1d7 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.0 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java new file mode 100644 index 000000000..ccb694686 --- /dev/null +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java @@ -0,0 +1,66 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18.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.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +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 Component 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 Component toComponent(@NotNull StringHolder holder) { + return new TextComponent(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 Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 5005f9735..307474f6f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_18 nms/1_17_1 nms/1_17_0 nms/1_16_4-5 From 7acd2f3c07a961ff215b5fab87ce215ad9db269b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 16 Dec 2021 20:51:43 +0100 Subject: [PATCH 080/382] Update GitHub Actions --- .github/workflows/maven.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e4c073052..3bfc4082a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -72,6 +72,18 @@ jobs: java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check cd ../ + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: 17 + - name: Run BuildTools 1.18 + 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 + java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check + cd ../ - uses: actions/checkout@v2 name: Checkout code - name: Build with Maven From b22bd67d5bf93c379880b55af0d13f2bdf5638e5 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 16 Dec 2021 21:03:20 +0100 Subject: [PATCH 081/382] Update dependency to 1.18 --- nms/1_18/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_18/pom.xml b/nms/1_18/pom.xml index 1f9e9812e..90ee74eda 100644 --- a/nms/1_18/pom.xml +++ b/nms/1_18/pom.xml @@ -26,7 +26,7 @@ org.spigotmc spigot - 1.18-rc3-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT remapped-mojang provided From 284193102fb196efb6d0c333fb2c3579b62f5ecd Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 16 Dec 2021 21:26:48 +0100 Subject: [PATCH 082/382] Add cache secret so I can invalidate the cache Why is this not possible manually? --- .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 3bfc4082a..8cb4dbaaf 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: paperclip ~/.m2/repository/io/papermc/paper ~/.m2/repository/org/spigotmc - key: ${{ runner.os }}-paperclip + key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-paperclip - name: Download Paperclip Jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | From 4a74bb084740a821044d54eb64ab007dfde544b2 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 18 Dec 2021 20:49:26 +0100 Subject: [PATCH 083/382] Update javadocs for 1.18 NMS --- .../nms/v1_18/AnvilInventoryImpl.java | 18 +++++++++--------- .../nms/v1_18/BeaconInventoryImpl.java | 12 ++++++------ .../v1_18/CartographyTableInventoryImpl.java | 12 ++++++------ .../v1_18/EnchantingTableInventoryImpl.java | 12 ++++++------ .../nms/v1_18/GrindstoneInventoryImpl.java | 16 ++++++++-------- .../nms/v1_18/MerchantInventoryImpl.java | 8 ++++---- .../nms/v1_18/SmithingTableInventoryImpl.java | 16 ++++++++-------- .../nms/v1_18/StonecutterInventoryImpl.java | 14 +++++++------- .../nms/v1_18/util/CustomInventoryUtil.java | 4 ++-- .../nms/v1_18/util/TextHolderUtil.java | 8 ++++---- 10 files changed, 60 insertions(+), 60 deletions(-) diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java index 2f0ef2e03..adedecc45 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java @@ -30,9 +30,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal anvil inventory for 1.17 R1 + * Internal anvil inventory for 1.18 * - * @since 0.10.0 + * @since 0.10.4 */ public class AnvilInventoryImpl extends AnvilInventory { @@ -124,7 +124,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.0 + * @since 0.10.4 */ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -138,7 +138,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.0 + * @since 0.10.4 */ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -153,7 +153,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.0 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -165,7 +165,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -178,7 +178,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -189,7 +189,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container anvil for responding to item renaming * - * @since 0.10.0 + * @since 0.10.4 */ private class ContainerAnvilImpl extends AnvilMenu { @@ -209,7 +209,7 @@ private class ContainerAnvilImpl extends AnvilMenu { * Creates a new custom anvil container for the specified player * * @param serverPlayer the player for who this anvil container is - * @since 0.10.0 + * @since 0.10.4 */ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack[] items) { diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java index dac276164..9d0f2569c 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java @@ -26,9 +26,9 @@ import java.lang.reflect.Field; /** - * Internal beacon inventory for 1.17 R1 + * Internal beacon inventory for 1.18 * - * @since 0.10.0 + * @since 0.10.4 */ public class BeaconInventoryImpl extends BeaconInventory { @@ -80,7 +80,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.0 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -92,7 +92,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -105,7 +105,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -116,7 +116,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container beacon * - * @since 0.10.0 + * @since 0.10.4 */ private class ContainerBeaconImpl extends BeaconMenu { diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java index dee9baf63..1301ad5b2 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java @@ -29,9 +29,9 @@ import java.lang.reflect.Field; /** - * Internal cartography table inventory for 1.17 R1 + * Internal cartography table inventory for 1.18 * - * @since 0.10.0 + * @since 0.10.4 */ public class CartographyTableInventoryImpl extends CartographyTableInventory { @@ -90,7 +90,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.0 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -102,7 +102,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -115,7 +115,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -126,7 +126,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container cartography table * - * @since 0.10.0 + * @since 0.10.4 */ private class ContainerCartographyTableImpl extends CartographyTableMenu { diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java index 16c188881..a63512e0d 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal enchanting table inventory for 1.17 R1 + * Internal enchanting table inventory for 1.18 * - * @since 0.10.0 + * @since 0.10.4 */ public class EnchantingTableInventoryImpl extends EnchantingTableInventory { @@ -92,7 +92,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.0 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -104,7 +104,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -117,7 +117,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -128,7 +128,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.0 + * @since 0.10.4 */ private class ContainerEnchantingTableImpl extends EnchantmentMenu { diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java index c9e9d0d8a..0088ccbd4 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java @@ -29,9 +29,9 @@ import java.lang.reflect.Field; /** - * Internal grindstone inventory for 1.17 R1 + * Internal grindstone inventory for 1.18 * - * @since 0.10.0 + * @since 0.10.4 */ public class GrindstoneInventoryImpl extends GrindstoneInventory { @@ -93,7 +93,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.0 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -105,7 +105,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -118,7 +118,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -129,7 +129,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container grindstone * - * @since 0.10.0 + * @since 0.10.4 */ private class ContainerGrindstoneImpl extends GrindstoneMenu { @@ -216,7 +216,7 @@ public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} * Gets the craft inventory * * @return the craft inventory - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -232,7 +232,7 @@ private Container getCraftInventory() { * Gets the result inventory * * @return the result inventory - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java index bab3caf77..63dc102d1 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java @@ -16,9 +16,9 @@ import java.util.Map; /** - * Internal merchant inventory for 1.17.1 + * Internal merchant inventory for 1.18 * - * @since 0.10.1 + * @since 0.10.4 */ public class MerchantInventoryImpl extends MerchantInventory { @@ -75,7 +75,7 @@ public void sendMerchantOffers(@NotNull Player player, * * @param player the player to get the server player from * @return the server player - * @since 0.10.1 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -88,7 +88,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.1 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java index bd4db9ea6..e46c535c6 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java @@ -29,9 +29,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal smithing table inventory for 1.17 R1 + * Internal smithing table inventory for 1.18 * - * @since 0.10.0 + * @since 0.10.4 */ public class SmithingTableInventoryImpl extends SmithingTableInventory { @@ -124,7 +124,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.0 + * @since 0.10.4 */ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -138,7 +138,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.0 + * @since 0.10.4 */ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -153,7 +153,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.0 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -165,7 +165,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -178,7 +178,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -189,7 +189,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container smithing table * - * @since 0.10.0 + * @since 0.10.4 */ private class ContainerSmithingTableImpl extends SmithingMenu { diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java index a92adbc41..9b45ad9ac 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal stonecutter inventory for 1.17 R1 + * Internal stonecutter inventory for 1.18 * - * @since 0.10.0 + * @since 0.10.4 */ public class StonecutterInventoryImpl extends StonecutterInventory { @@ -93,7 +93,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.0 + * @since 0.10.4 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -105,7 +105,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -118,7 +118,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -129,7 +129,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.0 + * @since 0.10.4 */ private class ContainerStonecutterImpl extends StonecutterMenu { @@ -204,7 +204,7 @@ public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} * Gets the result inventory * * @return the result inventory - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java index 2be71c1d7..12b657c21 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java @@ -10,7 +10,7 @@ /** * A utility class for custom inventories * - * @since 0.10.0 + * @since 0.10.4 */ public final class CustomInventoryUtil { @@ -25,7 +25,7 @@ private CustomInventoryUtil() {} * * @param items the items to convert * @return a list of converted items - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java index ccb694686..4461eefb8 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java +++ b/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since 0.10.0 + * @since 0.10.4 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static Component toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static Component toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.0 + * @since 0.10.4 */ @NotNull @Contract(pure = true) From 35bfa0b2168e414feed6316478991665dd96cb69 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 18 Dec 2021 21:25:30 +0100 Subject: [PATCH 084/382] Add 1.18.1 support --- IF/pom.xml | 8 +- .../util/version/Version.java | 15 +- .../util/version/VersionMatcher.java | 48 ++-- nms/{1_18 => 1_18_0}/pom.xml | 2 +- .../nms/v1_18_0}/AnvilInventoryImpl.java | 8 +- .../nms/v1_18_0}/BeaconInventoryImpl.java | 4 +- .../CartographyTableInventoryImpl.java | 8 +- .../EnchantingTableInventoryImpl.java | 6 +- .../nms/v1_18_0}/GrindstoneInventoryImpl.java | 8 +- .../nms/v1_18_0}/MerchantInventoryImpl.java | 4 +- .../v1_18_0}/SmithingTableInventoryImpl.java | 8 +- .../v1_18_0}/StonecutterInventoryImpl.java | 6 +- .../v1_18_0}/util/CustomInventoryUtil.java | 2 +- .../nms/v1_18_0}/util/TextHolderUtil.java | 2 +- nms/1_18_1/pom.xml | 73 +++++ .../nms/v1_18_1/AnvilInventoryImpl.java | 266 ++++++++++++++++++ .../nms/v1_18_1/BeaconInventoryImpl.java | 199 +++++++++++++ .../CartographyTableInventoryImpl.java | 213 ++++++++++++++ .../v1_18_1/EnchantingTableInventoryImpl.java | 213 ++++++++++++++ .../nms/v1_18_1/GrindstoneInventoryImpl.java | 247 ++++++++++++++++ .../nms/v1_18_1/MerchantInventoryImpl.java | 97 +++++++ .../v1_18_1/SmithingTableInventoryImpl.java | 251 +++++++++++++++++ .../nms/v1_18_1/StonecutterInventoryImpl.java | 219 ++++++++++++++ .../nms/v1_18_1/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_18_1/util/TextHolderUtil.java | 66 +++++ pom.xml | 3 +- 26 files changed, 1967 insertions(+), 50 deletions(-) rename nms/{1_18 => 1_18_0}/pom.xml (98%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/AnvilInventoryImpl.java (97%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/BeaconInventoryImpl.java (98%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/CartographyTableInventoryImpl.java (96%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/EnchantingTableInventoryImpl.java (97%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/GrindstoneInventoryImpl.java (96%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/MerchantInventoryImpl.java (97%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/SmithingTableInventoryImpl.java (97%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/StonecutterInventoryImpl.java (97%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/util/CustomInventoryUtil.java (94%) rename nms/{1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18 => 1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0}/util/TextHolderUtil.java (96%) create mode 100644 nms/1_18_1/pom.xml create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/BeaconInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/CartographyTableInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/EnchantingTableInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/MerchantInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/StonecutterInventoryImpl.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/CustomInventoryUtil.java create mode 100644 nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index 35610cf83..f3a48235f 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -84,7 +84,13 @@ com.github.stefvanschie.inventoryframework - 1_18 + 1_18_0 + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + 1_18_1 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 47f76cb36..d7eac3ddf 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -62,11 +62,18 @@ public enum Version { V1_17_1, /** - * Version 1.18 + * Version 1.18.0 * * @since 0.10.4 */ - V1_18; + V1_18_0, + + /** + * Version 1.18.1 + * + * @since 0.10.4 + */ + V1_18_1; /** * Gets the version currently being used. If the used version is not supported, an @@ -104,7 +111,9 @@ public static Version getVersion() { case "1.17.1": return V1_17_1; case "1.18": - return V1_18; + return V1_18_0; + case "1.18.1": + return V1_18_1; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 026abc2bd..0183c6912 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 @@ -246,8 +246,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -264,8 +266,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -282,8 +286,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -300,8 +306,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -318,8 +326,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -336,8 +346,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.MerchantInventoryImpl.class); - MERCHANT_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -350,8 +362,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -368,7 +382,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_17_0.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_18, - com.github.stefvanschie.inventoryframework.nms.v1_18.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_18_0, + com.github.stefvanschie.inventoryframework.nms.v1_18_0.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_18_1, + com.github.stefvanschie.inventoryframework.nms.v1_18_1.StonecutterInventoryImpl.class); } } diff --git a/nms/1_18/pom.xml b/nms/1_18_0/pom.xml similarity index 98% rename from nms/1_18/pom.xml rename to nms/1_18_0/pom.xml index 90ee74eda..15c360a22 100644 --- a/nms/1_18/pom.xml +++ b/nms/1_18_0/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_18 + 1_18_0 true diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java similarity index 97% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java index adedecc45..edb8cae9a 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/AnvilInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -30,7 +30,7 @@ import org.jetbrains.annotations.Nullable; /** - * Internal anvil inventory for 1.18 + * Internal anvil inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/BeaconInventoryImpl.java similarity index 98% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/BeaconInventoryImpl.java index 9d0f2569c..fd6a1ff4d 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/BeaconInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/BeaconInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import net.minecraft.core.NonNullList; @@ -26,7 +26,7 @@ import java.lang.reflect.Field; /** - * Internal beacon inventory for 1.18 + * Internal beacon inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/CartographyTableInventoryImpl.java similarity index 96% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/CartographyTableInventoryImpl.java index 1301ad5b2..0f4671deb 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/CartographyTableInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/CartographyTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -29,7 +29,7 @@ import java.lang.reflect.Field; /** - * Internal cartography table inventory for 1.18 + * Internal cartography table inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/EnchantingTableInventoryImpl.java similarity index 97% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/EnchantingTableInventoryImpl.java index a63512e0d..61c34b4af 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/EnchantingTableInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/EnchantingTableInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -28,7 +28,7 @@ import java.lang.reflect.Field; /** - * Internal enchanting table inventory for 1.18 + * Internal enchanting table inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java similarity index 96% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java index 0088ccbd4..ea056b769 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/GrindstoneInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -29,7 +29,7 @@ import java.lang.reflect.Field; /** - * Internal grindstone inventory for 1.18 + * Internal grindstone inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/MerchantInventoryImpl.java similarity index 97% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/MerchantInventoryImpl.java index 63dc102d1..fe2026e73 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/MerchantInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/MerchantInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import net.minecraft.server.level.ServerPlayer; @@ -16,7 +16,7 @@ import java.util.Map; /** - * Internal merchant inventory for 1.18 + * Internal merchant inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/SmithingTableInventoryImpl.java similarity index 97% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/SmithingTableInventoryImpl.java index e46c535c6..35e7f24fe 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/SmithingTableInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/SmithingTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable; /** - * Internal smithing table inventory for 1.18 + * Internal smithing table inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/StonecutterInventoryImpl.java similarity index 97% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/StonecutterInventoryImpl.java index 9b45ad9ac..c2f446f73 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/StonecutterInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/StonecutterInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_18.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -28,7 +28,7 @@ import java.lang.reflect.Field; /** - * Internal stonecutter inventory for 1.18 + * Internal stonecutter inventory for 1.18.0 * * @since 0.10.4 */ diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/util/CustomInventoryUtil.java similarity index 94% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/util/CustomInventoryUtil.java index 12b657c21..185262d0b 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/CustomInventoryUtil.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/util/CustomInventoryUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18.util; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; diff --git a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/util/TextHolderUtil.java similarity index 96% rename from nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java rename to nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/util/TextHolderUtil.java index 4461eefb8..6f2e5e3b2 100644 --- a/nms/1_18/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18/util/TextHolderUtil.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_18.util; +package com.github.stefvanschie.inventoryframework.nms.v1_18_0.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml new file mode 100644 index 000000000..b83e29eaf --- /dev/null +++ b/nms/1_18_1/pom.xml @@ -0,0 +1,73 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.3 + ../../pom.xml + + 4.0.0 + + 1_18_1 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.18-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java new file mode 100644 index 000000000..6444cdac9 --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java @@ -0,0 +1,266 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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; + +/** + * Internal anvil inventory for 1.18.1 + * + * @since 0.10.4 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.4 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.4 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.4 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.10.4 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/BeaconInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/BeaconInventoryImpl.java new file mode 100644 index 000000000..52f9cb4ae --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.18.1 + * + * @since 0.10.4 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + TranslatableComponent message = new TranslatableComponent("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, message)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.4 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/CartographyTableInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..48ce90a11 --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.18.1 + * + * @since 0.10.4 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.4 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/EnchantingTableInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..765c9bf28 --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.18.1 + * + * @since 0.10.4 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.4 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..8f6331938 --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java @@ -0,0 +1,247 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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 grindstone inventory for 1.18.1 + * + * @since 0.10.4 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.17.1"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.4 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/MerchantInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/MerchantInventoryImpl.java new file mode 100644 index 000000000..fabf4cfac --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_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.18.1 + * + * @since 0.10.4 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..f34ce72b2 --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java @@ -0,0 +1,251 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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; + +/** + * Internal smithing table inventory for 1.18.1 + * + * @since 0.10.4 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.4 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.4 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.4 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/StonecutterInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/StonecutterInventoryImpl.java new file mode 100644 index 000000000..cba4f6200 --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_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.18.1 + * + * @since 0.10.4 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.4 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/CustomInventoryUtil.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/CustomInventoryUtil.java new file mode 100644 index 000000000..f4edc2601 --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_1.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.4 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/TextHolderUtil.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/TextHolderUtil.java new file mode 100644 index 000000000..3e9e8741b --- /dev/null +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/util/TextHolderUtil.java @@ -0,0 +1,66 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_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.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +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.4 + */ +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.4 + */ + @NotNull + @Contract(pure = true) + public static Component 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.4 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return new TextComponent(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.4 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 307474f6f..da460b7b2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,8 @@ IF nms/abstraction - nms/1_18 + nms/1_18_1 + nms/1_18_0 nms/1_17_1 nms/1_17_0 nms/1_16_4-5 From 108c005abd005671eafdfb8e2acbc7aaff6e8118 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Dec 2021 05:19:36 +0000 Subject: [PATCH 085/382] Bump specialsource-maven-plugin from 1.2.3 to 1.2.4 Bumps [specialsource-maven-plugin](https://github.com/agaricusb/SpecialSourceMP) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/agaricusb/SpecialSourceMP/releases) - [Commits](https://github.com/agaricusb/SpecialSourceMP/commits) --- updated-dependencies: - dependency-name: net.md-5:specialsource-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_17_0/pom.xml | 2 +- nms/1_17_1/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index b0f267c2f..f855d8ce8 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -37,7 +37,7 @@ net.md-5 specialsource-maven-plugin - 1.2.3 + 1.2.4 package diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index f998d62fa..a8fa402f1 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -37,7 +37,7 @@ net.md-5 specialsource-maven-plugin - 1.2.3 + 1.2.4 package From 29cbab19a6221166ad1793e7566ee694b01fe9c7 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 19 Dec 2021 20:52:57 +0100 Subject: [PATCH 086/382] Build 1.18.1 --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8cb4dbaaf..9ae2b3a35 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -83,6 +83,7 @@ jobs: cd build/ wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check + java -jar BuildTools.jar --rev 1.18.1 --remapped --disable-java-check cd ../ - uses: actions/checkout@v2 name: Checkout code From 09db0907c9bfaeaa0c981e23c3de728ca7edc5c3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 19 Dec 2021 21:37:37 +0100 Subject: [PATCH 087/382] V 0.10.4 --- IF/pom.xml | 2 +- README.md | 6 +++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/abstraction/pom.xml | 2 +- pom.xml | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index f3a48235f..7c2cc566b 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 4.0.0 diff --git a/README.md b/README.md index 28a9a25de..eecc0accb 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.3 + 0.10.4 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.10.3' + compile 'com.github.stefvanschie.inventoryframework:IF:0.10.4' // ... } ``` @@ -76,7 +76,7 @@ shadowJar { You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. ```yaml libraries: - - com.github.stefvanschie.inventoryframework:IF:0.10.3 + - com.github.stefvanschie.inventoryframework:IF:0.10.4 ``` ## Building from source diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 8783e70ee..819b5a63c 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 76093d58b..36b05dc36 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index c7fb2ae3a..512bd811e 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index cf423cb74..ea9b298fa 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 729f82cb9..49201b4cc 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 500f411cc..9161e1a0e 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index fd3950ee4..dd4d17571 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index bf7bcea6f..962278d2c 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 15c360a22..599b45357 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index b83e29eaf..2e464f1fe 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 56a7d61ce..57016afdc 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.3 + 0.10.4 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index da460b7b2..1a3e18bb1 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.3 + 0.10.4 pom IF From 30c99f0bfe7f3b91e83ed165096cbad135515b90 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 3 Jan 2022 20:18:08 +0100 Subject: [PATCH 088/382] Update versions in readme --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eecc0accb..a552dc4f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IF Discord guild -*This framework works for Minecraft versions 1.14-1.17* +*This framework works for Minecraft versions 1.14-1.18* An inventory framework for managing GUIs diff --git a/pom.xml b/pom.xml index 1a3e18bb1..522b88706 100644 --- a/pom.xml +++ b/pom.xml @@ -132,7 +132,7 @@ com.thoughtworks.xstream xstream - 1.4.18 + 1.4.17 From 280eaeba7bb380ef330e953e3e975178698893b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jan 2022 05:17:35 +0000 Subject: [PATCH 089/382] Bump specialsource-maven-plugin from 1.2.3 to 1.2.4 Bumps [specialsource-maven-plugin](https://github.com/agaricusb/SpecialSourceMP) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/agaricusb/SpecialSourceMP/releases) - [Commits](https://github.com/agaricusb/SpecialSourceMP/commits) --- updated-dependencies: - dependency-name: net.md-5:specialsource-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_18_0/pom.xml | 2 +- nms/1_18_1/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 599b45357..fe9138c6e 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -37,7 +37,7 @@ net.md-5 specialsource-maven-plugin - 1.2.3 + 1.2.4 package diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 2e464f1fe..eb6d90e00 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -37,7 +37,7 @@ net.md-5 specialsource-maven-plugin - 1.2.3 + 1.2.4 package From 0c9c9d3c4bc3aa1d724e1881b3a3457529b28251 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 29 Jan 2022 16:58:00 +0100 Subject: [PATCH 090/382] Update maven-shade-plugin to 3.2.4 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a552dc4f1..94564ca0b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Now in order to shade the project into your project, add the following to your p org.apache.maven.plugins maven-shade-plugin - 3.2.2 + 3.2.4 ${project.build.directory}/dependency-reduced-pom.xml From d74b55717da648742ccafcb03b84289978a0420e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 05:18:05 +0000 Subject: [PATCH 091/382] Bump maven-javadoc-plugin from 3.3.1 to 3.3.2 in /IF Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.1 to 3.3.2. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.1...maven-javadoc-plugin-3.3.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index fab6a658e..26dbac733 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -231,7 +231,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.1 + 3.3.2 attach-javadocs From 45f10c55e705e87a24d2db39b9006cc7c8246742 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 05:18:20 +0000 Subject: [PATCH 092/382] Bump maven-javadoc-plugin from 3.3.1 to 3.3.2 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.1 to 3.3.2. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.1...maven-javadoc-plugin-3.3.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 715568198..f6ea258e0 100644 --- a/pom.xml +++ b/pom.xml @@ -152,7 +152,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.1 + 3.3.2 attach-javadocs From b58fa2833426c6e962e2dd6596523199decbba69 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Feb 2022 05:16:12 +0000 Subject: [PATCH 093/382] Bump nexus-staging-maven-plugin from 1.6.8 to 1.6.12 in /IF Bumps nexus-staging-maven-plugin from 1.6.8 to 1.6.12. --- updated-dependencies: - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 26dbac733..280eb82d6 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -200,7 +200,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.8 + 1.6.12 true ossrh From e574b8c89c8410c673e3bbfe5c3b8e990406adc0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Feb 2022 05:16:27 +0000 Subject: [PATCH 094/382] Bump nexus-staging-maven-plugin from 1.6.8 to 1.6.12 Bumps nexus-staging-maven-plugin from 1.6.8 to 1.6.12. --- updated-dependencies: - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f6ea258e0..269bd3574 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.8 + 1.6.12 true ossrh From 35f654ce4a0f654c44dcc2dadb408f842ff4e1c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Mar 2022 05:14:15 +0000 Subject: [PATCH 095/382] Bump adventure-api from 4.9.3 to 4.10.0 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.9.3 to 4.10.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.9.3...v4.10.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 269bd3574..cc36e0f30 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 1.8 true UTF-8 - 4.9.3 + 4.10.0 com.github.stefvanschie.inventoryframework From 064bb1f29f1f9eb65bd2b305473ea33e5e9ab1d9 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 8 Jan 2022 20:01:20 +0100 Subject: [PATCH 096/382] Fix duplicate items having the same action When two identical items would have different actions, all items would have the same action. This has now been resolved. --- IF/pom.xml | 2 +- .../inventoryframework/gui/InventoryComponent.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 280eb82d6..cd81b0f85 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -211,7 +211,7 @@ com.thoughtworks.xstream xstream - 1.4.18 + 1.4.17 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 83c846f00..a8e662aae 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 @@ -418,9 +418,10 @@ public void setItem(@NotNull GuiItem guiItem, int x, int y) { "; should be below " + getLength() + " and " + getHeight()); } - guiItem.applyUUID(); + GuiItem copy = guiItem.copy(); + copy.applyUUID(); - this.items[x][y] = guiItem.getItem(); + this.items[x][y] = copy.getItem(); } /** From f96ac26a532abc0abd5f9035e1f0c82ded36acb7 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 11 Jan 2022 20:57:28 +0100 Subject: [PATCH 097/382] Add delete page method to paginated pane Addresses #160 --- .../pane/PaginatedPane.java | 32 +++++++++++++++- .../pane/PaginatedPaneTest.java | 37 +++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index 4e9cc6fe4..7ce5aadfb 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -28,7 +28,7 @@ public class PaginatedPane extends Pane { * A set of panes for the different pages */ @NotNull - private final Map> panes = new HashMap<>(); + private Map> panes = new HashMap<>(); /** * The current page @@ -250,6 +250,36 @@ public PaginatedPane copy() { return paginatedPane; } + /** + * Deletes a page and all its associated panes from this paginated pane. It also decrements the indexes of all pages + * beyond the specified page by one. For example, given a sequence of pages 0, 1, 2, 3, 4, upon removing page 2, the + * new sequence of pages will be 0, 1, 2, 3. If the specified page does not exist, then this method will silently do + * nothing. + * + * @param page the page to delete + * @since 0.10.5 + */ + public void deletePage(int page) { + if (this.panes.remove(page) == null) { + return; + } + + Map> newPanes = new HashMap<>(); + + for (Map.Entry> entry : this.panes.entrySet()) { + int index = entry.getKey(); + List panes = entry.getValue(); + + if (index > page) { + newPanes.put(index - 1, panes); + } else { + newPanes.put(index, panes); + } + } + + this.panes = newPanes; + } + @NotNull @Contract(pure = true) @Override diff --git a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java index 6be43125d..559355f0e 100644 --- a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java +++ b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java @@ -1,9 +1,5 @@ package com.github.stefvanschie.inventoryframework.pane; -import com.github.stefvanschie.inventoryframework.font.util.Font; -import com.github.stefvanschie.inventoryframework.pane.component.Label; -import com.github.stefvanschie.inventoryframework.pane.component.PercentageBar; -import com.github.stefvanschie.inventoryframework.pane.component.ToggleButton; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -37,4 +33,37 @@ void testCopy() { assertEquals(original.getPages(), copy.getPages()); assertEquals(original.getUUID(), copy.getUUID()); } + + @Test + void testDeletePageExists() { + PaginatedPane pane = new PaginatedPane(0, 0, 1, 1); + + StaticPane staticPane = new StaticPane(0, 0, 1, 1); + + pane.addPane(0, new StaticPane(0, 0, 1, 1)); + pane.addPane(1, staticPane); + + pane.deletePage(0); + + assertEquals(1, pane.getPages()); + assertEquals(1, pane.getPanes(0).size()); + assertSame(staticPane, pane.getPanes(0).toArray(new Pane[0])[0]); + } + + @Test + void testDeletePageNotExists() { + PaginatedPane pane = new PaginatedPane(0, 0, 1, 1); + + StaticPane staticPane1 = new StaticPane(0, 0, 1, 1); + StaticPane staticPane2 = new StaticPane(0, 0, 1, 1); + + pane.addPane(0, staticPane1); + pane.addPane(1, staticPane2); + + pane.deletePage(2); + + assertEquals(2, pane.getPages()); + assertSame(staticPane1, pane.getPanes(0).toArray(new Pane[0])[0]); + assertSame(staticPane2, pane.getPanes(1).toArray(new Pane[0])[0]); + } } From ce53128cea330fa937eebb208553d0ee84fa36f6 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 13 Jan 2022 20:38:54 +0100 Subject: [PATCH 098/382] Fix item action not being fired on toggle button click Addresses #174 --- .../inventoryframework/pane/component/ToggleButton.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index b0e426a97..b54e96d56 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -117,10 +117,11 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int newX = paneOffsetX + x; int newY = paneOffsetY + y; + //swap panes, since we will already have toggled the enabled state here if (enabled) { - enabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); - } else { disabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); + } else { + enabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); } gui.update(); From 07865ebce61e3c176f3fe978b1ad79d35c7f9979 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 13 Jan 2022 20:59:51 +0100 Subject: [PATCH 099/382] Fix percentage bar of zero width being displayed Addresses #175 --- .../pane/component/util/VariableBar.java | 9 +- hs_err_pid7296.log | 695 ++++++++++++++++++ 2 files changed, 702 insertions(+), 2 deletions(-) create mode 100644 hs_err_pid7296.log diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java index 1b07921fe..01356cac4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java @@ -241,8 +241,13 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs int newMaxLength = Math.min(maxLength, getLength()); int newMaxHeight = Math.min(maxHeight, getHeight()); - this.backgroundPane.display(inventoryComponent, newPaneOffsetX, newPaneOffsetY, newMaxLength, newMaxHeight); - this.fillPane.display(inventoryComponent, newPaneOffsetX, newPaneOffsetY, newMaxLength, newMaxHeight); + if (this.backgroundPane.isVisible()) { + this.backgroundPane.display(inventoryComponent, newPaneOffsetX, newPaneOffsetY, newMaxLength, newMaxHeight); + } + + if (this.fillPane.isVisible()) { + this.fillPane.display(inventoryComponent, newPaneOffsetX, newPaneOffsetY, newMaxLength, newMaxHeight); + } } /** diff --git a/hs_err_pid7296.log b/hs_err_pid7296.log new file mode 100644 index 000000000..de794618c --- /dev/null +++ b/hs_err_pid7296.log @@ -0,0 +1,695 @@ +# +# There is insufficient memory for the Java Runtime Environment to continue. +# Native memory allocation (mmap) failed to map 23068672 bytes for G1 virtual space +# Possible reasons: +# The system is out of physical RAM or swap space +# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap +# Possible solutions: +# Reduce memory load on the system +# Increase physical memory or swap space +# Check if swap backing store is full +# Decrease Java heap size (-Xmx/-Xms) +# Decrease number of Java threads +# Decrease Java thread stack sizes (-Xss) +# Set larger code cache with -XX:ReservedCodeCacheSize= +# JVM is running with Unscaled Compressed Oops mode in which the Java heap is +# placed in the first 4GB address space. The Java Heap base address is the +# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress +# to set the Java Heap base and to place the Java Heap above 4GB virtual address. +# This output file may be truncated or incomplete. +# +# Out of Memory Error (os_windows.cpp:3469), pid=7296, tid=6840 +# +# JRE version: OpenJDK Runtime Environment Temurin-17.0.1+12 (17.0.1+12) (build 17.0.1+12) +# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (17.0.1+12, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) +# No core dump will be written. Minidumps are not enabled by default on client versions of Windows +# + +--------------- S U M M A R Y ------------ + +Command Line: -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\IF-parent -Dmaven.home=D:\Maven\apache-maven-3.8.4 -Dclassworlds.conf=D:\Maven\apache-maven-3.8.4\bin\m2.conf -Dmaven.ext.class.path=C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\plugins\maven\lib\maven-event-listener.jar -javaagent:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\lib\idea_rt.jar=52046:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin -Dfile.encoding=UTF-8 org.codehaus.classworlds.Launcher -Didea.version=2021.3.1 clean install + +Host: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz, 2 cores, 3G, Windows 7 , 64 bit Build 7601 (6.1.7601.24545) +Time: Thu Jan 13 20:33:50 2022 West-Europa (standaardtijd) elapsed time: 23.224401 seconds (0d 0h 0m 23s) + +--------------- T H R E A D --------------- + +Current thread (0x00000000003cf6e0): VMThread "VM Thread" [stack: 0x000000001ec60000,0x000000001ed60000] [id=6840] + +Stack: [0x000000001ec60000,0x000000001ed60000] +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +V [jvm.dll+0x6744da] +V [jvm.dll+0x82e144] +V [jvm.dll+0x82f8ee] +V [jvm.dll+0x82ff53] +V [jvm.dll+0x245175] +V [jvm.dll+0x6714c9] +V [jvm.dll+0x665f92] +V [jvm.dll+0x303c3b] +V [jvm.dll+0x30b176] +V [jvm.dll+0x35af1e] +V [jvm.dll+0x35b14f] +V [jvm.dll+0x2dab78] +V [jvm.dll+0x2d8e2c] +V [jvm.dll+0x2d83fc] +V [jvm.dll+0x31c571] +V [jvm.dll+0x8343bb] +V [jvm.dll+0x8350f4] +V [jvm.dll+0x83560c] +V [jvm.dll+0x8359e4] +V [jvm.dll+0x835ab0] +V [jvm.dll+0x7de51a] +V [jvm.dll+0x673305] +C [ucrtbase.DLL+0x1c1ae] +C [kernel32.dll+0x1556d] +C [ntdll.dll+0x5372d] + +VM_Operation (0x000000000201d6c0): G1TryInitiateConcMark, mode: safepoint, requested by thread 0x0000000000330310 + + +--------------- P R O C E S S --------------- + +Threads class SMR info: +_java_thread_list=0x000000002211ea80, length=13, elements={ +0x0000000000330310, 0x000000001e008760, 0x000000001e00a320, 0x000000001e0155a0, +0x000000001e017fd0, 0x000000001e018890, 0x000000001e01be50, 0x000000001e02b810, +0x000000001e02c5e0, 0x000000001e02db40, 0x000000001e2b29e0, 0x000000001ff0e910, +0x000000001ff0ede0 +} + +Java Threads: ( => current thread ) + 0x0000000000330310 JavaThread "main" [_thread_blocked, id=7316, stack(0x0000000001f20000,0x0000000002020000)] + 0x000000001e008760 JavaThread "Reference Handler" daemon [_thread_blocked, id=7392, stack(0x000000001ef50000,0x000000001f050000)] + 0x000000001e00a320 JavaThread "Finalizer" daemon [_thread_blocked, id=9184, stack(0x000000001f0d0000,0x000000001f1d0000)] + 0x000000001e0155a0 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=6976, stack(0x000000001f240000,0x000000001f340000)] + 0x000000001e017fd0 JavaThread "Attach Listener" daemon [_thread_blocked, id=8308, stack(0x000000001ed90000,0x000000001ee90000)] + 0x000000001e018890 JavaThread "Service Thread" daemon [_thread_blocked, id=8888, stack(0x000000001f460000,0x000000001f560000)] + 0x000000001e01be50 JavaThread "Monitor Deflation Thread" daemon [_thread_blocked, id=7452, stack(0x000000001f710000,0x000000001f810000)] + 0x000000001e02b810 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=4884, stack(0x000000001f8d0000,0x000000001f9d0000)] + 0x000000001e02c5e0 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=3892, stack(0x000000001fa40000,0x000000001fb40000)] + 0x000000001e02db40 JavaThread "Sweeper thread" daemon [_thread_blocked, id=6812, stack(0x000000001fbf0000,0x000000001fcf0000)] + 0x000000001e2b29e0 JavaThread "Common-Cleaner" daemon [_thread_blocked, id=1620, stack(0x000000001fdc0000,0x000000001fec0000)] + 0x000000001ff0e910 JavaThread "Monitor Ctrl-Break" daemon [_thread_in_native, id=7928, stack(0x0000000020370000,0x0000000020470000)] + 0x000000001ff0ede0 JavaThread "Notification Thread" daemon [_thread_blocked, id=5888, stack(0x000000001f590000,0x000000001f690000)] + +Other Threads: +=>0x00000000003cf6e0 VMThread "VM Thread" [stack: 0x000000001ec60000,0x000000001ed60000] [id=6840] + 0x000000001ff0f2b0 WatcherThread [stack: 0x000000001f350000,0x000000001f450000] [id=6304] + 0x0000000000363b00 GCTaskThread "GC Thread#0" [stack: 0x000000001b840000,0x000000001b940000] [id=6244] + 0x000000002017f2f0 GCTaskThread "GC Thread#1" [stack: 0x00000000206d0000,0x00000000207d0000] [id=9012] + 0x00000000003701d0 ConcurrentGCThread "G1 Main Marker" [stack: 0x000000001b980000,0x000000001ba80000] [id=1036] + 0x0000000000370af0 ConcurrentGCThread "G1 Conc#0" [stack: 0x000000001bb20000,0x000000001bc20000] [id=8296] + 0x00000000003b0cd0 ConcurrentGCThread "G1 Refine#0" [stack: 0x000000001de60000,0x000000001df60000] [id=4868] + 0x00000000003b1600 ConcurrentGCThread "G1 Service" [stack: 0x000000001e070000,0x000000001e170000] [id=6240] + +Threads with active compile tasks: + +VM state: at safepoint (normal execution) + +VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) +[0x000000000032ade0] Threads_lock - owner thread: 0x00000000003cf6e0 +[0x000000000032b410] Heap_lock - owner thread: 0x0000000000330310 + +Heap address: 0x00000000c1a00000, size: 998 MB, Compressed Oops mode: 32-bit + +CDS archive(s) mapped at: [0x0000000800000000-0x0000000800bc0000-0x0000000800bc0000), size 12320768, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 0. +Compressed class space mapped at: 0x0000000800c00000-0x0000000840c00000, reserved size: 1073741824 +Narrow klass base: 0x0000000800000000, Narrow klass shift: 0, Narrow klass range: 0x100000000 + +GC Precious Log: + CPUs: 2 total, 2 available + Memory: 3991M + Large Page Support: Disabled + NUMA Support: Disabled + Compressed Oops: Enabled (32-bit) + Heap Region Size: 1M + Heap Min Capacity: 8M + Heap Initial Capacity: 64M + Heap Max Capacity: 998M + Pre-touch: Disabled + Parallel Workers: 2 + Concurrent Workers: 1 + Concurrent Refinement Workers: 2 + Periodic GC: Disabled + +Heap: + garbage-first heap total 78848K, used 39429K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 2 young (2048K), 2 survivors (2048K) + Metaspace used 32402K, committed 32832K, reserved 1081344K + class space used 3764K, committed 3968K, reserved 1048576K + +Heap Regions: E=young(eden), S=young(survivor), O=old, HS=humongous(starts), HC=humongous(continues), CS=collection set, F=free, OA=open archive, CA=closed archive, TAMS=top-at-mark-start (previous, next) +| 0|0x00000000c1a00000, 0x00000000c1b00000, 0x00000000c1b00000|100%| O| |TAMS 0x00000000c1b00000, 0x00000000c1b00000| Untracked +| 1|0x00000000c1b00000, 0x00000000c1c00000, 0x00000000c1c00000|100%| O| |TAMS 0x00000000c1c00000, 0x00000000c1c00000| Untracked +| 2|0x00000000c1c00000, 0x00000000c1d00000, 0x00000000c1d00000|100%| O| |TAMS 0x00000000c1d00000, 0x00000000c1d00000| Untracked +| 3|0x00000000c1d00000, 0x00000000c1e00000, 0x00000000c1e00000|100%| O| |TAMS 0x00000000c1e00000, 0x00000000c1e00000| Untracked +| 4|0x00000000c1e00000, 0x00000000c1f00000, 0x00000000c1f00000|100%| O| |TAMS 0x00000000c1f00000, 0x00000000c1f00000| Untracked +| 5|0x00000000c1f00000, 0x00000000c2000000, 0x00000000c2000000|100%| O| |TAMS 0x00000000c2000000, 0x00000000c2000000| Untracked +| 6|0x00000000c2000000, 0x00000000c2100000, 0x00000000c2100000|100%| O| |TAMS 0x00000000c2100000, 0x00000000c2100000| Untracked +| 7|0x00000000c2100000, 0x00000000c2200000, 0x00000000c2200000|100%| O| |TAMS 0x00000000c2200000, 0x00000000c2200000| Untracked +| 8|0x00000000c2200000, 0x00000000c2300000, 0x00000000c2300000|100%| O| |TAMS 0x00000000c2300000, 0x00000000c2300000| Untracked +| 9|0x00000000c2300000, 0x00000000c2400000, 0x00000000c2400000|100%| O| |TAMS 0x00000000c2400000, 0x00000000c2400000| Untracked +| 10|0x00000000c2400000, 0x00000000c2500000, 0x00000000c2500000|100%| O| |TAMS 0x00000000c2500000, 0x00000000c2500000| Untracked +| 11|0x00000000c2500000, 0x00000000c2600000, 0x00000000c2600000|100%| O| |TAMS 0x00000000c2600000, 0x00000000c2600000| Untracked +| 12|0x00000000c2600000, 0x00000000c2700000, 0x00000000c2700000|100%| O| |TAMS 0x00000000c2700000, 0x00000000c2700000| Untracked +| 13|0x00000000c2700000, 0x00000000c2800000, 0x00000000c2800000|100%| O| |TAMS 0x00000000c2800000, 0x00000000c2800000| Untracked +| 14|0x00000000c2800000, 0x00000000c2900000, 0x00000000c2900000|100%| O| |TAMS 0x00000000c2900000, 0x00000000c2900000| Untracked +| 15|0x00000000c2900000, 0x00000000c2a00000, 0x00000000c2a00000|100%| O| |TAMS 0x00000000c2a00000, 0x00000000c2a00000| Untracked +| 16|0x00000000c2a00000, 0x00000000c2b00000, 0x00000000c2b00000|100%| O| |TAMS 0x00000000c2b00000, 0x00000000c2b00000| Untracked +| 17|0x00000000c2b00000, 0x00000000c2bef600, 0x00000000c2c00000| 93%| O| |TAMS 0x00000000c2bef600, 0x00000000c2bef600| Untracked +| 18|0x00000000c2c00000, 0x00000000c2d00000, 0x00000000c2d00000|100%| O| |TAMS 0x00000000c2c00000, 0x00000000c2d00000| Untracked +| 19|0x00000000c2d00000, 0x00000000c2e00000, 0x00000000c2e00000|100%| O| |TAMS 0x00000000c2d00000, 0x00000000c2e00000| Untracked +| 20|0x00000000c2e00000, 0x00000000c2f00000, 0x00000000c2f00000|100%| O| |TAMS 0x00000000c2e00000, 0x00000000c2f00000| Untracked +| 21|0x00000000c2f00000, 0x00000000c3000000, 0x00000000c3000000|100%|HS| |TAMS 0x00000000c2f00000, 0x00000000c3000000| Complete +| 22|0x00000000c3000000, 0x00000000c3100000, 0x00000000c3100000|100%|HC| |TAMS 0x00000000c3000000, 0x00000000c3100000| Complete +| 23|0x00000000c3100000, 0x00000000c3200000, 0x00000000c3200000|100%|HC| |TAMS 0x00000000c3100000, 0x00000000c3200000| Complete +| 24|0x00000000c3200000, 0x00000000c3300000, 0x00000000c3300000|100%|HC| |TAMS 0x00000000c3200000, 0x00000000c3300000| Complete +| 25|0x00000000c3300000, 0x00000000c3400000, 0x00000000c3400000|100%|HC| |TAMS 0x00000000c3300000, 0x00000000c3400000| Complete +| 26|0x00000000c3400000, 0x00000000c3500000, 0x00000000c3500000|100%| O| |TAMS 0x00000000c3400000, 0x00000000c3500000| Untracked +| 27|0x00000000c3500000, 0x00000000c3600000, 0x00000000c3600000|100%| O| |TAMS 0x00000000c3500000, 0x00000000c3600000| Untracked +| 28|0x00000000c3600000, 0x00000000c3700000, 0x00000000c3700000|100%|HS| |TAMS 0x00000000c3600000, 0x00000000c3700000| Complete +| 29|0x00000000c3700000, 0x00000000c3800000, 0x00000000c3800000|100%|HC| |TAMS 0x00000000c3700000, 0x00000000c3800000| Complete +| 30|0x00000000c3800000, 0x00000000c3900000, 0x00000000c3900000|100%|HC| |TAMS 0x00000000c3800000, 0x00000000c3900000| Complete +| 31|0x00000000c3900000, 0x00000000c3a00000, 0x00000000c3a00000|100%|HC| |TAMS 0x00000000c3900000, 0x00000000c3a00000| Complete +| 32|0x00000000c3a00000, 0x00000000c3b00000, 0x00000000c3b00000|100%|HC| |TAMS 0x00000000c3a00000, 0x00000000c3b00000| Complete +| 33|0x00000000c3b00000, 0x00000000c3b00000, 0x00000000c3c00000| 0%| F| |TAMS 0x00000000c3b00000, 0x00000000c3b00000| Untracked +| 34|0x00000000c3c00000, 0x00000000c3d00000, 0x00000000c3d00000|100%| O| |TAMS 0x00000000c3c00000, 0x00000000c3d00000| Untracked +| 35|0x00000000c3d00000, 0x00000000c3e00000, 0x00000000c3e00000|100%| O| |TAMS 0x00000000c3d00000, 0x00000000c3e00000| Untracked +| 36|0x00000000c3e00000, 0x00000000c3f00000, 0x00000000c3f00000|100%| O| |TAMS 0x00000000c3e00000, 0x00000000c3f00000| Untracked +| 37|0x00000000c3f00000, 0x00000000c3ffd600, 0x00000000c4000000| 98%| O| |TAMS 0x00000000c3f00000, 0x00000000c3ffd600| Untracked +| 38|0x00000000c4000000, 0x00000000c4000000, 0x00000000c4100000| 0%| F| |TAMS 0x00000000c4000000, 0x00000000c4000000| Untracked +| 39|0x00000000c4100000, 0x00000000c4100000, 0x00000000c4200000| 0%| F| |TAMS 0x00000000c4100000, 0x00000000c4100000| Untracked +| 40|0x00000000c4200000, 0x00000000c4200000, 0x00000000c4300000| 0%| F| |TAMS 0x00000000c4200000, 0x00000000c4200000| Untracked +| 41|0x00000000c4300000, 0x00000000c4300000, 0x00000000c4400000| 0%| F| |TAMS 0x00000000c4300000, 0x00000000c4300000| Untracked +| 42|0x00000000c4400000, 0x00000000c4400000, 0x00000000c4500000| 0%| F| |TAMS 0x00000000c4400000, 0x00000000c4400000| Untracked +| 43|0x00000000c4500000, 0x00000000c4500000, 0x00000000c4600000| 0%| F| |TAMS 0x00000000c4500000, 0x00000000c4500000| Untracked +| 44|0x00000000c4600000, 0x00000000c4600000, 0x00000000c4700000| 0%| F| |TAMS 0x00000000c4600000, 0x00000000c4600000| Untracked +| 45|0x00000000c4700000, 0x00000000c4700000, 0x00000000c4800000| 0%| F| |TAMS 0x00000000c4700000, 0x00000000c4700000| Untracked +| 46|0x00000000c4800000, 0x00000000c4800000, 0x00000000c4900000| 0%| F| |TAMS 0x00000000c4800000, 0x00000000c4800000| Untracked +| 47|0x00000000c4900000, 0x00000000c4900000, 0x00000000c4a00000| 0%| F| |TAMS 0x00000000c4900000, 0x00000000c4900000| Untracked +| 48|0x00000000c4a00000, 0x00000000c4a00000, 0x00000000c4b00000| 0%| F| |TAMS 0x00000000c4a00000, 0x00000000c4a00000| Untracked +| 49|0x00000000c4b00000, 0x00000000c4b00000, 0x00000000c4c00000| 0%| F| |TAMS 0x00000000c4b00000, 0x00000000c4b00000| Untracked +| 50|0x00000000c4c00000, 0x00000000c4c00000, 0x00000000c4d00000| 0%| F| |TAMS 0x00000000c4c00000, 0x00000000c4c00000| Untracked +| 51|0x00000000c4d00000, 0x00000000c4d00000, 0x00000000c4e00000| 0%| F| |TAMS 0x00000000c4d00000, 0x00000000c4d00000| Untracked +| 52|0x00000000c4e00000, 0x00000000c4e00000, 0x00000000c4f00000| 0%| F| |TAMS 0x00000000c4e00000, 0x00000000c4e00000| Untracked +| 53|0x00000000c4f00000, 0x00000000c4f00000, 0x00000000c5000000| 0%| F| |TAMS 0x00000000c4f00000, 0x00000000c4f00000| Untracked +| 54|0x00000000c5000000, 0x00000000c5000000, 0x00000000c5100000| 0%| F| |TAMS 0x00000000c5000000, 0x00000000c5000000| Untracked +| 55|0x00000000c5100000, 0x00000000c5100000, 0x00000000c5200000| 0%| F| |TAMS 0x00000000c5100000, 0x00000000c5100000| Untracked +| 56|0x00000000c5200000, 0x00000000c5200000, 0x00000000c5300000| 0%| F| |TAMS 0x00000000c5200000, 0x00000000c5200000| Untracked +| 57|0x00000000c5300000, 0x00000000c5300000, 0x00000000c5400000| 0%| F| |TAMS 0x00000000c5300000, 0x00000000c5300000| Untracked +| 58|0x00000000c5400000, 0x00000000c5400000, 0x00000000c5500000| 0%| F| |TAMS 0x00000000c5400000, 0x00000000c5400000| Untracked +| 59|0x00000000c5500000, 0x00000000c5500000, 0x00000000c5600000| 0%| F| |TAMS 0x00000000c5500000, 0x00000000c5500000| Untracked +| 60|0x00000000c5600000, 0x00000000c5600000, 0x00000000c5700000| 0%| F| |TAMS 0x00000000c5600000, 0x00000000c5600000| Untracked +| 61|0x00000000c5700000, 0x00000000c5700000, 0x00000000c5800000| 0%| F| |TAMS 0x00000000c5700000, 0x00000000c5700000| Untracked +| 62|0x00000000c5800000, 0x00000000c5800000, 0x00000000c5900000| 0%| F| |TAMS 0x00000000c5800000, 0x00000000c5800000| Untracked +| 63|0x00000000c5900000, 0x00000000c5900000, 0x00000000c5a00000| 0%| F| |TAMS 0x00000000c5900000, 0x00000000c5900000| Untracked +| 64|0x00000000c5a00000, 0x00000000c5a00000, 0x00000000c5b00000| 0%| F| |TAMS 0x00000000c5a00000, 0x00000000c5a00000| Untracked +| 65|0x00000000c5b00000, 0x00000000c5b00000, 0x00000000c5c00000| 0%| F| |TAMS 0x00000000c5b00000, 0x00000000c5b00000| Untracked +| 66|0x00000000c5c00000, 0x00000000c5c00000, 0x00000000c5d00000| 0%| F| |TAMS 0x00000000c5c00000, 0x00000000c5c00000| Untracked +| 67|0x00000000c5d00000, 0x00000000c5d00000, 0x00000000c5e00000| 0%| F| |TAMS 0x00000000c5d00000, 0x00000000c5d00000| Untracked +| 68|0x00000000c5e00000, 0x00000000c5e00000, 0x00000000c5f00000| 0%| F| |TAMS 0x00000000c5e00000, 0x00000000c5e00000| Untracked +| 69|0x00000000c5f00000, 0x00000000c5f00000, 0x00000000c6000000| 0%| F| |TAMS 0x00000000c5f00000, 0x00000000c5f00000| Untracked +| 70|0x00000000c6000000, 0x00000000c6000000, 0x00000000c6100000| 0%| F| |TAMS 0x00000000c6000000, 0x00000000c6000000| Untracked +| 71|0x00000000c6100000, 0x00000000c6100000, 0x00000000c6200000| 0%| F| |TAMS 0x00000000c6100000, 0x00000000c6100000| Untracked +| 72|0x00000000c6200000, 0x00000000c6200000, 0x00000000c6300000| 0%| F| |TAMS 0x00000000c6200000, 0x00000000c6200000| Untracked +| 73|0x00000000c6300000, 0x00000000c6300000, 0x00000000c6400000| 0%| F| |TAMS 0x00000000c6300000, 0x00000000c6300000| Untracked +| 74|0x00000000c6400000, 0x00000000c64948f0, 0x00000000c6500000| 58%| S|CS|TAMS 0x00000000c6400000, 0x00000000c6400000| Complete +| 75|0x00000000c6500000, 0x00000000c6600000, 0x00000000c6600000|100%| S|CS|TAMS 0x00000000c6500000, 0x00000000c6500000| Complete +| 76|0x00000000c6600000, 0x00000000c6600000, 0x00000000c6700000| 0%| F| |TAMS 0x00000000c6600000, 0x00000000c6600000| Untracked + +Card table byte_map: [0x0000000019420000,0x0000000019620000] _byte_map_base: 0x0000000018e13000 + +Marking Bits (Prev, Next): (CMBitMap*) 0x0000000000366020, (CMBitMap*) 0x0000000000366060 + Prev Bits: [0x0000000019820000, 0x000000001a7b8000) + Next Bits: [0x000000001a7c0000, 0x000000001b758000) + +Polling page: 0x00000000000a0000 + +Metaspace: + +Usage: + Non-class: 27.97 MB used. + Class: 3.68 MB used. + Both: 31.64 MB used. + +Virtual space: + Non-class space: 32.00 MB reserved, 28.19 MB ( 88%) committed, 4 nodes. + Class space: 1.00 GB reserved, 3.88 MB ( <1%) committed, 1 nodes. + Both: 1.03 GB reserved, 32.06 MB ( 3%) committed. + +Chunk freelists: + Non-Class: 2.98 MB + Class: 32.00 KB + Both: 3.02 MB + +MaxMetaspaceSize: unlimited +CompressedClassSpaceSize: 1.00 GB +Initial GC threshold: 21.00 MB +Current GC threshold: 49.63 MB +CDS: on +MetaspaceReclaimPolicy: balanced + - commit_granule_bytes: 65536. + - commit_granule_words: 8192. + - virtual_space_node_default_size: 1048576. + - enlarge_chunks_in_place: 1. + - new_chunks_are_fully_committed: 0. + - uncommit_free_chunks: 1. + - use_allocation_guard: 0. + - handle_deallocations: 1. + + +Internal statistics: + +num_allocs_failed_limit: 6. +num_arena_births: 204. +num_arena_deaths: 0. +num_vsnodes_births: 5. +num_vsnodes_deaths: 0. +num_space_committed: 513. +num_space_uncommitted: 0. +num_chunks_returned_to_freelist: 6. +num_chunks_taken_from_freelist: 1389. +num_chunk_merges: 6. +num_chunk_splits: 1009. +num_chunks_enlarged: 803. +num_purges: 0. +num_inconsistent_stats: 0. + +CodeHeap 'non-profiled nmethods': size=120064Kb used=2809Kb max_used=3011Kb free=117254Kb + bounds [0x00000000119d0000, 0x0000000011cd0000, 0x0000000018f10000] +CodeHeap 'profiled nmethods': size=120000Kb used=12119Kb max_used=12447Kb free=107880Kb + bounds [0x000000000a4a0000, 0x000000000b0d0000, 0x00000000119d0000] +CodeHeap 'non-nmethods': size=5696Kb used=1220Kb max_used=1262Kb free=4475Kb + bounds [0x0000000009f10000, 0x000000000a180000, 0x000000000a4a0000] + total_blobs=6237 nmethods=5706 adapters=442 + compilation: enabled + stopped_count=0, restarted_count=0 + full_count=0 + +Compilation events (20 events): +Event: 22.690 Thread 0x000000001e02c5e0 nmethod 6540 0x000000000abdb590 code [0x000000000abdb800, 0x000000000abdc5a8] +Event: 22.985 Thread 0x000000001e02b810 nmethod 6362 0x0000000011cc0e90 code [0x0000000011cc1360, 0x0000000011cc87e0] +Event: 22.985 Thread 0x000000001e02b810 6413 4 java.util.regex.Pattern$Start::match (90 bytes) +Event: 22.992 Thread 0x000000001e02b810 nmethod 6413 0x0000000011bded90 code [0x0000000011bdef60, 0x0000000011bdf588] +Event: 22.992 Thread 0x000000001e02b810 6357 4 org.eclipse.sisu.bean.DeclaredMembers$MemberIterator::hasNext (96 bytes) +Event: 23.058 Thread 0x000000001e02b810 nmethod 6357 0x0000000011b3c710 code [0x0000000011b3c9e0, 0x0000000011b3ed70] +Event: 23.102 Thread 0x000000001e02b810 6541 4 java.util.StringTokenizer::skipDelimiters (116 bytes) +Event: 23.102 Thread 0x000000001e02c5e0 6542 3 java.lang.String::substring (58 bytes) +Event: 23.103 Thread 0x000000001e02c5e0 nmethod 6542 0x000000000abdad10 code [0x000000000abdaf00, 0x000000000abdb3a8] +Event: 23.103 Thread 0x000000001e02c5e0 6544 3 org.codehaus.plexus.util.SelectorUtils::match (520 bytes) +Event: 23.104 Thread 0x000000001e02c5e0 nmethod 6544 0x000000000abcf910 code [0x000000000abcfc20, 0x000000000abd10b8] +Event: 23.105 Thread 0x000000001e02c5e0 6545 3 org.codehaus.plexus.util.SelectorUtils::equals (37 bytes) +Event: 23.105 Thread 0x000000001e02c5e0 nmethod 6545 0x000000000abda790 code [0x000000000abda960, 0x000000000abdac18] +Event: 23.108 Thread 0x000000001e02b810 nmethod 6541 0x0000000011bde590 code [0x0000000011bde720, 0x0000000011bdea68] +Event: 23.108 Thread 0x000000001e02b810 6543 4 java.lang.String::toCharArray (25 bytes) +Event: 23.109 Thread 0x000000001e02b810 nmethod 6543 0x0000000011a7cf10 code [0x0000000011a7d0a0, 0x0000000011a7d228] +Event: 23.134 Thread 0x000000001e02b810 6546 4 org.codehaus.plexus.classworlds.realm.ClassRealm::findClass (9 bytes) +Event: 23.135 Thread 0x000000001e02b810 nmethod 6546 0x0000000011b3c210 code [0x0000000011b3c3a0, 0x0000000011b3c488] +Event: 23.141 Thread 0x000000001e02b810 6547 4 java.lang.ReflectiveOperationException:: (7 bytes) +Event: 23.146 Thread 0x000000001e02b810 nmethod 6547 0x0000000011b3a890 code [0x0000000011b3aa20, 0x0000000011b3b148] + +GC Heap History (20 events): +Event: 5.477 GC heap after +{Heap after GC invocations=4 (full 0): + garbage-first heap total 65536K, used 5815K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 4 young (4096K), 4 survivors (4096K) + Metaspace used 10438K, committed 10560K, reserved 1064960K + class space used 1266K, committed 1344K, reserved 1048576K +} +Event: 8.029 GC heap before +{Heap before GC invocations=4 (full 0): + garbage-first heap total 65536K, used 40631K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 38 young (38912K), 4 survivors (4096K) + Metaspace used 12980K, committed 13184K, reserved 1064960K + class space used 1483K, committed 1600K, reserved 1048576K +} +Event: 8.074 GC heap after +{Heap after GC invocations=5 (full 0): + garbage-first heap total 65536K, used 8479K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 5 young (5120K), 5 survivors (5120K) + Metaspace used 12980K, committed 13184K, reserved 1064960K + class space used 1483K, committed 1600K, reserved 1048576K +} +Event: 9.632 GC heap before +{Heap before GC invocations=5 (full 0): + garbage-first heap total 65536K, used 42271K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 38 young (38912K), 5 survivors (5120K) + Metaspace used 14458K, committed 14656K, reserved 1064960K + class space used 1630K, committed 1728K, reserved 1048576K +} +Event: 9.709 GC heap after +{Heap after GC invocations=6 (full 0): + garbage-first heap total 78848K, used 11039K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 3 young (3072K), 3 survivors (3072K) + Metaspace used 14458K, committed 14656K, reserved 1064960K + class space used 1630K, committed 1728K, reserved 1048576K +} +Event: 11.260 GC heap before +{Heap before GC invocations=6 (full 0): + garbage-first heap total 78848K, used 55071K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 46 young (47104K), 3 survivors (3072K) + Metaspace used 15669K, committed 15872K, reserved 1064960K + class space used 1757K, committed 1856K, reserved 1048576K +} +Event: 11.302 GC heap after +{Heap after GC invocations=7 (full 0): + garbage-first heap total 78848K, used 14858K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 6 young (6144K), 6 survivors (6144K) + Metaspace used 15669K, committed 15872K, reserved 1064960K + class space used 1757K, committed 1856K, reserved 1048576K +} +Event: 12.807 GC heap before +{Heap before GC invocations=7 (full 0): + garbage-first heap total 78848K, used 55818K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 46 young (47104K), 6 survivors (6144K) + Metaspace used 16824K, committed 17088K, reserved 1064960K + class space used 1911K, committed 2048K, reserved 1048576K +} +Event: 12.875 GC heap after +{Heap after GC invocations=8 (full 0): + garbage-first heap total 78848K, used 17332K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 3 young (3072K), 3 survivors (3072K) + Metaspace used 16824K, committed 17088K, reserved 1064960K + class space used 1911K, committed 2048K, reserved 1048576K +} +Event: 14.388 GC heap before +{Heap before GC invocations=8 (full 0): + garbage-first heap total 78848K, used 59316K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 44 young (45056K), 3 survivors (3072K) + Metaspace used 17217K, committed 17472K, reserved 1064960K + class space used 1940K, committed 2048K, reserved 1048576K +} +Event: 14.397 GC heap after +{Heap after GC invocations=9 (full 0): + garbage-first heap total 78848K, used 18681K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 4 young (4096K), 4 survivors (4096K) + Metaspace used 17217K, committed 17472K, reserved 1064960K + class space used 1940K, committed 2048K, reserved 1048576K +} +Event: 15.637 GC heap before +{Heap before GC invocations=9 (full 0): + garbage-first heap total 78848K, used 60665K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 45 young (46080K), 4 survivors (4096K) + Metaspace used 19580K, committed 19904K, reserved 1073152K + class space used 2274K, committed 2432K, reserved 1048576K +} +Event: 15.650 GC heap after +{Heap after GC invocations=10 (full 0): + garbage-first heap total 78848K, used 21046K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 5 young (5120K), 5 survivors (5120K) + Metaspace used 19580K, committed 19904K, reserved 1073152K + class space used 2274K, committed 2432K, reserved 1048576K +} +Event: 18.749 GC heap before +{Heap before GC invocations=10 (full 0): + garbage-first heap total 78848K, used 56886K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 41 young (41984K), 5 survivors (5120K) + Metaspace used 21245K, committed 21504K, reserved 1073152K + class space used 2475K, committed 2624K, reserved 1048576K +} +Event: 18.774 GC heap after +{Heap after GC invocations=11 (full 0): + garbage-first heap total 78848K, used 22461K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 4 young (4096K), 4 survivors (4096K) + Metaspace used 21245K, committed 21504K, reserved 1073152K + class space used 2475K, committed 2624K, reserved 1048576K +} +Event: 20.888 GC heap before +{Heap before GC invocations=12 (full 0): + garbage-first heap total 78848K, used 62397K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 43 young (44032K), 4 survivors (4096K) + Metaspace used 30147K, committed 30464K, reserved 1081344K + class space used 3504K, committed 3648K, reserved 1048576K +} +Event: 20.919 GC heap after +{Heap after GC invocations=13 (full 0): + garbage-first heap total 78848K, used 27581K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 6 young (6144K), 6 survivors (6144K) + Metaspace used 30147K, committed 30464K, reserved 1081344K + class space used 3504K, committed 3648K, reserved 1048576K +} +Event: 23.155 GC heap before +{Heap before GC invocations=14 (full 0): + garbage-first heap total 78848K, used 64445K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 38 young (38912K), 6 survivors (6144K) + Metaspace used 32402K, committed 32832K, reserved 1081344K + class space used 3764K, committed 3968K, reserved 1048576K +} +Event: 23.188 GC heap after +{Heap after GC invocations=15 (full 0): + garbage-first heap total 78848K, used 34803K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 3 young (3072K), 3 survivors (3072K) + Metaspace used 32402K, committed 32832K, reserved 1081344K + class space used 3764K, committed 3968K, reserved 1048576K +} +Event: 23.194 GC heap before +{Heap before GC invocations=15 (full 0): + garbage-first heap total 78848K, used 39923K [0x00000000c1a00000, 0x0000000100000000) + region size 1024K, 4 young (4096K), 3 survivors (3072K) + Metaspace used 32402K, committed 32832K, reserved 1081344K + class space used 3764K, committed 3968K, reserved 1048576K +} + +Deoptimization events (20 events): +Event: 22.652 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 +Event: 22.652 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 +Event: 22.652 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 +Event: 22.652 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 +Event: 22.652 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 +Event: 22.652 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 +Event: 22.653 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 +Event: 22.653 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 +Event: 22.653 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 +Event: 22.653 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 +Event: 22.653 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 +Event: 22.653 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 +Event: 22.653 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 +Event: 22.653 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 +Event: 22.655 Thread 0x0000000000330310 DEOPT PACKING pc=0x000000000aee0488 sp=0x000000000201ddb0 +Event: 22.655 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f62b24 sp=0x000000000201d250 mode 0 +Event: 23.097 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011c49d84 relative=0x0000000000006844 +Event: 23.097 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011c49d84 method=org.apache.maven.model.BuildBase.clone()Lorg/apache/maven/model/BuildBase; @ 30 c2 +Event: 23.097 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011c49d84 sp=0x000000000201df00 +Event: 23.097 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de40 mode 2 + +Classes unloaded (0 events): +No events + +Classes redefined (0 events): +No events + +Internal exceptions (20 events): +Event: 20.625 Thread 0x0000000000330310 Exception (0x00000000c45a8618) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.626 Thread 0x0000000000330310 Exception (0x00000000c45a88b8) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.626 Thread 0x0000000000330310 Exception (0x00000000c45a9530) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.636 Thread 0x0000000000330310 Exception (0x00000000c45b4b10) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.652 Thread 0x0000000000330310 Exception (0x00000000c45caf28) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45cb248) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45ce348) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45ce5a8) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.654 Thread 0x0000000000330310 Exception (0x00000000c45d2e38) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.655 Thread 0x0000000000330310 Exception (0x00000000c45d3150) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.667 Thread 0x0000000000330310 Exception (0x00000000c45f7150) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] +Event: 20.670 Thread 0x0000000000330310 Exception (0x00000000c4402b40) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] +Event: 20.671 Thread 0x0000000000330310 Exception (0x00000000c4407470) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] +Event: 20.719 Thread 0x0000000000330310 Exception (0x00000000c4472ab8) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.744 Thread 0x0000000000330310 Exception (0x00000000c449aaa8) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 20.792 Thread 0x0000000000330310 Exception (0x00000000c43061b8) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] +Event: 21.266 Thread 0x0000000000330310 Exception (0x00000000c5622c28) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 862] +Event: 21.659 Thread 0x0000000020139240 Exception (0x00000000c534a4a8) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] +Event: 21.659 Thread 0x0000000020139240 Exception (0x00000000c5350be8) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] +Event: 21.660 Thread 0x0000000020139240 Exception (0x00000000c5354758) +thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] + +VM Operations (20 events): +Event: 20.640 Executing VM operation: ICBufferFull done +Event: 20.717 Executing VM operation: HandshakeAllThreads +Event: 20.717 Executing VM operation: HandshakeAllThreads done +Event: 20.813 Executing VM operation: ICBufferFull +Event: 20.826 Executing VM operation: ICBufferFull done +Event: 20.888 Executing VM operation: G1CollectForAllocation +Event: 20.919 Executing VM operation: G1CollectForAllocation done +Event: 21.015 Executing VM operation: G1Concurrent +Event: 21.031 Executing VM operation: G1Concurrent done +Event: 21.069 Executing VM operation: G1Concurrent +Event: 21.069 Executing VM operation: G1Concurrent done +Event: 21.247 Executing VM operation: HandshakeAllThreads +Event: 21.247 Executing VM operation: HandshakeAllThreads done +Event: 22.271 Executing VM operation: Cleanup +Event: 22.633 Executing VM operation: Cleanup done +Event: 22.881 Executing VM operation: HandshakeAllThreads +Event: 22.881 Executing VM operation: HandshakeAllThreads done +Event: 23.155 Executing VM operation: G1CollectForAllocation +Event: 23.189 Executing VM operation: G1CollectForAllocation done +Event: 23.194 Executing VM operation: G1TryInitiateConcMark + +Events (20 events): +Event: 21.661 loading class java/util/concurrent/SynchronousQueue$Transferer +Event: 21.661 loading class java/util/concurrent/SynchronousQueue$Transferer done +Event: 21.661 loading class java/util/concurrent/SynchronousQueue$TransferStack done +Event: 21.661 loading class java/util/concurrent/SynchronousQueue$TransferStack$SNode +Event: 21.661 loading class java/util/concurrent/ForkJoinPool$ManagedBlocker +Event: 21.662 loading class java/util/concurrent/ForkJoinPool$ManagedBlocker done +Event: 21.662 loading class java/util/concurrent/SynchronousQueue$TransferStack$SNode done +Event: 21.662 Thread 0x0000000020139240 Thread exited: 0x0000000020139240 +Event: 22.177 loading class java/util/Vector$Itr +Event: 22.177 loading class java/util/Vector$Itr done +Event: 22.193 loading class java/util/zip/Deflater +Event: 22.194 loading class java/util/zip/Deflater done +Event: 22.194 loading class java/util/zip/Deflater$DeflaterZStreamRef +Event: 22.194 loading class java/util/zip/Deflater$DeflaterZStreamRef done +Event: 22.197 loading class java/util/Vector$1 +Event: 22.197 loading class java/util/Vector$1 done +Event: 22.200 loading class java/io/DataOutputStream +Event: 22.625 loading class java/io/DataOutputStream done +Event: 23.139 loading class java/io/SequenceInputStream +Event: 23.139 loading class java/io/SequenceInputStream done + + +Dynamic libraries: +0x000000013f0d0000 - 0x000000013f0de000 C:\Program Files\Java\jdk-17\bin\java.exe +0x0000000077450000 - 0x00000000775ef000 C:\Windows\SYSTEM32\ntdll.dll +0x0000000077230000 - 0x000000007734f000 C:\Windows\system32\kernel32.dll +0x000007fefd0a0000 - 0x000007fefd107000 C:\Windows\system32\KERNELBASE.dll +0x000007feed7d0000 - 0x000007feed7e8000 C:\Program Files\Java\jdk-17\bin\jli.dll +0x000007fefb550000 - 0x000007fefb745000 C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.24483_none_e372d88f30fbb845\COMCTL32.dll +0x000007fefda30000 - 0x000007fefdacf000 C:\Windows\system32\msvcrt.dll +0x000007feff590000 - 0x000007feff5f7000 C:\Windows\system32\GDI32.dll +0x0000000077350000 - 0x000000007744b000 C:\Windows\system32\USER32.dll +0x000007fefdc00000 - 0x000007fefdc0e000 C:\Windows\system32\LPK.dll +0x000007fefeeb0000 - 0x000007fefef7b000 C:\Windows\system32\USP10.dll +0x000007feff130000 - 0x000007feff1a1000 C:\Windows\system32\SHLWAPI.dll +0x000007fee6950000 - 0x000007fee6969000 C:\Program Files\Java\jdk-17\bin\VCRUNTIME140.dll +0x000007feed7c0000 - 0x000007feed7c4000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-runtime-l1-1-0.dll +0x000007fee1890000 - 0x000007fee198a000 C:\Program Files\Java\jdk-17\bin\ucrtbase.DLL +0x000007fee9bb0000 - 0x000007fee9bb3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-localization-l1-2-0.dll +0x000007fee7980000 - 0x000007fee7983000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-processthreads-l1-1-1.dll +0x000007fee6ae0000 - 0x000007fee6ae3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-file-l1-2-0.dll +0x000007fee6940000 - 0x000007fee6943000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-timezone-l1-1-0.dll +0x000007fee6930000 - 0x000007fee6933000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-file-l2-1-0.dll +0x000007fee6920000 - 0x000007fee6923000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-synch-l1-2-0.dll +0x000007fee6910000 - 0x000007fee6913000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-heap-l1-1-0.dll +0x000007fee55a0000 - 0x000007fee55a4000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-string-l1-1-0.dll +0x000007fee3670000 - 0x000007fee3674000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-stdio-l1-1-0.dll +0x000007fee3660000 - 0x000007fee3664000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-convert-l1-1-0.dll +0x000007fee25d0000 - 0x000007fee25d3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-environment-l1-1-0.dll +0x000007fee25c0000 - 0x000007fee25c3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-filesystem-l1-1-0.dll +0x000007fee1c00000 - 0x000007fee1c05000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-math-l1-1-0.dll +0x000007fee1610000 - 0x000007fee1613000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-locale-l1-1-0.dll +0x000007fefdee0000 - 0x000007fefdf0e000 C:\Windows\system32\IMM32.DLL +0x000007feff020000 - 0x000007feff12b000 C:\Windows\system32\MSCTF.dll +0x000007fee1600000 - 0x000007fee160c000 C:\Program Files\Java\jdk-17\bin\vcruntime140_1.dll +0x000007fee1560000 - 0x000007fee15f1000 C:\Program Files\Java\jdk-17\bin\msvcp140.dll +0x000007fee1550000 - 0x000007fee1553000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-time-l1-1-0.dll +0x000007fee1540000 - 0x000007fee1543000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-utility-l1-1-0.dll +0x000007fed4b30000 - 0x000007fed5776000 C:\Program Files\Java\jdk-17\bin\server\jvm.dll +0x000007fefdad0000 - 0x000007fefdbab000 C:\Windows\system32\ADVAPI32.dll +0x000007fefd360000 - 0x000007fefd37f000 C:\Windows\SYSTEM32\sechost.dll +0x000007feff610000 - 0x000007feff73c000 C:\Windows\system32\RPCRT4.dll +0x000007fee5d80000 - 0x000007fee5d89000 C:\Windows\system32\WSOCK32.dll +0x000007fefdbb0000 - 0x000007fefdbfd000 C:\Windows\system32\WS2_32.dll +0x000007feff600000 - 0x000007feff608000 C:\Windows\system32\NSI.dll +0x000007fefa2a0000 - 0x000007fefa2db000 C:\Windows\system32\WINMM.dll +0x000007fefbeb0000 - 0x000007fefbebc000 C:\Windows\system32\VERSION.dll +0x00000000775f0000 - 0x00000000775f7000 C:\Windows\system32\PSAPI.DLL +0x000007fee1530000 - 0x000007fee153a000 C:\Program Files\Java\jdk-17\bin\jimage.dll +0x000007fee5630000 - 0x000007fee5755000 C:\Windows\system32\DBGHELP.DLL +0x000007fee1520000 - 0x000007fee152e000 C:\Program Files\Java\jdk-17\bin\instrument.dll +0x000007fee14f0000 - 0x000007fee1515000 C:\Program Files\Java\jdk-17\bin\java.dll +0x000007fee0c20000 - 0x000007fee0cf6000 C:\Program Files\Java\jdk-17\bin\svml.dll +0x000007fefdf90000 - 0x000007fefed1b000 C:\Windows\system32\SHELL32.dll +0x000007feff1b0000 - 0x000007feff3af000 C:\Windows\system32\ole32.dll +0x000007fefcfb0000 - 0x000007fefcfbf000 C:\Windows\system32\profapi.dll +0x000007fee0c00000 - 0x000007fee0c18000 C:\Program Files\Java\jdk-17\bin\zip.dll +0x000007fee0be0000 - 0x000007fee0bf9000 C:\Program Files\Java\jdk-17\bin\net.dll +0x000007fefab40000 - 0x000007fefabb1000 C:\Windows\system32\WINHTTP.dll +0x000007fefaad0000 - 0x000007fefab35000 C:\Windows\system32\webio.dll +0x000007fefc4b0000 - 0x000007fefc505000 C:\Windows\system32\mswsock.dll +0x000007fefc590000 - 0x000007fefc597000 C:\Windows\System32\wship6.dll +0x000007fee0740000 - 0x000007fee0755000 C:\Program Files\Java\jdk-17\bin\nio.dll +0x000007fee0720000 - 0x000007fee073a000 C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin\breakgen64.dll +0x0000000069ac0000 - 0x0000000069ae4000 C:\Users\Stef\AppData\Local\Temp\jansi-2.4.0-9689c7ed58c33b92-jansi.dll +0x000007fee14e0000 - 0x000007fee14f0000 C:\Program Files\Java\jdk-17\bin\verify.dll + +dbghelp: loaded successfully - version: 4.0.5 - missing functions: none +symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Program Files\Java\jdk-17\bin;C:\Windows\SYSTEM32;C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.24483_none_e372d88f30fbb845;C:\Program Files\Java\jdk-17\bin\server;C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin;C:\Users\Stef\AppData\Local\Temp + +VM Arguments: +jvm_args: -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\IF-parent -Dmaven.home=D:\Maven\apache-maven-3.8.4 -Dclassworlds.conf=D:\Maven\apache-maven-3.8.4\bin\m2.conf -Dmaven.ext.class.path=C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\plugins\maven\lib\maven-event-listener.jar -javaagent:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\lib\idea_rt.jar=52046:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin -Dfile.encoding=UTF-8 +java_command: org.codehaus.classworlds.Launcher -Didea.version=2021.3.1 clean install +java_class_path (initial): D:\Maven\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;D:\Maven\apache-maven-3.8.4\boot\plexus-classworlds.license +Launcher Type: SUN_STANDARD + +[Global flags] + intx CICompilerCount = 2 {product} {ergonomic} + uint ConcGCThreads = 1 {product} {ergonomic} + uint G1ConcRefinementThreads = 2 {product} {ergonomic} + size_t G1HeapRegionSize = 1048576 {product} {ergonomic} + uintx GCDrainStackTargetSize = 64 {product} {ergonomic} + size_t InitialHeapSize = 67108864 {product} {ergonomic} + size_t MarkStackSize = 4194304 {product} {ergonomic} + size_t MaxHeapSize = 1046478848 {product} {ergonomic} + size_t MaxNewSize = 627048448 {product} {ergonomic} + size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic} + size_t MinHeapSize = 8388608 {product} {ergonomic} + uintx NonNMethodCodeHeapSize = 5826188 {pd product} {ergonomic} + uintx NonProfiledCodeHeapSize = 122916026 {pd product} {ergonomic} + uintx ProfiledCodeHeapSize = 122916026 {pd product} {ergonomic} + uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic} + bool SegmentedCodeCache = true {product} {ergonomic} + size_t SoftMaxHeapSize = 1046478848 {manageable} {ergonomic} + bool UseCompressedClassPointers = true {product lp64_product} {ergonomic} + bool UseCompressedOops = true {product lp64_product} {ergonomic} + bool UseG1GC = true {product} {ergonomic} + bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic} + +Logging: +Log output configuration: + #0: stdout all=warning uptime,level,tags + #1: stderr all=off uptime,level,tags + +Environment Variables: +JAVA_HOME=C:\Program Files\Java\jdk-17\ +CLASSPATH=C:\Users\Stef\.m2\repository\com\thoughtworks\xstream\xstream\1.4.18\xstream-1.4.18.jar +PATH=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI;C:\Ruby27-x64\bin;D:\NDS\MicroLua\devkitPro\msys2\usr\bin;C:\Python34;C:\Python34\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;C:\Program Files (x86)\Windows Live\Shared;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;"C:\Program Files\Java\jdk-17\bin";D:\CE Development\CEdev\bin;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Gpg4win\..\GnuPG\bin;D:\Yarnpkg\bin\;D:\Node.js\;C:\Program Files\Microsoft Network Monitor 3\;C:\Program Files\dotnet\;C:\Program Files (x86)\scala\\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\dotnet\;C:\Gradle\gradle-7.0.2\bin;D:\Python\Scripts\;D:\Python\;C:\Users\Stef\AppData\Local\Programs\Python\Launcher\;D:\CEDevelopment\CEdev\bin;D:\Maven\apache-maven-3.8.4\bin;D:\Gradle\gradle-7.0.2\bin;C:\MinGW\bin;D:\LaTeX\miktex\bin\x64\;D:\Lua\lua53.dll;"C:\Program Files (x86)\";C:\Users\Stef\AppData\Local\Yarn\bin;C:\Users\Stef\AppData\Roaming\npm;C:\Program Files\CMake\bin;C:\cygwin64\bin +USERNAME=Stef +OS=Windows_NT +PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 10, GenuineIntel + + + +--------------- S Y S T E M --------------- + +OS: + Windows 7 , 64 bit Build 7601 (6.1.7601.24545) +OS uptime: 0 days 6:52 hours + +CPU: total 2 (initial active 2) (2 cores per cpu, 1 threads per core) family 6 model 23 stepping 10 microcode 0x0, cx8, cmov, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, tsc, clflush + +Memory: 4k page, system-wide physical 3991M (144M free) +TotalPageFile size 8082M (AvailPageFile size 15M) +current process WorkingSet (physical memory assigned to process): 208M, peak: 209M +current process commit charge ("private bytes"): 235M, peak: 256M + +vm_info: OpenJDK 64-Bit Server VM (17.0.1+12) for windows-amd64 JRE (17.0.1+12), built on Oct 20 2021 07:42:55 by "" with MS VC++ 16.7 (VS2019) + +END. From def85b767dbc50266ddff7bb8d74d22db3aa000a Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 19 Jan 2022 21:37:49 +0100 Subject: [PATCH 100/382] Fix Mask#getColumn not working for non-square masks Addresses #176 --- .../inventoryframework/pane/OutlinePane.java | 72 ++++++++++--------- .../inventoryframework/pane/util/Mask.java | 2 +- .../pane/util/MaskTest.java | 5 ++ 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java index 623972e6a..157a4d52d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java @@ -169,44 +169,46 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs } for (int opposingVectorIndex = 0; opposingVectorIndex < maskLine.length; opposingVectorIndex++) { - if (maskLine[opposingVectorIndex]) { - if (index >= 0 && index < items.length && items[index] != null) { - int x, y; - - if (getOrientation() == Orientation.HORIZONTAL) { - x = opposingVectorIndex; - y = vectorIndex; - } else if (getOrientation() == Orientation.VERTICAL) { - x = vectorIndex; - y = opposingVectorIndex; - } else { - throw new IllegalStateException("Unknown orientation '" + getOrientation() + "'"); - } - - if (flipHorizontally) { - x = length - x - 1; - } - - if (flipVertically) { - y = height - y - 1; - } - - Map.Entry coordinates = GeometryUtil.processClockwiseRotation(x, y, - length, height, rotation); - - x = coordinates.getKey(); - y = coordinates.getValue(); - - if (x >= 0 && x < length && y >= 0 && y < height) { - int finalRow = getY() + y + paneOffsetY; - int finalColumn = getX() + x + paneOffsetX; - - inventoryComponent.setItem(items[index], finalColumn, finalRow); - } + if (!maskLine[opposingVectorIndex]) { + continue; + } + + if (index >= 0 && index < items.length && items[index] != null) { + int x, y; + + if (getOrientation() == Orientation.HORIZONTAL) { + x = opposingVectorIndex; + y = vectorIndex; + } else if (getOrientation() == Orientation.VERTICAL) { + x = vectorIndex; + y = opposingVectorIndex; + } else { + throw new IllegalStateException("Unknown orientation '" + getOrientation() + "'"); + } + + if (flipHorizontally) { + x = length - x - 1; + } + + if (flipVertically) { + y = height - y - 1; } - index++; + Map.Entry coordinates = GeometryUtil.processClockwiseRotation(x, y, + length, height, rotation); + + x = coordinates.getKey(); + y = coordinates.getValue(); + + if (x >= 0 && x < length && y >= 0 && y < height) { + int finalRow = getY() + y + paneOffsetY; + int finalColumn = getX() + x + paneOffsetX; + + inventoryComponent.setItem(items[index], finalColumn, finalRow); + } } + + index++; } } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Mask.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Mask.java index 55bce832f..901d854a4 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Mask.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Mask.java @@ -154,7 +154,7 @@ public int amountOfEnabledSlots() { * @since 0.5.16 */ public boolean[] getColumn(int index) { - boolean[] column = new boolean[mask[0].length]; + boolean[] column = new boolean[mask.length]; for (int i = 0; i < getHeight(); i++) { column[i] = mask[i][index]; diff --git a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/MaskTest.java b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/MaskTest.java index 3545e05ab..189af67ef 100644 --- a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/MaskTest.java +++ b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/MaskTest.java @@ -39,6 +39,11 @@ void testGetColumn() { "10", "00" ).getColumn(0)); + + assertArrayEquals(new boolean[] {true, false}, new Mask( + "1", + "0" + ).getColumn(0)); } @Test From c06c453c32eeb4f8f8c097c21c3f5d0b87dfba91 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 20 Jan 2022 21:15:19 +0100 Subject: [PATCH 101/382] Allow for processor in Label#setText --- .../pane/component/Label.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java index 205315ad2..3927f35f9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java @@ -12,6 +12,8 @@ import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; +import java.util.function.BiFunction; + /** * A label for displaying text. * @@ -81,12 +83,18 @@ public Label(int length, int height, @NotNull Font font) { } /** - * Sets the text to be displayed in this label + * Sets the text to be displayed in this label. If this label already had text, this text will be overwritten. The + * specified processor will be called for each character that is part of the specified text. The provided character + * will be the original character that was attempted to be shown - it is not subject to any transformations that may + * be applied for finding a valid item corresponding to this character, such as capitalization changes. * * @param text the new text - * @since 0.5.0 + * @param processor processes each character before using them + * @since 0.10.4 */ - public void setText(@NotNull String text) { + public void setText(@NotNull String text, + @NotNull BiFunction processor) { this.text = text; clear(); @@ -106,10 +114,21 @@ public void setText(@NotNull String text) { item = font.getDefaultItem(); } - addItem(new GuiItem(item)); + addItem(processor.apply(character, item.clone())); } } + /** + * Sets the text to be displayed in this label. If this label already had text, this text will be overwritten. + * + * @param text the new text + * @see #setText(String, BiFunction) + * @since 0.5.0 + */ + public void setText(@NotNull String text) { + setText(text, (character, item) -> new GuiItem(item)); + } + @NotNull @Contract(pure = true) @Override From 07944829858fcdfe8a11d641412cb3164e9787ce Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 21 Jan 2022 20:59:34 +0100 Subject: [PATCH 102/382] Fix titles being improperly displayed in virtual inventories --- .../stefvanschie/inventoryframework/gui/type/AnvilGui.java | 2 +- .../inventoryframework/gui/type/CartographyTableGui.java | 2 +- .../inventoryframework/gui/type/EnchantingTableGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/GrindstoneGui.java | 2 +- .../inventoryframework/gui/type/SmithingTableGui.java | 2 +- .../inventoryframework/gui/type/StonecutterGui.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) 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 93109f647..ed5b31fe8 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 @@ -124,7 +124,7 @@ public void show(@NotNull HumanEntity humanEntity) { //also let Bukkit know that we opened an inventory humanEntity.openInventory(getInventory()); - anvilInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); + anvilInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); this.viewers.add(humanEntity); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 3f8f1bed6..d755a6e30 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -118,7 +118,7 @@ public void show(@NotNull HumanEntity humanEntity) { //also let Bukkit know that we opened an inventory humanEntity.openInventory(getInventory()); - cartographyTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); + cartographyTableInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); } @NotNull diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 79548aaff..d21990976 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -101,7 +101,7 @@ public void show(@NotNull HumanEntity humanEntity) { //also let Bukkit know that we opened an inventory humanEntity.openInventory(getInventory()); - enchantingTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); + enchantingTableInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); } @NotNull diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index ef3b9ba6f..24e1d160f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -108,7 +108,7 @@ public void show(@NotNull HumanEntity humanEntity) { //also let Bukkit know that we opened an inventory humanEntity.openInventory(getInventory()); - grindstoneInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); + grindstoneInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); } @NotNull diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 542e0e6a6..51e9f2c0f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -116,7 +116,7 @@ public void show(@NotNull HumanEntity humanEntity) { //also let Bukkit know that we opened an inventory humanEntity.openInventory(getInventory()); - smithingTableInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); + smithingTableInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); } @NotNull diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 04be02e41..abc348dc5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -109,7 +109,7 @@ public void show(@NotNull HumanEntity humanEntity) { //also let Bukkit know that we opened an inventory humanEntity.openInventory(getInventory()); - stonecutterInventory.openInventory((Player) humanEntity, getTitle(), getTopItems()); + stonecutterInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); } @NotNull From 6845e3836fa7a9c1ffdef9b8006c6855cf3d0d31 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 24 Jan 2022 21:08:36 +0100 Subject: [PATCH 103/382] Improve off-hand ghost item removal Since 1.17 the client accepts off-hand packets when an inventory is open. Because of this, we can refresh the off-hand earlier to get rid of a ghost item due to a client issue. --- .../inventoryframework/gui/GuiListener.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index d5a266ea0..c2e979cd9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -64,6 +64,16 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { } gui.click(event); + + if (event.isCancelled()) { + Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { + PlayerInventory playerInventory = event.getWhoClicked().getInventory(); + + /* due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly + client-side */ + playerInventory.setItemInOffHand(playerInventory.getItemInOffHand()); + }); + } } /** From 21b3ab2ebcf1cfbb4fdd523db1e404685d682213 Mon Sep 17 00:00:00 2001 From: makindotcc <9150636+makindotcc@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:42:19 +0100 Subject: [PATCH 104/382] Pass raw slot to InventoryClickEvent --- .../stefvanschie/inventoryframework/gui/GuiListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index c2e979cd9..d45ac402e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -243,12 +243,12 @@ public void onInventoryDrag(@NotNull InventoryDragEvent event) { } InventoryView view = event.getView(); - Set inventorySlots = event.getInventorySlots(); + Set inventorySlots = event.getRawSlots(); if (inventorySlots.size() > 1) { boolean top = false, bottom = false; - for (int inventorySlot : event.getRawSlots()) { + for (int inventorySlot : inventorySlots) { Inventory inventory = view.getInventory(inventorySlot); if (view.getTopInventory().equals(inventory)) { From 55c10e9f816aff987315be942c16627b79a48c10 Mon Sep 17 00:00:00 2001 From: makindotcc <9150636+makindotcc@users.noreply.github.com> Date: Mon, 7 Feb 2022 22:48:28 +0100 Subject: [PATCH 105/382] Overwrite getCursor in fake InventoryClickEvent --- .../stefvanschie/inventoryframework/gui/GuiListener.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index d45ac402e..b15498900 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -280,11 +280,18 @@ public void onInventoryDrag(@NotNull InventoryDragEvent event) { ClickType clickType = even ? ClickType.LEFT : ClickType.RIGHT; InventoryAction inventoryAction = even ? InventoryAction.PLACE_SOME : InventoryAction.PLACE_ONE; + ItemStack previousViewCursor = view.getCursor(); + // Overwrite getCursor in inventory click event to mimic real event fired by Bukkit. + view.setCursor(event.getOldCursor()); //this is a fake click event, firing this may cause other plugins to function incorrectly, so keep it local InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(view, slotType, index, clickType, inventoryAction); onInventoryClick(inventoryClickEvent); + // Restore previous cursor only if someone has not changed it manually in onInventoryClick. + if (Objects.equals(view.getCursor(), event.getOldCursor())) { + view.setCursor(previousViewCursor); + } event.setCancelled(inventoryClickEvent.isCancelled()); } From 2aec7491119081c5167f3312378f2b1212931527 Mon Sep 17 00:00:00 2001 From: Rollczi Date: Sun, 13 Feb 2022 08:30:21 +0100 Subject: [PATCH 106/382] Clone panes before iteration to safely execute a foreach loop. --- .../stefvanschie/inventoryframework/gui/InventoryComponent.java | 2 +- .../stefvanschie/inventoryframework/pane/MasonryPane.java | 2 +- .../stefvanschie/inventoryframework/pane/PaginatedPane.java | 2 +- 3 files changed, 3 insertions(+), 3 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 a8e662aae..159a5d5f2 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 @@ -196,7 +196,7 @@ public void placeItems(@NotNull Inventory inventory, int offset) { * @since 0.8.0 */ public void click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int slot) { - List panes = getPanes(); + List panes = new ArrayList<>(getPanes()); //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--) { diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java index 2b09ca057..24949a858 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java @@ -164,7 +164,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp boolean success = false; - for (Pane pane : panes) { + for (Pane pane : new ArrayList<>(panes)) { success = success || pane.click(gui, inventoryComponent, event, slot, paneOffsetX + getX(), paneOffsetY + getY(), length, height); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index 7ce5aadfb..e1be5d3d7 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -220,7 +220,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp boolean success = false; - for (Pane pane : this.panes.getOrDefault(page, Collections.emptyList())) { + for (Pane pane : new ArrayList<>(this.panes.getOrDefault(page, Collections.emptyList()))) { success = success || pane.click(gui, inventoryComponent, event, slot,paneOffsetX + getX(), paneOffsetY + getY(), length, height); } From a3a73e2231b8060da4b3cd9fc8d2109ddea89e3b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 1 Mar 2022 20:31:29 +0100 Subject: [PATCH 107/382] Add 1.18.2 support --- IF/pom.xml | 6 + .../util/version/Version.java | 11 +- .../util/version/VersionMatcher.java | 16 ++ nms/1_18_2/pom.xml | 73 +++++ .../nms/v1_18_2/AnvilInventoryImpl.java | 266 ++++++++++++++++++ .../nms/v1_18_2/BeaconInventoryImpl.java | 199 +++++++++++++ .../CartographyTableInventoryImpl.java | 213 ++++++++++++++ .../v1_18_2/EnchantingTableInventoryImpl.java | 213 ++++++++++++++ .../nms/v1_18_2/GrindstoneInventoryImpl.java | 247 ++++++++++++++++ .../nms/v1_18_2/MerchantInventoryImpl.java | 97 +++++++ .../v1_18_2/SmithingTableInventoryImpl.java | 251 +++++++++++++++++ .../nms/v1_18_2/StonecutterInventoryImpl.java | 219 ++++++++++++++ .../nms/v1_18_2/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_18_2/util/TextHolderUtil.java | 66 +++++ pom.xml | 7 + 15 files changed, 1924 insertions(+), 1 deletion(-) create mode 100644 nms/1_18_2/pom.xml create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java create mode 100644 nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index cd81b0f85..446401c37 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -94,6 +94,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_18_2 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index d7eac3ddf..cd71bd4a2 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -73,7 +73,14 @@ public enum Version { * * @since 0.10.4 */ - V1_18_1; + V1_18_1, + + /** + * Version 1.18.2 + * + * @since 0.10.5 + */ + V1_18_2; /** * Gets the version currently being used. If the used version is not supported, an @@ -114,6 +121,8 @@ public static Version getVersion() { return V1_18_0; case "1.18.1": return V1_18_1; + case "1.18.2": + return V1_18_2; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 0183c6912..c9830865f 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 @@ -250,6 +250,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -270,6 +272,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -290,6 +294,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -310,6 +316,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -330,6 +338,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -350,6 +360,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -366,6 +378,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -386,5 +400,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_0.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_18_2, + com.github.stefvanschie.inventoryframework.nms.v1_18_2.StonecutterInventoryImpl.class); } } diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml new file mode 100644 index 000000000..322448bce --- /dev/null +++ b/nms/1_18_2/pom.xml @@ -0,0 +1,73 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.4 + ../../pom.xml + + 4.0.0 + + 1_18_2 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.18.2-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java new file mode 100644 index 000000000..8e5bc5441 --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java @@ -0,0 +1,266 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.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; + +/** + * Internal anvil inventory for 1.18.1 + * + * @since 0.10.4 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.4 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.4 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.4 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.10.4 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java new file mode 100644 index 000000000..cf13321ca --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.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.18.1 + * + * @since 0.10.4 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + TranslatableComponent message = new TranslatableComponent("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, message)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.4 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..25c6a6a4f --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.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.18.1 + * + * @since 0.10.4 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.4 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..1128078dd --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.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.18.1 + * + * @since 0.10.4 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.4 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..798127a51 --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java @@ -0,0 +1,247 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.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 grindstone inventory for 1.18.1 + * + * @since 0.10.4 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.17.1"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.4 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java new file mode 100644 index 000000000..612ddf910 --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_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.18.1 + * + * @since 0.10.4 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..326629c2f --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java @@ -0,0 +1,251 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.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; + +/** + * Internal smithing table inventory for 1.18.1 + * + * @since 0.10.4 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.4 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.4 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.4 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java new file mode 100644 index 000000000..399a3b641 --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_18_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.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.18.1 + * + * @since 0.10.4 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.4 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.4 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java new file mode 100644 index 000000000..6276a4dcb --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.4 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.4 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java new file mode 100644 index 000000000..ae8bc0769 --- /dev/null +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java @@ -0,0 +1,66 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_18_2.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.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +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.4 + */ +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.4 + */ + @NotNull + @Contract(pure = true) + public static Component 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.4 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return new TextComponent(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.4 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index cc36e0f30..00557ee06 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_18_2 nms/1_18_1 nms/1_18_0 nms/1_17_1 @@ -161,6 +162,12 @@ + + + https://hub.spigotmc.org/javadocs/bukkit/ + https://jd.adventure.kyori.net/api/4.10.0/ + + From d20451e112112184504d919d201226f7660962b3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 1 Mar 2022 20:39:25 +0100 Subject: [PATCH 108/382] V 0.10.5 --- IF/pom.xml | 2 +- README.md | 6 +++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/abstraction/pom.xml | 2 +- pom.xml | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 446401c37..eb0d765b5 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 4.0.0 diff --git a/README.md b/README.md index 94564ca0b..3620b9349 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.4 + 0.10.5 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.10.4' + compile 'com.github.stefvanschie.inventoryframework:IF:0.10.5' // ... } ``` @@ -76,7 +76,7 @@ shadowJar { You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. ```yaml libraries: - - com.github.stefvanschie.inventoryframework:IF:0.10.4 + - com.github.stefvanschie.inventoryframework:IF:0.10.5 ``` ## Building from source diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 819b5a63c..89cf9fa4b 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 36b05dc36..33cffb51c 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 512bd811e..f7f50b565 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index ea9b298fa..6b3aba55e 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 49201b4cc..9779b9b42 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 9161e1a0e..a4c442fa2 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 574d5767d..5290eac61 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index b1245edfa..b4b09522a 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index fe9138c6e..964257a19 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index eb6d90e00..5cfbddf7e 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 322448bce..676b3dc4a 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 57016afdc..c13a01419 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.4 + 0.10.5 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 00557ee06..012949a83 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.4 + 0.10.5 pom IF From 26e24d141705d6cc8f6e6486da5a13b0b8eb9890 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 1 Mar 2022 20:41:04 +0100 Subject: [PATCH 109/382] Add 1.18.2 to Maven workflow --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9ae2b3a35..722bb53cb 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -84,6 +84,7 @@ jobs: wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check java -jar BuildTools.jar --rev 1.18.1 --remapped --disable-java-check + java -jar BuildTools.jar --rev 1.18.2 --remapped --disable-java-check cd ../ - uses: actions/checkout@v2 name: Checkout code From e348f344489f0c2dba0bc0b357e6945c4fb423d0 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 1 Mar 2022 20:44:05 +0100 Subject: [PATCH 110/382] Update javadocs in 1.18.2 NMS module --- .../nms/v1_18_2/AnvilInventoryImpl.java | 18 +++++++++--------- .../nms/v1_18_2/BeaconInventoryImpl.java | 12 ++++++------ .../v1_18_2/CartographyTableInventoryImpl.java | 12 ++++++------ .../v1_18_2/EnchantingTableInventoryImpl.java | 12 ++++++------ .../nms/v1_18_2/GrindstoneInventoryImpl.java | 16 ++++++++-------- .../nms/v1_18_2/MerchantInventoryImpl.java | 8 ++++---- .../v1_18_2/SmithingTableInventoryImpl.java | 16 ++++++++-------- .../nms/v1_18_2/StonecutterInventoryImpl.java | 14 +++++++------- .../nms/v1_18_2/util/CustomInventoryUtil.java | 4 ++-- .../nms/v1_18_2/util/TextHolderUtil.java | 8 ++++---- 10 files changed, 60 insertions(+), 60 deletions(-) diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java index 8e5bc5441..fd6f703bb 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java @@ -30,9 +30,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal anvil inventory for 1.18.1 + * Internal anvil inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class AnvilInventoryImpl extends AnvilInventory { @@ -124,7 +124,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.4 + * @since 0.10.5 */ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -138,7 +138,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.4 + * @since 0.10.5 */ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -153,7 +153,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -165,7 +165,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -178,7 +178,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -189,7 +189,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container anvil for responding to item renaming * - * @since 0.10.4 + * @since 0.10.5 */ private class ContainerAnvilImpl extends AnvilMenu { @@ -209,7 +209,7 @@ private class ContainerAnvilImpl extends AnvilMenu { * Creates a new custom anvil container for the specified player * * @param serverPlayer the player for who this anvil container is - * @since 0.10.4 + * @since 0.10.5 */ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack[] items) { diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java index cf13321ca..094ed0e72 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/BeaconInventoryImpl.java @@ -26,9 +26,9 @@ import java.lang.reflect.Field; /** - * Internal beacon inventory for 1.18.1 + * Internal beacon inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class BeaconInventoryImpl extends BeaconInventory { @@ -80,7 +80,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -92,7 +92,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -105,7 +105,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -116,7 +116,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container beacon * - * @since 0.10.4 + * @since 0.10.5 */ private class ContainerBeaconImpl extends BeaconMenu { diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java index 25c6a6a4f..4075fa17f 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/CartographyTableInventoryImpl.java @@ -29,9 +29,9 @@ import java.lang.reflect.Field; /** - * Internal cartography table inventory for 1.18.1 + * Internal cartography table inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class CartographyTableInventoryImpl extends CartographyTableInventory { @@ -90,7 +90,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -102,7 +102,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -115,7 +115,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -126,7 +126,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container cartography table * - * @since 0.10.4 + * @since 0.10.5 */ private class ContainerCartographyTableImpl extends CartographyTableMenu { diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java index 1128078dd..862287315 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/EnchantingTableInventoryImpl.java @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal enchanting table inventory for 1.18.1 + * Internal enchanting table inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class EnchantingTableInventoryImpl extends EnchantingTableInventory { @@ -92,7 +92,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -104,7 +104,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -117,7 +117,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -128,7 +128,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.4 + * @since 0.10.5 */ private class ContainerEnchantingTableImpl extends EnchantmentMenu { diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java index 798127a51..5c9c1b9aa 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java @@ -29,9 +29,9 @@ import java.lang.reflect.Field; /** - * Internal grindstone inventory for 1.18.1 + * Internal grindstone inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class GrindstoneInventoryImpl extends GrindstoneInventory { @@ -93,7 +93,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -105,7 +105,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -118,7 +118,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -129,7 +129,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container grindstone * - * @since 0.10.4 + * @since 0.10.5 */ private class ContainerGrindstoneImpl extends GrindstoneMenu { @@ -216,7 +216,7 @@ public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} * Gets the craft inventory * * @return the craft inventory - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -232,7 +232,7 @@ private Container getCraftInventory() { * Gets the result inventory * * @return the result inventory - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java index 612ddf910..c1a9a6ede 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/MerchantInventoryImpl.java @@ -16,9 +16,9 @@ import java.util.Map; /** - * Internal merchant inventory for 1.18.1 + * Internal merchant inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class MerchantInventoryImpl extends MerchantInventory { @@ -75,7 +75,7 @@ public void sendMerchantOffers(@NotNull Player player, * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -88,7 +88,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java index 326629c2f..c9a1895d3 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java @@ -29,9 +29,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal smithing table inventory for 1.18.1 + * Internal smithing table inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class SmithingTableInventoryImpl extends SmithingTableInventory { @@ -124,7 +124,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.4 + * @since 0.10.5 */ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -138,7 +138,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.4 + * @since 0.10.5 */ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); @@ -153,7 +153,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -165,7 +165,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -178,7 +178,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -189,7 +189,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container smithing table * - * @since 0.10.4 + * @since 0.10.5 */ private class ContainerSmithingTableImpl extends SmithingMenu { diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java index 399a3b641..b9598e81d 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/StonecutterInventoryImpl.java @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal stonecutter inventory for 1.18.1 + * Internal stonecutter inventory for 1.18.2 * - * @since 0.10.4 + * @since 0.10.5 */ public class StonecutterInventoryImpl extends StonecutterInventory { @@ -93,7 +93,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.4 + * @since 0.10.5 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -105,7 +105,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -118,7 +118,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -129,7 +129,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.4 + * @since 0.10.5 */ private class ContainerStonecutterImpl extends StonecutterMenu { @@ -204,7 +204,7 @@ public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} * Gets the result inventory * * @return the result inventory - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java index 6276a4dcb..1f20cc3ca 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/CustomInventoryUtil.java @@ -10,7 +10,7 @@ /** * A utility class for custom inventories * - * @since 0.10.4 + * @since 0.10.5 */ public final class CustomInventoryUtil { @@ -25,7 +25,7 @@ private CustomInventoryUtil() {} * * @param items the items to convert * @return a list of converted items - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java index ae8bc0769..2e2fe9542 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/util/TextHolderUtil.java @@ -13,7 +13,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since 0.10.4 + * @since 0.10.5 */ public final class TextHolderUtil { @@ -26,7 +26,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -43,7 +43,7 @@ public static Component toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) @@ -56,7 +56,7 @@ private static Component toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.4 + * @since 0.10.5 */ @NotNull @Contract(pure = true) From e48b78f18edd18c15eecb7b1d9475acf2fe44080 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Mar 2022 05:18:12 +0000 Subject: [PATCH 111/382] Bump adventure-api from 4.10.0 to 4.10.1 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.10.0 to 4.10.1. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.10.0...v4.10.1) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 012949a83..81295651a 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 1.8 true UTF-8 - 4.10.0 + 4.10.1 com.github.stefvanschie.inventoryframework From 2bec95f8265acb03a750746adc8c015f23337604 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Mar 2022 05:19:26 +0000 Subject: [PATCH 112/382] Bump maven-shade-plugin from 3.2.4 to 3.3.0 Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.4 to 3.3.0. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.4...maven-shade-plugin-3.3.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index eb0d765b5..795d87f9a 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -193,7 +193,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.3.0 package From eee83903696cf980c4e8c6b15f287b73e5b5c05a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 05:16:31 +0000 Subject: [PATCH 113/382] Bump maven-javadoc-plugin from 3.3.2 to 3.4.0 in /IF Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.2 to 3.4.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.2...maven-javadoc-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 795d87f9a..a2933ab6a 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -237,7 +237,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.2 + 3.4.0 attach-javadocs From 471cfca0c28a7038e18c70755c5714c1e74fc5b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 05:16:43 +0000 Subject: [PATCH 114/382] Bump maven-javadoc-plugin from 3.3.2 to 3.4.0 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.2 to 3.4.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.2...maven-javadoc-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 81295651a..18bf99541 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.2 + 3.4.0 attach-javadocs From 5061008fe50f530b0e79541a5506abf7b3c1ec05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Apr 2022 05:15:16 +0000 Subject: [PATCH 115/382] Bump nexus-staging-maven-plugin from 1.6.12 to 1.6.13 in /IF Bumps nexus-staging-maven-plugin from 1.6.12 to 1.6.13. --- updated-dependencies: - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index a2933ab6a..d45d51b7c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -206,7 +206,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.12 + 1.6.13 true ossrh From e2f75f4068ad32de38b4eccbdcb125c70dcdcf2e Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 29 Apr 2022 20:36:42 +0200 Subject: [PATCH 116/382] Remove manual xstream override --- IF/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index d45d51b7c..6da0262c1 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -213,13 +213,6 @@ https://oss.sonatype.org/ true - - - com.thoughtworks.xstream - xstream - 1.4.17 - - org.apache.maven.plugins From fbfaf8fc61ba74bbb9f5fb234a041dac50375397 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Apr 2022 05:15:50 +0000 Subject: [PATCH 117/382] Bump nexus-staging-maven-plugin from 1.6.12 to 1.6.13 Bumps nexus-staging-maven-plugin from 1.6.12 to 1.6.13. --- updated-dependencies: - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 18bf99541..84bb8d86f 100644 --- a/pom.xml +++ b/pom.xml @@ -122,7 +122,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.12 + 1.6.13 true ossrh From 1f9079b3400a122d7780ed39797c043a34a50784 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 29 Apr 2022 20:38:58 +0200 Subject: [PATCH 118/382] Remove manual xstream override --- pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pom.xml b/pom.xml index 84bb8d86f..25bd9b2cc 100644 --- a/pom.xml +++ b/pom.xml @@ -129,13 +129,6 @@ https://oss.sonatype.org/ true - - - com.thoughtworks.xstream - xstream - 1.4.17 - - org.apache.maven.plugins From 7f815cf88f07210c68802e69359795d436dd3b58 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 30 Apr 2022 21:18:13 +0200 Subject: [PATCH 119/382] Update local build instructions --- README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3620b9349..c4924fcf2 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,66 @@ libraries: ``` ## Building from source -If you want to build this project from source, run the following from Git Bash: +If you want to build this project from source, run the following: git clone https://github.com/stefvanschie/IF.git - cd IF - mvn clean package -The build can then be found in /IF/target/. +This will clone this repository to your device. This project relies on NMS, for which the dependencies are not available online. Because of this, you'll need to follow additional steps to obtain all these dependencies locally. + +### Installing Paper +For versions 1.14-1.16, we use Paper. Run the following scripts for each version to install the dependencies locally. Running these commands generate additional files in the folder where you execute them. To ensure that you don't accidentallly overwrite other files, execute this in an empty folder. The files that get created can be deleted afterwards (either after installing a single version or after installing all of them), since they're no longer necessary. + +#### 1.14.4 +``` +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 +java -jar paper-1.14.4.jar +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" +``` + +#### 1.15.2 +``` +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 +java -jar paper-1.15.2.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" +``` + +#### 1.16.1 +``` +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 +java -jar paper-1.16.1.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" +``` + +#### 1.16.3 +``` +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 +java -jar paper-1.16.3.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" +``` + +#### 1.16.4 +``` +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 +java -jar paper-1.16.4.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" +``` + +### Installing Spigot +For versions 1.17-1.18, we use Spigot. To install these versions locally, we use Spigot's BuildTools system. Using BuildTools will create additional files, so we recommend running the following in an empty folder. The files can be deleted afterwards. +``` +wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar +java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.18.1 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.18.2 --remapped --disable-java-check +``` + +Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. +``` +mvn clean package +``` +Your build is now available in the /IF/target folder. ## Adventure support From cfa3756d2392bae8d1c6a851ce3d30b36fa0f240 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 2 May 2022 19:08:02 +0200 Subject: [PATCH 120/382] Add log files to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 77a4b1128..64169b5de 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ target IF-Test *.iml *.txt -dependency-reduced-pom.xml \ No newline at end of file +dependency-reduced-pom.xml +*.log \ No newline at end of file From 1f18c6d972f79e3ea32faffc478b67632eabae5b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 2 May 2022 19:11:24 +0200 Subject: [PATCH 121/382] Remove spurious log file --- hs_err_pid7296.log | 695 --------------------------------------------- 1 file changed, 695 deletions(-) delete mode 100644 hs_err_pid7296.log diff --git a/hs_err_pid7296.log b/hs_err_pid7296.log deleted file mode 100644 index de794618c..000000000 --- a/hs_err_pid7296.log +++ /dev/null @@ -1,695 +0,0 @@ -# -# There is insufficient memory for the Java Runtime Environment to continue. -# Native memory allocation (mmap) failed to map 23068672 bytes for G1 virtual space -# Possible reasons: -# The system is out of physical RAM or swap space -# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap -# Possible solutions: -# Reduce memory load on the system -# Increase physical memory or swap space -# Check if swap backing store is full -# Decrease Java heap size (-Xmx/-Xms) -# Decrease number of Java threads -# Decrease Java thread stack sizes (-Xss) -# Set larger code cache with -XX:ReservedCodeCacheSize= -# JVM is running with Unscaled Compressed Oops mode in which the Java heap is -# placed in the first 4GB address space. The Java Heap base address is the -# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress -# to set the Java Heap base and to place the Java Heap above 4GB virtual address. -# This output file may be truncated or incomplete. -# -# Out of Memory Error (os_windows.cpp:3469), pid=7296, tid=6840 -# -# JRE version: OpenJDK Runtime Environment Temurin-17.0.1+12 (17.0.1+12) (build 17.0.1+12) -# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (17.0.1+12, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) -# No core dump will be written. Minidumps are not enabled by default on client versions of Windows -# - ---------------- S U M M A R Y ------------ - -Command Line: -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\IF-parent -Dmaven.home=D:\Maven\apache-maven-3.8.4 -Dclassworlds.conf=D:\Maven\apache-maven-3.8.4\bin\m2.conf -Dmaven.ext.class.path=C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\plugins\maven\lib\maven-event-listener.jar -javaagent:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\lib\idea_rt.jar=52046:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin -Dfile.encoding=UTF-8 org.codehaus.classworlds.Launcher -Didea.version=2021.3.1 clean install - -Host: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz, 2 cores, 3G, Windows 7 , 64 bit Build 7601 (6.1.7601.24545) -Time: Thu Jan 13 20:33:50 2022 West-Europa (standaardtijd) elapsed time: 23.224401 seconds (0d 0h 0m 23s) - ---------------- T H R E A D --------------- - -Current thread (0x00000000003cf6e0): VMThread "VM Thread" [stack: 0x000000001ec60000,0x000000001ed60000] [id=6840] - -Stack: [0x000000001ec60000,0x000000001ed60000] -Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) -V [jvm.dll+0x6744da] -V [jvm.dll+0x82e144] -V [jvm.dll+0x82f8ee] -V [jvm.dll+0x82ff53] -V [jvm.dll+0x245175] -V [jvm.dll+0x6714c9] -V [jvm.dll+0x665f92] -V [jvm.dll+0x303c3b] -V [jvm.dll+0x30b176] -V [jvm.dll+0x35af1e] -V [jvm.dll+0x35b14f] -V [jvm.dll+0x2dab78] -V [jvm.dll+0x2d8e2c] -V [jvm.dll+0x2d83fc] -V [jvm.dll+0x31c571] -V [jvm.dll+0x8343bb] -V [jvm.dll+0x8350f4] -V [jvm.dll+0x83560c] -V [jvm.dll+0x8359e4] -V [jvm.dll+0x835ab0] -V [jvm.dll+0x7de51a] -V [jvm.dll+0x673305] -C [ucrtbase.DLL+0x1c1ae] -C [kernel32.dll+0x1556d] -C [ntdll.dll+0x5372d] - -VM_Operation (0x000000000201d6c0): G1TryInitiateConcMark, mode: safepoint, requested by thread 0x0000000000330310 - - ---------------- P R O C E S S --------------- - -Threads class SMR info: -_java_thread_list=0x000000002211ea80, length=13, elements={ -0x0000000000330310, 0x000000001e008760, 0x000000001e00a320, 0x000000001e0155a0, -0x000000001e017fd0, 0x000000001e018890, 0x000000001e01be50, 0x000000001e02b810, -0x000000001e02c5e0, 0x000000001e02db40, 0x000000001e2b29e0, 0x000000001ff0e910, -0x000000001ff0ede0 -} - -Java Threads: ( => current thread ) - 0x0000000000330310 JavaThread "main" [_thread_blocked, id=7316, stack(0x0000000001f20000,0x0000000002020000)] - 0x000000001e008760 JavaThread "Reference Handler" daemon [_thread_blocked, id=7392, stack(0x000000001ef50000,0x000000001f050000)] - 0x000000001e00a320 JavaThread "Finalizer" daemon [_thread_blocked, id=9184, stack(0x000000001f0d0000,0x000000001f1d0000)] - 0x000000001e0155a0 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=6976, stack(0x000000001f240000,0x000000001f340000)] - 0x000000001e017fd0 JavaThread "Attach Listener" daemon [_thread_blocked, id=8308, stack(0x000000001ed90000,0x000000001ee90000)] - 0x000000001e018890 JavaThread "Service Thread" daemon [_thread_blocked, id=8888, stack(0x000000001f460000,0x000000001f560000)] - 0x000000001e01be50 JavaThread "Monitor Deflation Thread" daemon [_thread_blocked, id=7452, stack(0x000000001f710000,0x000000001f810000)] - 0x000000001e02b810 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=4884, stack(0x000000001f8d0000,0x000000001f9d0000)] - 0x000000001e02c5e0 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=3892, stack(0x000000001fa40000,0x000000001fb40000)] - 0x000000001e02db40 JavaThread "Sweeper thread" daemon [_thread_blocked, id=6812, stack(0x000000001fbf0000,0x000000001fcf0000)] - 0x000000001e2b29e0 JavaThread "Common-Cleaner" daemon [_thread_blocked, id=1620, stack(0x000000001fdc0000,0x000000001fec0000)] - 0x000000001ff0e910 JavaThread "Monitor Ctrl-Break" daemon [_thread_in_native, id=7928, stack(0x0000000020370000,0x0000000020470000)] - 0x000000001ff0ede0 JavaThread "Notification Thread" daemon [_thread_blocked, id=5888, stack(0x000000001f590000,0x000000001f690000)] - -Other Threads: -=>0x00000000003cf6e0 VMThread "VM Thread" [stack: 0x000000001ec60000,0x000000001ed60000] [id=6840] - 0x000000001ff0f2b0 WatcherThread [stack: 0x000000001f350000,0x000000001f450000] [id=6304] - 0x0000000000363b00 GCTaskThread "GC Thread#0" [stack: 0x000000001b840000,0x000000001b940000] [id=6244] - 0x000000002017f2f0 GCTaskThread "GC Thread#1" [stack: 0x00000000206d0000,0x00000000207d0000] [id=9012] - 0x00000000003701d0 ConcurrentGCThread "G1 Main Marker" [stack: 0x000000001b980000,0x000000001ba80000] [id=1036] - 0x0000000000370af0 ConcurrentGCThread "G1 Conc#0" [stack: 0x000000001bb20000,0x000000001bc20000] [id=8296] - 0x00000000003b0cd0 ConcurrentGCThread "G1 Refine#0" [stack: 0x000000001de60000,0x000000001df60000] [id=4868] - 0x00000000003b1600 ConcurrentGCThread "G1 Service" [stack: 0x000000001e070000,0x000000001e170000] [id=6240] - -Threads with active compile tasks: - -VM state: at safepoint (normal execution) - -VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) -[0x000000000032ade0] Threads_lock - owner thread: 0x00000000003cf6e0 -[0x000000000032b410] Heap_lock - owner thread: 0x0000000000330310 - -Heap address: 0x00000000c1a00000, size: 998 MB, Compressed Oops mode: 32-bit - -CDS archive(s) mapped at: [0x0000000800000000-0x0000000800bc0000-0x0000000800bc0000), size 12320768, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 0. -Compressed class space mapped at: 0x0000000800c00000-0x0000000840c00000, reserved size: 1073741824 -Narrow klass base: 0x0000000800000000, Narrow klass shift: 0, Narrow klass range: 0x100000000 - -GC Precious Log: - CPUs: 2 total, 2 available - Memory: 3991M - Large Page Support: Disabled - NUMA Support: Disabled - Compressed Oops: Enabled (32-bit) - Heap Region Size: 1M - Heap Min Capacity: 8M - Heap Initial Capacity: 64M - Heap Max Capacity: 998M - Pre-touch: Disabled - Parallel Workers: 2 - Concurrent Workers: 1 - Concurrent Refinement Workers: 2 - Periodic GC: Disabled - -Heap: - garbage-first heap total 78848K, used 39429K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 2 young (2048K), 2 survivors (2048K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K - -Heap Regions: E=young(eden), S=young(survivor), O=old, HS=humongous(starts), HC=humongous(continues), CS=collection set, F=free, OA=open archive, CA=closed archive, TAMS=top-at-mark-start (previous, next) -| 0|0x00000000c1a00000, 0x00000000c1b00000, 0x00000000c1b00000|100%| O| |TAMS 0x00000000c1b00000, 0x00000000c1b00000| Untracked -| 1|0x00000000c1b00000, 0x00000000c1c00000, 0x00000000c1c00000|100%| O| |TAMS 0x00000000c1c00000, 0x00000000c1c00000| Untracked -| 2|0x00000000c1c00000, 0x00000000c1d00000, 0x00000000c1d00000|100%| O| |TAMS 0x00000000c1d00000, 0x00000000c1d00000| Untracked -| 3|0x00000000c1d00000, 0x00000000c1e00000, 0x00000000c1e00000|100%| O| |TAMS 0x00000000c1e00000, 0x00000000c1e00000| Untracked -| 4|0x00000000c1e00000, 0x00000000c1f00000, 0x00000000c1f00000|100%| O| |TAMS 0x00000000c1f00000, 0x00000000c1f00000| Untracked -| 5|0x00000000c1f00000, 0x00000000c2000000, 0x00000000c2000000|100%| O| |TAMS 0x00000000c2000000, 0x00000000c2000000| Untracked -| 6|0x00000000c2000000, 0x00000000c2100000, 0x00000000c2100000|100%| O| |TAMS 0x00000000c2100000, 0x00000000c2100000| Untracked -| 7|0x00000000c2100000, 0x00000000c2200000, 0x00000000c2200000|100%| O| |TAMS 0x00000000c2200000, 0x00000000c2200000| Untracked -| 8|0x00000000c2200000, 0x00000000c2300000, 0x00000000c2300000|100%| O| |TAMS 0x00000000c2300000, 0x00000000c2300000| Untracked -| 9|0x00000000c2300000, 0x00000000c2400000, 0x00000000c2400000|100%| O| |TAMS 0x00000000c2400000, 0x00000000c2400000| Untracked -| 10|0x00000000c2400000, 0x00000000c2500000, 0x00000000c2500000|100%| O| |TAMS 0x00000000c2500000, 0x00000000c2500000| Untracked -| 11|0x00000000c2500000, 0x00000000c2600000, 0x00000000c2600000|100%| O| |TAMS 0x00000000c2600000, 0x00000000c2600000| Untracked -| 12|0x00000000c2600000, 0x00000000c2700000, 0x00000000c2700000|100%| O| |TAMS 0x00000000c2700000, 0x00000000c2700000| Untracked -| 13|0x00000000c2700000, 0x00000000c2800000, 0x00000000c2800000|100%| O| |TAMS 0x00000000c2800000, 0x00000000c2800000| Untracked -| 14|0x00000000c2800000, 0x00000000c2900000, 0x00000000c2900000|100%| O| |TAMS 0x00000000c2900000, 0x00000000c2900000| Untracked -| 15|0x00000000c2900000, 0x00000000c2a00000, 0x00000000c2a00000|100%| O| |TAMS 0x00000000c2a00000, 0x00000000c2a00000| Untracked -| 16|0x00000000c2a00000, 0x00000000c2b00000, 0x00000000c2b00000|100%| O| |TAMS 0x00000000c2b00000, 0x00000000c2b00000| Untracked -| 17|0x00000000c2b00000, 0x00000000c2bef600, 0x00000000c2c00000| 93%| O| |TAMS 0x00000000c2bef600, 0x00000000c2bef600| Untracked -| 18|0x00000000c2c00000, 0x00000000c2d00000, 0x00000000c2d00000|100%| O| |TAMS 0x00000000c2c00000, 0x00000000c2d00000| Untracked -| 19|0x00000000c2d00000, 0x00000000c2e00000, 0x00000000c2e00000|100%| O| |TAMS 0x00000000c2d00000, 0x00000000c2e00000| Untracked -| 20|0x00000000c2e00000, 0x00000000c2f00000, 0x00000000c2f00000|100%| O| |TAMS 0x00000000c2e00000, 0x00000000c2f00000| Untracked -| 21|0x00000000c2f00000, 0x00000000c3000000, 0x00000000c3000000|100%|HS| |TAMS 0x00000000c2f00000, 0x00000000c3000000| Complete -| 22|0x00000000c3000000, 0x00000000c3100000, 0x00000000c3100000|100%|HC| |TAMS 0x00000000c3000000, 0x00000000c3100000| Complete -| 23|0x00000000c3100000, 0x00000000c3200000, 0x00000000c3200000|100%|HC| |TAMS 0x00000000c3100000, 0x00000000c3200000| Complete -| 24|0x00000000c3200000, 0x00000000c3300000, 0x00000000c3300000|100%|HC| |TAMS 0x00000000c3200000, 0x00000000c3300000| Complete -| 25|0x00000000c3300000, 0x00000000c3400000, 0x00000000c3400000|100%|HC| |TAMS 0x00000000c3300000, 0x00000000c3400000| Complete -| 26|0x00000000c3400000, 0x00000000c3500000, 0x00000000c3500000|100%| O| |TAMS 0x00000000c3400000, 0x00000000c3500000| Untracked -| 27|0x00000000c3500000, 0x00000000c3600000, 0x00000000c3600000|100%| O| |TAMS 0x00000000c3500000, 0x00000000c3600000| Untracked -| 28|0x00000000c3600000, 0x00000000c3700000, 0x00000000c3700000|100%|HS| |TAMS 0x00000000c3600000, 0x00000000c3700000| Complete -| 29|0x00000000c3700000, 0x00000000c3800000, 0x00000000c3800000|100%|HC| |TAMS 0x00000000c3700000, 0x00000000c3800000| Complete -| 30|0x00000000c3800000, 0x00000000c3900000, 0x00000000c3900000|100%|HC| |TAMS 0x00000000c3800000, 0x00000000c3900000| Complete -| 31|0x00000000c3900000, 0x00000000c3a00000, 0x00000000c3a00000|100%|HC| |TAMS 0x00000000c3900000, 0x00000000c3a00000| Complete -| 32|0x00000000c3a00000, 0x00000000c3b00000, 0x00000000c3b00000|100%|HC| |TAMS 0x00000000c3a00000, 0x00000000c3b00000| Complete -| 33|0x00000000c3b00000, 0x00000000c3b00000, 0x00000000c3c00000| 0%| F| |TAMS 0x00000000c3b00000, 0x00000000c3b00000| Untracked -| 34|0x00000000c3c00000, 0x00000000c3d00000, 0x00000000c3d00000|100%| O| |TAMS 0x00000000c3c00000, 0x00000000c3d00000| Untracked -| 35|0x00000000c3d00000, 0x00000000c3e00000, 0x00000000c3e00000|100%| O| |TAMS 0x00000000c3d00000, 0x00000000c3e00000| Untracked -| 36|0x00000000c3e00000, 0x00000000c3f00000, 0x00000000c3f00000|100%| O| |TAMS 0x00000000c3e00000, 0x00000000c3f00000| Untracked -| 37|0x00000000c3f00000, 0x00000000c3ffd600, 0x00000000c4000000| 98%| O| |TAMS 0x00000000c3f00000, 0x00000000c3ffd600| Untracked -| 38|0x00000000c4000000, 0x00000000c4000000, 0x00000000c4100000| 0%| F| |TAMS 0x00000000c4000000, 0x00000000c4000000| Untracked -| 39|0x00000000c4100000, 0x00000000c4100000, 0x00000000c4200000| 0%| F| |TAMS 0x00000000c4100000, 0x00000000c4100000| Untracked -| 40|0x00000000c4200000, 0x00000000c4200000, 0x00000000c4300000| 0%| F| |TAMS 0x00000000c4200000, 0x00000000c4200000| Untracked -| 41|0x00000000c4300000, 0x00000000c4300000, 0x00000000c4400000| 0%| F| |TAMS 0x00000000c4300000, 0x00000000c4300000| Untracked -| 42|0x00000000c4400000, 0x00000000c4400000, 0x00000000c4500000| 0%| F| |TAMS 0x00000000c4400000, 0x00000000c4400000| Untracked -| 43|0x00000000c4500000, 0x00000000c4500000, 0x00000000c4600000| 0%| F| |TAMS 0x00000000c4500000, 0x00000000c4500000| Untracked -| 44|0x00000000c4600000, 0x00000000c4600000, 0x00000000c4700000| 0%| F| |TAMS 0x00000000c4600000, 0x00000000c4600000| Untracked -| 45|0x00000000c4700000, 0x00000000c4700000, 0x00000000c4800000| 0%| F| |TAMS 0x00000000c4700000, 0x00000000c4700000| Untracked -| 46|0x00000000c4800000, 0x00000000c4800000, 0x00000000c4900000| 0%| F| |TAMS 0x00000000c4800000, 0x00000000c4800000| Untracked -| 47|0x00000000c4900000, 0x00000000c4900000, 0x00000000c4a00000| 0%| F| |TAMS 0x00000000c4900000, 0x00000000c4900000| Untracked -| 48|0x00000000c4a00000, 0x00000000c4a00000, 0x00000000c4b00000| 0%| F| |TAMS 0x00000000c4a00000, 0x00000000c4a00000| Untracked -| 49|0x00000000c4b00000, 0x00000000c4b00000, 0x00000000c4c00000| 0%| F| |TAMS 0x00000000c4b00000, 0x00000000c4b00000| Untracked -| 50|0x00000000c4c00000, 0x00000000c4c00000, 0x00000000c4d00000| 0%| F| |TAMS 0x00000000c4c00000, 0x00000000c4c00000| Untracked -| 51|0x00000000c4d00000, 0x00000000c4d00000, 0x00000000c4e00000| 0%| F| |TAMS 0x00000000c4d00000, 0x00000000c4d00000| Untracked -| 52|0x00000000c4e00000, 0x00000000c4e00000, 0x00000000c4f00000| 0%| F| |TAMS 0x00000000c4e00000, 0x00000000c4e00000| Untracked -| 53|0x00000000c4f00000, 0x00000000c4f00000, 0x00000000c5000000| 0%| F| |TAMS 0x00000000c4f00000, 0x00000000c4f00000| Untracked -| 54|0x00000000c5000000, 0x00000000c5000000, 0x00000000c5100000| 0%| F| |TAMS 0x00000000c5000000, 0x00000000c5000000| Untracked -| 55|0x00000000c5100000, 0x00000000c5100000, 0x00000000c5200000| 0%| F| |TAMS 0x00000000c5100000, 0x00000000c5100000| Untracked -| 56|0x00000000c5200000, 0x00000000c5200000, 0x00000000c5300000| 0%| F| |TAMS 0x00000000c5200000, 0x00000000c5200000| Untracked -| 57|0x00000000c5300000, 0x00000000c5300000, 0x00000000c5400000| 0%| F| |TAMS 0x00000000c5300000, 0x00000000c5300000| Untracked -| 58|0x00000000c5400000, 0x00000000c5400000, 0x00000000c5500000| 0%| F| |TAMS 0x00000000c5400000, 0x00000000c5400000| Untracked -| 59|0x00000000c5500000, 0x00000000c5500000, 0x00000000c5600000| 0%| F| |TAMS 0x00000000c5500000, 0x00000000c5500000| Untracked -| 60|0x00000000c5600000, 0x00000000c5600000, 0x00000000c5700000| 0%| F| |TAMS 0x00000000c5600000, 0x00000000c5600000| Untracked -| 61|0x00000000c5700000, 0x00000000c5700000, 0x00000000c5800000| 0%| F| |TAMS 0x00000000c5700000, 0x00000000c5700000| Untracked -| 62|0x00000000c5800000, 0x00000000c5800000, 0x00000000c5900000| 0%| F| |TAMS 0x00000000c5800000, 0x00000000c5800000| Untracked -| 63|0x00000000c5900000, 0x00000000c5900000, 0x00000000c5a00000| 0%| F| |TAMS 0x00000000c5900000, 0x00000000c5900000| Untracked -| 64|0x00000000c5a00000, 0x00000000c5a00000, 0x00000000c5b00000| 0%| F| |TAMS 0x00000000c5a00000, 0x00000000c5a00000| Untracked -| 65|0x00000000c5b00000, 0x00000000c5b00000, 0x00000000c5c00000| 0%| F| |TAMS 0x00000000c5b00000, 0x00000000c5b00000| Untracked -| 66|0x00000000c5c00000, 0x00000000c5c00000, 0x00000000c5d00000| 0%| F| |TAMS 0x00000000c5c00000, 0x00000000c5c00000| Untracked -| 67|0x00000000c5d00000, 0x00000000c5d00000, 0x00000000c5e00000| 0%| F| |TAMS 0x00000000c5d00000, 0x00000000c5d00000| Untracked -| 68|0x00000000c5e00000, 0x00000000c5e00000, 0x00000000c5f00000| 0%| F| |TAMS 0x00000000c5e00000, 0x00000000c5e00000| Untracked -| 69|0x00000000c5f00000, 0x00000000c5f00000, 0x00000000c6000000| 0%| F| |TAMS 0x00000000c5f00000, 0x00000000c5f00000| Untracked -| 70|0x00000000c6000000, 0x00000000c6000000, 0x00000000c6100000| 0%| F| |TAMS 0x00000000c6000000, 0x00000000c6000000| Untracked -| 71|0x00000000c6100000, 0x00000000c6100000, 0x00000000c6200000| 0%| F| |TAMS 0x00000000c6100000, 0x00000000c6100000| Untracked -| 72|0x00000000c6200000, 0x00000000c6200000, 0x00000000c6300000| 0%| F| |TAMS 0x00000000c6200000, 0x00000000c6200000| Untracked -| 73|0x00000000c6300000, 0x00000000c6300000, 0x00000000c6400000| 0%| F| |TAMS 0x00000000c6300000, 0x00000000c6300000| Untracked -| 74|0x00000000c6400000, 0x00000000c64948f0, 0x00000000c6500000| 58%| S|CS|TAMS 0x00000000c6400000, 0x00000000c6400000| Complete -| 75|0x00000000c6500000, 0x00000000c6600000, 0x00000000c6600000|100%| S|CS|TAMS 0x00000000c6500000, 0x00000000c6500000| Complete -| 76|0x00000000c6600000, 0x00000000c6600000, 0x00000000c6700000| 0%| F| |TAMS 0x00000000c6600000, 0x00000000c6600000| Untracked - -Card table byte_map: [0x0000000019420000,0x0000000019620000] _byte_map_base: 0x0000000018e13000 - -Marking Bits (Prev, Next): (CMBitMap*) 0x0000000000366020, (CMBitMap*) 0x0000000000366060 - Prev Bits: [0x0000000019820000, 0x000000001a7b8000) - Next Bits: [0x000000001a7c0000, 0x000000001b758000) - -Polling page: 0x00000000000a0000 - -Metaspace: - -Usage: - Non-class: 27.97 MB used. - Class: 3.68 MB used. - Both: 31.64 MB used. - -Virtual space: - Non-class space: 32.00 MB reserved, 28.19 MB ( 88%) committed, 4 nodes. - Class space: 1.00 GB reserved, 3.88 MB ( <1%) committed, 1 nodes. - Both: 1.03 GB reserved, 32.06 MB ( 3%) committed. - -Chunk freelists: - Non-Class: 2.98 MB - Class: 32.00 KB - Both: 3.02 MB - -MaxMetaspaceSize: unlimited -CompressedClassSpaceSize: 1.00 GB -Initial GC threshold: 21.00 MB -Current GC threshold: 49.63 MB -CDS: on -MetaspaceReclaimPolicy: balanced - - commit_granule_bytes: 65536. - - commit_granule_words: 8192. - - virtual_space_node_default_size: 1048576. - - enlarge_chunks_in_place: 1. - - new_chunks_are_fully_committed: 0. - - uncommit_free_chunks: 1. - - use_allocation_guard: 0. - - handle_deallocations: 1. - - -Internal statistics: - -num_allocs_failed_limit: 6. -num_arena_births: 204. -num_arena_deaths: 0. -num_vsnodes_births: 5. -num_vsnodes_deaths: 0. -num_space_committed: 513. -num_space_uncommitted: 0. -num_chunks_returned_to_freelist: 6. -num_chunks_taken_from_freelist: 1389. -num_chunk_merges: 6. -num_chunk_splits: 1009. -num_chunks_enlarged: 803. -num_purges: 0. -num_inconsistent_stats: 0. - -CodeHeap 'non-profiled nmethods': size=120064Kb used=2809Kb max_used=3011Kb free=117254Kb - bounds [0x00000000119d0000, 0x0000000011cd0000, 0x0000000018f10000] -CodeHeap 'profiled nmethods': size=120000Kb used=12119Kb max_used=12447Kb free=107880Kb - bounds [0x000000000a4a0000, 0x000000000b0d0000, 0x00000000119d0000] -CodeHeap 'non-nmethods': size=5696Kb used=1220Kb max_used=1262Kb free=4475Kb - bounds [0x0000000009f10000, 0x000000000a180000, 0x000000000a4a0000] - total_blobs=6237 nmethods=5706 adapters=442 - compilation: enabled - stopped_count=0, restarted_count=0 - full_count=0 - -Compilation events (20 events): -Event: 22.690 Thread 0x000000001e02c5e0 nmethod 6540 0x000000000abdb590 code [0x000000000abdb800, 0x000000000abdc5a8] -Event: 22.985 Thread 0x000000001e02b810 nmethod 6362 0x0000000011cc0e90 code [0x0000000011cc1360, 0x0000000011cc87e0] -Event: 22.985 Thread 0x000000001e02b810 6413 4 java.util.regex.Pattern$Start::match (90 bytes) -Event: 22.992 Thread 0x000000001e02b810 nmethod 6413 0x0000000011bded90 code [0x0000000011bdef60, 0x0000000011bdf588] -Event: 22.992 Thread 0x000000001e02b810 6357 4 org.eclipse.sisu.bean.DeclaredMembers$MemberIterator::hasNext (96 bytes) -Event: 23.058 Thread 0x000000001e02b810 nmethod 6357 0x0000000011b3c710 code [0x0000000011b3c9e0, 0x0000000011b3ed70] -Event: 23.102 Thread 0x000000001e02b810 6541 4 java.util.StringTokenizer::skipDelimiters (116 bytes) -Event: 23.102 Thread 0x000000001e02c5e0 6542 3 java.lang.String::substring (58 bytes) -Event: 23.103 Thread 0x000000001e02c5e0 nmethod 6542 0x000000000abdad10 code [0x000000000abdaf00, 0x000000000abdb3a8] -Event: 23.103 Thread 0x000000001e02c5e0 6544 3 org.codehaus.plexus.util.SelectorUtils::match (520 bytes) -Event: 23.104 Thread 0x000000001e02c5e0 nmethod 6544 0x000000000abcf910 code [0x000000000abcfc20, 0x000000000abd10b8] -Event: 23.105 Thread 0x000000001e02c5e0 6545 3 org.codehaus.plexus.util.SelectorUtils::equals (37 bytes) -Event: 23.105 Thread 0x000000001e02c5e0 nmethod 6545 0x000000000abda790 code [0x000000000abda960, 0x000000000abdac18] -Event: 23.108 Thread 0x000000001e02b810 nmethod 6541 0x0000000011bde590 code [0x0000000011bde720, 0x0000000011bdea68] -Event: 23.108 Thread 0x000000001e02b810 6543 4 java.lang.String::toCharArray (25 bytes) -Event: 23.109 Thread 0x000000001e02b810 nmethod 6543 0x0000000011a7cf10 code [0x0000000011a7d0a0, 0x0000000011a7d228] -Event: 23.134 Thread 0x000000001e02b810 6546 4 org.codehaus.plexus.classworlds.realm.ClassRealm::findClass (9 bytes) -Event: 23.135 Thread 0x000000001e02b810 nmethod 6546 0x0000000011b3c210 code [0x0000000011b3c3a0, 0x0000000011b3c488] -Event: 23.141 Thread 0x000000001e02b810 6547 4 java.lang.ReflectiveOperationException:: (7 bytes) -Event: 23.146 Thread 0x000000001e02b810 nmethod 6547 0x0000000011b3a890 code [0x0000000011b3aa20, 0x0000000011b3b148] - -GC Heap History (20 events): -Event: 5.477 GC heap after -{Heap after GC invocations=4 (full 0): - garbage-first heap total 65536K, used 5815K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 4 survivors (4096K) - Metaspace used 10438K, committed 10560K, reserved 1064960K - class space used 1266K, committed 1344K, reserved 1048576K -} -Event: 8.029 GC heap before -{Heap before GC invocations=4 (full 0): - garbage-first heap total 65536K, used 40631K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 38 young (38912K), 4 survivors (4096K) - Metaspace used 12980K, committed 13184K, reserved 1064960K - class space used 1483K, committed 1600K, reserved 1048576K -} -Event: 8.074 GC heap after -{Heap after GC invocations=5 (full 0): - garbage-first heap total 65536K, used 8479K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 5 young (5120K), 5 survivors (5120K) - Metaspace used 12980K, committed 13184K, reserved 1064960K - class space used 1483K, committed 1600K, reserved 1048576K -} -Event: 9.632 GC heap before -{Heap before GC invocations=5 (full 0): - garbage-first heap total 65536K, used 42271K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 38 young (38912K), 5 survivors (5120K) - Metaspace used 14458K, committed 14656K, reserved 1064960K - class space used 1630K, committed 1728K, reserved 1048576K -} -Event: 9.709 GC heap after -{Heap after GC invocations=6 (full 0): - garbage-first heap total 78848K, used 11039K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 3 young (3072K), 3 survivors (3072K) - Metaspace used 14458K, committed 14656K, reserved 1064960K - class space used 1630K, committed 1728K, reserved 1048576K -} -Event: 11.260 GC heap before -{Heap before GC invocations=6 (full 0): - garbage-first heap total 78848K, used 55071K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 46 young (47104K), 3 survivors (3072K) - Metaspace used 15669K, committed 15872K, reserved 1064960K - class space used 1757K, committed 1856K, reserved 1048576K -} -Event: 11.302 GC heap after -{Heap after GC invocations=7 (full 0): - garbage-first heap total 78848K, used 14858K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 6 young (6144K), 6 survivors (6144K) - Metaspace used 15669K, committed 15872K, reserved 1064960K - class space used 1757K, committed 1856K, reserved 1048576K -} -Event: 12.807 GC heap before -{Heap before GC invocations=7 (full 0): - garbage-first heap total 78848K, used 55818K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 46 young (47104K), 6 survivors (6144K) - Metaspace used 16824K, committed 17088K, reserved 1064960K - class space used 1911K, committed 2048K, reserved 1048576K -} -Event: 12.875 GC heap after -{Heap after GC invocations=8 (full 0): - garbage-first heap total 78848K, used 17332K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 3 young (3072K), 3 survivors (3072K) - Metaspace used 16824K, committed 17088K, reserved 1064960K - class space used 1911K, committed 2048K, reserved 1048576K -} -Event: 14.388 GC heap before -{Heap before GC invocations=8 (full 0): - garbage-first heap total 78848K, used 59316K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 44 young (45056K), 3 survivors (3072K) - Metaspace used 17217K, committed 17472K, reserved 1064960K - class space used 1940K, committed 2048K, reserved 1048576K -} -Event: 14.397 GC heap after -{Heap after GC invocations=9 (full 0): - garbage-first heap total 78848K, used 18681K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 4 survivors (4096K) - Metaspace used 17217K, committed 17472K, reserved 1064960K - class space used 1940K, committed 2048K, reserved 1048576K -} -Event: 15.637 GC heap before -{Heap before GC invocations=9 (full 0): - garbage-first heap total 78848K, used 60665K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 45 young (46080K), 4 survivors (4096K) - Metaspace used 19580K, committed 19904K, reserved 1073152K - class space used 2274K, committed 2432K, reserved 1048576K -} -Event: 15.650 GC heap after -{Heap after GC invocations=10 (full 0): - garbage-first heap total 78848K, used 21046K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 5 young (5120K), 5 survivors (5120K) - Metaspace used 19580K, committed 19904K, reserved 1073152K - class space used 2274K, committed 2432K, reserved 1048576K -} -Event: 18.749 GC heap before -{Heap before GC invocations=10 (full 0): - garbage-first heap total 78848K, used 56886K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 41 young (41984K), 5 survivors (5120K) - Metaspace used 21245K, committed 21504K, reserved 1073152K - class space used 2475K, committed 2624K, reserved 1048576K -} -Event: 18.774 GC heap after -{Heap after GC invocations=11 (full 0): - garbage-first heap total 78848K, used 22461K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 4 survivors (4096K) - Metaspace used 21245K, committed 21504K, reserved 1073152K - class space used 2475K, committed 2624K, reserved 1048576K -} -Event: 20.888 GC heap before -{Heap before GC invocations=12 (full 0): - garbage-first heap total 78848K, used 62397K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 43 young (44032K), 4 survivors (4096K) - Metaspace used 30147K, committed 30464K, reserved 1081344K - class space used 3504K, committed 3648K, reserved 1048576K -} -Event: 20.919 GC heap after -{Heap after GC invocations=13 (full 0): - garbage-first heap total 78848K, used 27581K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 6 young (6144K), 6 survivors (6144K) - Metaspace used 30147K, committed 30464K, reserved 1081344K - class space used 3504K, committed 3648K, reserved 1048576K -} -Event: 23.155 GC heap before -{Heap before GC invocations=14 (full 0): - garbage-first heap total 78848K, used 64445K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 38 young (38912K), 6 survivors (6144K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K -} -Event: 23.188 GC heap after -{Heap after GC invocations=15 (full 0): - garbage-first heap total 78848K, used 34803K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 3 young (3072K), 3 survivors (3072K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K -} -Event: 23.194 GC heap before -{Heap before GC invocations=15 (full 0): - garbage-first heap total 78848K, used 39923K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 3 survivors (3072K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K -} - -Deoptimization events (20 events): -Event: 22.652 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.652 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.652 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 -Event: 22.652 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 -Event: 22.652 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.652 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 -Event: 22.653 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.653 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 -Event: 22.653 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.653 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.655 Thread 0x0000000000330310 DEOPT PACKING pc=0x000000000aee0488 sp=0x000000000201ddb0 -Event: 22.655 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f62b24 sp=0x000000000201d250 mode 0 -Event: 23.097 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011c49d84 relative=0x0000000000006844 -Event: 23.097 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011c49d84 method=org.apache.maven.model.BuildBase.clone()Lorg/apache/maven/model/BuildBase; @ 30 c2 -Event: 23.097 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011c49d84 sp=0x000000000201df00 -Event: 23.097 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de40 mode 2 - -Classes unloaded (0 events): -No events - -Classes redefined (0 events): -No events - -Internal exceptions (20 events): -Event: 20.625 Thread 0x0000000000330310 Exception (0x00000000c45a8618) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.626 Thread 0x0000000000330310 Exception (0x00000000c45a88b8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.626 Thread 0x0000000000330310 Exception (0x00000000c45a9530) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.636 Thread 0x0000000000330310 Exception (0x00000000c45b4b10) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.652 Thread 0x0000000000330310 Exception (0x00000000c45caf28) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45cb248) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45ce348) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45ce5a8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.654 Thread 0x0000000000330310 Exception (0x00000000c45d2e38) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.655 Thread 0x0000000000330310 Exception (0x00000000c45d3150) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.667 Thread 0x0000000000330310 Exception (0x00000000c45f7150) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 20.670 Thread 0x0000000000330310 Exception (0x00000000c4402b40) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 20.671 Thread 0x0000000000330310 Exception (0x00000000c4407470) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 20.719 Thread 0x0000000000330310 Exception (0x00000000c4472ab8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.744 Thread 0x0000000000330310 Exception (0x00000000c449aaa8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.792 Thread 0x0000000000330310 Exception (0x00000000c43061b8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 21.266 Thread 0x0000000000330310 Exception (0x00000000c5622c28) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 862] -Event: 21.659 Thread 0x0000000020139240 Exception (0x00000000c534a4a8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 21.659 Thread 0x0000000020139240 Exception (0x00000000c5350be8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 21.660 Thread 0x0000000020139240 Exception (0x00000000c5354758) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] - -VM Operations (20 events): -Event: 20.640 Executing VM operation: ICBufferFull done -Event: 20.717 Executing VM operation: HandshakeAllThreads -Event: 20.717 Executing VM operation: HandshakeAllThreads done -Event: 20.813 Executing VM operation: ICBufferFull -Event: 20.826 Executing VM operation: ICBufferFull done -Event: 20.888 Executing VM operation: G1CollectForAllocation -Event: 20.919 Executing VM operation: G1CollectForAllocation done -Event: 21.015 Executing VM operation: G1Concurrent -Event: 21.031 Executing VM operation: G1Concurrent done -Event: 21.069 Executing VM operation: G1Concurrent -Event: 21.069 Executing VM operation: G1Concurrent done -Event: 21.247 Executing VM operation: HandshakeAllThreads -Event: 21.247 Executing VM operation: HandshakeAllThreads done -Event: 22.271 Executing VM operation: Cleanup -Event: 22.633 Executing VM operation: Cleanup done -Event: 22.881 Executing VM operation: HandshakeAllThreads -Event: 22.881 Executing VM operation: HandshakeAllThreads done -Event: 23.155 Executing VM operation: G1CollectForAllocation -Event: 23.189 Executing VM operation: G1CollectForAllocation done -Event: 23.194 Executing VM operation: G1TryInitiateConcMark - -Events (20 events): -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$Transferer -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$Transferer done -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$TransferStack done -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$TransferStack$SNode -Event: 21.661 loading class java/util/concurrent/ForkJoinPool$ManagedBlocker -Event: 21.662 loading class java/util/concurrent/ForkJoinPool$ManagedBlocker done -Event: 21.662 loading class java/util/concurrent/SynchronousQueue$TransferStack$SNode done -Event: 21.662 Thread 0x0000000020139240 Thread exited: 0x0000000020139240 -Event: 22.177 loading class java/util/Vector$Itr -Event: 22.177 loading class java/util/Vector$Itr done -Event: 22.193 loading class java/util/zip/Deflater -Event: 22.194 loading class java/util/zip/Deflater done -Event: 22.194 loading class java/util/zip/Deflater$DeflaterZStreamRef -Event: 22.194 loading class java/util/zip/Deflater$DeflaterZStreamRef done -Event: 22.197 loading class java/util/Vector$1 -Event: 22.197 loading class java/util/Vector$1 done -Event: 22.200 loading class java/io/DataOutputStream -Event: 22.625 loading class java/io/DataOutputStream done -Event: 23.139 loading class java/io/SequenceInputStream -Event: 23.139 loading class java/io/SequenceInputStream done - - -Dynamic libraries: -0x000000013f0d0000 - 0x000000013f0de000 C:\Program Files\Java\jdk-17\bin\java.exe -0x0000000077450000 - 0x00000000775ef000 C:\Windows\SYSTEM32\ntdll.dll -0x0000000077230000 - 0x000000007734f000 C:\Windows\system32\kernel32.dll -0x000007fefd0a0000 - 0x000007fefd107000 C:\Windows\system32\KERNELBASE.dll -0x000007feed7d0000 - 0x000007feed7e8000 C:\Program Files\Java\jdk-17\bin\jli.dll -0x000007fefb550000 - 0x000007fefb745000 C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.24483_none_e372d88f30fbb845\COMCTL32.dll -0x000007fefda30000 - 0x000007fefdacf000 C:\Windows\system32\msvcrt.dll -0x000007feff590000 - 0x000007feff5f7000 C:\Windows\system32\GDI32.dll -0x0000000077350000 - 0x000000007744b000 C:\Windows\system32\USER32.dll -0x000007fefdc00000 - 0x000007fefdc0e000 C:\Windows\system32\LPK.dll -0x000007fefeeb0000 - 0x000007fefef7b000 C:\Windows\system32\USP10.dll -0x000007feff130000 - 0x000007feff1a1000 C:\Windows\system32\SHLWAPI.dll -0x000007fee6950000 - 0x000007fee6969000 C:\Program Files\Java\jdk-17\bin\VCRUNTIME140.dll -0x000007feed7c0000 - 0x000007feed7c4000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-runtime-l1-1-0.dll -0x000007fee1890000 - 0x000007fee198a000 C:\Program Files\Java\jdk-17\bin\ucrtbase.DLL -0x000007fee9bb0000 - 0x000007fee9bb3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-localization-l1-2-0.dll -0x000007fee7980000 - 0x000007fee7983000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-processthreads-l1-1-1.dll -0x000007fee6ae0000 - 0x000007fee6ae3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-file-l1-2-0.dll -0x000007fee6940000 - 0x000007fee6943000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-timezone-l1-1-0.dll -0x000007fee6930000 - 0x000007fee6933000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-file-l2-1-0.dll -0x000007fee6920000 - 0x000007fee6923000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-synch-l1-2-0.dll -0x000007fee6910000 - 0x000007fee6913000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-heap-l1-1-0.dll -0x000007fee55a0000 - 0x000007fee55a4000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-string-l1-1-0.dll -0x000007fee3670000 - 0x000007fee3674000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-stdio-l1-1-0.dll -0x000007fee3660000 - 0x000007fee3664000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-convert-l1-1-0.dll -0x000007fee25d0000 - 0x000007fee25d3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-environment-l1-1-0.dll -0x000007fee25c0000 - 0x000007fee25c3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-filesystem-l1-1-0.dll -0x000007fee1c00000 - 0x000007fee1c05000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-math-l1-1-0.dll -0x000007fee1610000 - 0x000007fee1613000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-locale-l1-1-0.dll -0x000007fefdee0000 - 0x000007fefdf0e000 C:\Windows\system32\IMM32.DLL -0x000007feff020000 - 0x000007feff12b000 C:\Windows\system32\MSCTF.dll -0x000007fee1600000 - 0x000007fee160c000 C:\Program Files\Java\jdk-17\bin\vcruntime140_1.dll -0x000007fee1560000 - 0x000007fee15f1000 C:\Program Files\Java\jdk-17\bin\msvcp140.dll -0x000007fee1550000 - 0x000007fee1553000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-time-l1-1-0.dll -0x000007fee1540000 - 0x000007fee1543000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-utility-l1-1-0.dll -0x000007fed4b30000 - 0x000007fed5776000 C:\Program Files\Java\jdk-17\bin\server\jvm.dll -0x000007fefdad0000 - 0x000007fefdbab000 C:\Windows\system32\ADVAPI32.dll -0x000007fefd360000 - 0x000007fefd37f000 C:\Windows\SYSTEM32\sechost.dll -0x000007feff610000 - 0x000007feff73c000 C:\Windows\system32\RPCRT4.dll -0x000007fee5d80000 - 0x000007fee5d89000 C:\Windows\system32\WSOCK32.dll -0x000007fefdbb0000 - 0x000007fefdbfd000 C:\Windows\system32\WS2_32.dll -0x000007feff600000 - 0x000007feff608000 C:\Windows\system32\NSI.dll -0x000007fefa2a0000 - 0x000007fefa2db000 C:\Windows\system32\WINMM.dll -0x000007fefbeb0000 - 0x000007fefbebc000 C:\Windows\system32\VERSION.dll -0x00000000775f0000 - 0x00000000775f7000 C:\Windows\system32\PSAPI.DLL -0x000007fee1530000 - 0x000007fee153a000 C:\Program Files\Java\jdk-17\bin\jimage.dll -0x000007fee5630000 - 0x000007fee5755000 C:\Windows\system32\DBGHELP.DLL -0x000007fee1520000 - 0x000007fee152e000 C:\Program Files\Java\jdk-17\bin\instrument.dll -0x000007fee14f0000 - 0x000007fee1515000 C:\Program Files\Java\jdk-17\bin\java.dll -0x000007fee0c20000 - 0x000007fee0cf6000 C:\Program Files\Java\jdk-17\bin\svml.dll -0x000007fefdf90000 - 0x000007fefed1b000 C:\Windows\system32\SHELL32.dll -0x000007feff1b0000 - 0x000007feff3af000 C:\Windows\system32\ole32.dll -0x000007fefcfb0000 - 0x000007fefcfbf000 C:\Windows\system32\profapi.dll -0x000007fee0c00000 - 0x000007fee0c18000 C:\Program Files\Java\jdk-17\bin\zip.dll -0x000007fee0be0000 - 0x000007fee0bf9000 C:\Program Files\Java\jdk-17\bin\net.dll -0x000007fefab40000 - 0x000007fefabb1000 C:\Windows\system32\WINHTTP.dll -0x000007fefaad0000 - 0x000007fefab35000 C:\Windows\system32\webio.dll -0x000007fefc4b0000 - 0x000007fefc505000 C:\Windows\system32\mswsock.dll -0x000007fefc590000 - 0x000007fefc597000 C:\Windows\System32\wship6.dll -0x000007fee0740000 - 0x000007fee0755000 C:\Program Files\Java\jdk-17\bin\nio.dll -0x000007fee0720000 - 0x000007fee073a000 C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin\breakgen64.dll -0x0000000069ac0000 - 0x0000000069ae4000 C:\Users\Stef\AppData\Local\Temp\jansi-2.4.0-9689c7ed58c33b92-jansi.dll -0x000007fee14e0000 - 0x000007fee14f0000 C:\Program Files\Java\jdk-17\bin\verify.dll - -dbghelp: loaded successfully - version: 4.0.5 - missing functions: none -symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Program Files\Java\jdk-17\bin;C:\Windows\SYSTEM32;C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.24483_none_e372d88f30fbb845;C:\Program Files\Java\jdk-17\bin\server;C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin;C:\Users\Stef\AppData\Local\Temp - -VM Arguments: -jvm_args: -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\IF-parent -Dmaven.home=D:\Maven\apache-maven-3.8.4 -Dclassworlds.conf=D:\Maven\apache-maven-3.8.4\bin\m2.conf -Dmaven.ext.class.path=C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\plugins\maven\lib\maven-event-listener.jar -javaagent:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\lib\idea_rt.jar=52046:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin -Dfile.encoding=UTF-8 -java_command: org.codehaus.classworlds.Launcher -Didea.version=2021.3.1 clean install -java_class_path (initial): D:\Maven\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;D:\Maven\apache-maven-3.8.4\boot\plexus-classworlds.license -Launcher Type: SUN_STANDARD - -[Global flags] - intx CICompilerCount = 2 {product} {ergonomic} - uint ConcGCThreads = 1 {product} {ergonomic} - uint G1ConcRefinementThreads = 2 {product} {ergonomic} - size_t G1HeapRegionSize = 1048576 {product} {ergonomic} - uintx GCDrainStackTargetSize = 64 {product} {ergonomic} - size_t InitialHeapSize = 67108864 {product} {ergonomic} - size_t MarkStackSize = 4194304 {product} {ergonomic} - size_t MaxHeapSize = 1046478848 {product} {ergonomic} - size_t MaxNewSize = 627048448 {product} {ergonomic} - size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic} - size_t MinHeapSize = 8388608 {product} {ergonomic} - uintx NonNMethodCodeHeapSize = 5826188 {pd product} {ergonomic} - uintx NonProfiledCodeHeapSize = 122916026 {pd product} {ergonomic} - uintx ProfiledCodeHeapSize = 122916026 {pd product} {ergonomic} - uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic} - bool SegmentedCodeCache = true {product} {ergonomic} - size_t SoftMaxHeapSize = 1046478848 {manageable} {ergonomic} - bool UseCompressedClassPointers = true {product lp64_product} {ergonomic} - bool UseCompressedOops = true {product lp64_product} {ergonomic} - bool UseG1GC = true {product} {ergonomic} - bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic} - -Logging: -Log output configuration: - #0: stdout all=warning uptime,level,tags - #1: stderr all=off uptime,level,tags - -Environment Variables: -JAVA_HOME=C:\Program Files\Java\jdk-17\ -CLASSPATH=C:\Users\Stef\.m2\repository\com\thoughtworks\xstream\xstream\1.4.18\xstream-1.4.18.jar -PATH=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI;C:\Ruby27-x64\bin;D:\NDS\MicroLua\devkitPro\msys2\usr\bin;C:\Python34;C:\Python34\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;C:\Program Files (x86)\Windows Live\Shared;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;"C:\Program Files\Java\jdk-17\bin";D:\CE Development\CEdev\bin;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Gpg4win\..\GnuPG\bin;D:\Yarnpkg\bin\;D:\Node.js\;C:\Program Files\Microsoft Network Monitor 3\;C:\Program Files\dotnet\;C:\Program Files (x86)\scala\\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\dotnet\;C:\Gradle\gradle-7.0.2\bin;D:\Python\Scripts\;D:\Python\;C:\Users\Stef\AppData\Local\Programs\Python\Launcher\;D:\CEDevelopment\CEdev\bin;D:\Maven\apache-maven-3.8.4\bin;D:\Gradle\gradle-7.0.2\bin;C:\MinGW\bin;D:\LaTeX\miktex\bin\x64\;D:\Lua\lua53.dll;"C:\Program Files (x86)\";C:\Users\Stef\AppData\Local\Yarn\bin;C:\Users\Stef\AppData\Roaming\npm;C:\Program Files\CMake\bin;C:\cygwin64\bin -USERNAME=Stef -OS=Windows_NT -PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 10, GenuineIntel - - - ---------------- S Y S T E M --------------- - -OS: - Windows 7 , 64 bit Build 7601 (6.1.7601.24545) -OS uptime: 0 days 6:52 hours - -CPU: total 2 (initial active 2) (2 cores per cpu, 1 threads per core) family 6 model 23 stepping 10 microcode 0x0, cx8, cmov, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, tsc, clflush - -Memory: 4k page, system-wide physical 3991M (144M free) -TotalPageFile size 8082M (AvailPageFile size 15M) -current process WorkingSet (physical memory assigned to process): 208M, peak: 209M -current process commit charge ("private bytes"): 235M, peak: 256M - -vm_info: OpenJDK 64-Bit Server VM (17.0.1+12) for windows-amd64 JRE (17.0.1+12), built on Oct 20 2021 07:42:55 by "" with MS VC++ 16.7 (VS2019) - -END. From df53f0d8d33f7e64d779037522df788491fab269 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:17:55 +0200 Subject: [PATCH 122/382] Replace BuildTools with the paper-nms-maven-plugin --- .github/workflows/maven.yml | 36 +++++++++---------------------- .gitignore | 3 ++- README.md | 19 ++++++++-------- nms/1_17_0/pom.xml | 43 +++++++++++++------------------------ nms/1_17_1/pom.xml | 42 ++++++++++++------------------------ nms/1_18_0/pom.xml | 42 ++++++++++++------------------------ nms/1_18_1/pom.xml | 42 ++++++++++++------------------------ nms/1_18_2/pom.xml | 42 ++++++++++++------------------------ 8 files changed, 92 insertions(+), 177 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 722bb53cb..1cfd2f5bf 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest name: 'Build' steps: - - name: Cache Paperclip Jars + - name: Cache Paper(clip) jars id: cache-paperclip-jars uses: actions/cache@v2 with: @@ -24,9 +24,8 @@ jobs: build paperclip ~/.m2/repository/io/papermc/paper - ~/.m2/repository/org/spigotmc key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-paperclip - - name: Download Paperclip Jars + - name: Download Paperclip jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p paperclip @@ -39,7 +38,7 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 - - name: Generate 1.14 - 1.16 Paper Jars + - name: Generate 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | cd paperclip/ @@ -49,7 +48,7 @@ jobs: java -jar paper-1.16.3.jar java -jar paper-1.16.4.jar cd ../ - - name: Install 1.14 - 1.16 Paper Jars + - name: Install 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | cd paperclip/ @@ -59,33 +58,18 @@ jobs: 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" cd ../ - - name: Set up JDK 16 - uses: actions/setup-java@v1 - with: - java-version: 16 - - name: Run BuildTools 1.17 - 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 - java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check - cd ../ - name: Set up JDK 17 uses: actions/setup-java@v1 with: java-version: 17 - - name: Run BuildTools 1.18 + - name: Run paper-nms init 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 - java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.18.1 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.18.2 --remapped --disable-java-check - cd ../ + 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 - uses: actions/checkout@v2 name: Checkout code - name: Build with Maven diff --git a/.gitignore b/.gitignore index 64169b5de..c78733736 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ IF-Test *.iml *.txt dependency-reduced-pom.xml -*.log \ No newline at end of file +*.log +.paper-nms \ No newline at end of file diff --git a/README.md b/README.md index c4924fcf2..ecb0884ad 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,8 @@ If you want to build this project from source, run the following: This will clone this repository to your device. This project relies on NMS, for which the dependencies are not available online. Because of this, you'll need to follow additional steps to obtain all these dependencies locally. -### Installing Paper -For versions 1.14-1.16, we use Paper. Run the following scripts for each version to install the dependencies locally. Running these commands generate additional files in the folder where you execute them. To ensure that you don't accidentallly overwrite other files, execute this in an empty folder. The files that get created can be deleted afterwards (either after installing a single version or after installing all of them), since they're no longer necessary. +### Installing Paper manually +For versions 1.14-1.16, we have to manually install Paper. Run the following scripts for each version to install the dependencies locally. Running these commands generate additional files in the folder where you execute them. To ensure that you don't accidentallly overwrite other files, execute this in an empty folder. The files that get created can be deleted afterwards (either after installing a single version or after installing all of them), since they're no longer necessary. #### 1.14.4 ``` @@ -124,15 +124,14 @@ java -jar paper-1.16.4.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" ``` -### Installing Spigot -For versions 1.17-1.18, we use Spigot. To install these versions locally, we use Spigot's BuildTools system. Using BuildTools will create additional files, so we recommend running the following in an empty folder. The files can be deleted afterwards. +### Installing Paper via the maven plugin +For versions 1.17-1.18, we use Paper via the [paper-nms-maven-plugin](https://github.com/Alvinn8/paper-nms-maven-plugin). To install these versions locally, we must run a few maven commands. These commands should be ran in the root directory of the project. ``` -wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar -java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.18.1 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.18.2 --remapped --disable-java-check +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 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 5290eac61..07005b1ae 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.17-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.17-SNAPSHOT provided @@ -35,38 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-obf - + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index b4b09522a..87fede8a2 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.17.1-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.17.1-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 964257a19..14cde080b 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.18-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.18-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.18-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 5cfbddf7e..c93d5f9b5 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.18-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.18.1-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 676b3dc4a..151e925ad 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.18.2-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.18.2-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file From b067329ac05d7a8f821153f114f7bcbc36a807f2 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:23:02 +0200 Subject: [PATCH 123/382] check out before running task --- .github/workflows/maven.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1cfd2f5bf..c90f00347 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -40,16 +40,16 @@ jobs: java-version: 11 - name: Generate 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + working-directory: paperclip run: | - cd paperclip/ 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 - cd ../ - name: Install 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + working-directory: paperclip run: | cd paperclip/ 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" @@ -62,6 +62,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 17 + - uses: actions/checkout@v2 + name: Checkout code - name: Run paper-nms init if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | @@ -70,7 +72,5 @@ jobs: 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 - - uses: actions/checkout@v2 - name: Checkout code - name: Build with Maven run: mvn -B package --file pom.xml From 4eeeed24ed78dfffdcedc89c5ae08c36460d682f Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:24:45 +0200 Subject: [PATCH 124/382] remove leftover cd... --- .github/workflows/maven.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c90f00347..586e1491f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -51,13 +51,11 @@ jobs: if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' working-directory: paperclip run: | - cd paperclip/ 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" - cd ../ - name: Set up JDK 17 uses: actions/setup-java@v1 with: From a8ee22bce05d9f47cf14b5deca2a6eec66fe2390 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:38:51 +0200 Subject: [PATCH 125/382] update to stable release --- 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 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 07005b1ae..3d5c9c3bc 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 87fede8a2..9d37adedf 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 14cde080b..3ae564f3b 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index c93d5f9b5..71acb1d58 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 151e925ad..7656dad23 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.2-SNAPSHOT + 1.2 process-classes From a4f7d1be27af63ea924d76a6f5d81fb67c93035d Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 13:56:12 +0200 Subject: [PATCH 126/382] cache paper-nms jars --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 586e1491f..21006883c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -24,6 +24,7 @@ jobs: 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' From 9afdc5158c20e746ebd9280e9514e0af20c8c5c4 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 17 May 2022 20:13:14 +0200 Subject: [PATCH 127/382] Don't support using the libraries section in the plugin.yml --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index ecb0884ad..75fa081fc 100644 --- a/README.md +++ b/README.md @@ -73,11 +73,7 @@ shadowJar { ``` ## Dependency via plugin.yml -You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. -```yaml -libraries: - - com.github.stefvanschie.inventoryframework:IF:0.10.5 -``` +IF does **not** support declaring the dependency via the libraries section in the plugin.yml. Please make use of a build tool as described above to use IF as a dependency. ## Building from source If you want to build this project from source, run the following: From 406099c12ca7e6aa586dcb03facb095771f3d85b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 19 May 2022 21:07:00 +0200 Subject: [PATCH 128/382] Fix cycle button not handling item clicks --- .../inventoryframework/pane/component/CycleButton.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java index 709d70284..93bc3c471 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java @@ -61,6 +61,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp return false; } + int previousPosition = position; + position++; if (position == panes.size()) { @@ -69,7 +71,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp callOnClick(event); - Pane pane = panes.get(position); + //use the previous position, since that will have the pane we clicked on + Pane pane = panes.get(previousPosition); pane.click(gui, inventoryComponent, event, slot, paneOffsetX + x, paneOffsetY + y, length, height); From ed0701832a6973d49ade826ae31fe967752f7a05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 05:19:40 +0000 Subject: [PATCH 129/382] Bump paper-nms-maven-plugin from 1.2 to 1.2.1 Bumps paper-nms-maven-plugin from 1.2 to 1.2.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- 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 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 3d5c9c3bc..99be8eda5 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.2 + 1.2.1 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 9d37adedf..8e14cc360 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.2 + 1.2.1 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 3ae564f3b..ee140c169 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.2 + 1.2.1 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 71acb1d58..c4c9fb64e 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.2 + 1.2.1 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 7656dad23..04a62c9bf 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.2 + 1.2.1 process-classes From 3e0a47d269ccab47b94d4eb332734e57d19705e1 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 2 May 2022 19:08:02 +0200 Subject: [PATCH 130/382] Add log files to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 77a4b1128..64169b5de 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ target IF-Test *.iml *.txt -dependency-reduced-pom.xml \ No newline at end of file +dependency-reduced-pom.xml +*.log \ No newline at end of file From b0e617ced8f1bfc0c9647a3894a53b0953738528 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 2 May 2022 19:11:24 +0200 Subject: [PATCH 131/382] Remove spurious log file --- hs_err_pid7296.log | 695 --------------------------------------------- 1 file changed, 695 deletions(-) delete mode 100644 hs_err_pid7296.log diff --git a/hs_err_pid7296.log b/hs_err_pid7296.log deleted file mode 100644 index de794618c..000000000 --- a/hs_err_pid7296.log +++ /dev/null @@ -1,695 +0,0 @@ -# -# There is insufficient memory for the Java Runtime Environment to continue. -# Native memory allocation (mmap) failed to map 23068672 bytes for G1 virtual space -# Possible reasons: -# The system is out of physical RAM or swap space -# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap -# Possible solutions: -# Reduce memory load on the system -# Increase physical memory or swap space -# Check if swap backing store is full -# Decrease Java heap size (-Xmx/-Xms) -# Decrease number of Java threads -# Decrease Java thread stack sizes (-Xss) -# Set larger code cache with -XX:ReservedCodeCacheSize= -# JVM is running with Unscaled Compressed Oops mode in which the Java heap is -# placed in the first 4GB address space. The Java Heap base address is the -# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress -# to set the Java Heap base and to place the Java Heap above 4GB virtual address. -# This output file may be truncated or incomplete. -# -# Out of Memory Error (os_windows.cpp:3469), pid=7296, tid=6840 -# -# JRE version: OpenJDK Runtime Environment Temurin-17.0.1+12 (17.0.1+12) (build 17.0.1+12) -# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (17.0.1+12, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) -# No core dump will be written. Minidumps are not enabled by default on client versions of Windows -# - ---------------- S U M M A R Y ------------ - -Command Line: -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\IF-parent -Dmaven.home=D:\Maven\apache-maven-3.8.4 -Dclassworlds.conf=D:\Maven\apache-maven-3.8.4\bin\m2.conf -Dmaven.ext.class.path=C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\plugins\maven\lib\maven-event-listener.jar -javaagent:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\lib\idea_rt.jar=52046:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin -Dfile.encoding=UTF-8 org.codehaus.classworlds.Launcher -Didea.version=2021.3.1 clean install - -Host: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz, 2 cores, 3G, Windows 7 , 64 bit Build 7601 (6.1.7601.24545) -Time: Thu Jan 13 20:33:50 2022 West-Europa (standaardtijd) elapsed time: 23.224401 seconds (0d 0h 0m 23s) - ---------------- T H R E A D --------------- - -Current thread (0x00000000003cf6e0): VMThread "VM Thread" [stack: 0x000000001ec60000,0x000000001ed60000] [id=6840] - -Stack: [0x000000001ec60000,0x000000001ed60000] -Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) -V [jvm.dll+0x6744da] -V [jvm.dll+0x82e144] -V [jvm.dll+0x82f8ee] -V [jvm.dll+0x82ff53] -V [jvm.dll+0x245175] -V [jvm.dll+0x6714c9] -V [jvm.dll+0x665f92] -V [jvm.dll+0x303c3b] -V [jvm.dll+0x30b176] -V [jvm.dll+0x35af1e] -V [jvm.dll+0x35b14f] -V [jvm.dll+0x2dab78] -V [jvm.dll+0x2d8e2c] -V [jvm.dll+0x2d83fc] -V [jvm.dll+0x31c571] -V [jvm.dll+0x8343bb] -V [jvm.dll+0x8350f4] -V [jvm.dll+0x83560c] -V [jvm.dll+0x8359e4] -V [jvm.dll+0x835ab0] -V [jvm.dll+0x7de51a] -V [jvm.dll+0x673305] -C [ucrtbase.DLL+0x1c1ae] -C [kernel32.dll+0x1556d] -C [ntdll.dll+0x5372d] - -VM_Operation (0x000000000201d6c0): G1TryInitiateConcMark, mode: safepoint, requested by thread 0x0000000000330310 - - ---------------- P R O C E S S --------------- - -Threads class SMR info: -_java_thread_list=0x000000002211ea80, length=13, elements={ -0x0000000000330310, 0x000000001e008760, 0x000000001e00a320, 0x000000001e0155a0, -0x000000001e017fd0, 0x000000001e018890, 0x000000001e01be50, 0x000000001e02b810, -0x000000001e02c5e0, 0x000000001e02db40, 0x000000001e2b29e0, 0x000000001ff0e910, -0x000000001ff0ede0 -} - -Java Threads: ( => current thread ) - 0x0000000000330310 JavaThread "main" [_thread_blocked, id=7316, stack(0x0000000001f20000,0x0000000002020000)] - 0x000000001e008760 JavaThread "Reference Handler" daemon [_thread_blocked, id=7392, stack(0x000000001ef50000,0x000000001f050000)] - 0x000000001e00a320 JavaThread "Finalizer" daemon [_thread_blocked, id=9184, stack(0x000000001f0d0000,0x000000001f1d0000)] - 0x000000001e0155a0 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=6976, stack(0x000000001f240000,0x000000001f340000)] - 0x000000001e017fd0 JavaThread "Attach Listener" daemon [_thread_blocked, id=8308, stack(0x000000001ed90000,0x000000001ee90000)] - 0x000000001e018890 JavaThread "Service Thread" daemon [_thread_blocked, id=8888, stack(0x000000001f460000,0x000000001f560000)] - 0x000000001e01be50 JavaThread "Monitor Deflation Thread" daemon [_thread_blocked, id=7452, stack(0x000000001f710000,0x000000001f810000)] - 0x000000001e02b810 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=4884, stack(0x000000001f8d0000,0x000000001f9d0000)] - 0x000000001e02c5e0 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=3892, stack(0x000000001fa40000,0x000000001fb40000)] - 0x000000001e02db40 JavaThread "Sweeper thread" daemon [_thread_blocked, id=6812, stack(0x000000001fbf0000,0x000000001fcf0000)] - 0x000000001e2b29e0 JavaThread "Common-Cleaner" daemon [_thread_blocked, id=1620, stack(0x000000001fdc0000,0x000000001fec0000)] - 0x000000001ff0e910 JavaThread "Monitor Ctrl-Break" daemon [_thread_in_native, id=7928, stack(0x0000000020370000,0x0000000020470000)] - 0x000000001ff0ede0 JavaThread "Notification Thread" daemon [_thread_blocked, id=5888, stack(0x000000001f590000,0x000000001f690000)] - -Other Threads: -=>0x00000000003cf6e0 VMThread "VM Thread" [stack: 0x000000001ec60000,0x000000001ed60000] [id=6840] - 0x000000001ff0f2b0 WatcherThread [stack: 0x000000001f350000,0x000000001f450000] [id=6304] - 0x0000000000363b00 GCTaskThread "GC Thread#0" [stack: 0x000000001b840000,0x000000001b940000] [id=6244] - 0x000000002017f2f0 GCTaskThread "GC Thread#1" [stack: 0x00000000206d0000,0x00000000207d0000] [id=9012] - 0x00000000003701d0 ConcurrentGCThread "G1 Main Marker" [stack: 0x000000001b980000,0x000000001ba80000] [id=1036] - 0x0000000000370af0 ConcurrentGCThread "G1 Conc#0" [stack: 0x000000001bb20000,0x000000001bc20000] [id=8296] - 0x00000000003b0cd0 ConcurrentGCThread "G1 Refine#0" [stack: 0x000000001de60000,0x000000001df60000] [id=4868] - 0x00000000003b1600 ConcurrentGCThread "G1 Service" [stack: 0x000000001e070000,0x000000001e170000] [id=6240] - -Threads with active compile tasks: - -VM state: at safepoint (normal execution) - -VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) -[0x000000000032ade0] Threads_lock - owner thread: 0x00000000003cf6e0 -[0x000000000032b410] Heap_lock - owner thread: 0x0000000000330310 - -Heap address: 0x00000000c1a00000, size: 998 MB, Compressed Oops mode: 32-bit - -CDS archive(s) mapped at: [0x0000000800000000-0x0000000800bc0000-0x0000000800bc0000), size 12320768, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 0. -Compressed class space mapped at: 0x0000000800c00000-0x0000000840c00000, reserved size: 1073741824 -Narrow klass base: 0x0000000800000000, Narrow klass shift: 0, Narrow klass range: 0x100000000 - -GC Precious Log: - CPUs: 2 total, 2 available - Memory: 3991M - Large Page Support: Disabled - NUMA Support: Disabled - Compressed Oops: Enabled (32-bit) - Heap Region Size: 1M - Heap Min Capacity: 8M - Heap Initial Capacity: 64M - Heap Max Capacity: 998M - Pre-touch: Disabled - Parallel Workers: 2 - Concurrent Workers: 1 - Concurrent Refinement Workers: 2 - Periodic GC: Disabled - -Heap: - garbage-first heap total 78848K, used 39429K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 2 young (2048K), 2 survivors (2048K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K - -Heap Regions: E=young(eden), S=young(survivor), O=old, HS=humongous(starts), HC=humongous(continues), CS=collection set, F=free, OA=open archive, CA=closed archive, TAMS=top-at-mark-start (previous, next) -| 0|0x00000000c1a00000, 0x00000000c1b00000, 0x00000000c1b00000|100%| O| |TAMS 0x00000000c1b00000, 0x00000000c1b00000| Untracked -| 1|0x00000000c1b00000, 0x00000000c1c00000, 0x00000000c1c00000|100%| O| |TAMS 0x00000000c1c00000, 0x00000000c1c00000| Untracked -| 2|0x00000000c1c00000, 0x00000000c1d00000, 0x00000000c1d00000|100%| O| |TAMS 0x00000000c1d00000, 0x00000000c1d00000| Untracked -| 3|0x00000000c1d00000, 0x00000000c1e00000, 0x00000000c1e00000|100%| O| |TAMS 0x00000000c1e00000, 0x00000000c1e00000| Untracked -| 4|0x00000000c1e00000, 0x00000000c1f00000, 0x00000000c1f00000|100%| O| |TAMS 0x00000000c1f00000, 0x00000000c1f00000| Untracked -| 5|0x00000000c1f00000, 0x00000000c2000000, 0x00000000c2000000|100%| O| |TAMS 0x00000000c2000000, 0x00000000c2000000| Untracked -| 6|0x00000000c2000000, 0x00000000c2100000, 0x00000000c2100000|100%| O| |TAMS 0x00000000c2100000, 0x00000000c2100000| Untracked -| 7|0x00000000c2100000, 0x00000000c2200000, 0x00000000c2200000|100%| O| |TAMS 0x00000000c2200000, 0x00000000c2200000| Untracked -| 8|0x00000000c2200000, 0x00000000c2300000, 0x00000000c2300000|100%| O| |TAMS 0x00000000c2300000, 0x00000000c2300000| Untracked -| 9|0x00000000c2300000, 0x00000000c2400000, 0x00000000c2400000|100%| O| |TAMS 0x00000000c2400000, 0x00000000c2400000| Untracked -| 10|0x00000000c2400000, 0x00000000c2500000, 0x00000000c2500000|100%| O| |TAMS 0x00000000c2500000, 0x00000000c2500000| Untracked -| 11|0x00000000c2500000, 0x00000000c2600000, 0x00000000c2600000|100%| O| |TAMS 0x00000000c2600000, 0x00000000c2600000| Untracked -| 12|0x00000000c2600000, 0x00000000c2700000, 0x00000000c2700000|100%| O| |TAMS 0x00000000c2700000, 0x00000000c2700000| Untracked -| 13|0x00000000c2700000, 0x00000000c2800000, 0x00000000c2800000|100%| O| |TAMS 0x00000000c2800000, 0x00000000c2800000| Untracked -| 14|0x00000000c2800000, 0x00000000c2900000, 0x00000000c2900000|100%| O| |TAMS 0x00000000c2900000, 0x00000000c2900000| Untracked -| 15|0x00000000c2900000, 0x00000000c2a00000, 0x00000000c2a00000|100%| O| |TAMS 0x00000000c2a00000, 0x00000000c2a00000| Untracked -| 16|0x00000000c2a00000, 0x00000000c2b00000, 0x00000000c2b00000|100%| O| |TAMS 0x00000000c2b00000, 0x00000000c2b00000| Untracked -| 17|0x00000000c2b00000, 0x00000000c2bef600, 0x00000000c2c00000| 93%| O| |TAMS 0x00000000c2bef600, 0x00000000c2bef600| Untracked -| 18|0x00000000c2c00000, 0x00000000c2d00000, 0x00000000c2d00000|100%| O| |TAMS 0x00000000c2c00000, 0x00000000c2d00000| Untracked -| 19|0x00000000c2d00000, 0x00000000c2e00000, 0x00000000c2e00000|100%| O| |TAMS 0x00000000c2d00000, 0x00000000c2e00000| Untracked -| 20|0x00000000c2e00000, 0x00000000c2f00000, 0x00000000c2f00000|100%| O| |TAMS 0x00000000c2e00000, 0x00000000c2f00000| Untracked -| 21|0x00000000c2f00000, 0x00000000c3000000, 0x00000000c3000000|100%|HS| |TAMS 0x00000000c2f00000, 0x00000000c3000000| Complete -| 22|0x00000000c3000000, 0x00000000c3100000, 0x00000000c3100000|100%|HC| |TAMS 0x00000000c3000000, 0x00000000c3100000| Complete -| 23|0x00000000c3100000, 0x00000000c3200000, 0x00000000c3200000|100%|HC| |TAMS 0x00000000c3100000, 0x00000000c3200000| Complete -| 24|0x00000000c3200000, 0x00000000c3300000, 0x00000000c3300000|100%|HC| |TAMS 0x00000000c3200000, 0x00000000c3300000| Complete -| 25|0x00000000c3300000, 0x00000000c3400000, 0x00000000c3400000|100%|HC| |TAMS 0x00000000c3300000, 0x00000000c3400000| Complete -| 26|0x00000000c3400000, 0x00000000c3500000, 0x00000000c3500000|100%| O| |TAMS 0x00000000c3400000, 0x00000000c3500000| Untracked -| 27|0x00000000c3500000, 0x00000000c3600000, 0x00000000c3600000|100%| O| |TAMS 0x00000000c3500000, 0x00000000c3600000| Untracked -| 28|0x00000000c3600000, 0x00000000c3700000, 0x00000000c3700000|100%|HS| |TAMS 0x00000000c3600000, 0x00000000c3700000| Complete -| 29|0x00000000c3700000, 0x00000000c3800000, 0x00000000c3800000|100%|HC| |TAMS 0x00000000c3700000, 0x00000000c3800000| Complete -| 30|0x00000000c3800000, 0x00000000c3900000, 0x00000000c3900000|100%|HC| |TAMS 0x00000000c3800000, 0x00000000c3900000| Complete -| 31|0x00000000c3900000, 0x00000000c3a00000, 0x00000000c3a00000|100%|HC| |TAMS 0x00000000c3900000, 0x00000000c3a00000| Complete -| 32|0x00000000c3a00000, 0x00000000c3b00000, 0x00000000c3b00000|100%|HC| |TAMS 0x00000000c3a00000, 0x00000000c3b00000| Complete -| 33|0x00000000c3b00000, 0x00000000c3b00000, 0x00000000c3c00000| 0%| F| |TAMS 0x00000000c3b00000, 0x00000000c3b00000| Untracked -| 34|0x00000000c3c00000, 0x00000000c3d00000, 0x00000000c3d00000|100%| O| |TAMS 0x00000000c3c00000, 0x00000000c3d00000| Untracked -| 35|0x00000000c3d00000, 0x00000000c3e00000, 0x00000000c3e00000|100%| O| |TAMS 0x00000000c3d00000, 0x00000000c3e00000| Untracked -| 36|0x00000000c3e00000, 0x00000000c3f00000, 0x00000000c3f00000|100%| O| |TAMS 0x00000000c3e00000, 0x00000000c3f00000| Untracked -| 37|0x00000000c3f00000, 0x00000000c3ffd600, 0x00000000c4000000| 98%| O| |TAMS 0x00000000c3f00000, 0x00000000c3ffd600| Untracked -| 38|0x00000000c4000000, 0x00000000c4000000, 0x00000000c4100000| 0%| F| |TAMS 0x00000000c4000000, 0x00000000c4000000| Untracked -| 39|0x00000000c4100000, 0x00000000c4100000, 0x00000000c4200000| 0%| F| |TAMS 0x00000000c4100000, 0x00000000c4100000| Untracked -| 40|0x00000000c4200000, 0x00000000c4200000, 0x00000000c4300000| 0%| F| |TAMS 0x00000000c4200000, 0x00000000c4200000| Untracked -| 41|0x00000000c4300000, 0x00000000c4300000, 0x00000000c4400000| 0%| F| |TAMS 0x00000000c4300000, 0x00000000c4300000| Untracked -| 42|0x00000000c4400000, 0x00000000c4400000, 0x00000000c4500000| 0%| F| |TAMS 0x00000000c4400000, 0x00000000c4400000| Untracked -| 43|0x00000000c4500000, 0x00000000c4500000, 0x00000000c4600000| 0%| F| |TAMS 0x00000000c4500000, 0x00000000c4500000| Untracked -| 44|0x00000000c4600000, 0x00000000c4600000, 0x00000000c4700000| 0%| F| |TAMS 0x00000000c4600000, 0x00000000c4600000| Untracked -| 45|0x00000000c4700000, 0x00000000c4700000, 0x00000000c4800000| 0%| F| |TAMS 0x00000000c4700000, 0x00000000c4700000| Untracked -| 46|0x00000000c4800000, 0x00000000c4800000, 0x00000000c4900000| 0%| F| |TAMS 0x00000000c4800000, 0x00000000c4800000| Untracked -| 47|0x00000000c4900000, 0x00000000c4900000, 0x00000000c4a00000| 0%| F| |TAMS 0x00000000c4900000, 0x00000000c4900000| Untracked -| 48|0x00000000c4a00000, 0x00000000c4a00000, 0x00000000c4b00000| 0%| F| |TAMS 0x00000000c4a00000, 0x00000000c4a00000| Untracked -| 49|0x00000000c4b00000, 0x00000000c4b00000, 0x00000000c4c00000| 0%| F| |TAMS 0x00000000c4b00000, 0x00000000c4b00000| Untracked -| 50|0x00000000c4c00000, 0x00000000c4c00000, 0x00000000c4d00000| 0%| F| |TAMS 0x00000000c4c00000, 0x00000000c4c00000| Untracked -| 51|0x00000000c4d00000, 0x00000000c4d00000, 0x00000000c4e00000| 0%| F| |TAMS 0x00000000c4d00000, 0x00000000c4d00000| Untracked -| 52|0x00000000c4e00000, 0x00000000c4e00000, 0x00000000c4f00000| 0%| F| |TAMS 0x00000000c4e00000, 0x00000000c4e00000| Untracked -| 53|0x00000000c4f00000, 0x00000000c4f00000, 0x00000000c5000000| 0%| F| |TAMS 0x00000000c4f00000, 0x00000000c4f00000| Untracked -| 54|0x00000000c5000000, 0x00000000c5000000, 0x00000000c5100000| 0%| F| |TAMS 0x00000000c5000000, 0x00000000c5000000| Untracked -| 55|0x00000000c5100000, 0x00000000c5100000, 0x00000000c5200000| 0%| F| |TAMS 0x00000000c5100000, 0x00000000c5100000| Untracked -| 56|0x00000000c5200000, 0x00000000c5200000, 0x00000000c5300000| 0%| F| |TAMS 0x00000000c5200000, 0x00000000c5200000| Untracked -| 57|0x00000000c5300000, 0x00000000c5300000, 0x00000000c5400000| 0%| F| |TAMS 0x00000000c5300000, 0x00000000c5300000| Untracked -| 58|0x00000000c5400000, 0x00000000c5400000, 0x00000000c5500000| 0%| F| |TAMS 0x00000000c5400000, 0x00000000c5400000| Untracked -| 59|0x00000000c5500000, 0x00000000c5500000, 0x00000000c5600000| 0%| F| |TAMS 0x00000000c5500000, 0x00000000c5500000| Untracked -| 60|0x00000000c5600000, 0x00000000c5600000, 0x00000000c5700000| 0%| F| |TAMS 0x00000000c5600000, 0x00000000c5600000| Untracked -| 61|0x00000000c5700000, 0x00000000c5700000, 0x00000000c5800000| 0%| F| |TAMS 0x00000000c5700000, 0x00000000c5700000| Untracked -| 62|0x00000000c5800000, 0x00000000c5800000, 0x00000000c5900000| 0%| F| |TAMS 0x00000000c5800000, 0x00000000c5800000| Untracked -| 63|0x00000000c5900000, 0x00000000c5900000, 0x00000000c5a00000| 0%| F| |TAMS 0x00000000c5900000, 0x00000000c5900000| Untracked -| 64|0x00000000c5a00000, 0x00000000c5a00000, 0x00000000c5b00000| 0%| F| |TAMS 0x00000000c5a00000, 0x00000000c5a00000| Untracked -| 65|0x00000000c5b00000, 0x00000000c5b00000, 0x00000000c5c00000| 0%| F| |TAMS 0x00000000c5b00000, 0x00000000c5b00000| Untracked -| 66|0x00000000c5c00000, 0x00000000c5c00000, 0x00000000c5d00000| 0%| F| |TAMS 0x00000000c5c00000, 0x00000000c5c00000| Untracked -| 67|0x00000000c5d00000, 0x00000000c5d00000, 0x00000000c5e00000| 0%| F| |TAMS 0x00000000c5d00000, 0x00000000c5d00000| Untracked -| 68|0x00000000c5e00000, 0x00000000c5e00000, 0x00000000c5f00000| 0%| F| |TAMS 0x00000000c5e00000, 0x00000000c5e00000| Untracked -| 69|0x00000000c5f00000, 0x00000000c5f00000, 0x00000000c6000000| 0%| F| |TAMS 0x00000000c5f00000, 0x00000000c5f00000| Untracked -| 70|0x00000000c6000000, 0x00000000c6000000, 0x00000000c6100000| 0%| F| |TAMS 0x00000000c6000000, 0x00000000c6000000| Untracked -| 71|0x00000000c6100000, 0x00000000c6100000, 0x00000000c6200000| 0%| F| |TAMS 0x00000000c6100000, 0x00000000c6100000| Untracked -| 72|0x00000000c6200000, 0x00000000c6200000, 0x00000000c6300000| 0%| F| |TAMS 0x00000000c6200000, 0x00000000c6200000| Untracked -| 73|0x00000000c6300000, 0x00000000c6300000, 0x00000000c6400000| 0%| F| |TAMS 0x00000000c6300000, 0x00000000c6300000| Untracked -| 74|0x00000000c6400000, 0x00000000c64948f0, 0x00000000c6500000| 58%| S|CS|TAMS 0x00000000c6400000, 0x00000000c6400000| Complete -| 75|0x00000000c6500000, 0x00000000c6600000, 0x00000000c6600000|100%| S|CS|TAMS 0x00000000c6500000, 0x00000000c6500000| Complete -| 76|0x00000000c6600000, 0x00000000c6600000, 0x00000000c6700000| 0%| F| |TAMS 0x00000000c6600000, 0x00000000c6600000| Untracked - -Card table byte_map: [0x0000000019420000,0x0000000019620000] _byte_map_base: 0x0000000018e13000 - -Marking Bits (Prev, Next): (CMBitMap*) 0x0000000000366020, (CMBitMap*) 0x0000000000366060 - Prev Bits: [0x0000000019820000, 0x000000001a7b8000) - Next Bits: [0x000000001a7c0000, 0x000000001b758000) - -Polling page: 0x00000000000a0000 - -Metaspace: - -Usage: - Non-class: 27.97 MB used. - Class: 3.68 MB used. - Both: 31.64 MB used. - -Virtual space: - Non-class space: 32.00 MB reserved, 28.19 MB ( 88%) committed, 4 nodes. - Class space: 1.00 GB reserved, 3.88 MB ( <1%) committed, 1 nodes. - Both: 1.03 GB reserved, 32.06 MB ( 3%) committed. - -Chunk freelists: - Non-Class: 2.98 MB - Class: 32.00 KB - Both: 3.02 MB - -MaxMetaspaceSize: unlimited -CompressedClassSpaceSize: 1.00 GB -Initial GC threshold: 21.00 MB -Current GC threshold: 49.63 MB -CDS: on -MetaspaceReclaimPolicy: balanced - - commit_granule_bytes: 65536. - - commit_granule_words: 8192. - - virtual_space_node_default_size: 1048576. - - enlarge_chunks_in_place: 1. - - new_chunks_are_fully_committed: 0. - - uncommit_free_chunks: 1. - - use_allocation_guard: 0. - - handle_deallocations: 1. - - -Internal statistics: - -num_allocs_failed_limit: 6. -num_arena_births: 204. -num_arena_deaths: 0. -num_vsnodes_births: 5. -num_vsnodes_deaths: 0. -num_space_committed: 513. -num_space_uncommitted: 0. -num_chunks_returned_to_freelist: 6. -num_chunks_taken_from_freelist: 1389. -num_chunk_merges: 6. -num_chunk_splits: 1009. -num_chunks_enlarged: 803. -num_purges: 0. -num_inconsistent_stats: 0. - -CodeHeap 'non-profiled nmethods': size=120064Kb used=2809Kb max_used=3011Kb free=117254Kb - bounds [0x00000000119d0000, 0x0000000011cd0000, 0x0000000018f10000] -CodeHeap 'profiled nmethods': size=120000Kb used=12119Kb max_used=12447Kb free=107880Kb - bounds [0x000000000a4a0000, 0x000000000b0d0000, 0x00000000119d0000] -CodeHeap 'non-nmethods': size=5696Kb used=1220Kb max_used=1262Kb free=4475Kb - bounds [0x0000000009f10000, 0x000000000a180000, 0x000000000a4a0000] - total_blobs=6237 nmethods=5706 adapters=442 - compilation: enabled - stopped_count=0, restarted_count=0 - full_count=0 - -Compilation events (20 events): -Event: 22.690 Thread 0x000000001e02c5e0 nmethod 6540 0x000000000abdb590 code [0x000000000abdb800, 0x000000000abdc5a8] -Event: 22.985 Thread 0x000000001e02b810 nmethod 6362 0x0000000011cc0e90 code [0x0000000011cc1360, 0x0000000011cc87e0] -Event: 22.985 Thread 0x000000001e02b810 6413 4 java.util.regex.Pattern$Start::match (90 bytes) -Event: 22.992 Thread 0x000000001e02b810 nmethod 6413 0x0000000011bded90 code [0x0000000011bdef60, 0x0000000011bdf588] -Event: 22.992 Thread 0x000000001e02b810 6357 4 org.eclipse.sisu.bean.DeclaredMembers$MemberIterator::hasNext (96 bytes) -Event: 23.058 Thread 0x000000001e02b810 nmethod 6357 0x0000000011b3c710 code [0x0000000011b3c9e0, 0x0000000011b3ed70] -Event: 23.102 Thread 0x000000001e02b810 6541 4 java.util.StringTokenizer::skipDelimiters (116 bytes) -Event: 23.102 Thread 0x000000001e02c5e0 6542 3 java.lang.String::substring (58 bytes) -Event: 23.103 Thread 0x000000001e02c5e0 nmethod 6542 0x000000000abdad10 code [0x000000000abdaf00, 0x000000000abdb3a8] -Event: 23.103 Thread 0x000000001e02c5e0 6544 3 org.codehaus.plexus.util.SelectorUtils::match (520 bytes) -Event: 23.104 Thread 0x000000001e02c5e0 nmethod 6544 0x000000000abcf910 code [0x000000000abcfc20, 0x000000000abd10b8] -Event: 23.105 Thread 0x000000001e02c5e0 6545 3 org.codehaus.plexus.util.SelectorUtils::equals (37 bytes) -Event: 23.105 Thread 0x000000001e02c5e0 nmethod 6545 0x000000000abda790 code [0x000000000abda960, 0x000000000abdac18] -Event: 23.108 Thread 0x000000001e02b810 nmethod 6541 0x0000000011bde590 code [0x0000000011bde720, 0x0000000011bdea68] -Event: 23.108 Thread 0x000000001e02b810 6543 4 java.lang.String::toCharArray (25 bytes) -Event: 23.109 Thread 0x000000001e02b810 nmethod 6543 0x0000000011a7cf10 code [0x0000000011a7d0a0, 0x0000000011a7d228] -Event: 23.134 Thread 0x000000001e02b810 6546 4 org.codehaus.plexus.classworlds.realm.ClassRealm::findClass (9 bytes) -Event: 23.135 Thread 0x000000001e02b810 nmethod 6546 0x0000000011b3c210 code [0x0000000011b3c3a0, 0x0000000011b3c488] -Event: 23.141 Thread 0x000000001e02b810 6547 4 java.lang.ReflectiveOperationException:: (7 bytes) -Event: 23.146 Thread 0x000000001e02b810 nmethod 6547 0x0000000011b3a890 code [0x0000000011b3aa20, 0x0000000011b3b148] - -GC Heap History (20 events): -Event: 5.477 GC heap after -{Heap after GC invocations=4 (full 0): - garbage-first heap total 65536K, used 5815K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 4 survivors (4096K) - Metaspace used 10438K, committed 10560K, reserved 1064960K - class space used 1266K, committed 1344K, reserved 1048576K -} -Event: 8.029 GC heap before -{Heap before GC invocations=4 (full 0): - garbage-first heap total 65536K, used 40631K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 38 young (38912K), 4 survivors (4096K) - Metaspace used 12980K, committed 13184K, reserved 1064960K - class space used 1483K, committed 1600K, reserved 1048576K -} -Event: 8.074 GC heap after -{Heap after GC invocations=5 (full 0): - garbage-first heap total 65536K, used 8479K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 5 young (5120K), 5 survivors (5120K) - Metaspace used 12980K, committed 13184K, reserved 1064960K - class space used 1483K, committed 1600K, reserved 1048576K -} -Event: 9.632 GC heap before -{Heap before GC invocations=5 (full 0): - garbage-first heap total 65536K, used 42271K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 38 young (38912K), 5 survivors (5120K) - Metaspace used 14458K, committed 14656K, reserved 1064960K - class space used 1630K, committed 1728K, reserved 1048576K -} -Event: 9.709 GC heap after -{Heap after GC invocations=6 (full 0): - garbage-first heap total 78848K, used 11039K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 3 young (3072K), 3 survivors (3072K) - Metaspace used 14458K, committed 14656K, reserved 1064960K - class space used 1630K, committed 1728K, reserved 1048576K -} -Event: 11.260 GC heap before -{Heap before GC invocations=6 (full 0): - garbage-first heap total 78848K, used 55071K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 46 young (47104K), 3 survivors (3072K) - Metaspace used 15669K, committed 15872K, reserved 1064960K - class space used 1757K, committed 1856K, reserved 1048576K -} -Event: 11.302 GC heap after -{Heap after GC invocations=7 (full 0): - garbage-first heap total 78848K, used 14858K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 6 young (6144K), 6 survivors (6144K) - Metaspace used 15669K, committed 15872K, reserved 1064960K - class space used 1757K, committed 1856K, reserved 1048576K -} -Event: 12.807 GC heap before -{Heap before GC invocations=7 (full 0): - garbage-first heap total 78848K, used 55818K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 46 young (47104K), 6 survivors (6144K) - Metaspace used 16824K, committed 17088K, reserved 1064960K - class space used 1911K, committed 2048K, reserved 1048576K -} -Event: 12.875 GC heap after -{Heap after GC invocations=8 (full 0): - garbage-first heap total 78848K, used 17332K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 3 young (3072K), 3 survivors (3072K) - Metaspace used 16824K, committed 17088K, reserved 1064960K - class space used 1911K, committed 2048K, reserved 1048576K -} -Event: 14.388 GC heap before -{Heap before GC invocations=8 (full 0): - garbage-first heap total 78848K, used 59316K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 44 young (45056K), 3 survivors (3072K) - Metaspace used 17217K, committed 17472K, reserved 1064960K - class space used 1940K, committed 2048K, reserved 1048576K -} -Event: 14.397 GC heap after -{Heap after GC invocations=9 (full 0): - garbage-first heap total 78848K, used 18681K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 4 survivors (4096K) - Metaspace used 17217K, committed 17472K, reserved 1064960K - class space used 1940K, committed 2048K, reserved 1048576K -} -Event: 15.637 GC heap before -{Heap before GC invocations=9 (full 0): - garbage-first heap total 78848K, used 60665K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 45 young (46080K), 4 survivors (4096K) - Metaspace used 19580K, committed 19904K, reserved 1073152K - class space used 2274K, committed 2432K, reserved 1048576K -} -Event: 15.650 GC heap after -{Heap after GC invocations=10 (full 0): - garbage-first heap total 78848K, used 21046K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 5 young (5120K), 5 survivors (5120K) - Metaspace used 19580K, committed 19904K, reserved 1073152K - class space used 2274K, committed 2432K, reserved 1048576K -} -Event: 18.749 GC heap before -{Heap before GC invocations=10 (full 0): - garbage-first heap total 78848K, used 56886K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 41 young (41984K), 5 survivors (5120K) - Metaspace used 21245K, committed 21504K, reserved 1073152K - class space used 2475K, committed 2624K, reserved 1048576K -} -Event: 18.774 GC heap after -{Heap after GC invocations=11 (full 0): - garbage-first heap total 78848K, used 22461K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 4 survivors (4096K) - Metaspace used 21245K, committed 21504K, reserved 1073152K - class space used 2475K, committed 2624K, reserved 1048576K -} -Event: 20.888 GC heap before -{Heap before GC invocations=12 (full 0): - garbage-first heap total 78848K, used 62397K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 43 young (44032K), 4 survivors (4096K) - Metaspace used 30147K, committed 30464K, reserved 1081344K - class space used 3504K, committed 3648K, reserved 1048576K -} -Event: 20.919 GC heap after -{Heap after GC invocations=13 (full 0): - garbage-first heap total 78848K, used 27581K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 6 young (6144K), 6 survivors (6144K) - Metaspace used 30147K, committed 30464K, reserved 1081344K - class space used 3504K, committed 3648K, reserved 1048576K -} -Event: 23.155 GC heap before -{Heap before GC invocations=14 (full 0): - garbage-first heap total 78848K, used 64445K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 38 young (38912K), 6 survivors (6144K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K -} -Event: 23.188 GC heap after -{Heap after GC invocations=15 (full 0): - garbage-first heap total 78848K, used 34803K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 3 young (3072K), 3 survivors (3072K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K -} -Event: 23.194 GC heap before -{Heap before GC invocations=15 (full 0): - garbage-first heap total 78848K, used 39923K [0x00000000c1a00000, 0x0000000100000000) - region size 1024K, 4 young (4096K), 3 survivors (3072K) - Metaspace used 32402K, committed 32832K, reserved 1081344K - class space used 3764K, committed 3968K, reserved 1048576K -} - -Deoptimization events (20 events): -Event: 22.652 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.652 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.652 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 -Event: 22.652 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 -Event: 22.652 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.652 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 -Event: 22.653 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.653 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011b918c4 relative=0x00000000000004a4 -Event: 22.653 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011b918c4 method=java.util.Hashtable.get(Ljava/lang/Object;)Ljava/lang/Object; @ 6 c2 -Event: 22.653 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011b918c4 sp=0x000000000201de70 -Event: 22.653 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de20 mode 2 -Event: 22.655 Thread 0x0000000000330310 DEOPT PACKING pc=0x000000000aee0488 sp=0x000000000201ddb0 -Event: 22.655 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f62b24 sp=0x000000000201d250 mode 0 -Event: 23.097 Thread 0x0000000000330310 Uncommon trap: trap_request=0xffffffde fr.pc=0x0000000011c49d84 relative=0x0000000000006844 -Event: 23.097 Thread 0x0000000000330310 Uncommon trap: reason=class_check action=maybe_recompile pc=0x0000000011c49d84 method=org.apache.maven.model.BuildBase.clone()Lorg/apache/maven/model/BuildBase; @ 30 c2 -Event: 23.097 Thread 0x0000000000330310 DEOPT PACKING pc=0x0000000011c49d84 sp=0x000000000201df00 -Event: 23.097 Thread 0x0000000000330310 DEOPT UNPACKING pc=0x0000000009f6239d sp=0x000000000201de40 mode 2 - -Classes unloaded (0 events): -No events - -Classes redefined (0 events): -No events - -Internal exceptions (20 events): -Event: 20.625 Thread 0x0000000000330310 Exception (0x00000000c45a8618) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.626 Thread 0x0000000000330310 Exception (0x00000000c45a88b8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.626 Thread 0x0000000000330310 Exception (0x00000000c45a9530) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.636 Thread 0x0000000000330310 Exception (0x00000000c45b4b10) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.652 Thread 0x0000000000330310 Exception (0x00000000c45caf28) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45cb248) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45ce348) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.653 Thread 0x0000000000330310 Exception (0x00000000c45ce5a8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.654 Thread 0x0000000000330310 Exception (0x00000000c45d2e38) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.655 Thread 0x0000000000330310 Exception (0x00000000c45d3150) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.667 Thread 0x0000000000330310 Exception (0x00000000c45f7150) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 20.670 Thread 0x0000000000330310 Exception (0x00000000c4402b40) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 20.671 Thread 0x0000000000330310 Exception (0x00000000c4407470) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 20.719 Thread 0x0000000000330310 Exception (0x00000000c4472ab8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.744 Thread 0x0000000000330310 Exception (0x00000000c449aaa8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 20.792 Thread 0x0000000000330310 Exception (0x00000000c43061b8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\prims\jni.cpp, line 516] -Event: 21.266 Thread 0x0000000000330310 Exception (0x00000000c5622c28) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 862] -Event: 21.659 Thread 0x0000000020139240 Exception (0x00000000c534a4a8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 21.659 Thread 0x0000000020139240 Exception (0x00000000c5350be8) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] -Event: 21.660 Thread 0x0000000020139240 Exception (0x00000000c5354758) -thrown [e:\jenkins\tmp\workspace\build\src\src\hotspot\share\interpreter\linkResolver.cpp, line 766] - -VM Operations (20 events): -Event: 20.640 Executing VM operation: ICBufferFull done -Event: 20.717 Executing VM operation: HandshakeAllThreads -Event: 20.717 Executing VM operation: HandshakeAllThreads done -Event: 20.813 Executing VM operation: ICBufferFull -Event: 20.826 Executing VM operation: ICBufferFull done -Event: 20.888 Executing VM operation: G1CollectForAllocation -Event: 20.919 Executing VM operation: G1CollectForAllocation done -Event: 21.015 Executing VM operation: G1Concurrent -Event: 21.031 Executing VM operation: G1Concurrent done -Event: 21.069 Executing VM operation: G1Concurrent -Event: 21.069 Executing VM operation: G1Concurrent done -Event: 21.247 Executing VM operation: HandshakeAllThreads -Event: 21.247 Executing VM operation: HandshakeAllThreads done -Event: 22.271 Executing VM operation: Cleanup -Event: 22.633 Executing VM operation: Cleanup done -Event: 22.881 Executing VM operation: HandshakeAllThreads -Event: 22.881 Executing VM operation: HandshakeAllThreads done -Event: 23.155 Executing VM operation: G1CollectForAllocation -Event: 23.189 Executing VM operation: G1CollectForAllocation done -Event: 23.194 Executing VM operation: G1TryInitiateConcMark - -Events (20 events): -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$Transferer -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$Transferer done -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$TransferStack done -Event: 21.661 loading class java/util/concurrent/SynchronousQueue$TransferStack$SNode -Event: 21.661 loading class java/util/concurrent/ForkJoinPool$ManagedBlocker -Event: 21.662 loading class java/util/concurrent/ForkJoinPool$ManagedBlocker done -Event: 21.662 loading class java/util/concurrent/SynchronousQueue$TransferStack$SNode done -Event: 21.662 Thread 0x0000000020139240 Thread exited: 0x0000000020139240 -Event: 22.177 loading class java/util/Vector$Itr -Event: 22.177 loading class java/util/Vector$Itr done -Event: 22.193 loading class java/util/zip/Deflater -Event: 22.194 loading class java/util/zip/Deflater done -Event: 22.194 loading class java/util/zip/Deflater$DeflaterZStreamRef -Event: 22.194 loading class java/util/zip/Deflater$DeflaterZStreamRef done -Event: 22.197 loading class java/util/Vector$1 -Event: 22.197 loading class java/util/Vector$1 done -Event: 22.200 loading class java/io/DataOutputStream -Event: 22.625 loading class java/io/DataOutputStream done -Event: 23.139 loading class java/io/SequenceInputStream -Event: 23.139 loading class java/io/SequenceInputStream done - - -Dynamic libraries: -0x000000013f0d0000 - 0x000000013f0de000 C:\Program Files\Java\jdk-17\bin\java.exe -0x0000000077450000 - 0x00000000775ef000 C:\Windows\SYSTEM32\ntdll.dll -0x0000000077230000 - 0x000000007734f000 C:\Windows\system32\kernel32.dll -0x000007fefd0a0000 - 0x000007fefd107000 C:\Windows\system32\KERNELBASE.dll -0x000007feed7d0000 - 0x000007feed7e8000 C:\Program Files\Java\jdk-17\bin\jli.dll -0x000007fefb550000 - 0x000007fefb745000 C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.24483_none_e372d88f30fbb845\COMCTL32.dll -0x000007fefda30000 - 0x000007fefdacf000 C:\Windows\system32\msvcrt.dll -0x000007feff590000 - 0x000007feff5f7000 C:\Windows\system32\GDI32.dll -0x0000000077350000 - 0x000000007744b000 C:\Windows\system32\USER32.dll -0x000007fefdc00000 - 0x000007fefdc0e000 C:\Windows\system32\LPK.dll -0x000007fefeeb0000 - 0x000007fefef7b000 C:\Windows\system32\USP10.dll -0x000007feff130000 - 0x000007feff1a1000 C:\Windows\system32\SHLWAPI.dll -0x000007fee6950000 - 0x000007fee6969000 C:\Program Files\Java\jdk-17\bin\VCRUNTIME140.dll -0x000007feed7c0000 - 0x000007feed7c4000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-runtime-l1-1-0.dll -0x000007fee1890000 - 0x000007fee198a000 C:\Program Files\Java\jdk-17\bin\ucrtbase.DLL -0x000007fee9bb0000 - 0x000007fee9bb3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-localization-l1-2-0.dll -0x000007fee7980000 - 0x000007fee7983000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-processthreads-l1-1-1.dll -0x000007fee6ae0000 - 0x000007fee6ae3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-file-l1-2-0.dll -0x000007fee6940000 - 0x000007fee6943000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-timezone-l1-1-0.dll -0x000007fee6930000 - 0x000007fee6933000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-file-l2-1-0.dll -0x000007fee6920000 - 0x000007fee6923000 C:\Program Files\Java\jdk-17\bin\api-ms-win-core-synch-l1-2-0.dll -0x000007fee6910000 - 0x000007fee6913000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-heap-l1-1-0.dll -0x000007fee55a0000 - 0x000007fee55a4000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-string-l1-1-0.dll -0x000007fee3670000 - 0x000007fee3674000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-stdio-l1-1-0.dll -0x000007fee3660000 - 0x000007fee3664000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-convert-l1-1-0.dll -0x000007fee25d0000 - 0x000007fee25d3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-environment-l1-1-0.dll -0x000007fee25c0000 - 0x000007fee25c3000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-filesystem-l1-1-0.dll -0x000007fee1c00000 - 0x000007fee1c05000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-math-l1-1-0.dll -0x000007fee1610000 - 0x000007fee1613000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-locale-l1-1-0.dll -0x000007fefdee0000 - 0x000007fefdf0e000 C:\Windows\system32\IMM32.DLL -0x000007feff020000 - 0x000007feff12b000 C:\Windows\system32\MSCTF.dll -0x000007fee1600000 - 0x000007fee160c000 C:\Program Files\Java\jdk-17\bin\vcruntime140_1.dll -0x000007fee1560000 - 0x000007fee15f1000 C:\Program Files\Java\jdk-17\bin\msvcp140.dll -0x000007fee1550000 - 0x000007fee1553000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-time-l1-1-0.dll -0x000007fee1540000 - 0x000007fee1543000 C:\Program Files\Java\jdk-17\bin\api-ms-win-crt-utility-l1-1-0.dll -0x000007fed4b30000 - 0x000007fed5776000 C:\Program Files\Java\jdk-17\bin\server\jvm.dll -0x000007fefdad0000 - 0x000007fefdbab000 C:\Windows\system32\ADVAPI32.dll -0x000007fefd360000 - 0x000007fefd37f000 C:\Windows\SYSTEM32\sechost.dll -0x000007feff610000 - 0x000007feff73c000 C:\Windows\system32\RPCRT4.dll -0x000007fee5d80000 - 0x000007fee5d89000 C:\Windows\system32\WSOCK32.dll -0x000007fefdbb0000 - 0x000007fefdbfd000 C:\Windows\system32\WS2_32.dll -0x000007feff600000 - 0x000007feff608000 C:\Windows\system32\NSI.dll -0x000007fefa2a0000 - 0x000007fefa2db000 C:\Windows\system32\WINMM.dll -0x000007fefbeb0000 - 0x000007fefbebc000 C:\Windows\system32\VERSION.dll -0x00000000775f0000 - 0x00000000775f7000 C:\Windows\system32\PSAPI.DLL -0x000007fee1530000 - 0x000007fee153a000 C:\Program Files\Java\jdk-17\bin\jimage.dll -0x000007fee5630000 - 0x000007fee5755000 C:\Windows\system32\DBGHELP.DLL -0x000007fee1520000 - 0x000007fee152e000 C:\Program Files\Java\jdk-17\bin\instrument.dll -0x000007fee14f0000 - 0x000007fee1515000 C:\Program Files\Java\jdk-17\bin\java.dll -0x000007fee0c20000 - 0x000007fee0cf6000 C:\Program Files\Java\jdk-17\bin\svml.dll -0x000007fefdf90000 - 0x000007fefed1b000 C:\Windows\system32\SHELL32.dll -0x000007feff1b0000 - 0x000007feff3af000 C:\Windows\system32\ole32.dll -0x000007fefcfb0000 - 0x000007fefcfbf000 C:\Windows\system32\profapi.dll -0x000007fee0c00000 - 0x000007fee0c18000 C:\Program Files\Java\jdk-17\bin\zip.dll -0x000007fee0be0000 - 0x000007fee0bf9000 C:\Program Files\Java\jdk-17\bin\net.dll -0x000007fefab40000 - 0x000007fefabb1000 C:\Windows\system32\WINHTTP.dll -0x000007fefaad0000 - 0x000007fefab35000 C:\Windows\system32\webio.dll -0x000007fefc4b0000 - 0x000007fefc505000 C:\Windows\system32\mswsock.dll -0x000007fefc590000 - 0x000007fefc597000 C:\Windows\System32\wship6.dll -0x000007fee0740000 - 0x000007fee0755000 C:\Program Files\Java\jdk-17\bin\nio.dll -0x000007fee0720000 - 0x000007fee073a000 C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin\breakgen64.dll -0x0000000069ac0000 - 0x0000000069ae4000 C:\Users\Stef\AppData\Local\Temp\jansi-2.4.0-9689c7ed58c33b92-jansi.dll -0x000007fee14e0000 - 0x000007fee14f0000 C:\Program Files\Java\jdk-17\bin\verify.dll - -dbghelp: loaded successfully - version: 4.0.5 - missing functions: none -symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Program Files\Java\jdk-17\bin;C:\Windows\SYSTEM32;C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.24483_none_e372d88f30fbb845;C:\Program Files\Java\jdk-17\bin\server;C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin;C:\Users\Stef\AppData\Local\Temp - -VM Arguments: -jvm_args: -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\IF-parent -Dmaven.home=D:\Maven\apache-maven-3.8.4 -Dclassworlds.conf=D:\Maven\apache-maven-3.8.4\bin\m2.conf -Dmaven.ext.class.path=C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\plugins\maven\lib\maven-event-listener.jar -javaagent:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\lib\idea_rt.jar=52046:C:\Users\Stef\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\213.6461.79\bin -Dfile.encoding=UTF-8 -java_command: org.codehaus.classworlds.Launcher -Didea.version=2021.3.1 clean install -java_class_path (initial): D:\Maven\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;D:\Maven\apache-maven-3.8.4\boot\plexus-classworlds.license -Launcher Type: SUN_STANDARD - -[Global flags] - intx CICompilerCount = 2 {product} {ergonomic} - uint ConcGCThreads = 1 {product} {ergonomic} - uint G1ConcRefinementThreads = 2 {product} {ergonomic} - size_t G1HeapRegionSize = 1048576 {product} {ergonomic} - uintx GCDrainStackTargetSize = 64 {product} {ergonomic} - size_t InitialHeapSize = 67108864 {product} {ergonomic} - size_t MarkStackSize = 4194304 {product} {ergonomic} - size_t MaxHeapSize = 1046478848 {product} {ergonomic} - size_t MaxNewSize = 627048448 {product} {ergonomic} - size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic} - size_t MinHeapSize = 8388608 {product} {ergonomic} - uintx NonNMethodCodeHeapSize = 5826188 {pd product} {ergonomic} - uintx NonProfiledCodeHeapSize = 122916026 {pd product} {ergonomic} - uintx ProfiledCodeHeapSize = 122916026 {pd product} {ergonomic} - uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic} - bool SegmentedCodeCache = true {product} {ergonomic} - size_t SoftMaxHeapSize = 1046478848 {manageable} {ergonomic} - bool UseCompressedClassPointers = true {product lp64_product} {ergonomic} - bool UseCompressedOops = true {product lp64_product} {ergonomic} - bool UseG1GC = true {product} {ergonomic} - bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic} - -Logging: -Log output configuration: - #0: stdout all=warning uptime,level,tags - #1: stderr all=off uptime,level,tags - -Environment Variables: -JAVA_HOME=C:\Program Files\Java\jdk-17\ -CLASSPATH=C:\Users\Stef\.m2\repository\com\thoughtworks\xstream\xstream\1.4.18\xstream-1.4.18.jar -PATH=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI;C:\Ruby27-x64\bin;D:\NDS\MicroLua\devkitPro\msys2\usr\bin;C:\Python34;C:\Python34\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;C:\Program Files (x86)\Windows Live\Shared;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;"C:\Program Files\Java\jdk-17\bin";D:\CE Development\CEdev\bin;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Gpg4win\..\GnuPG\bin;D:\Yarnpkg\bin\;D:\Node.js\;C:\Program Files\Microsoft Network Monitor 3\;C:\Program Files\dotnet\;C:\Program Files (x86)\scala\\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\dotnet\;C:\Gradle\gradle-7.0.2\bin;D:\Python\Scripts\;D:\Python\;C:\Users\Stef\AppData\Local\Programs\Python\Launcher\;D:\CEDevelopment\CEdev\bin;D:\Maven\apache-maven-3.8.4\bin;D:\Gradle\gradle-7.0.2\bin;C:\MinGW\bin;D:\LaTeX\miktex\bin\x64\;D:\Lua\lua53.dll;"C:\Program Files (x86)\";C:\Users\Stef\AppData\Local\Yarn\bin;C:\Users\Stef\AppData\Roaming\npm;C:\Program Files\CMake\bin;C:\cygwin64\bin -USERNAME=Stef -OS=Windows_NT -PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 23 Stepping 10, GenuineIntel - - - ---------------- S Y S T E M --------------- - -OS: - Windows 7 , 64 bit Build 7601 (6.1.7601.24545) -OS uptime: 0 days 6:52 hours - -CPU: total 2 (initial active 2) (2 cores per cpu, 1 threads per core) family 6 model 23 stepping 10 microcode 0x0, cx8, cmov, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, tsc, clflush - -Memory: 4k page, system-wide physical 3991M (144M free) -TotalPageFile size 8082M (AvailPageFile size 15M) -current process WorkingSet (physical memory assigned to process): 208M, peak: 209M -current process commit charge ("private bytes"): 235M, peak: 256M - -vm_info: OpenJDK 64-Bit Server VM (17.0.1+12) for windows-amd64 JRE (17.0.1+12), built on Oct 20 2021 07:42:55 by "" with MS VC++ 16.7 (VS2019) - -END. From 8d7a96147495f0fb9e27c41a0ddd16e793674432 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:17:55 +0200 Subject: [PATCH 132/382] Replace BuildTools with the paper-nms-maven-plugin --- .github/workflows/maven.yml | 36 +++++++++---------------------- .gitignore | 3 ++- README.md | 19 ++++++++-------- nms/1_17_0/pom.xml | 43 +++++++++++++------------------------ nms/1_17_1/pom.xml | 42 ++++++++++++------------------------ nms/1_18_0/pom.xml | 42 ++++++++++++------------------------ nms/1_18_1/pom.xml | 42 ++++++++++++------------------------ nms/1_18_2/pom.xml | 42 ++++++++++++------------------------ 8 files changed, 92 insertions(+), 177 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 722bb53cb..1cfd2f5bf 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest name: 'Build' steps: - - name: Cache Paperclip Jars + - name: Cache Paper(clip) jars id: cache-paperclip-jars uses: actions/cache@v2 with: @@ -24,9 +24,8 @@ jobs: build paperclip ~/.m2/repository/io/papermc/paper - ~/.m2/repository/org/spigotmc key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-paperclip - - name: Download Paperclip Jars + - name: Download Paperclip jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p paperclip @@ -39,7 +38,7 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 - - name: Generate 1.14 - 1.16 Paper Jars + - name: Generate 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | cd paperclip/ @@ -49,7 +48,7 @@ jobs: java -jar paper-1.16.3.jar java -jar paper-1.16.4.jar cd ../ - - name: Install 1.14 - 1.16 Paper Jars + - name: Install 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | cd paperclip/ @@ -59,33 +58,18 @@ jobs: 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" cd ../ - - name: Set up JDK 16 - uses: actions/setup-java@v1 - with: - java-version: 16 - - name: Run BuildTools 1.17 - 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 - java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check - cd ../ - name: Set up JDK 17 uses: actions/setup-java@v1 with: java-version: 17 - - name: Run BuildTools 1.18 + - name: Run paper-nms init 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 - java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.18.1 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.18.2 --remapped --disable-java-check - cd ../ + 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 - uses: actions/checkout@v2 name: Checkout code - name: Build with Maven diff --git a/.gitignore b/.gitignore index 64169b5de..c78733736 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ IF-Test *.iml *.txt dependency-reduced-pom.xml -*.log \ No newline at end of file +*.log +.paper-nms \ No newline at end of file diff --git a/README.md b/README.md index c4924fcf2..ecb0884ad 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,8 @@ If you want to build this project from source, run the following: This will clone this repository to your device. This project relies on NMS, for which the dependencies are not available online. Because of this, you'll need to follow additional steps to obtain all these dependencies locally. -### Installing Paper -For versions 1.14-1.16, we use Paper. Run the following scripts for each version to install the dependencies locally. Running these commands generate additional files in the folder where you execute them. To ensure that you don't accidentallly overwrite other files, execute this in an empty folder. The files that get created can be deleted afterwards (either after installing a single version or after installing all of them), since they're no longer necessary. +### Installing Paper manually +For versions 1.14-1.16, we have to manually install Paper. Run the following scripts for each version to install the dependencies locally. Running these commands generate additional files in the folder where you execute them. To ensure that you don't accidentallly overwrite other files, execute this in an empty folder. The files that get created can be deleted afterwards (either after installing a single version or after installing all of them), since they're no longer necessary. #### 1.14.4 ``` @@ -124,15 +124,14 @@ java -jar paper-1.16.4.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" ``` -### Installing Spigot -For versions 1.17-1.18, we use Spigot. To install these versions locally, we use Spigot's BuildTools system. Using BuildTools will create additional files, so we recommend running the following in an empty folder. The files can be deleted afterwards. +### Installing Paper via the maven plugin +For versions 1.17-1.18, we use Paper via the [paper-nms-maven-plugin](https://github.com/Alvinn8/paper-nms-maven-plugin). To install these versions locally, we must run a few maven commands. These commands should be ran in the root directory of the project. ``` -wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar -java -jar BuildTools.jar --rev 1.17 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.17.1 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.18 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.18.1 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.18.2 --remapped --disable-java-check +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 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 5290eac61..07005b1ae 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.17-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.17-SNAPSHOT provided @@ -35,38 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.17-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:jar:remapped-obf - + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index b4b09522a..87fede8a2 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.17.1-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.17.1-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 964257a19..14cde080b 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.18-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.18-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.18-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 5cfbddf7e..c93d5f9b5 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.18-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.18.1-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 676b3dc4a..151e925ad 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -24,10 +24,9 @@ compile - org.spigotmc - spigot - 1.18.2-R0.1-SNAPSHOT - remapped-mojang + ca.bkaw + paper-nms + 1.18.2-SNAPSHOT provided @@ -35,39 +34,26 @@ - net.md-5 - specialsource-maven-plugin - 1.2.4 + ca.bkaw + paper-nms-maven-plugin + 1.2-SNAPSHOT - package + process-classes remap - remap-obf - - org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-obf - + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file From 6902d676f890bc6286cbae688df701834502a324 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:23:02 +0200 Subject: [PATCH 133/382] check out before running task --- .github/workflows/maven.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1cfd2f5bf..c90f00347 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -40,16 +40,16 @@ jobs: java-version: 11 - name: Generate 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + working-directory: paperclip run: | - cd paperclip/ 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 - cd ../ - name: Install 1.14 - 1.16 Paper jars if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' + working-directory: paperclip run: | cd paperclip/ 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" @@ -62,6 +62,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 17 + - uses: actions/checkout@v2 + name: Checkout code - name: Run paper-nms init if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | @@ -70,7 +72,5 @@ jobs: 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 - - uses: actions/checkout@v2 - name: Checkout code - name: Build with Maven run: mvn -B package --file pom.xml From e64cd116be599678749892b7c50b2b3b757df0d1 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:24:45 +0200 Subject: [PATCH 134/382] remove leftover cd... --- .github/workflows/maven.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c90f00347..586e1491f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -51,13 +51,11 @@ jobs: if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' working-directory: paperclip run: | - cd paperclip/ 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" - cd ../ - name: Set up JDK 17 uses: actions/setup-java@v1 with: From adb4175c637564c165098d06d6ee395dbec9480f Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 12:38:51 +0200 Subject: [PATCH 135/382] update to stable release --- 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 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 07005b1ae..3d5c9c3bc 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 87fede8a2..9d37adedf 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 14cde080b..3ae564f3b 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index c93d5f9b5..71acb1d58 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.2-SNAPSHOT + 1.2 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 151e925ad..7656dad23 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.2-SNAPSHOT + 1.2 process-classes From 4c6ff375a3b39d05c2fbaa9ef89da4417d7a7a16 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 May 2022 13:56:12 +0200 Subject: [PATCH 136/382] cache paper-nms jars --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 586e1491f..21006883c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -24,6 +24,7 @@ jobs: 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' From 4df4bff9eb9840bf6fe11c033a2f513016de424a Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 17 May 2022 20:13:14 +0200 Subject: [PATCH 137/382] Don't support using the libraries section in the plugin.yml --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index ecb0884ad..75fa081fc 100644 --- a/README.md +++ b/README.md @@ -73,11 +73,7 @@ shadowJar { ``` ## Dependency via plugin.yml -You can also specify your dependency directly in your plugin.yml. Please note that this downloads the dependency on the server, which means that you can only use the plugin on a server with an internet connection. -```yaml -libraries: - - com.github.stefvanschie.inventoryframework:IF:0.10.5 -``` +IF does **not** support declaring the dependency via the libraries section in the plugin.yml. Please make use of a build tool as described above to use IF as a dependency. ## Building from source If you want to build this project from source, run the following: From b2218b0b56bb33e58b5e626033df73624a9338e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 05:19:40 +0000 Subject: [PATCH 138/382] Bump paper-nms-maven-plugin from 1.2 to 1.2.1 Bumps paper-nms-maven-plugin from 1.2 to 1.2.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- 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 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 3d5c9c3bc..99be8eda5 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.2 + 1.2.1 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 9d37adedf..8e14cc360 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.2 + 1.2.1 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 3ae564f3b..ee140c169 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.2 + 1.2.1 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 71acb1d58..c4c9fb64e 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.2 + 1.2.1 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 7656dad23..04a62c9bf 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.2 + 1.2.1 process-classes From eed1a908d0e5f8ce4e80c02c5ba4f95038996964 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 30 May 2022 06:19:30 +0200 Subject: [PATCH 139/382] Added support for CustomModelData for gui items in XML files. --- .../github/stefvanschie/inventoryframework/pane/Pane.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 381993fc7..734cd36b8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -391,6 +391,12 @@ public static GuiItem loadItem(@NotNull Object instance, @NotNull Element elemen TextHolder.deserialize(item.getTextContent()) .asItemDisplayName(itemMeta); + itemStack.setItemMeta(itemMeta); + } else if (nodeName.equals("modeldata")) { + ItemMeta itemMeta = Objects.requireNonNull(itemStack.getItemMeta()); + + itemMeta.setCustomModelData(Integer.parseInt(item.getTextContent())); + itemStack.setItemMeta(itemMeta); } else if (nodeName.equals("skull") && itemStack.getItemMeta() instanceof SkullMeta) { SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta(); From da5c65540e6d1d0d47ae94337028de0d68f8be67 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Jun 2022 05:25:31 +0000 Subject: [PATCH 140/382] Bump adventure-api from 4.10.1 to 4.11.0 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.10.1 to 4.11.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.10.1...v4.11.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 25bd9b2cc..c747ace9c 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 1.8 true UTF-8 - 4.10.1 + 4.11.0 com.github.stefvanschie.inventoryframework From f197761f0afe2565519ebc30761ed9cec527fe1d Mon Sep 17 00:00:00 2001 From: jdkeke142 Date: Fri, 3 Jun 2022 07:07:04 +0200 Subject: [PATCH 141/382] Fixed a typo with dirty rows --- .../stefvanschie/inventoryframework/gui/type/ChestGui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index fd2c46bce..33ba4c602 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -81,7 +81,7 @@ public ChestGui(int rows, @NotNull TextHolder title) { public void show(@NotNull HumanEntity humanEntity) { if (isDirty() || dirtyRows) { this.inventory = createInventory(); - this.dirtyRows = true; + this.dirtyRows = false; markChanges(); } From 1112dc4340a3981b98b86d2b7385f251ba0b79ee Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 13 Jun 2022 19:53:01 +0200 Subject: [PATCH 142/382] Add 1.19 support --- .github/workflows/maven.yml | 1 + IF/pom.xml | 6 + .../util/version/Version.java | 11 +- .../util/version/VersionMatcher.java | 16 ++ nms/1_19/pom.xml | 58 ++++ .../nms/v1_19/AnvilInventoryImpl.java | 266 ++++++++++++++++++ .../nms/v1_19/BeaconInventoryImpl.java | 199 +++++++++++++ .../v1_19/CartographyTableInventoryImpl.java | 213 ++++++++++++++ .../v1_19/EnchantingTableInventoryImpl.java | 213 ++++++++++++++ .../nms/v1_19/GrindstoneInventoryImpl.java | 247 ++++++++++++++++ .../nms/v1_19/MerchantInventoryImpl.java | 97 +++++++ .../nms/v1_19/SmithingTableInventoryImpl.java | 251 +++++++++++++++++ .../nms/v1_19/StonecutterInventoryImpl.java | 219 ++++++++++++++ .../nms/v1_19/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_19/util/TextHolderUtil.java | 65 +++++ pom.xml | 1 + 16 files changed, 1903 insertions(+), 1 deletion(-) create mode 100644 nms/1_19/pom.xml create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/AnvilInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/BeaconInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/CartographyTableInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/EnchantingTableInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/GrindstoneInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/MerchantInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/SmithingTableInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/StonecutterInventoryImpl.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/CustomInventoryUtil.java create mode 100644 nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/TextHolderUtil.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 21006883c..fe9645324 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -71,5 +71,6 @@ jobs: 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 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 6da0262c1..72bdbf772 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -100,6 +100,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_19 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index cd71bd4a2..a3bf3087e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -80,7 +80,14 @@ public enum Version { * * @since 0.10.5 */ - V1_18_2; + V1_18_2, + + /** + * Version 1.19 + * + * @since 0.10.6 + */ + V1_19; /** * Gets the version currently being used. If the used version is not supported, an @@ -123,6 +130,8 @@ public static Version getVersion() { return V1_18_1; case "1.18.2": return V1_18_2; + case "1.19": + return V1_19; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 c9830865f..debac58c6 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 @@ -252,6 +252,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -274,6 +276,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -296,6 +300,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -318,6 +324,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -340,6 +348,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -362,6 +372,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -380,6 +392,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -402,5 +416,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_19, + com.github.stefvanschie.inventoryframework.nms.v1_19.StonecutterInventoryImpl.class); } } diff --git a/nms/1_19/pom.xml b/nms/1_19/pom.xml new file mode 100644 index 000000000..24912d23d --- /dev/null +++ b/nms/1_19/pom.xml @@ -0,0 +1,58 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.5 + ../../pom.xml + + 4.0.0 + + 1_19 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.19-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.2.1 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/AnvilInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/AnvilInventoryImpl.java new file mode 100644 index 000000000..545d5512a --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/AnvilInventoryImpl.java @@ -0,0 +1,266 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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; + +/** + * Internal anvil inventory for 1.19 + * + * @since 0.10.6 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.6 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.6 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.6 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.10.6 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/BeaconInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/BeaconInventoryImpl.java new file mode 100644 index 000000000..793e79174 --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19 + * + * @since 0.10.6 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.6 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/CartographyTableInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..fef036b04 --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19 + * + * @since 0.10.6 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.6 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/EnchantingTableInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..25b50c11e --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19 + * + * @since 0.10.6 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.6 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/GrindstoneInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..933d50c5b --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/GrindstoneInventoryImpl.java @@ -0,0 +1,247 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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 grindstone inventory for 1.19 + * + * @since 0.10.6 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.17.1"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.6 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/MerchantInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/MerchantInventoryImpl.java new file mode 100644 index 000000000..d93a58a32 --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_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.19 + * + * @since 0.10.6 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/SmithingTableInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..c317dae80 --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/SmithingTableInventoryImpl.java @@ -0,0 +1,251 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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; + +/** + * Internal smithing table inventory for 1.19 + * + * @since 0.10.6 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.6 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.6 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.6 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/StonecutterInventoryImpl.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/StonecutterInventoryImpl.java new file mode 100644 index 000000000..eafd1cbbd --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19 + * + * @since 0.10.6 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.6 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.6 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/CustomInventoryUtil.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/CustomInventoryUtil.java new file mode 100644 index 000000000..30d58cdd0 --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.6 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.6 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/TextHolderUtil.java b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/TextHolderUtil.java new file mode 100644 index 000000000..c3df6407a --- /dev/null +++ b/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19.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.network.chat.Component; +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.6 + */ +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.6 + */ + @NotNull + @Contract(pure = true) + public static Component 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.6 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.6 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 25bd9b2cc..98a7a245c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_19 nms/1_18_2 nms/1_18_1 nms/1_18_0 From 8d70a9669177c0ba249da4823fecc9b0d6944fc9 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 13 Jun 2022 20:13:31 +0200 Subject: [PATCH 143/382] Version 0.10.6 --- IF/pom.xml | 2 +- README.md | 7 ++++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 16 files changed, 19 insertions(+), 18 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 72bdbf772..83cac916b 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 4.0.0 diff --git a/README.md b/README.md index 75fa081fc..d27a92dc8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IF Discord guild -*This framework works for Minecraft versions 1.14-1.18* +*This framework works for Minecraft versions 1.14-1.19* An inventory framework for managing GUIs @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.5 + 0.10.6 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.10.5' + compile 'com.github.stefvanschie.inventoryframework:IF:0.10.6' // ... } ``` @@ -128,6 +128,7 @@ 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 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 89cf9fa4b..a5521d71d 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 33cffb51c..ea9d4cb37 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index f7f50b565..5d3182071 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 6b3aba55e..21ad9a5f1 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 9779b9b42..383f3dfe9 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index a4c442fa2..90265ab99 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 99be8eda5..f51760b43 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 8e14cc360..3a02e8719 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index ee140c169..f48b74b97 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index c4c9fb64e..5bd4d221c 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 04a62c9bf..402415658 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/1_19/pom.xml b/nms/1_19/pom.xml index 24912d23d..32c4bed6b 100644 --- a/nms/1_19/pom.xml +++ b/nms/1_19/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index c13a01419..9c2de33ea 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.5 + 0.10.6 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 98a7a245c..a534700d9 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.5 + 0.10.6 pom IF From 4d41d613d7a3469b8f0197aa9a619d43bae9a441 Mon Sep 17 00:00:00 2001 From: RobotHanzo <36107150+RobotHanzo@users.noreply.github.com> Date: Tue, 28 Jun 2022 16:19:41 +0800 Subject: [PATCH 144/382] Changed the syntax to fit the latest version of gradle --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d27a92dc8..a3c5b9107 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - compile 'com.github.stefvanschie.inventoryframework:IF:0.10.6' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.6' // ... } ``` @@ -63,7 +63,10 @@ repositories { ``` In order to include the project in your own project, you will need to use the `shadowJar` plugin. If you don't have it already, add the following to the top of your file: ```Groovy -apply plugin: 'com.github.johnrengelman.shadow' +plugins { + // ... + id "com.github.johnrengelman.shadow" version "7.1.2" +} ``` To relocate the project's classes to your own namespace, add the following, with [YOUR PACKAGE] being the top-level package of your project: ```Groovy From 06d774355c43ec0385368a956ae22dea2d92207a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Jul 2022 05:20:50 +0000 Subject: [PATCH 145/382] Bump junit-jupiter-engine from 5.8.2 to 5.9.0 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.8.2 to 5.9.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.2...r5.9.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 83cac916b..3f6597207 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -192,7 +192,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.9.0 diff --git a/pom.xml b/pom.xml index 72476e5fd..df5987b71 100644 --- a/pom.xml +++ b/pom.xml @@ -116,7 +116,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.9.0 From c687f647f73a9bb9a2faa6b328be16fb3733e013 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Jul 2022 05:20:56 +0000 Subject: [PATCH 146/382] Bump junit-jupiter-api from 5.8.2 to 5.9.0 in /IF Bumps [junit-jupiter-api](https://github.com/junit-team/junit5) from 5.8.2 to 5.9.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.2...r5.9.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 3f6597207..a00429c61 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -135,7 +135,7 @@ org.junit.jupiter junit-jupiter-api - 5.8.2 + 5.9.0 test From 1f630521c9ee2795418d4333378d2403d451e2bd Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 5 Jul 2022 19:55:45 +0200 Subject: [PATCH 147/382] Fix ToggleButton not executing item event Addresses #210. --- .../pane/component/ToggleButton.java | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index b54e96d56..cd1c1bac3 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -49,11 +49,11 @@ public ToggleButton(int x, int y, int length, int height, @NotNull Priority prio public ToggleButton(int length, int height) { super(length, height); - this.enabledPane = new OutlinePane(0, 0, length, height); + this.enabledPane = new OutlinePane(this.x, this.y, length, height); this.enabledPane.addItem(new GuiItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE))); this.enabledPane.setRepeat(true); - this.disabledPane = new OutlinePane(0, 0, length, height); + this.disabledPane = new OutlinePane(this.x, this.y, length, height); this.disabledPane.addItem(new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE))); this.disabledPane.setRepeat(true); } @@ -80,16 +80,13 @@ public ToggleButton(int x, int y, int length, int height, boolean enabled) { @Override public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { - int newX = paneOffsetX + x; - int newY = paneOffsetY + y; - int newMaxLength = Math.min(maxLength, length); int newMaxHeight = Math.min(maxHeight, height); if (enabled) { - enabledPane.display(inventoryComponent, newX, newY, newMaxLength, newMaxHeight); + this.enabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); } else { - disabledPane.display(inventoryComponent, newX, newY, newMaxLength, newMaxHeight); + this.disabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); } } @@ -146,6 +143,38 @@ public ToggleButton copy() { return toggleButton; } + @Override + public void setLength(int length) { + super.setLength(length); + + this.disabledPane.setLength(length); + this.enabledPane.setLength(length); + } + + @Override + public void setHeight(int height) { + super.setHeight(height); + + this.disabledPane.setHeight(height); + this.enabledPane.setHeight(height); + } + + @Override + public void setX(int x) { + super.setX(x); + + this.disabledPane.setX(x); + this.enabledPane.setX(x); + } + + @Override + public void setY(int y) { + super.setY(y); + + this.disabledPane.setY(y); + this.enabledPane.setY(y); + } + /** * Sets the item to use when the button is set to disabled * From 4e9a72fe955500fb5273b03ab8162482b972fc70 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 5 Jul 2022 20:22:36 +0200 Subject: [PATCH 148/382] Fix ChestGui#setRows getting rid of panes Addresses #227. --- .../inventoryframework/gui/type/ChestGui.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 33ba4c602..9acbd9bf8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -147,7 +147,13 @@ public void setRows(int rows) { throw new IllegalArgumentException("Rows should be between 1 and 6"); } - this.inventoryComponent = new InventoryComponent(9, rows + 4); + InventoryComponent inventoryComponent = new InventoryComponent(9, rows + 4); + + for (Pane pane : this.inventoryComponent.getPanes()) { + inventoryComponent.addPane(pane); + } + + this.inventoryComponent = inventoryComponent; this.dirtyRows = true; } From 999d1fe563c76208942b48c539f9c53509def949 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 5 Jul 2022 21:00:29 +0200 Subject: [PATCH 149/382] Human entity inventory is not restored after updating gui Addresses #229. --- .../inventoryframework/HumanEntityCache.java | 11 ++++++++ .../inventoryframework/gui/GuiListener.java | 26 +++++++++---------- .../inventoryframework/gui/type/AnvilGui.java | 7 ++++- .../gui/type/BarrelGui.java | 7 ++++- .../gui/type/BeaconGui.java | 7 ++++- .../gui/type/BlastFurnaceGui.java | 7 ++++- .../gui/type/BrewingStandGui.java | 7 ++++- .../gui/type/CartographyTableGui.java | 7 ++++- .../inventoryframework/gui/type/ChestGui.java | 7 ++++- .../gui/type/CraftingTableGui.java | 7 ++++- .../gui/type/DispenserGui.java | 7 ++++- .../gui/type/DropperGui.java | 7 ++++- .../gui/type/EnchantingTableGui.java | 7 ++++- .../gui/type/EnderChestGui.java | 7 ++++- .../gui/type/FurnaceGui.java | 7 ++++- .../gui/type/GrindstoneGui.java | 7 ++++- .../gui/type/HopperGui.java | 7 ++++- .../gui/type/MerchantGui.java | 7 ++++- .../gui/type/ShulkerBoxGui.java | 7 ++++- .../gui/type/SmithingTableGui.java | 7 ++++- .../gui/type/SmokerGui.java | 7 ++++- .../gui/type/StonecutterGui.java | 7 ++++- 22 files changed, 144 insertions(+), 33 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/HumanEntityCache.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/HumanEntityCache.java index 51d6920c7..cb0b11798 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/HumanEntityCache.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/HumanEntityCache.java @@ -155,6 +155,17 @@ private void restoreAll() { inventories.keySet().forEach(this::restore); } + /** + * Checks if the provided human entity appears in the cache, returning true if this is the case. + * + * @param humanEntity the human entity to check whether it is present in the cache + * @return true if the human entity is in the cache, false otherwise + * @since 0.10.7 + */ + public boolean contains(@NotNull HumanEntity humanEntity) { + return this.inventories.containsKey(humanEntity); + } + /** * Clear the cache for the specified human entity * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index b15498900..aba794ba7 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -325,22 +325,22 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { humanEntity.closeInventory(); } }); - } - //delay because merchants put items in slots back in the player inventory - Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { - gui.getHumanEntityCache().restoreAndForget(humanEntity); + //delay because merchants put items in slots back in the player inventory + Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { + gui.getHumanEntityCache().restoreAndForget(humanEntity); - if (gui.getViewerCount() == 1) { - activeGuiInstances.remove(gui); - } + if (gui.getViewerCount() == 1) { + activeGuiInstances.remove(gui); + } - if (gui instanceof AnvilGui) { - ((AnvilGui) gui).handleClose(humanEntity); - } else if (gui instanceof MerchantGui) { - ((MerchantGui) gui).handleClose(humanEntity); - } - }); + if (gui instanceof AnvilGui) { + ((AnvilGui) gui).handleClose(humanEntity); + } else if (gui instanceof MerchantGui) { + ((MerchantGui) gui).handleClose(humanEntity); + } + }); + } } /** 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 ed5b31fe8..4fd6d8280 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 @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -116,7 +117,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index 445c2aa0c..8651f0f54 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; @@ -82,7 +83,11 @@ public void show(@NotNull HumanEntity humanEntity) { topComponent.placeItems(getInventory(), 0); if (bottomComponent.hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } bottomComponent.placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java index 4bdb08cd2..6716e2c6f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -67,7 +68,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index 69d7a8f85..b41408f6f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -91,7 +92,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 85f06e468..57b82c68c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -105,7 +106,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index d755a6e30..8ff553cd6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -110,7 +111,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 9acbd9bf8..64c8ef7d9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -98,7 +99,11 @@ public void show(@NotNull HumanEntity humanEntity) { topComponent.placeItems(getInventory(), 0); if (bottomComponent.hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } bottomComponent.placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index a992c9b93..549d0f08d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -84,7 +85,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index 39d244599..c68ea7137 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -77,7 +78,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index df50567fe..7ed2bd3c8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -77,7 +78,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index d21990976..78004f0eb 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -93,7 +94,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index aaf65daad..dd4e07f34 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; @@ -82,7 +83,11 @@ public void show(@NotNull HumanEntity humanEntity) { topComponent.placeItems(getInventory(), 0); if (bottomComponent.hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } bottomComponent.placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index ce19331a6..5ad6fa8d6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -91,7 +92,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index 24e1d160f..42a1de060 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -100,7 +101,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index 9d19c941f..b377bdb10 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -77,7 +78,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index c8c926940..7585880ff 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; @@ -139,7 +140,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index 0dd753324..d9ac269c3 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.GuiItem; @@ -81,7 +82,11 @@ public void show(@NotNull HumanEntity humanEntity) { topComponent.placeItems(getInventory(), 0); if (bottomComponent.hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } bottomComponent.placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 51e9f2c0f..d1edcb9a0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -108,7 +109,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index 3b4bad105..600b6441b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; @@ -91,7 +92,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index abc348dc5..769d794eb 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui.type; +import com.github.stefvanschie.inventoryframework.HumanEntityCache; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; @@ -101,7 +102,11 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().display(); if (getPlayerInventoryComponent().hasItem()) { - getHumanEntityCache().storeAndClear(humanEntity); + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } From d739a0d77fc9c2982d589d98276dde1452bbd877 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 6 Jul 2022 20:59:21 +0200 Subject: [PATCH 150/382] Fix nested panes ignoring visibility Addresses #232 --- .../stefvanschie/inventoryframework/pane/MasonryPane.java | 8 ++++++++ .../inventoryframework/pane/PaginatedPane.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java index 24949a858..9847f2984 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java @@ -64,6 +64,10 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs for (int paneIndex = 0; paneIndex < panes.size(); paneIndex++) { Pane pane = panes.get(paneIndex); + if (!pane.isVisible()) { + continue; + } + if (orientation == Orientation.HORIZONTAL) { outerLoop: for (int y = 0; y < height; y++) { @@ -165,6 +169,10 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp boolean success = false; for (Pane pane : new ArrayList<>(panes)) { + if (!pane.isVisible()) { + continue; + } + success = success || pane.click(gui, inventoryComponent, event, slot, paneOffsetX + getX(), paneOffsetY + getY(), length, height); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index e1be5d3d7..cc8d98331 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -190,6 +190,10 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs } for (Pane pane : panes) { + if (!pane.isVisible()) { + continue; + } + int newPaneOffsetX = paneOffsetX + getX(); int newPaneOffsetY = paneOffsetY + getY(); int newMaxLength = Math.min(length, maxLength); @@ -221,6 +225,10 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp boolean success = false; for (Pane pane : new ArrayList<>(this.panes.getOrDefault(page, Collections.emptyList()))) { + if (!pane.isVisible()) { + continue; + } + success = success || pane.click(gui, inventoryComponent, event, slot,paneOffsetX + getX(), paneOffsetY + getY(), length, height); } From aed8c81d354b668e69d21047f95058543751b4c7 Mon Sep 17 00:00:00 2001 From: wordandahalf <10679776+wordandahalf@users.noreply.github.com> Date: Thu, 7 Jul 2022 11:28:47 -0500 Subject: [PATCH 151/382] Increase visibility of callCallback to allow for overriding in subclasses --- .../stefvanschie/inventoryframework/gui/type/util/Gui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 74fa560b5..6633f1f18 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 @@ -539,7 +539,7 @@ public void callOnClose(@NotNull InventoryCloseEvent event) { * @param callbackName the name of the action, used for logging * @param the type of the value the consumer is accepting */ - private void callCallback(@Nullable Consumer callback, + protected void callCallback(@Nullable Consumer callback, @NotNull T event, @NotNull String callbackName) { if (callback == null) { return; From 8fcbccb0764d76d8c151699706a456afac680fad Mon Sep 17 00:00:00 2001 From: wordandahalf <10679776+wordandahalf@users.noreply.github.com> Date: Thu, 7 Jul 2022 11:29:35 -0500 Subject: [PATCH 152/382] Add TradeSelectEvent callback --- .../gui/type/MerchantGui.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index 7585880ff..bd4ba8603 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -9,11 +9,13 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.util.XMLUtil; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.TradeSelectEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; @@ -36,6 +38,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Consumer; /** * Represents a gui in the form of a merchant. @@ -44,6 +47,12 @@ */ public class MerchantGui extends NamedGui { + /** + * The consumer that will be called once a players selects a trade listed + * on the left side of the gui + */ + private Consumer onTradeSelect; + /** * Represents the inventory component for the input */ @@ -113,6 +122,37 @@ public MerchantGui(@NotNull TextHolder title) { this.merchant = getTitleHolder().asMerchantTitle(); } + /** + * Set the consumer that should be called whenever a trade is selected + * in this gui. + * + * @param onTradeSelect the consumer that gets called + */ + public void setOnTradeSelect(@Nullable Consumer onTradeSelect) { + this.onTradeSelect = onTradeSelect; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnTradeSelect(Consumer)}, + * so the consumer that should be called whenever a trade is selected in this gui. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + */ + public void callOnTradeSelect(@NotNull TradeSelectEvent event) { + callCallback(onTradeSelect, event, "onTradeSelect"); + } + + @Override + protected void initializeOrThrow(@NotNull Object instance, @NotNull Element element) { + super.initializeOrThrow(instance, element); + + if (element.hasAttribute("onTradeSelect")) { + setOnTradeSelect(XMLUtil.loadOnEventAttribute(instance, + element, TradeSelectEvent.class, "onTradeSelect")); + } + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { From 056f4bf68870571f958e6846a6516701504b4baa Mon Sep 17 00:00:00 2001 From: wordandahalf <10679776+wordandahalf@users.noreply.github.com> Date: Thu, 7 Jul 2022 11:30:25 -0500 Subject: [PATCH 153/382] Call TradeSelectEvent callback when event is fired --- .../inventoryframework/gui/GuiListener.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index aba794ba7..41aa6aa06 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -297,6 +297,22 @@ public void onInventoryDrag(@NotNull InventoryDragEvent event) { } } + /** + * Handles the selection of trades in merchant guis + * + * @param event the event fired + */ + @EventHandler(ignoreCancelled = true) + public void onTradeSelect(@NotNull TradeSelectEvent event) { + Gui gui = getGui(event.getInventory()); + + if (!(gui instanceof MerchantGui)) { + return; + } + + ((MerchantGui) gui).callOnTradeSelect(event); + } + /** * Handles closing in inventories * From a30b2e230b98c2a64f0dc180c8e99efa01f9974c Mon Sep 17 00:00:00 2001 From: wordandahalf <10679776+wordandahalf@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:56:39 -0500 Subject: [PATCH 154/382] Respect PECS --- .../stefvanschie/inventoryframework/gui/type/MerchantGui.java | 4 ++-- .../stefvanschie/inventoryframework/gui/type/util/Gui.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index bd4ba8603..dbb9da667 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -51,7 +51,7 @@ public class MerchantGui extends NamedGui { * The consumer that will be called once a players selects a trade listed * on the left side of the gui */ - private Consumer onTradeSelect; + private Consumer onTradeSelect; /** * Represents the inventory component for the input @@ -128,7 +128,7 @@ public MerchantGui(@NotNull TextHolder title) { * * @param onTradeSelect the consumer that gets called */ - public void setOnTradeSelect(@Nullable Consumer onTradeSelect) { + public void setOnTradeSelect(@Nullable Consumer onTradeSelect) { this.onTradeSelect = onTradeSelect; } 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 6633f1f18..4d8261075 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 @@ -539,7 +539,7 @@ public void callOnClose(@NotNull InventoryCloseEvent event) { * @param callbackName the name of the action, used for logging * @param the type of the value the consumer is accepting */ - protected void callCallback(@Nullable Consumer callback, + protected void callCallback(@Nullable Consumer callback, @NotNull T event, @NotNull String callbackName) { if (callback == null) { return; From 2637492d8cf65b4589b6b5644c3dddcdef5df2d8 Mon Sep 17 00:00:00 2001 From: Ryan J <10679776+wordandahalf@users.noreply.github.com> Date: Thu, 7 Jul 2022 22:53:13 -0500 Subject: [PATCH 155/382] Update copy to set TradeSelectEvent consumer --- .../stefvanschie/inventoryframework/gui/type/MerchantGui.java | 1 + 1 file changed, 1 insertion(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index dbb9da667..bf3cd2dc8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -222,6 +222,7 @@ public Gui copy() { gui.setOnBottomClick(this.onBottomClick); gui.setOnGlobalClick(this.onGlobalClick); gui.setOnOutsideClick(this.onOutsideClick); + gui.setOnTradeSelect(this.onTradeSelect); gui.setOnClose(this.onClose); return gui; From f72c5512b1893dec098151a81e1cc548f22dc4d3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 9 Jul 2022 20:49:20 +0200 Subject: [PATCH 156/382] Fix MerchantGui#copy() not copying all data Addresses #235. --- .../gui/type/MerchantGui.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index bf3cd2dc8..bb24ffecf 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -218,6 +218,30 @@ public Gui copy() { gui.inputComponent = inputComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); + gui.experience = experience; + gui.level = level; + + for (Map.Entry trade : trades) { + MerchantRecipe originalRecipe = trade.getKey(); + + ItemStack result = originalRecipe.getResult().clone(); + int uses = originalRecipe.getUses(); + int maxUses = originalRecipe.getMaxUses(); + boolean experienceReward = originalRecipe.hasExperienceReward(); + int villagerExperience = originalRecipe.getVillagerExperience(); + float priceMultiplier = originalRecipe.getPriceMultiplier(); + + MerchantRecipe recipe = new MerchantRecipe( + result, uses, maxUses, experienceReward, villagerExperience, priceMultiplier + ); + + for (ItemStack ingredient : originalRecipe.getIngredients()) { + recipe.addIngredient(ingredient.clone()); + } + + gui.trades.add(new AbstractMap.SimpleImmutableEntry<>(recipe, trade.getValue())); + } + gui.setOnTopClick(this.onTopClick); gui.setOnBottomClick(this.onBottomClick); gui.setOnGlobalClick(this.onGlobalClick); From d1113d6635f317a7af14901cf91287375825f8c3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 10 Jul 2022 21:03:15 +0200 Subject: [PATCH 157/382] Add Pane#createBorder Creates a pane which displays a border. --- .../inventoryframework/pane/Pane.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 734cd36b8..93b67e84c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -6,6 +6,8 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.exception.XMLReflectionException; +import com.github.stefvanschie.inventoryframework.pane.util.Mask; +import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import com.github.stefvanschie.inventoryframework.util.SkullUtil; import com.github.stefvanschie.inventoryframework.util.UUIDTagType; import com.github.stefvanschie.inventoryframework.util.XMLUtil; @@ -637,6 +639,59 @@ protected void callOnClick(@NotNull InventoryClickEvent event) { } } + /** + * Creates a pane which displays as a border around the outside of the pane consisting of the provided item. The x, + * y, length and height parameters are used for the respective properties of the pane. If either the length or + * height is negative an {@link IllegalArgumentException} will be thrown. + * + * @param x the x coordinate of the pane + * @param y the y coordinate of the pane + * @param length the length of the pane + * @param height the height of the pane + * @param item the item of which the border is made + * @return the created pane which displays a border + * @since 0.10.7 + * @throws IllegalArgumentException if length or height is negative + */ + @NotNull + @Contract(pure = true) + public static Pane createBorder(int x, int y, int length, int height, @NotNull GuiItem item) { + if (length < 0) { + throw new IllegalArgumentException("Length should be non-negative"); + } + + if (height < 0) { + throw new IllegalArgumentException("Height should be non-negative"); + } + + String[] mask = new String[height]; + + if (height > 0) { + mask[0] = createLine(length); + } + + if (height > 1) { + mask[height - 1] = createLine(length); + } + + for (int yIndex = 1; yIndex < height - 1; yIndex++) { + StringBuilder builder = new StringBuilder("1"); + + for (int i = 0; i < length - 2; i++) { + builder.append('0'); + } + + mask[yIndex] = builder.append('1').toString(); + } + + OutlinePane pane = new OutlinePane(x, y, length, height); + pane.applyMask(new Mask(mask)); + pane.addItem(item); + pane.setRepeat(true); + + return pane; + } + /** * Registers a property that can be used inside an XML file to add additional new properties. * The use of {@link Gui#registerProperty(String, Function)} is preferred over this method. @@ -655,6 +710,31 @@ public static void registerProperty(@NotNull String attributeName, @NotNull Func PROPERTY_MAPPINGS.put(attributeName, function); } + /** + * Creates a string containing the character '1' repeated length amount of times. If the provided length is negative + * an {@link IllegalArgumentException} will be thrown. + * + * @param length the length of the string + * @return the string containing '1's + * @since 0.10.7 + * @throws IllegalArgumentException if length is negative + */ + @NotNull + @Contract(pure = true) + private static String createLine(int length) { + if (length < 0) { + throw new IllegalArgumentException("Length should be non-negative"); + } + + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < length; i++) { + builder.append('1'); + } + + return builder.toString(); + } + /** * An enum representing the rendering priorities for the panes. Uses a similar system to Bukkit's * {@link org.bukkit.event.EventPriority} system From 4c935a6ac35f3a469afe46b3373bb16bb8a198ec Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 11 Aug 2022 19:43:02 +0200 Subject: [PATCH 158/382] Add version 1.19.1 --- .github/workflows/maven.yml | 3 +- IF/pom.xml | 8 +- .../util/version/Version.java | 11 +- .../util/version/VersionMatcher.java | 32 ++- README.md | 3 +- nms/{1_19 => 1_19_0}/pom.xml | 2 +- .../nms/v1_19_0}/AnvilInventoryImpl.java | 6 +- .../nms/v1_19_0}/BeaconInventoryImpl.java | 2 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 4 +- .../nms/v1_19_0}/GrindstoneInventoryImpl.java | 6 +- .../nms/v1_19_0}/MerchantInventoryImpl.java | 2 +- .../v1_19_0}/SmithingTableInventoryImpl.java | 6 +- .../v1_19_0}/StonecutterInventoryImpl.java | 4 +- .../v1_19_0}/util/CustomInventoryUtil.java | 2 +- .../nms/v1_19_0}/util/TextHolderUtil.java | 2 +- nms/1_19_1/pom.xml | 58 ++++ .../nms/v1_19_1/AnvilInventoryImpl.java | 266 ++++++++++++++++++ .../nms/v1_19_1/BeaconInventoryImpl.java | 199 +++++++++++++ .../CartographyTableInventoryImpl.java | 213 ++++++++++++++ .../v1_19_1/EnchantingTableInventoryImpl.java | 213 ++++++++++++++ .../nms/v1_19_1/GrindstoneInventoryImpl.java | 247 ++++++++++++++++ .../nms/v1_19_1/MerchantInventoryImpl.java | 97 +++++++ .../v1_19_1/SmithingTableInventoryImpl.java | 251 +++++++++++++++++ .../nms/v1_19_1/StonecutterInventoryImpl.java | 219 ++++++++++++++ .../nms/v1_19_1/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_19_1/util/TextHolderUtil.java | 65 +++++ pom.xml | 3 +- 28 files changed, 1937 insertions(+), 34 deletions(-) rename nms/{1_19 => 1_19_0}/pom.xml (98%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/AnvilInventoryImpl.java (97%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/BeaconInventoryImpl.java (99%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/CartographyTableInventoryImpl.java (97%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/EnchantingTableInventoryImpl.java (98%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/GrindstoneInventoryImpl.java (97%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/MerchantInventoryImpl.java (98%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/SmithingTableInventoryImpl.java (97%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/StonecutterInventoryImpl.java (98%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/util/CustomInventoryUtil.java (94%) rename nms/{1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19 => 1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0}/util/TextHolderUtil.java (96%) create mode 100644 nms/1_19_1/pom.xml create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/BeaconInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/CartographyTableInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/EnchantingTableInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/MerchantInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/StonecutterInventoryImpl.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/CustomInventoryUtil.java create mode 100644 nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/TextHolderUtil.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fe9645324..4462ef65f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -71,6 +71,7 @@ jobs: 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 + mvn paper-nms:init -pl nms/1_19_0 + mvn paper-nms:init -pl nms/1_19_1 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index a00429c61..70ff7b3b4 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -102,7 +102,13 @@ com.github.stefvanschie.inventoryframework - 1_19 + 1_19_0 + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + 1_19_1 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index a3bf3087e..162894523 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -87,7 +87,14 @@ public enum Version { * * @since 0.10.6 */ - V1_19; + V1_19, + + /** + * Version 1.19.1 + * + * @since 0.10.7 + */ + V1_19_1; /** * Gets the version currently being used. If the used version is not supported, an @@ -132,6 +139,8 @@ public static Version getVersion() { return V1_18_2; case "1.19": return V1_19; + case "1.19.1": + return V1_19_1; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 debac58c6..d22a0a79d 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 @@ -253,7 +253,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers ANVIL_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.AnvilInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -277,7 +279,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers BEACON_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.BeaconInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -301,7 +305,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.CartographyTableInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -325,7 +331,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.EnchantingTableInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -349,7 +357,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers GRINDSTONE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.GrindstoneInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -373,7 +383,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers MERCHANT_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.MerchantInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -393,7 +405,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers SMITHING_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.SmithingTableInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -417,6 +431,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers STONECUTTER_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_19, - com.github.stefvanschie.inventoryframework.nms.v1_19.StonecutterInventoryImpl.class); + com.github.stefvanschie.inventoryframework.nms.v1_19_0.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_19_1, + com.github.stefvanschie.inventoryframework.nms.v1_19_1.StonecutterInventoryImpl.class); } } diff --git a/README.md b/README.md index a3c5b9107..bd5e79a4b 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,8 @@ 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 +mvn paper-nms:init -pl nms/1_19_0 +mvn paper-nms:init -pl nms/1_19_1 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/nms/1_19/pom.xml b/nms/1_19_0/pom.xml similarity index 98% rename from nms/1_19/pom.xml rename to nms/1_19_0/pom.xml index 32c4bed6b..358d347fb 100644 --- a/nms/1_19/pom.xml +++ b/nms/1_19_0/pom.xml @@ -10,7 +10,7 @@ 4.0.0 - 1_19 + 1_19_0 true diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/AnvilInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java similarity index 97% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/AnvilInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java index 545d5512a..2e72bf853 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/AnvilInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/BeaconInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/BeaconInventoryImpl.java similarity index 99% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/BeaconInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/BeaconInventoryImpl.java index 793e79174..4ea1651d7 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/BeaconInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/BeaconInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import net.minecraft.core.NonNullList; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/CartographyTableInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/CartographyTableInventoryImpl.java similarity index 97% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/CartographyTableInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/CartographyTableInventoryImpl.java index fef036b04..222f3f661 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/CartographyTableInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/CartographyTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/EnchantingTableInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/EnchantingTableInventoryImpl.java similarity index 98% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/EnchantingTableInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/EnchantingTableInventoryImpl.java index 25b50c11e..c560bc371 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/EnchantingTableInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/EnchantingTableInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/GrindstoneInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java similarity index 97% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/GrindstoneInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java index 933d50c5b..0ac7771ca 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/GrindstoneInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/MerchantInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/MerchantInventoryImpl.java similarity index 98% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/MerchantInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/MerchantInventoryImpl.java index d93a58a32..1be13bd16 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/MerchantInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/MerchantInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import net.minecraft.server.level.ServerPlayer; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/SmithingTableInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/SmithingTableInventoryImpl.java similarity index 97% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/SmithingTableInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/SmithingTableInventoryImpl.java index c317dae80..809fc2996 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/SmithingTableInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/SmithingTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/StonecutterInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/StonecutterInventoryImpl.java similarity index 98% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/StonecutterInventoryImpl.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/StonecutterInventoryImpl.java index eafd1cbbd..ceaaefd48 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/StonecutterInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/StonecutterInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_19.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/CustomInventoryUtil.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/util/CustomInventoryUtil.java similarity index 94% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/CustomInventoryUtil.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/util/CustomInventoryUtil.java index 30d58cdd0..2b26b05fe 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/CustomInventoryUtil.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/util/CustomInventoryUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19.util; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; diff --git a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/TextHolderUtil.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/util/TextHolderUtil.java similarity index 96% rename from nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/TextHolderUtil.java rename to nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/util/TextHolderUtil.java index c3df6407a..470eecbea 100644 --- a/nms/1_19/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19/util/TextHolderUtil.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_19.util; +package com.github.stefvanschie.inventoryframework.nms.v1_19_0.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml new file mode 100644 index 000000000..d6025f2cb --- /dev/null +++ b/nms/1_19_1/pom.xml @@ -0,0 +1,58 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.6 + ../../pom.xml + + 4.0.0 + + 1_19_1 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.19.1-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.2.1 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java new file mode 100644 index 000000000..0b4968c6d --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java @@ -0,0 +1,266 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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; + +/** + * Internal anvil inventory for 1.19.1 + * + * @since 0.10.7 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.7 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.7 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.7 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.10.7 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/BeaconInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/BeaconInventoryImpl.java new file mode 100644 index 000000000..0f6c40c68 --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.1 + * + * @since 0.10.7 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.7 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/CartographyTableInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..3e16d2013 --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.1 + * + * @since 0.10.7 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.7 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/EnchantingTableInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..79f19e57f --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.1 + * + * @since 0.10.7 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.7 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..a8dd8e091 --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java @@ -0,0 +1,247 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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 grindstone inventory for 1.19.1 + * + * @since 0.10.7 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.1"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.7 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/MerchantInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/MerchantInventoryImpl.java new file mode 100644 index 000000000..baf2108f7 --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_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.19.1 + * + * @since 0.10.7 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..91d88f77b --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java @@ -0,0 +1,251 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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; + +/** + * Internal smithing table inventory for 1.19.1 + * + * @since 0.10.7 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.7 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.7 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.7 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/StonecutterInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/StonecutterInventoryImpl.java new file mode 100644 index 000000000..cb634ed0e --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.1 + * + * @since 0.10.7 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.7 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/CustomInventoryUtil.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/CustomInventoryUtil.java new file mode 100644 index 000000000..3c826da20 --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_1.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.7 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/TextHolderUtil.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/TextHolderUtil.java new file mode 100644 index 000000000..058d4ad06 --- /dev/null +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_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.network.chat.Component; +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.7 + */ +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.7 + */ + @NotNull + @Contract(pure = true) + public static Component 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.7 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.7 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index df5987b71..2ca1369be 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,8 @@ IF nms/abstraction - nms/1_19 + nms/1_19_1 + nms/1_19_0 nms/1_18_2 nms/1_18_1 nms/1_18_0 From bcd66b64977790e401e872e4b1f926964b1e4327 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 11 Aug 2022 20:37:13 +0200 Subject: [PATCH 159/382] Add version 1.19.2 --- .github/workflows/maven.yml | 1 + IF/pom.xml | 6 + .../util/version/Version.java | 17 +- .../util/version/VersionMatcher.java | 32 ++- README.md | 1 + nms/1_19_2/pom.xml | 58 ++++ .../nms/v1_19_2/AnvilInventoryImpl.java | 266 ++++++++++++++++++ .../nms/v1_19_2/BeaconInventoryImpl.java | 199 +++++++++++++ .../CartographyTableInventoryImpl.java | 213 ++++++++++++++ .../v1_19_2/EnchantingTableInventoryImpl.java | 213 ++++++++++++++ .../nms/v1_19_2/GrindstoneInventoryImpl.java | 247 ++++++++++++++++ .../nms/v1_19_2/MerchantInventoryImpl.java | 97 +++++++ .../v1_19_2/SmithingTableInventoryImpl.java | 251 +++++++++++++++++ .../nms/v1_19_2/StonecutterInventoryImpl.java | 219 ++++++++++++++ .../nms/v1_19_2/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_19_2/util/TextHolderUtil.java | 65 +++++ pom.xml | 1 + 17 files changed, 1915 insertions(+), 12 deletions(-) create mode 100644 nms/1_19_2/pom.xml create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/BeaconInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/CartographyTableInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/EnchantingTableInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/MerchantInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/StonecutterInventoryImpl.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/CustomInventoryUtil.java create mode 100644 nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/TextHolderUtil.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4462ef65f..35cce1a8a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -73,5 +73,6 @@ jobs: 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 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 70ff7b3b4..540dedf39 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -112,6 +112,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_19_2 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 162894523..7a3c9918a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -83,18 +83,25 @@ public enum Version { V1_18_2, /** - * Version 1.19 + * Version 1.19.0 * * @since 0.10.6 */ - V1_19, + V1_19_0, /** * Version 1.19.1 * * @since 0.10.7 */ - V1_19_1; + V1_19_1, + + /** + * Version 1.19.2 + * + * @since 0.10.7 + */ + V1_19_2; /** * Gets the version currently being used. If the used version is not supported, an @@ -138,9 +145,11 @@ public static Version getVersion() { case "1.18.2": return V1_18_2; case "1.19": - return V1_19; + return V1_19_0; case "1.19.1": return V1_19_1; + case "1.19.2": + return V1_19_2; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 d22a0a79d..7d78c3481 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 @@ -252,10 +252,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_19, + ANVIL_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -278,10 +280,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_19, + BEACON_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -304,10 +308,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19, + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -330,10 +336,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19, + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -356,10 +364,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_19, + GRINDSTONE_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -382,10 +392,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.MerchantInventoryImpl.class); - MERCHANT_INVENTORIES.put(Version.V1_19, + MERCHANT_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -404,10 +416,12 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_19, + SMITHING_TABLE_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -430,9 +444,11 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_18_1.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_19, + STONECUTTER_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_19_2, + com.github.stefvanschie.inventoryframework.nms.v1_19_2.StonecutterInventoryImpl.class); } } diff --git a/README.md b/README.md index bd5e79a4b..117bbee1d 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ 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 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml new file mode 100644 index 000000000..f2241ad67 --- /dev/null +++ b/nms/1_19_2/pom.xml @@ -0,0 +1,58 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.6 + ../../pom.xml + + 4.0.0 + + 1_19_2 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.19.2-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.2.1 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java new file mode 100644 index 000000000..80fb89694 --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java @@ -0,0 +1,266 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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; + +/** + * Internal anvil inventory for 1.19.2 + * + * @since 0.10.7 + */ +public class AnvilInventoryImpl extends AnvilInventory { + + public AnvilInventoryImpl(@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 an anvil should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerAnvil; + + int id = containerAnvil.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.7 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.7 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.7 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * The player for whom this anvil container is + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container anvil + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for who this anvil container is + * @since 0.10.7 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + Location location = access.getLocation(); + CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, + this) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + bukkitEntity = new CraftInventoryView(player, inventory, this); + } + + return bukkitEntity; + } + + @Override + public void setItemName(@Nullable String name) { + text = name == null ? "" : name; + + sendResultItem(player, resultSlots.getItem(0)); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/BeaconInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/BeaconInventoryImpl.java new file mode 100644 index 000000000..5ae4ba937 --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.2 + * + * @since 0.10.7 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.7 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/CartographyTableInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..bf6b8303c --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.2 + * + * @since 0.10.7 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.7 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/EnchantingTableInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..f519e751e --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.2 + * + * @since 0.10.7 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.7 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..2852d2928 --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java @@ -0,0 +1,247 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryGrindstone; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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 grindstone inventory for 1.19.2 + * + * @since 0.10.7 + */ +public class GrindstoneInventoryImpl extends GrindstoneInventory { + + public GrindstoneInventoryImpl(@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 grindstone should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerGrindstone; + + int id = containerGrindstone.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.7 + */ + private class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * The player for this grindstone container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container grindstone + */ + @Nullable + private CraftInventoryView bukkitEntity; + + /** + * Field for accessing the craft inventory field + */ + @NotNull + private final Field repairSlotsField; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultSlotsField; + + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots + this.repairSlotsField.setAccessible(true); + + //noinspection JavaReflectionMemberAccess + this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots + this.resultSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); + getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + + getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the craft inventory + * + * @return the craft inventory + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private Container getCraftInventory() { + try { + return (Container) repairSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultSlotsField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/MerchantInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/MerchantInventoryImpl.java new file mode 100644 index 000000000..1909a5147 --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_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.19.2 + * + * @since 0.10.7 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..0af9f0071 --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java @@ -0,0 +1,251 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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; + +/** + * Internal smithing table inventory for 1.19.2 + * + * @since 0.10.7 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.7 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.7 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.7 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/StonecutterInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/StonecutterInventoryImpl.java new file mode 100644 index 000000000..a6c3f38fd --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.2 + * + * @since 0.10.7 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.7 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.7 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/CustomInventoryUtil.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/CustomInventoryUtil.java new file mode 100644 index 000000000..fcda8d03c --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.7 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.7 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/TextHolderUtil.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/TextHolderUtil.java new file mode 100644 index 000000000..5760f79be --- /dev/null +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_2.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.network.chat.Component; +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.7 + */ +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.7 + */ + @NotNull + @Contract(pure = true) + public static Component 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.7 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.7 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 2ca1369be..86024fd1e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_19_2 nms/1_19_1 nms/1_19_0 nms/1_18_2 From 28783e04e9e230a79f1c2a66479acf2c01ca25a3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 11 Aug 2022 20:55:05 +0200 Subject: [PATCH 160/382] Version 0.10.7 --- IF/pom.xml | 2 +- README.md | 4 ++-- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/abstraction/pom.xml | 2 +- pom.xml | 2 +- 18 files changed, 19 insertions(+), 19 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 540dedf39..b1c22d14e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 4.0.0 diff --git a/README.md b/README.md index 117bbee1d..bcaa98e81 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.6 + 0.10.7 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.6' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.7' // ... } ``` diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index a5521d71d..19ff541db 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index ea9d4cb37..ed2acc715 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 5d3182071..4ee5a055e 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 21ad9a5f1..ca352c750 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 383f3dfe9..e7de2bc17 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 90265ab99..6638da999 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index f51760b43..95491d8e4 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 3a02e8719..376ac8dcc 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index f48b74b97..bece017cf 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 5bd4d221c..f79122953 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 402415658..1f6b26b2f 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 358d347fb..92da38f26 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index d6025f2cb..a2f59c831 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index f2241ad67..c85013c96 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 9c2de33ea..457b0e556 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.6 + 0.10.7 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 86024fd1e..c438a4bdb 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.6 + 0.10.7 pom IF From 299bdcfb2668d4f315bdd887c05096aaf0ce760e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Aug 2022 05:16:15 +0000 Subject: [PATCH 161/382] Bump maven-javadoc-plugin from 3.4.0 to 3.4.1 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.0...maven-javadoc-plugin-3.4.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index b1c22d14e..4e03bb118 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -248,7 +248,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.0 + 3.4.1 attach-javadocs diff --git a/pom.xml b/pom.xml index c438a4bdb..f101f3ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -149,7 +149,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.0 + 3.4.1 attach-javadocs From e53721de727009dac19a92a24f53a54fd5157ba1 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 17 Aug 2022 18:00:59 +0200 Subject: [PATCH 162/382] Allow users to specify their own plugin instance Addresses #241 --- .../inventoryframework/gui/GuiItem.java | 62 ++++- .../inventoryframework/gui/GuiListener.java | 34 ++- .../inventoryframework/gui/type/AnvilGui.java | 71 +++++- .../gui/type/BarrelGui.java | 71 +++++- .../gui/type/BeaconGui.java | 67 ++++- .../gui/type/BlastFurnaceGui.java | 72 +++++- .../gui/type/BrewingStandGui.java | 70 +++++- .../gui/type/CartographyTableGui.java | 73 +++++- .../inventoryframework/gui/type/ChestGui.java | 77 +++++- .../gui/type/CraftingTableGui.java | 71 +++++- .../gui/type/DispenserGui.java | 72 +++++- .../gui/type/DropperGui.java | 71 +++++- .../gui/type/EnchantingTableGui.java | 72 +++++- .../gui/type/EnderChestGui.java | 72 +++++- .../gui/type/FurnaceGui.java | 71 +++++- .../gui/type/GrindstoneGui.java | 72 +++++- .../gui/type/HopperGui.java | 71 +++++- .../gui/type/MerchantGui.java | 74 +++++- .../gui/type/ShulkerBoxGui.java | 72 +++++- .../gui/type/SmithingTableGui.java | 71 +++++- .../gui/type/SmokerGui.java | 71 +++++- .../gui/type/StonecutterGui.java | 72 +++++- .../inventoryframework/gui/type/util/Gui.java | 232 +++++++++++++----- .../gui/type/util/NamedGui.java | 28 +++ .../inventoryframework/pane/MasonryPane.java | 23 +- .../inventoryframework/pane/OutlinePane.java | 23 +- .../pane/PaginatedPane.java | 61 ++++- .../inventoryframework/pane/Pane.java | 56 +++-- .../inventoryframework/pane/PatternPane.java | 23 +- .../inventoryframework/pane/StaticPane.java | 45 +++- .../pane/component/CycleButton.java | 25 +- .../pane/component/Label.java | 108 ++++++-- .../pane/component/PercentageBar.java | 67 ++++- .../pane/component/Slider.java | 67 ++++- .../pane/component/ToggleButton.java | 154 ++++++++++-- .../pane/component/util/VariableBar.java | 60 ++++- .../inventoryframework/util/TriFunction.java | 25 ++ 37 files changed, 2212 insertions(+), 314 deletions(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/util/TriFunction.java 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 fe09b0d6a..20140dc22 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 @@ -7,6 +7,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -24,11 +25,18 @@ */ public class GuiItem { + /** + * The logger to log errors with + */ + @NotNull + private Logger logger; + /** * The {@link NamespacedKey} that specifies the location of the (internal) {@link UUID} in {@link PersistentDataContainer}s. * The {@link PersistentDataType} that should be used is {@link UUIDTagType}. */ - public static final NamespacedKey KEY_UUID = new NamespacedKey(JavaPlugin.getProvidingPlugin(GuiItem.class), "IF-uuid"); + @NotNull + private NamespacedKey keyUUID; /** * An action for the inventory @@ -64,8 +72,13 @@ public class GuiItem { * * @param item the item stack * @param action the action called whenever an interaction with this item happens + * @param plugin the owning plugin of this item + * @see #GuiItem(ItemStack, Consumer) + * @since 0.10.8 */ - public GuiItem(@NotNull ItemStack item, @Nullable Consumer action) { + public GuiItem(@NotNull ItemStack item, @Nullable Consumer action, @NotNull Plugin plugin) { + this.logger = plugin.getLogger(); + this.keyUUID = new NamespacedKey(plugin, "IF-uuid"); this.action = action; this.visible = true; this.properties = new ArrayList<>(); @@ -75,13 +88,35 @@ public GuiItem(@NotNull ItemStack item, @Nullable Consumer applyUUID(); } + /** + * Creates a new gui item based on the item stack and action + * + * @param item the item stack + * @param plugin the owning plugin of this item + * @see #GuiItem(ItemStack) + * @since 0.10.8 + */ + public GuiItem(@NotNull ItemStack item, @NotNull Plugin plugin) { + this(item, event -> {}, plugin); + } + + /** + * Creates a new gui item based on the item stack and action + * + * @param item the item stack + * @param action the action called whenever an interaction with this item happens + */ + public GuiItem(@NotNull ItemStack item, @Nullable Consumer action) { + this(item, action, JavaPlugin.getProvidingPlugin(GuiItem.class)); + } + /** * Creates a new gui item based on the item stack and action * * @param item the item stack */ public GuiItem(@NotNull ItemStack item) { - this(item, null); + this(item, event -> {}); } /** @@ -97,6 +132,8 @@ public GuiItem(@NotNull ItemStack item) { public GuiItem copy() { GuiItem guiItem = new GuiItem(item.clone(), action); + guiItem.logger = this.logger; + guiItem.keyUUID = this.keyUUID; guiItem.visible = visible; guiItem.uuid = uuid; guiItem.properties = new ArrayList<>(properties); @@ -106,7 +143,7 @@ public GuiItem copy() { throw new IllegalArgumentException("item must be able to have ItemMeta (it mustn't be AIR)"); } - meta.getPersistentDataContainer().set(KEY_UUID, UUIDTagType.INSTANCE, guiItem.uuid); + meta.getPersistentDataContainer().set(keyUUID, UUIDTagType.INSTANCE, guiItem.uuid); guiItem.item.setItemMeta(meta); return guiItem; @@ -128,8 +165,7 @@ public void callAction(@NotNull InventoryClickEvent event) { try { action.accept(event); } catch (Throwable t) { - Logger logger = JavaPlugin.getProvidingPlugin(getClass()).getLogger(); - logger.log(Level.SEVERE, "Exception while handling click event in inventory '" + this.logger.log(Level.SEVERE, "Exception while handling click event in inventory '" + event.getView().getTitle() + "', slot=" + event.getSlot() + ", item=" + item.getType(), t); } } @@ -144,7 +180,7 @@ public void applyUUID() { ItemMeta meta = item.getItemMeta(); if (meta != null) { - meta.getPersistentDataContainer().set(KEY_UUID, UUIDTagType.INSTANCE, uuid); + meta.getPersistentDataContainer().set(this.keyUUID, UUIDTagType.INSTANCE, uuid); item.setItemMeta(meta); } } @@ -192,6 +228,18 @@ public ItemStack getItem() { return item; } + /** + * Gets the namespaced key used for this item. + * + * @return the namespaced key + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + public NamespacedKey getKey() { + return keyUUID; + } + /** * Gets the {@link UUID} associated with this {@link GuiItem}. This is for internal use only, and should not be * used. diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index 41aa6aa06..b2873fdb0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -13,12 +13,12 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.inventory.*; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.logging.Logger; /** * Listens to events for {@link Gui}s. Only one instance of this class gets constructed. @@ -28,12 +28,28 @@ */ public class GuiListener implements Listener { + /** + * The owning plugin of this listener. + */ + @NotNull + private final Plugin plugin; + /** * A collection of all {@link Gui} instances that have at least one viewer. */ @NotNull private final Set activeGuiInstances = new HashSet<>(); + /** + * Creates a new listener for all guis for the provided {@code plugin}. + * + * @param plugin the owning plugin of this listener + * @since 0.10.8 + */ + public GuiListener(@NotNull Plugin plugin) { + this.plugin = plugin; + } + /** * Handles clicks in inventories * @@ -66,7 +82,7 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { gui.click(event); if (event.isCancelled()) { - Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { + Bukkit.getScheduler().runTask(this.plugin, () -> { PlayerInventory playerInventory = event.getWhoClicked().getInventory(); /* due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly @@ -334,7 +350,7 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { playerInventory.setItemInOffHand(playerInventory.getItemInOffHand()); if (!gui.isUpdating()) {//this is a hack to remove items correctly when players press the x button in a beacon - Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { + Bukkit.getScheduler().runTask(this.plugin, () -> { gui.callOnClose(event); if (humanEntity.getOpenInventory().getTopInventory() instanceof PlayerInventory) { @@ -343,7 +359,7 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { }); //delay because merchants put items in slots back in the player inventory - Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> { + Bukkit.getScheduler().runTask(this.plugin, () -> { gui.getHumanEntityCache().restoreAndForget(humanEntity); if (gui.getViewerCount() == 1) { @@ -384,8 +400,7 @@ public void onInventoryOpen(@NotNull InventoryOpenEvent event) { */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPluginDisable(@NotNull PluginDisableEvent event) { - Plugin thisPlugin = JavaPlugin.getProvidingPlugin(getClass()); - if (event.getPlugin() != thisPlugin) { + if (event.getPlugin() != this.plugin) { return; } @@ -400,8 +415,11 @@ public void onPluginDisable(@NotNull PluginDisableEvent event) { } if (counter == maxCount) { - thisPlugin.getLogger().warning("Unable to close GUIs on plugin disable: they keep getting opened " - + "(tried: " + maxCount + " times)"); + Logger logger = this.plugin.getLogger(); + + logger.warning( + "Unable to close GUIs on plugin disable: they keep getting opened (tried: " + maxCount + " times)" + ); } } 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 4fd6d8280..c1014f7c0 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 @@ -15,6 +15,8 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -97,6 +99,30 @@ public AnvilGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new anvil gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #AnvilGui(String) + * @since 0.10.8 + */ + public AnvilGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new anvil gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #AnvilGui(TextHolder) + * @since 0.10.8 + */ + public AnvilGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { @@ -138,7 +164,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public AnvilGui copy() { - AnvilGui gui = new AnvilGui(getTitleHolder()); + AnvilGui gui = new AnvilGui(getTitleHolder(), super.plugin); gui.firstItemComponent = firstItemComponent.copy(); gui.secondItemComponent = secondItemComponent.copy(); @@ -332,19 +358,21 @@ private ItemStack[] getTopItems() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded anvil gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static AnvilGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static AnvilGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -356,16 +384,18 @@ public static AnvilGui load(@NotNull Object instance, @NotNull InputStream input * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will own the created gui * @return the loaded anvil gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static AnvilGui load(@NotNull Object instance, @NotNull Element element) { + public static AnvilGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - AnvilGui anvilGui = new AnvilGui(element.getAttribute("title")); + AnvilGui anvilGui = new AnvilGui(element.getAttribute("title"), plugin); anvilGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -415,4 +445,31 @@ public static AnvilGui load(@NotNull Object instance, @NotNull Element element) return anvilGui; } + + /** + * Loads an anvil gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded anvil gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static AnvilGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(AnvilGui.class)); + } + + /** + * Loads an anvil gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded anvil gui + * @since 0.8.0 + */ + @NotNull + public static AnvilGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(AnvilGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index 8651f0f54..cefc4de2d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -13,6 +13,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,6 +66,30 @@ public BarrelGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new barrel gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #BarrelGui(String) + * @since 0.10.8 + */ + public BarrelGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new barrel gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #BarrelGui(TextHolder) + * @since 0.10.8 + */ + public BarrelGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -99,7 +125,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public BarrelGui copy() { - BarrelGui gui = new BarrelGui(getTitleHolder()); + BarrelGui gui = new BarrelGui(getTitleHolder(), super.plugin); gui.inventoryComponent = inventoryComponent.copy(); @@ -184,19 +210,21 @@ public InventoryComponent getInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded barrel gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static BarrelGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static BarrelGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -208,16 +236,18 @@ public static BarrelGui load(@NotNull Object instance, @NotNull InputStream inpu * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded barrel gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static BarrelGui load(@NotNull Object instance, @NotNull Element element) { + public static BarrelGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - BarrelGui barrelGui = new BarrelGui(element.getAttribute("title")); + BarrelGui barrelGui = new BarrelGui(element.getAttribute("title"), plugin); barrelGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -247,4 +277,31 @@ public static BarrelGui load(@NotNull Object instance, @NotNull Element element) return barrelGui; } + + /** + * Loads a barrel gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded barrel gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static BarrelGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(BarrelGui.class)); + } + + /** + * Loads a barrel gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded barrel gui + * @since 0.8.0 + */ + @NotNull + public static BarrelGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(BarrelGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java index 6716e2c6f..dbe19ef54 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java @@ -14,6 +14,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,6 +58,26 @@ public class BeaconGui extends Gui implements InventoryBased { private final BeaconInventory beaconInventory = VersionMatcher.newBeaconInventory(Version.getVersion(), this); + /** + * Constructs a new beacon gui. + * + * @since 0.8.0 + */ + public BeaconGui() { + this(JavaPlugin.getProvidingPlugin(BeaconGui.class)); + } + + /** + * Constructs a new beacon gui for the given {@code plugin}. + * + * @param plugin the owning plugin of this gui + * @see #BeaconGui() + * @since 0.10.8 + */ + public BeaconGui(@NotNull Plugin plugin) { + super(plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { @@ -87,7 +109,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public BeaconGui copy() { - BeaconGui gui = new BeaconGui(); + BeaconGui gui = new BeaconGui(super.plugin); gui.paymentItemComponent = paymentItemComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); @@ -196,19 +218,21 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded beacon gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static BeaconGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static BeaconGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -220,16 +244,18 @@ public static BeaconGui load(@NotNull Object instance, @NotNull InputStream inpu * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded beacon gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static BeaconGui load(@NotNull Object instance, @NotNull Element element) { + public static BeaconGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - BeaconGui beaconGui = new BeaconGui(); + BeaconGui beaconGui = new BeaconGui(plugin); beaconGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -273,4 +299,31 @@ public static BeaconGui load(@NotNull Object instance, @NotNull Element element) return beaconGui; } + + /** + * Loads a beacon gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded beacon gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static BeaconGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(BeaconGui.class)); + } + + /** + * Loads a beacon gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded beacon gui + * @since 0.8.0 + */ + @NotNull + public static BeaconGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(BeaconGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index b41408f6f..8a21c61e3 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,6 +79,30 @@ public BlastFurnaceGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new blast furnace gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #BlastFurnaceGui(String) + * @since 0.10.8 + */ + public BlastFurnaceGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new blast furnace gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #BlastFurnaceGui(TextHolder) + * @since 0.10.8 + */ + public BlastFurnaceGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -108,7 +134,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public BlastFurnaceGui copy() { - BlastFurnaceGui gui = new BlastFurnaceGui(getTitleHolder()); + BlastFurnaceGui gui = new BlastFurnaceGui(getTitleHolder(), super.plugin); gui.ingredientComponent = ingredientComponent.copy(); gui.fuelComponent = fuelComponent.copy(); @@ -228,19 +254,22 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded blast furnace gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static BlastFurnaceGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static BlastFurnaceGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -252,16 +281,18 @@ public static BlastFurnaceGui load(@NotNull Object instance, @NotNull InputStrea * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded blast furnace gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static BlastFurnaceGui load(@NotNull Object instance, @NotNull Element element) { + public static BlastFurnaceGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - BlastFurnaceGui blastFurnaceGui = new BlastFurnaceGui(element.getAttribute("title")); + BlastFurnaceGui blastFurnaceGui = new BlastFurnaceGui(element.getAttribute("title"), plugin); blastFurnaceGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -311,4 +342,31 @@ public static BlastFurnaceGui load(@NotNull Object instance, @NotNull Element el return blastFurnaceGui; } + + /** + * Loads a blast furnace gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded blast furnace gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static BlastFurnaceGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(BlastFurnaceGui.class)); + } + + /** + * Loads a blast furnace gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded blast furnace gui + * @since 0.8.0 + */ + @NotNull + public static BlastFurnaceGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(BlastFurnaceGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 57b82c68c..8a6b85dec 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -89,6 +91,30 @@ public BrewingStandGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new brewing stand gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #BrewingStandGui(String) + * @since 0.10.8 + */ + public BrewingStandGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new brewing stand gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #BrewingStandGui(TextHolder) + * @since 0.10.8 + */ + public BrewingStandGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -122,7 +148,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public BrewingStandGui copy() { - BrewingStandGui gui = new BrewingStandGui(getTitleHolder()); + BrewingStandGui gui = new BrewingStandGui(getTitleHolder(), super.plugin); gui.firstBottleComponent = firstBottleComponent.copy(); gui.secondBottleComponent = secondBottleComponent.copy(); @@ -276,19 +302,22 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded brewing stand gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static BrewingStandGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static BrewingStandGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -300,11 +329,13 @@ public static BrewingStandGui load(@NotNull Object instance, @NotNull InputStrea * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded brewing stand gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static BrewingStandGui load(@NotNull Object instance, @NotNull Element element) { + public static BrewingStandGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } @@ -365,4 +396,31 @@ public static BrewingStandGui load(@NotNull Object instance, @NotNull Element el return brewingStandGui; } + + /** + * Loads a brewing stand gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded brewing stand gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static BrewingStandGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(BrewingStandGui.class)); + } + + /** + * Loads a brewing stand gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded brewing stand gui + * @since 0.8.0 + */ + @NotNull + public static BrewingStandGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(BrewingStandGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 8ff553cd6..53c7c705c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -16,6 +16,7 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -92,6 +93,30 @@ public CartographyTableGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new cartography table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #CartographyTableGui(String) + * @since 0.10.8 + */ + public CartographyTableGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new cartography table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #CartographyTableGui(TextHolder) + * @since 0.10.8 + */ + public CartographyTableGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { @@ -211,8 +236,8 @@ public void handleClickEvent(@NotNull InventoryClickEvent event) { cartographyTableInventory.sendItems(player, getTopItems()); } else if (slot >= 0 && slot <= 2) { //the client rejects the output item if send immediately - Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(getClass()), () -> - cartographyTableInventory.sendItems(player, getTopItems())); + Bukkit.getScheduler().runTask(super.plugin, () -> + cartographyTableInventory.sendItems(player, getTopItems())); if (event.isCancelled()) { cartographyTableInventory.clearCursor(player); @@ -289,19 +314,22 @@ private ItemStack[] getTopItems() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded cartography table gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static CartographyTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static CartographyTableGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -313,16 +341,18 @@ public static CartographyTableGui load(@NotNull Object instance, @NotNull InputS * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded cartography table gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static CartographyTableGui load(@NotNull Object instance, @NotNull Element element) { + public static CartographyTableGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - CartographyTableGui cartographyTableGui = new CartographyTableGui(element.getAttribute("title")); + CartographyTableGui cartographyTableGui = new CartographyTableGui(element.getAttribute("title"), plugin); cartographyTableGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -372,4 +402,31 @@ public static CartographyTableGui load(@NotNull Object instance, @NotNull Elemen return cartographyTableGui; } + + /** + * Loads a cartography table gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded cartography table gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static CartographyTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(CartographyTableGui.class)); + } + + /** + * Loads a cartography table gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded cartography table gui + * @since 0.8.0 + */ + @NotNull + public static CartographyTableGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(CartographyTableGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index 64c8ef7d9..db5c0d6b0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -13,6 +13,8 @@ import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,7 +60,7 @@ public class ChestGui extends NamedGui implements MergedGui, InventoryBased { * @since 0.8.0 */ public ChestGui(int rows, @NotNull String title) { - this(rows, StringHolder.of(title)); + this(rows, StringHolder.of(title), JavaPlugin.getProvidingPlugin(ChestGui.class)); } /** @@ -69,7 +71,33 @@ public ChestGui(int rows, @NotNull String title) { * @since 0.10.0 */ public ChestGui(int rows, @NotNull TextHolder title) { - super(title); + this(rows, title, JavaPlugin.getProvidingPlugin(ChestGui.class)); + } + + /** + * Constructs a new chest gui for the given {@code plugin}. + * + * @param rows the amount of rows this gui should contain, in range 1..6. + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #ChestGui(int, String) + * @since 0.10.8 + */ + public ChestGui(int rows, @NotNull String title, @NotNull Plugin plugin) { + this(rows, StringHolder.of(title), plugin); + } + + /** + * Constructs a new chest gui for the given {@code plugin}. + * + * @param rows the amount of rows this gui should contain, in range 1..6. + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #ChestGui(int, TextHolder) + * @since 0.10.8 + */ + public ChestGui(int rows, @NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); if (!(rows >= 1 && rows <= 6)) { throw new IllegalArgumentException("Rows should be between 1 and 6"); @@ -115,7 +143,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public ChestGui copy() { - ChestGui gui = new ChestGui(getRows(), getTitleHolder()); + ChestGui gui = new ChestGui(getRows(), getTitleHolder(), super.plugin); gui.inventoryComponent = inventoryComponent.copy(); @@ -234,19 +262,21 @@ public InventoryComponent getInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded chest gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static ChestGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static ChestGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -258,11 +288,13 @@ public static ChestGui load(@NotNull Object instance, @NotNull InputStream input * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded chest gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static ChestGui load(@NotNull Object instance, @NotNull Element element) { + public static ChestGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } @@ -279,7 +311,7 @@ public static ChestGui load(@NotNull Object instance, @NotNull Element element) throw new XMLLoadException("Rows attribute is not an integer", exception); } - ChestGui chestGui = new ChestGui(rows, element.getAttribute("title")); + ChestGui chestGui = new ChestGui(rows, element.getAttribute("title"), plugin); chestGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -309,4 +341,31 @@ public static ChestGui load(@NotNull Object instance, @NotNull Element element) return chestGui; } + + /** + * Loads a chest gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded chest gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static ChestGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(ChestGui.class)); + } + + /** + * Loads a chest gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded chest gui + * @since 0.8.0 + */ + @NotNull + public static ChestGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(ChestGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index 549d0f08d..8e2df39c0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -71,6 +73,30 @@ public CraftingTableGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new crafting table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #CraftingTableGui(String) + * @since 0.10.8 + */ + public CraftingTableGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new crafting table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #CraftingTableGui(TextHolder) + * @since 0.10.8 + */ + public CraftingTableGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -104,7 +130,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public CraftingTableGui copy() { - CraftingTableGui gui = new CraftingTableGui(getTitleHolder()); + CraftingTableGui gui = new CraftingTableGui(getTitleHolder(), super.plugin); gui.inputComponent = inputComponent.copy(); gui.outputComponent = outputComponent.copy(); @@ -209,19 +235,22 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded crafting table gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static CraftingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static CraftingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -233,16 +262,17 @@ public static CraftingTableGui load(@NotNull Object instance, @NotNull InputStre * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded crafting table gui - * @since 0.8.0 + * @since 0.10.8 */ @NotNull - public static CraftingTableGui load(@NotNull Object instance, @NotNull Element element) { + public static CraftingTableGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - CraftingTableGui craftingTableGui = new CraftingTableGui(element.getAttribute("title")); + CraftingTableGui craftingTableGui = new CraftingTableGui(element.getAttribute("title"), plugin); craftingTableGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -289,4 +319,31 @@ public static CraftingTableGui load(@NotNull Object instance, @NotNull Element e return craftingTableGui; } + + /** + * Loads a crafting table gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded crafting table gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static CraftingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(CraftingTableGui.class)); + } + + /** + * Loads a crafting table gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded crafting table gui + * @since 0.8.0 + */ + @NotNull + public static CraftingTableGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(CraftingTableGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index c68ea7137..afe5ab6fa 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,6 +67,30 @@ public DispenserGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new dispenser gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #DispenserGui(String) + * @since 0.10.8 + */ + public DispenserGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new dispenser gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #DispenserGui(TextHolder) + * @since 0.10.8 + */ + public DispenserGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -94,7 +120,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public DispenserGui copy() { - DispenserGui gui = new DispenserGui(getTitleHolder()); + DispenserGui gui = new DispenserGui(getTitleHolder(), super.plugin); gui.contentsComponent = contentsComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); @@ -188,19 +214,22 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded dispenser gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static DispenserGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static DispenserGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -212,16 +241,18 @@ public static DispenserGui load(@NotNull Object instance, @NotNull InputStream i * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded dispenser gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static DispenserGui load(@NotNull Object instance, @NotNull Element element) { + public static DispenserGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - DispenserGui dispenserGui = new DispenserGui(element.getAttribute("title")); + DispenserGui dispenserGui = new DispenserGui(element.getAttribute("title"), plugin); dispenserGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -265,4 +296,31 @@ public static DispenserGui load(@NotNull Object instance, @NotNull Element eleme return dispenserGui; } + + /** + * Loads a dispenser gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded dispenser gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static DispenserGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(DispenserGui.class)); + } + + /** + * Loads a dispenser gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded dispenser gui + * @since 0.8.0 + */ + @NotNull + public static DispenserGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(DispenserGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index 7ed2bd3c8..0107982d0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,6 +67,30 @@ public DropperGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new dropper gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #DropperGui(String) + * @since 0.10.8 + */ + public DropperGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new dropper gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #DropperGui(TextHolder) + * @since 0.10.8 + */ + public DropperGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -94,7 +120,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public DropperGui copy() { - DropperGui gui = new DropperGui(getTitleHolder()); + DropperGui gui = new DropperGui(getTitleHolder(), super.plugin); gui.contentsComponent = contentsComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); @@ -188,19 +214,21 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded dropper gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static DropperGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static DropperGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -212,16 +240,18 @@ public static DropperGui load(@NotNull Object instance, @NotNull InputStream inp * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded dropper gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static DropperGui load(@NotNull Object instance, @NotNull Element element) { + public static DropperGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - DropperGui dropperGui = new DropperGui(element.getAttribute("title")); + DropperGui dropperGui = new DropperGui(element.getAttribute("title"), plugin); dropperGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -265,4 +295,31 @@ public static DropperGui load(@NotNull Object instance, @NotNull Element element return dropperGui; } + + /** + * Loads a dropper gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded dropper gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static DropperGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(DropperGui.class)); + } + + /** + * Loads a dropper gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded dropper gui + * @since 0.8.0 + */ + @NotNull + public static DropperGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(DropperGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 78004f0eb..879d5c76c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -15,6 +15,8 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,6 +79,30 @@ public EnchantingTableGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new enchanting table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #EnchantingTableGui(String) + * @since 0.10.8 + */ + public EnchantingTableGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new enchanting table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #EnchantingTableGui(TextHolder) + * @since 0.10.8 + */ + public EnchantingTableGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { @@ -113,7 +139,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public EnchantingTableGui copy() { - EnchantingTableGui gui = new EnchantingTableGui(getTitleHolder()); + EnchantingTableGui gui = new EnchantingTableGui(getTitleHolder(), super.plugin); gui.inputComponent = inputComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); @@ -237,19 +263,22 @@ private ItemStack[] getTopItems() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded enchanting table gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static EnchantingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static EnchantingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -261,16 +290,18 @@ public static EnchantingTableGui load(@NotNull Object instance, @NotNull InputSt * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded enchanting table gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static EnchantingTableGui load(@NotNull Object instance, @NotNull Element element) { + public static EnchantingTableGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - EnchantingTableGui enchantingTableGui = new EnchantingTableGui(element.getAttribute("title")); + EnchantingTableGui enchantingTableGui = new EnchantingTableGui(element.getAttribute("title"), plugin); enchantingTableGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -314,4 +345,31 @@ public static EnchantingTableGui load(@NotNull Object instance, @NotNull Element return enchantingTableGui; } + + /** + * Loads an enchanting table gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded enchanting table gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static EnchantingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(EnchantingTableGui.class)); + } + + /** + * Loads an enchanting table gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded enchanting table gui + * @since 0.8.0 + */ + @NotNull + public static EnchantingTableGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(EnchantingTableGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index dd4e07f34..dab9c634c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -13,6 +13,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,6 +66,30 @@ public EnderChestGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new ender chest gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #EnderChestGui(String) + * @since 0.10.8 + */ + public EnderChestGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new ender chest gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #EnderChestGui(TextHolder) + * @since 0.10.8 + */ + public EnderChestGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -99,7 +125,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public EnderChestGui copy() { - EnderChestGui gui = new EnderChestGui(getTitleHolder()); + EnderChestGui gui = new EnderChestGui(getTitleHolder(), super.plugin); gui.inventoryComponent = inventoryComponent.copy(); @@ -184,19 +210,22 @@ public InventoryComponent getInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded ender chest gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static EnderChestGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static EnderChestGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -208,16 +237,18 @@ public static EnderChestGui load(@NotNull Object instance, @NotNull InputStream * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded ender chest gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static EnderChestGui load(@NotNull Object instance, @NotNull Element element) { + public static EnderChestGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - EnderChestGui enderChestGui = new EnderChestGui(element.getAttribute("title")); + EnderChestGui enderChestGui = new EnderChestGui(element.getAttribute("title"), plugin); enderChestGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -247,4 +278,31 @@ public static EnderChestGui load(@NotNull Object instance, @NotNull Element elem return enderChestGui; } + + /** + * Loads an ender chest gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded ender chest gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static EnderChestGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(EnderChestGui.class)); + } + + /** + * Loads an ender chest gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded ender chest gui + * @since 0.8.0 + */ + @NotNull + public static EnderChestGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(EnderChestGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index 5ad6fa8d6..cc90a4f1b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,6 +79,30 @@ public FurnaceGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new furnace gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #FurnaceGui(String) + * @since 0.10.8 + */ + public FurnaceGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new furnace gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #FurnaceGui(TextHolder) + * @since 0.10.8 + */ + public FurnaceGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -108,7 +134,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public FurnaceGui copy() { - FurnaceGui gui = new FurnaceGui(getTitleHolder()); + FurnaceGui gui = new FurnaceGui(getTitleHolder(), super.plugin); gui.ingredientComponent = ingredientComponent.copy(); gui.fuelComponent = fuelComponent.copy(); @@ -232,19 +258,21 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded furnace gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static FurnaceGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static FurnaceGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -256,16 +284,18 @@ public static FurnaceGui load(@NotNull Object instance, @NotNull InputStream inp * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded furnace gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static FurnaceGui load(@NotNull Object instance, @NotNull Element element) { + public static FurnaceGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - FurnaceGui furnaceGui = new FurnaceGui(element.getAttribute("title")); + FurnaceGui furnaceGui = new FurnaceGui(element.getAttribute("title"), plugin); furnaceGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -315,4 +345,31 @@ public static FurnaceGui load(@NotNull Object instance, @NotNull Element element return furnaceGui; } + + /** + * Loads a furnace gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded furnace gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static FurnaceGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(FurnaceGui.class)); + } + + /** + * Loads a furnace gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded furnace gui + * @since 0.8.0 + */ + @NotNull + public static FurnaceGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(FurnaceGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index 42a1de060..82e6dc0ca 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -15,6 +15,8 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -83,6 +85,30 @@ public GrindstoneGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new grindstone gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #GrindstoneGui(String) + * @since 0.10.8 + */ + public GrindstoneGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new grindstone gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #GrindstoneGui(TextHolder) + * @since 0.10.8 + */ + public GrindstoneGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { @@ -120,7 +146,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public GrindstoneGui copy() { - GrindstoneGui gui = new GrindstoneGui(getTitleHolder()); + GrindstoneGui gui = new GrindstoneGui(getTitleHolder(), super.plugin); gui.itemsComponent = itemsComponent.copy(); gui.resultComponent = resultComponent.copy(); @@ -262,19 +288,22 @@ private ItemStack[] getTopItems() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded furnace gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static GrindstoneGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static GrindstoneGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -286,16 +315,18 @@ public static GrindstoneGui load(@NotNull Object instance, @NotNull InputStream * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded grindstone gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static GrindstoneGui load(@NotNull Object instance, @NotNull Element element) { + public static GrindstoneGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - GrindstoneGui grindstoneGui = new GrindstoneGui(element.getAttribute("title")); + GrindstoneGui grindstoneGui = new GrindstoneGui(element.getAttribute("title"), plugin); grindstoneGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -342,4 +373,31 @@ public static GrindstoneGui load(@NotNull Object instance, @NotNull Element elem return grindstoneGui; } + + /** + * Loads a grindstone gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded furnace gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static GrindstoneGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(GrindstoneGui.class)); + } + + /** + * Loads a grindstone gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded grindstone gui + * @since 0.8.0 + */ + @NotNull + public static GrindstoneGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(GrindstoneGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index b377bdb10..01f10d1b5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,6 +67,30 @@ public HopperGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new hopper gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #HopperGui(String) + * @since 0.10.8 + */ + public HopperGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new hopper gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #HopperGui(TextHolder) + * @since 0.10.8 + */ + public HopperGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -94,7 +120,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public HopperGui copy() { - HopperGui gui = new HopperGui(getTitleHolder()); + HopperGui gui = new HopperGui(getTitleHolder(), super.plugin); gui.slotsComponent = slotsComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); @@ -188,19 +214,21 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded hopper gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static HopperGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static HopperGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -212,16 +240,18 @@ public static HopperGui load(@NotNull Object instance, @NotNull InputStream inpu * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded hopper gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static HopperGui load(@NotNull Object instance, @NotNull Element element) { + public static HopperGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - HopperGui hopperGui = new HopperGui(element.getAttribute("title")); + HopperGui hopperGui = new HopperGui(element.getAttribute("title"), plugin); hopperGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -265,4 +295,31 @@ public static HopperGui load(@NotNull Object instance, @NotNull Element element) return hopperGui; } + + /** + * Loads a hopper gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded hopper gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static HopperGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(HopperGui.class)); + } + + /** + * Loads a hopper gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded hopper gui + * @since 0.8.0 + */ + @NotNull + public static HopperGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(HopperGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index bb24ffecf..fbde4b5d9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -21,6 +21,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Merchant; import org.bukkit.inventory.MerchantRecipe; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -117,7 +119,31 @@ public MerchantGui(@NotNull String title) { * @since 0.10.0 */ public MerchantGui(@NotNull TextHolder title) { - super(title); + this(title, JavaPlugin.getProvidingPlugin(MerchantGui.class)); + } + + /** + * Constructs a new merchant gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #MerchantGui(String) + * @since 0.10.8 + */ + public MerchantGui(@NotNull String title, @NotNull Plugin plugin) { + this(StringHolder.of(title), plugin); + } + + /** + * Constructs a new merchant gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #MerchantGui(TextHolder) + * @since 0.10.8 + */ + public MerchantGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); this.merchant = getTitleHolder().asMerchantTitle(); } @@ -213,7 +239,7 @@ public void show(@NotNull HumanEntity humanEntity) { @NotNull @Override public Gui copy() { - MerchantGui gui = new MerchantGui(getTitleHolder()); + MerchantGui gui = new MerchantGui(getTitleHolder(), super.plugin); gui.inputComponent = inputComponent.copy(); gui.playerInventoryComponent = playerInventoryComponent.copy(); @@ -386,19 +412,21 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded merchant gui - * @since 0.10.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static MerchantGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static MerchantGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -410,17 +438,19 @@ public static MerchantGui load(@NotNull Object instance, @NotNull InputStream in * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded merchant gui - * @since 0.10.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull @Contract(pure = true) - public static MerchantGui load(@NotNull Object instance, @NotNull Element element) { + public static MerchantGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - MerchantGui merchantGui = new MerchantGui(element.getAttribute("title")); + MerchantGui merchantGui = new MerchantGui(element.getAttribute("title"), plugin); merchantGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -530,4 +560,32 @@ public static MerchantGui load(@NotNull Object instance, @NotNull Element elemen return merchantGui; } + + /** + * Loads a merchant gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded merchant gui + * @since 0.10.0 + */ + @Nullable + @Contract(pure = true) + public static MerchantGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(MerchantGui.class)); + } + + /** + * Loads a merchant gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded merchant gui + * @since 0.10.0 + */ + @NotNull + @Contract(pure = true) + public static MerchantGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(MerchantGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index d9ac269c3..9d0733a77 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -13,6 +13,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,6 +66,30 @@ public ShulkerBoxGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new shulker box gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #ShulkerBoxGui(String) + * @since 0.10.8 + */ + public ShulkerBoxGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new shulker box gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #ShulkerBoxGui(TextHolder) + * @since 0.10.8 + */ + public ShulkerBoxGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -98,7 +124,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public ShulkerBoxGui copy() { - ShulkerBoxGui gui = new ShulkerBoxGui(getTitleHolder()); + ShulkerBoxGui gui = new ShulkerBoxGui(getTitleHolder(), super.plugin); gui.inventoryComponent = inventoryComponent.copy(); @@ -183,19 +209,22 @@ public InventoryComponent getInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded shulker box gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static ShulkerBoxGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static ShulkerBoxGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -207,16 +236,18 @@ public static ShulkerBoxGui load(@NotNull Object instance, @NotNull InputStream * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded shulker box gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static ShulkerBoxGui load(@NotNull Object instance, @NotNull Element element) { + public static ShulkerBoxGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - ShulkerBoxGui shulkerBoxGui = new ShulkerBoxGui(element.getAttribute("title")); + ShulkerBoxGui shulkerBoxGui = new ShulkerBoxGui(element.getAttribute("title"), plugin); shulkerBoxGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -246,4 +277,31 @@ public static ShulkerBoxGui load(@NotNull Object instance, @NotNull Element elem return shulkerBoxGui; } + + /** + * Loads a shulker box gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded shulker box gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static ShulkerBoxGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(ShulkerBoxGui.class)); + } + + /** + * Loads a shulker box gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded shulker box gui + * @since 0.8.0 + */ + @NotNull + public static ShulkerBoxGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(ShulkerBoxGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index d1edcb9a0..0c39e80c9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -15,6 +15,8 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -90,6 +92,30 @@ public SmithingTableGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new smithing table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #SmithingTableGui(String) + * @since 0.10.8 + */ + public SmithingTableGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new smithing table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #SmithingTableGui(TextHolder) + * @since 0.10.8 + */ + public SmithingTableGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { @@ -128,7 +154,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public SmithingTableGui copy() { - SmithingTableGui gui = new SmithingTableGui(getTitleHolder()); + SmithingTableGui gui = new SmithingTableGui(getTitleHolder(), super.plugin); gui.firstItemComponent = firstItemComponent.copy(); gui.secondItemComponent = secondItemComponent.copy(); @@ -299,19 +325,22 @@ private ItemStack[] getTopItems() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded smithing table gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static SmithingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static SmithingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -323,16 +352,17 @@ public static SmithingTableGui load(@NotNull Object instance, @NotNull InputStre * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded smithing table gui - * @since 0.8.0 + * @since 0.10.8 */ @NotNull - public static SmithingTableGui load(@NotNull Object instance, @NotNull Element element) { + public static SmithingTableGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - SmithingTableGui smithingTableGui = new SmithingTableGui(element.getAttribute("title")); + SmithingTableGui smithingTableGui = new SmithingTableGui(element.getAttribute("title"), plugin); smithingTableGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -382,4 +412,31 @@ public static SmithingTableGui load(@NotNull Object instance, @NotNull Element e return smithingTableGui; } + + /** + * Loads a smithing table gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded smithing table gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static SmithingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(SmithingTableGui.class)); + } + + /** + * Loads a smithing table gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded smithing table gui + * @since 0.8.0 + */ + @NotNull + public static SmithingTableGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(SmithingTableGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index 600b6441b..b54dea119 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -10,6 +10,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,6 +79,30 @@ public SmokerGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new smoker gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #SmokerGui(String) + * @since 0.10.8 + */ + public SmokerGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new smoker gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #SmokerGui(TextHolder) + * @since 0.10.8 + */ + public SmokerGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (isDirty()) { @@ -108,7 +134,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public SmokerGui copy() { - SmokerGui gui = new SmokerGui(getTitleHolder()); + SmokerGui gui = new SmokerGui(getTitleHolder(), super.plugin); gui.ingredientComponent = ingredientComponent.copy(); gui.fuelComponent = fuelComponent.copy(); @@ -228,19 +254,21 @@ public InventoryComponent getPlayerInventoryComponent() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded smoker gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static SmokerGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static SmokerGui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -252,16 +280,18 @@ public static SmokerGui load(@NotNull Object instance, @NotNull InputStream inpu * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded smoker gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static SmokerGui load(@NotNull Object instance, @NotNull Element element) { + public static SmokerGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - SmokerGui smokerGui = new SmokerGui(element.getAttribute("title")); + SmokerGui smokerGui = new SmokerGui(element.getAttribute("title"), plugin); smokerGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -311,4 +341,31 @@ public static SmokerGui load(@NotNull Object instance, @NotNull Element element) return smokerGui; } + + /** + * Loads a smoker gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded smoker gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static SmokerGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(SmokerGui.class)); + } + + /** + * Loads a smoker gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded smoker gui + * @since 0.8.0 + */ + @NotNull + public static SmokerGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(SmokerGui.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 769d794eb..8f25e24b6 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -15,6 +15,8 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -84,6 +86,30 @@ public StonecutterGui(@NotNull TextHolder title) { super(title); } + /** + * Constructs a new stonecutter gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #StonecutterGui(String) + * @since 0.10.8 + */ + public StonecutterGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new stonecutter gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #StonecutterGui(TextHolder) + * @since 0.10.8 + */ + public StonecutterGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + @Override public void show(@NotNull HumanEntity humanEntity) { if (!(humanEntity instanceof Player)) { @@ -121,7 +147,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public StonecutterGui copy() { - StonecutterGui gui = new StonecutterGui(getTitleHolder()); + StonecutterGui gui = new StonecutterGui(getTitleHolder(), super.plugin); gui.inputComponent = inputComponent.copy(); gui.resultComponent = resultComponent.copy(); @@ -262,19 +288,22 @@ private ItemStack[] getTopItems() { * * @param instance the instance on which to reference fields and methods * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui * @return the loaded stone cutter gui - * @since 0.8.0 + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable @Contract(pure = true) - public static StonecutterGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static StonecutterGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); documentElement.normalize(); - return load(instance, documentElement); + return load(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; @@ -286,16 +315,18 @@ public static StonecutterGui load(@NotNull Object instance, @NotNull InputStream * * @param instance the instance on which to reference fields and methods * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui * @return the loaded stonecutter gui - * @since 0.8.0 + * @see #load(Object, Element) + * @since 0.10.8 */ @NotNull - public static StonecutterGui load(@NotNull Object instance, @NotNull Element element) { + public static StonecutterGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { if (!element.hasAttribute("title")) { throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); } - StonecutterGui stonecutterGui = new StonecutterGui(element.getAttribute("title")); + StonecutterGui stonecutterGui = new StonecutterGui(element.getAttribute("title"), plugin); stonecutterGui.initializeOrThrow(instance, element); if (element.hasAttribute("populate")) { @@ -342,4 +373,31 @@ public static StonecutterGui load(@NotNull Object instance, @NotNull Element ele return stonecutterGui; } + + /** + * Loads a stone cutter gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded stone cutter gui + * @since 0.8.0 + */ + @Nullable + @Contract(pure = true) + public static StonecutterGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(StonecutterGui.class)); + } + + /** + * Loads a stonecutter gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded stonecutter gui + * @since 0.8.0 + */ + @NotNull + public static StonecutterGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(StonecutterGui.class)); + } } 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 4d8261075..a1d721021 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 @@ -6,6 +6,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.*; import com.github.stefvanschie.inventoryframework.pane.*; import com.github.stefvanschie.inventoryframework.pane.component.*; +import com.github.stefvanschie.inventoryframework.util.TriFunction; import com.github.stefvanschie.inventoryframework.util.XMLUtil; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -16,6 +17,7 @@ import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -34,13 +36,18 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.logging.Level; -import java.util.logging.Logger; /** * The base class of all GUIs */ public abstract class Gui { + /** + * The plugin that owns this gui + */ + @NotNull + protected final Plugin plugin; + /** * The inventory of this gui */ @@ -110,14 +117,15 @@ public abstract class Gui { * The pane mapping which will allow users to register their own panes to be used in XML files */ @NotNull - private static final Map> PANE_MAPPINGS = new HashMap<>(); + private static final Map> + PANE_MAPPINGS = new HashMap<>(); /** * The gui mappings which determine which gui type belongs to which identifier */ @NotNull - private static final Map> GUI_MAPPINGS - = new HashMap<>(); + private static final Map> + GUI_MAPPINGS = new HashMap<>(); /** * A map containing the relations between inventories and their respective gui. This is needed because Bukkit and @@ -132,25 +140,17 @@ public abstract class Gui { */ private static boolean hasRegisteredListeners; - /** - * Constructs a new GUI - * - * @since 0.8.0 - */ - public Gui() { - this(JavaPlugin.getProvidingPlugin(Gui.class)); - } - /** * Constructs a new gui with the provided plugin. * * @param plugin the plugin - * @see Gui#Gui() for a constructor that automatically detects the wanted plugin - * @since 0.10.0 + * @since 0.10.8 */ - public Gui(@NotNull JavaPlugin plugin) { + public Gui(@NotNull Plugin plugin) { + this.plugin = plugin; + if (!hasRegisteredListeners) { - Bukkit.getPluginManager().registerEvents(new GuiListener(), plugin); + Bukkit.getPluginManager().registerEvents(new GuiListener(plugin), plugin); hasRegisteredListeners = true; } @@ -167,7 +167,8 @@ public Gui(@NotNull JavaPlugin plugin) { * Makes a copy of this gui and returns it. This makes a deep copy of the gui. This entails that the underlying * panes will be copied as per their {@link Pane#copy} and miscellaneous data will be copied. The copy of this gui, * will however have no viewers even if this gui currently has viewers. With this, cache data for viewers will also - * be non-existent for the copied gui. The returned gui will never be reference equal to the current gui. + * be non-existent for the copied gui. The original owning plugin of the gui is preserved, but the plugin will not + * be deeply copied. The returned gui will never be reference equal to the current gui. * * @return a copy of the gui * @since 0.6.2 @@ -276,14 +277,16 @@ public HumanEntityCache getHumanEntityCache() { /** * Loads a Gui from a given input stream. - * Returns null instead of throwing an exception in case of a failure. * * @param instance the class instance for all reflection lookups * @param inputStream the file * @return the gui or null if the loading failed + * @throws XMLLoadException if loading could not finish successfully, due to e.g., a malformed file + * @see #load(Object, InputStream) + * @since 0.10.8 */ @Nullable - public static Gui load(@NotNull Object instance, @NotNull InputStream inputStream) { + public static Gui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); Element documentElement = document.getDocumentElement(); @@ -294,13 +297,35 @@ public static Gui load(@NotNull Object instance, @NotNull InputStream inputStrea throw new XMLLoadException("Type attribute must be specified when loading via Gui.load"); } - return GUI_MAPPINGS.get(documentElement.getAttribute("type")).apply(instance, documentElement); + String type = documentElement.getAttribute("type"); + TriFunction mapping = GUI_MAPPINGS + .get(type); + + if (mapping == null) { + throw new XMLLoadException("Type attribute '" + type + "' is invalid"); + } + + return mapping.apply(instance, documentElement, plugin); } catch (SAXException | ParserConfigurationException | IOException e) { e.printStackTrace(); return null; } } + /** + * Loads a Gui from a given input stream. + * Returns null instead of throwing an exception in case of a failure. + * + * @param instance the class instance for all reflection lookups + * @param inputStream the file + * @return the gui or null if the loading failed + * @throws XMLLoadException if loading could not finish successfully, due to e.g., a malformed file + */ + @Nullable + public static Gui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(Gui.class)); + } + /** * Initializes standard fields from a Gui from a given input stream. * Throws a {@link RuntimeException} instead of returning null in case of a failure. @@ -548,13 +573,13 @@ protected void callCallback(@Nullable Consumer biFunction) { + public static void registerPane(@NotNull String name, + @NotNull TriFunction triFunction) { if (PANE_MAPPINGS.containsKey(name)) { throw new IllegalArgumentException("pane name '" + name + "' is already registered"); } - PANE_MAPPINGS.put(name, biFunction); + PANE_MAPPINGS.put(name, triFunction); + } + + /** + * Registers a name that can be used inside an XML file to add custom panes + * + * @param name the name of the pane to be used in the XML file + * @param biFunction how the pane loading should be processed + * @throws IllegalArgumentException when a pane with this name is already registered + */ + public static void registerPane(@NotNull String name, @NotNull BiFunction biFunction) { + registerPane(name, (object, element, plugin) -> biFunction.apply(object, element)); } /** * Registers a type that can be used inside an XML file to specify the gui type * * @param name the name of the type of gui to be used in an XML file - * @param biFunction how the gui creation should be processed + * @param triFunction how the gui creation should be processed * @throws IllegalArgumentException when a gui type with this name is already registered + * @since 0.10.8 */ - public static void registerGui(@NotNull String name, @NotNull BiFunction biFunction) { + public static void registerGui(@NotNull String name, + @NotNull TriFunction triFunction) { if (GUI_MAPPINGS.containsKey(name)) { throw new IllegalArgumentException("Gui name '" + name + "' is already registered"); } - GUI_MAPPINGS.put(name, biFunction); + GUI_MAPPINGS.put(name, triFunction); + } + + /** + * Registers a type that can be used inside an XML file to specify the gui type + * + * @param name the name of the type of gui to be used in an XML file + * @param biFunction how the gui creation should be processed + * @throws IllegalArgumentException when a gui type with this name is already registered + * @deprecated this method is no longer used internally and has been superseded by + * {@link #registerPane(String, TriFunction)} + */ + @Deprecated + public static void registerGui(@NotNull String name, + @NotNull BiFunction biFunction) { + registerGui(name, (object, element, plugin) -> biFunction.apply(object, element)); + } + + /** + * Loads a pane by the given instance and node + * + * @param instance the instance + * @param node the node + * @param plugin the plugin to load the pane with + * @return the pane + * @throws XMLLoadException if the name of the node does not correspond to a valid pane. + * @since 0.10.8 + */ + @NotNull + public static Pane loadPane(@NotNull Object instance, @NotNull Node node, @NotNull Plugin plugin) { + String name = node.getNodeName(); + TriFunction mapping = PANE_MAPPINGS.get(name); + + if (mapping == null) { + throw new XMLLoadException("Pane '" + name + "' is not registered or does not exist"); + } + + return mapping.apply(instance, (Element) node, plugin); } /** @@ -622,41 +700,71 @@ public static void registerGui(@NotNull String name, @NotNull BiFunction) MasonryPane::load); + registerPane("outlinepane", + (TriFunction) OutlinePane::load); + registerPane("paginatedpane", + (TriFunction) PaginatedPane::load); + registerPane("patternpane", + (TriFunction) PatternPane::load); + registerPane("staticpane", + (TriFunction) StaticPane::load); + + registerPane("cyclebutton", + (TriFunction) CycleButton::load); + registerPane("label", + (TriFunction) Label::load); + registerPane("percentagebar", + (TriFunction) PercentageBar::load); + registerPane("slider", + (TriFunction) Slider::load); + registerPane("togglebutton", + (TriFunction) ToggleButton::load); + + registerGui("anvil", + (TriFunction) AnvilGui::load); + registerGui("barrel", + (TriFunction) BarrelGui::load); + registerGui("beacon", + (TriFunction) BeaconGui::load); + registerGui("blast-furnace", + (TriFunction) BlastFurnaceGui::load); + registerGui("brewing-stand", + (TriFunction) BrewingStandGui::load); + registerGui("cartography-table", + (TriFunction) CartographyTableGui::load); + registerGui("chest", + (TriFunction) ChestGui::load); + registerGui("crafting-table", + (TriFunction) CraftingTableGui::load); + registerGui("dispenser", + (TriFunction) DispenserGui::load); + registerGui("dropper", + (TriFunction) DropperGui::load); + registerGui("enchanting-table", + (TriFunction) EnchantingTableGui::load); + registerGui("ender-chest", + (TriFunction) EnderChestGui::load); + registerGui("furnace", + (TriFunction) FurnaceGui::load); + registerGui("grindstone", + (TriFunction) GrindstoneGui::load); + registerGui("hopper", + (TriFunction) HopperGui::load); + registerGui("merchant", + (TriFunction) MerchantGui::load); + registerGui("shulker-box", + (TriFunction) ShulkerBoxGui::load); + registerGui("smithing-table", + (TriFunction) SmithingTableGui::load); + registerGui("smoker", + (TriFunction) SmokerGui::load); + registerGui("stonecutter", + (TriFunction) StonecutterGui::load); } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java index 95d07b360..2bba5b869 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/util/NamedGui.java @@ -2,6 +2,8 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -35,6 +37,32 @@ public NamedGui(@NotNull String title) { * @since 0.10.0 */ public NamedGui(@NotNull TextHolder title) { + this(title, JavaPlugin.getProvidingPlugin(NamedGui.class)); + } + + /** + * Constructs a new gui with a title for the given {@code plugin}. + * + * @param title the title/name of this gui + * @param plugin the owning plugin of this gui + * @see #NamedGui(String) + * @since 0.10.8 + */ + public NamedGui(@NotNull String title, @NotNull Plugin plugin) { + this(StringHolder.of(title), plugin); + } + + /** + * Constructs a new gui with a title for the given {@code plugin}. + * + * @param title the title/name of this gui + * @param plugin the owning plugin of this gui + * @see #NamedGui(TextHolder) + * @since 0.10.8 + */ + public NamedGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(plugin); + this.title = title; } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java index 9847f2984..f9a717135 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java @@ -5,6 +5,8 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -249,10 +251,12 @@ public void setOrientation(@NotNull Orientation orientation) { * * @param instance the instance class * @param element the element + * @param plugin the plugin that will be the owner of the created items * @return the masonry pane + * @since 0.10.8 */ @NotNull - public static MasonryPane load(@NotNull Object instance, @NotNull Element element) { + public static MasonryPane load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { try { MasonryPane masonryPane = new MasonryPane( Integer.parseInt(element.getAttribute("length")), @@ -275,7 +279,7 @@ public static MasonryPane load(@NotNull Object instance, @NotNull Element elemen continue; } - masonryPane.addPane(Gui.loadPane(instance, pane)); + masonryPane.addPane(Gui.loadPane(instance, pane, plugin)); } return masonryPane; @@ -283,4 +287,19 @@ public static MasonryPane load(@NotNull Object instance, @NotNull Element elemen throw new XMLLoadException(exception); } } + + /** + * Loads a masonry pane from a given element + * + * @param instance the instance class + * @param element the element + * @return the masonry pane + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Deprecated + public static MasonryPane load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(MasonryPane.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java index 157a4d52d..34fde4ea0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java @@ -9,6 +9,8 @@ import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -488,10 +490,12 @@ public boolean isFlippedVertically() { * * @param instance the instance class * @param element the element + * @param plugin the plugin that will be the owner of the created items * @return the outline pane + * @since 0.10.8 */ @NotNull - public static OutlinePane load(@NotNull Object instance, @NotNull Element element) { + public static OutlinePane load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { try { OutlinePane outlinePane = new OutlinePane( Integer.parseInt(element.getAttribute("length")), @@ -525,7 +529,7 @@ public static OutlinePane load(@NotNull Object instance, @NotNull Element elemen continue; if (item.getNodeName().equals("empty")) - outlinePane.addItem(new GuiItem(new ItemStack(Material.AIR))); + outlinePane.addItem(new GuiItem(new ItemStack(Material.AIR), plugin)); else outlinePane.addItem(Pane.loadItem(instance, (Element) item)); } @@ -536,6 +540,21 @@ public static OutlinePane load(@NotNull Object instance, @NotNull Element elemen } } + /** + * Loads an outline pane from a given element + * + * @param instance the instance class + * @param element the element + * @return the outline pane + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Deprecated + public static OutlinePane load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(OutlinePane.class)); + } + /** * An enum containing different alignments that can be used on the outline pane. * diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index cc8d98331..99693d4a2 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -9,6 +9,8 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -95,9 +97,11 @@ public void setPage(int page) { * This can be helpful when dealing with lists of unknown size. * * @param items The list to populate the pane with + * @param plugin the plugin that will be the owner of the items created + * @see #populateWithItemStacks(List) + * @since 0.10.8 */ - @Contract("null -> fail") - public void populateWithItemStacks(@NotNull List items) { + public void populateWithItemStacks(@NotNull List<@NotNull ItemStack> items, @NotNull Plugin plugin) { //Don't do anything if the list is empty if (items.isEmpty()) { return; @@ -117,13 +121,22 @@ public void populateWithItemStacks(@NotNull List items) { break; } - page.addItem(new GuiItem(items.get(index))); + page.addItem(new GuiItem(items.get(index), plugin)); } this.addPane(i, page); } } + /** + * Populates the PaginatedPane based on the provided list by adding new pages until all items can fit. + * This can be helpful when dealing with lists of unknown size. + * + * @param items The list to populate the pane with + */ + public void populateWithItemStacks(@NotNull List items) { + populateWithItemStacks(items, JavaPlugin.getProvidingPlugin(PaginatedPane.class)); + } /** * Populates the PaginatedPane based on the provided list by adding new pages until all items can fit. @@ -166,9 +179,12 @@ public void populateWithGuiItems(@NotNull List items) { * * @param displayNames The display names for all the items * @param material The material to use for the {@link org.bukkit.inventory.ItemStack}s + * @param plugin the plugin that will be the owner of the created items + * @see #populateWithNames(List, Material) + * @since 0.10.8 */ - @Contract("null, _ -> fail") - public void populateWithNames(@NotNull List displayNames, @Nullable Material material) { + public void populateWithNames(@NotNull List displayNames, @Nullable Material material, + @NotNull Plugin plugin) { if(material == null || material == Material.AIR) return; populateWithItemStacks(displayNames.stream().map(name -> { @@ -177,9 +193,21 @@ public void populateWithNames(@NotNull List displayNames, @Nullable Mate itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); itemStack.setItemMeta(itemMeta); return itemStack; - }).collect(Collectors.toList())); + }).collect(Collectors.toList()), plugin); } + /** + * This method creates a list of ItemStacks all with the given {@code material} and the display names. + * After that it calls {@link #populateWithItemStacks(List)} + * This method also translates the color char {@code &} for all names. + * + * @param displayNames The display names for all the items + * @param material The material to use for the {@link org.bukkit.inventory.ItemStack}s + */ + public void populateWithNames(@NotNull List displayNames, @Nullable Material material) { + populateWithNames(displayNames, material, JavaPlugin.getProvidingPlugin(PaginatedPane.class)); + } + @Override public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { @@ -344,10 +372,12 @@ public void clear() { * * @param instance the instance class * @param element the element + * @param plugin the plugin that will be used to create the items * @return the paginated pane + * @since 0.10.8 */ @NotNull - public static PaginatedPane load(@NotNull Object instance, @NotNull Element element) { + public static PaginatedPane load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { try { PaginatedPane paginatedPane = new PaginatedPane( Integer.parseInt(element.getAttribute("length")), @@ -379,7 +409,7 @@ public static PaginatedPane load(@NotNull Object instance, @NotNull Element elem continue; } - paginatedPane.addPane(pageCount, Gui.loadPane(instance, pane)); + paginatedPane.addPane(pageCount, Gui.loadPane(instance, pane, plugin)); } pageCount++; @@ -390,4 +420,19 @@ public static PaginatedPane load(@NotNull Object instance, @NotNull Element elem throw new XMLLoadException(exception); } } + + /** + * Loads a paginated pane from a given element + * + * @param instance the instance class + * @param element the element + * @return the paginated pane + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Deprecated + public static PaginatedPane load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(PaginatedPane.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 93b67e84c..f36e41ecc 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -7,7 +7,6 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.exception.XMLReflectionException; import com.github.stefvanschie.inventoryframework.pane.util.Mask; -import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import com.github.stefvanschie.inventoryframework.util.SkullUtil; import com.github.stefvanschie.inventoryframework.util.UUIDTagType; import com.github.stefvanschie.inventoryframework.util.XMLUtil; @@ -19,6 +18,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -33,8 +33,6 @@ import java.util.*; import java.util.function.Consumer; import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; /** * The base class for all panes. @@ -300,11 +298,14 @@ public void setPriority(@NotNull Priority priority) { * * @param instance the instance * @param element the element + * @param plugin the plugin that will be the owner of the created item * @return the gui item + * @see #loadItem(Object, Element) + * @since 0.10.8 */ @NotNull @Contract(pure = true) - public static GuiItem loadItem(@NotNull Object instance, @NotNull Element element) { + public static GuiItem loadItem(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { String id = element.getAttribute("id"); Material material = Material.matchMaterial(id.toUpperCase(Locale.getDefault())); @@ -483,7 +484,7 @@ else if (parameterCount == properties.size() + 1) { } } - GuiItem item = new GuiItem(itemStack, action); + GuiItem item = new GuiItem(itemStack, action, plugin); if (element.hasAttribute("field")) XMLUtil.loadFieldAttribute(instance, element, item); @@ -497,6 +498,19 @@ else if (parameterCount == properties.size() + 1) { return item; } + /** + * Loads an item from an instance and an element + * + * @param instance the instance + * @param element the element + * @return the gui item + */ + @NotNull + @Contract(pure = true) + public static GuiItem loadItem(@NotNull Object instance, @NotNull Element element) { + return loadItem(instance, element, JavaPlugin.getProvidingPlugin(Pane.class)); + } + public static void load(@NotNull Pane pane, @NotNull Object instance, @NotNull Element element) { if (element.hasAttribute("x")) { pane.setX(Integer.parseInt(element.getAttribute("x"))); @@ -552,19 +566,21 @@ public static void load(@NotNull Pane pane, @NotNull Object instance, @NotNull E @Nullable @Contract(pure = true) protected static T findMatchingItem(@NotNull Collection items, @NotNull ItemStack item) { - ItemMeta meta = item.getItemMeta(); - if (meta == null) { - return null; - } + for (T guiItem : items) { + ItemMeta meta = item.getItemMeta(); - UUID uuid = meta.getPersistentDataContainer().get(GuiItem.KEY_UUID, UUIDTagType.INSTANCE); - if (uuid == null) { - return null; + if (meta == null) { + return null; + } + + UUID uuid = meta.getPersistentDataContainer().get(guiItem.getKey(), UUIDTagType.INSTANCE); + + if (guiItem.getUUID().equals(uuid)) { + return guiItem; + } } - return items.stream() - .filter(guiItem -> guiItem.getUUID().equals(uuid)) - .findAny().orElse(null); + return null; } /** @@ -619,7 +635,6 @@ public void setOnClick(@Nullable Consumer onClick) { /** * Calls the consumer (if it's not null) that was specified using {@link #setOnClick(Consumer)}, * so the consumer that should be called whenever this pane is clicked in. - * Catches and logs all exceptions the consumer might throw. * * @param event the event to handle * @since 0.6.0 @@ -632,10 +647,13 @@ protected void callOnClick(@NotNull InventoryClickEvent event) { try { onClick.accept(event); } catch (Throwable t) { - Logger logger = JavaPlugin.getProvidingPlugin(getClass()).getLogger(); - logger.log(Level.SEVERE, "Exception while handling click event in inventory '" + throw new RuntimeException( + "Exception while handling click event in inventory '" + event.getView().getTitle() + "', slot=" + event.getSlot() + ", for " - + getClass().getSimpleName() + ", x=" + x + ", y=" + y + ", length=" + length + ", height=" + height, t); + + getClass().getSimpleName() + ", x=" + x + ", y=" + y + + ", length=" + length + ", height=" + height, + t + ); } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java index 4adde932e..2d7670f6f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java @@ -8,6 +8,8 @@ import com.github.stefvanschie.inventoryframework.util.GeometryUtil; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -339,11 +341,13 @@ public int getRotation() { * Loads a pattern pane from a given element * * @param instance the instance class - * @param element the element + * @param element the element + * @param plugin the plugin that will own the underlying items * @return the pattern pane + * @since 0.10.8 */ @NotNull - public static PatternPane load(@NotNull Object instance, @NotNull Element element) { + public static PatternPane load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { try { NodeList childNodes = element.getChildNodes(); @@ -422,4 +426,19 @@ public static PatternPane load(@NotNull Object instance, @NotNull Element elemen throw new XMLLoadException(exception); } } + + /** + * Loads a pattern pane from a given element + * + * @param instance the instance class + * @param element the element + * @return the pattern pane + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Deprecated + public static PatternPane load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(PatternPane.class)); + } } 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 9c395e056..faaa92a7d 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 @@ -7,6 +7,8 @@ import com.github.stefvanschie.inventoryframework.util.GeometryUtil; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -200,10 +202,13 @@ public void setRotation(int rotation) { * Fills all empty space in the pane with the given {@code itemStack} and adds the given action * * @param itemStack The {@link ItemStack} to fill the empty space with - * @param action The action called whenever an interaction with the item happens - * @since 0.5.9 + * @param action The action called whenever an interaction with the item happens + * @param plugin the plugin that will be the owner of the created items + * @see #fillWith(ItemStack, Consumer) + * @since 0.10.8 */ - public void fillWith(@NotNull ItemStack itemStack, @Nullable Consumer action) { + public void fillWith(@NotNull ItemStack itemStack, @Nullable Consumer action, + @NotNull Plugin plugin) { //The non empty spots Set> locations = this.items.keySet(); @@ -219,12 +224,23 @@ public void fillWith(@NotNull ItemStack itemStack, @Nullable Consumer action) { + fillWith(itemStack, action, JavaPlugin.getProvidingPlugin(StaticPane.class)); + } + /** * Fills all empty space in the pane with the given {@code itemStack} * @@ -286,11 +302,13 @@ public boolean isFlippedVertically() { * Loads an outline pane from a given element * * @param instance the instance class - * @param element the element + * @param element the element + * @param plugin the plugin that will be the owner of the udnerlying items * @return the outline pane + * @since 0.10.8 */ @NotNull - public static StaticPane load(@NotNull Object instance, @NotNull Element element) { + public static StaticPane load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { try { StaticPane staticPane = new StaticPane( Integer.parseInt(element.getAttribute("length")), @@ -323,4 +341,19 @@ public static StaticPane load(@NotNull Object instance, @NotNull Element element throw new XMLLoadException(exception); } } + + /** + * Loads an outline pane from a given element + * + * @param instance the instance class + * @param element the element + * @return the outline pane + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Deprecated + public static StaticPane load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(StaticPane.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java index 93bc3c471..3a186700a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java @@ -6,6 +6,8 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.pane.Pane; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -165,11 +167,12 @@ public void cycle() { * * @param instance the instance class * @param element the element + * @param plugin the plugin that will be the owner of the underlying items * @return the cycle button - * @since 0.5.0 + * @since 0.10.8 */ @NotNull - public static CycleButton load(@NotNull Object instance, @NotNull Element element) { + public static CycleButton load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { int length; int height; @@ -197,9 +200,25 @@ public static CycleButton load(@NotNull Object instance, @NotNull Element elemen continue; } - cycleButton.addPane(Gui.loadPane(instance, pane)); + cycleButton.addPane(Gui.loadPane(instance, pane, plugin)); } return cycleButton; } + + /** + * Loads a cycle button from a given element + * + * @param instance the instance class + * @param element the element + * @return the cycle button + * @since 0.5.0 + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Deprecated + public static CycleButton load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(CycleButton.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java index 3927f35f9..940ee93cb 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java @@ -8,6 +8,8 @@ import com.github.stefvanschie.inventoryframework.pane.*; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -33,6 +35,12 @@ public class Label extends OutlinePane { @NotNull private String text; + /** + * The plugin to be sed for creating items + */ + @NotNull + private final Plugin plugin; + /** * Creates a new label * @@ -42,10 +50,21 @@ public class Label extends OutlinePane { * @param height the height * @param priority the priority * @param font the character set - * @since 0.5.0 + * @param plugin the plugin that will be the owner for this label's items + * @see #Label(int, int, int, int, Priority, Font) + * @since 0.10.8 */ - public Label(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Font font) { - this(x, y, length, height, font); + public Label(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Font font, + @NotNull Plugin plugin) { + super(length, height); + + this.x = x; + this.y = y; + + this.font = font; + this.text = ""; + + this.plugin = plugin; setPriority(priority); } @@ -58,13 +77,55 @@ public Label(int x, int y, int length, int height, @NotNull Priority priority, @ * @param length the length * @param height the height * @param font the character set + * @param plugin the plugin that will be the owner for this label's items + * @see #Label(int, int, int, int, Font) + * @since 0.10.8 + */ + public Label(int x, int y, int length, int height, @NotNull Font font, @NotNull Plugin plugin) { + this(x, y, length, height, Priority.NORMAL, font, plugin); + } + + /** + * Creates a new label + * + * @param length the length + * @param height the height + * @param font the character set + * @param plugin the plugin that will be the owner for this label's items + * @see #Label(int, int, Font) + * @since 0.10.8 + */ + public Label(int length, int height, @NotNull Font font, @NotNull Plugin plugin) { + this(0, 0, length, height, font, plugin); + } + + /** + * Creates a new label + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param priority the priority + * @param font the character set * @since 0.5.0 */ - public Label(int x, int y, int length, int height, @NotNull Font font) { - this(length, height, font); + public Label(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Font font) { + this(x, y, length, height, priority, font, JavaPlugin.getProvidingPlugin(Label.class)); + } - this.x = x; - this.y = y; + /** + * Creates a new label + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param font the character set + * @since 0.5.0 + */ + public Label(int x, int y, int length, int height, @NotNull Font font) { + this(x, y, length, height, Priority.NORMAL, font); } /** @@ -76,10 +137,7 @@ public Label(int x, int y, int length, int height, @NotNull Font font) { * @since 0.5.0 */ public Label(int length, int height, @NotNull Font font) { - super(length, height); - - this.font = font; - this.text = ""; + this(0, 0, length, height, font); } /** @@ -126,14 +184,14 @@ public void setText(@NotNull String text, * @since 0.5.0 */ public void setText(@NotNull String text) { - setText(text, (character, item) -> new GuiItem(item)); + setText(text, (character, item) -> new GuiItem(item, this.plugin)); } @NotNull @Contract(pure = true) @Override public Label copy() { - Label label = new Label(x, y, length, height, getPriority(), font); + Label label = new Label(x, y, length, height, getPriority(), font, this.plugin); for (GuiItem item : getItems()) { label.addItem(item.copy()); @@ -193,12 +251,14 @@ public Font getFont() { * Loads a label from a given element * * @param instance the instance class - * @param element the element + * @param element the element + * @param plugin the plugin that will be the owner of the underlying items * @return the percentage bar + * @since 0.10.8 */ @NotNull @Contract(pure = true) - public static Label load(@NotNull Object instance, @NotNull Element element) { + public static Label load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { int length; int height; @@ -219,7 +279,7 @@ public static Label load(@NotNull Object instance, @NotNull Element element) { throw new XMLLoadException("Incorrect font specified for label"); } - Label label = new Label(length, height, font); + Label label = new Label(length, height, font, plugin); Pane.load(label, instance, element); Orientable.load(label, element); @@ -236,4 +296,20 @@ public static Label load(@NotNull Object instance, @NotNull Element element) { return label; } + + /** + * Loads a label from a given element + * + * @param instance the instance class + * @param element the element + * @return the percentage bar + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Contract(pure = true) + @Deprecated + public static Label load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(Label.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java index 49340a8cd..5ecd8f0ee 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java @@ -8,6 +8,8 @@ import com.github.stefvanschie.inventoryframework.pane.Pane; import com.github.stefvanschie.inventoryframework.pane.component.util.VariableBar; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -19,6 +21,47 @@ */ public class PercentageBar extends VariableBar { + /** + * Creates a new percentage bar + * + * @param x the x coordinate of the bar + * @param y the y coordinate of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param priority the priority of the bar + * @param plugin the plugin that will be the owner for this percentage bar's items + * @since 0.10.8 + */ + public PercentageBar(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { + super(x, y, length, height, priority, plugin); + } + + /** + * Creates a new percentage bar + * + * @param x the x coordinate of the bar + * @param y the y coordinate of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param plugin the plugin that will be the owner for this percentage bar's items + * @since 0.10.8 + */ + public PercentageBar(int x, int y, int length, int height, @NotNull Plugin plugin) { + super(x, y, length, height, plugin); + } + + /** + * Creates a new percentage bar + * + * @param length the length of the bar + * @param height the height of the bar + * @param plugin the plugin that will be the owner for this percentage bar's items + * @since 0.10.8 + */ + public PercentageBar(int length, int height, @NotNull Plugin plugin) { + super(length, height, plugin); + } + public PercentageBar(int x, int y, int length, int height, @NotNull Priority priority) { super(x, y, length, height, priority); } @@ -100,12 +143,14 @@ public float getPercentage() { * Loads a percentage bar from a given element * * @param instance the instance class - * @param element the element + * @param element the element + * @param plugin the plugin that will be the owner of the underlying items * @return the percentage bar + * @since 0.10.8 */ @NotNull @Contract(pure = true) - public static PercentageBar load(@NotNull Object instance, @NotNull Element element) { + public static PercentageBar load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { int length; int height; @@ -116,7 +161,7 @@ public static PercentageBar load(@NotNull Object instance, @NotNull Element elem throw new XMLLoadException(exception); } - PercentageBar percentageBar = new PercentageBar(length, height); + PercentageBar percentageBar = new PercentageBar(length, height, plugin); Pane.load(percentageBar, instance, element); Orientable.load(percentageBar, element); @@ -136,4 +181,20 @@ public static PercentageBar load(@NotNull Object instance, @NotNull Element elem return percentageBar; } + + /** + * Loads a percentage bar from a given element + * + * @param instance the instance class + * @param element the element + * @return the percentage bar + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Contract(pure = true) + @Deprecated + public static PercentageBar load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(PercentageBar.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java index 17e873ff7..a439b336e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java @@ -8,6 +8,8 @@ import com.github.stefvanschie.inventoryframework.pane.Pane; import com.github.stefvanschie.inventoryframework.pane.component.util.VariableBar; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -19,6 +21,47 @@ */ public class Slider extends VariableBar { + /** + * Creates a new slider + * + * @param x the x coordinate of the slider + * @param y the y coordinate of the slier + * @param length the length of the slider + * @param height the height of the slider + * @param priority the priority of the slider + * @param plugin the plugin that will be the owner of the slider's items + * @since 0.10.8 + */ + public Slider(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { + super(x, y, length, height, priority, plugin); + } + + /** + * Creates a new slider + * + * @param x the x coordinate of the slider + * @param y the y coordinate of the slier + * @param length the length of the slider + * @param height the height of the slider + * @param plugin the plugin that will be the owner of the slider's items + * @since 0.10.8 + */ + public Slider(int x, int y, int length, int height, @NotNull Plugin plugin) { + super(x, y, length, height, plugin); + } + + /** + * Creates a new slider + * + * @param length the length of the slider + * @param height the height of the slider + * @param plugin the plugin that will be the owner of the slider's items + * @since 0.10.8 + */ + public Slider(int length, int height, @NotNull Plugin plugin) { + super(length, height, plugin); + } + public Slider(int x, int y, int length, int height, @NotNull Priority priority) { super(x, y, length, height, priority); } @@ -109,12 +152,14 @@ public float getValue() { * Loads a percentage bar from a given element * * @param instance the instance class - * @param element the element + * @param element the element + * @param plugin the plugin that will be the owner of the udnerlying items * @return the percentage bar + * @since 0.10.8 */ @NotNull @Contract(pure = true) - public static Slider load(@NotNull Object instance, @NotNull Element element) { + public static Slider load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { int length; int height; @@ -125,7 +170,7 @@ public static Slider load(@NotNull Object instance, @NotNull Element element) { throw new XMLLoadException(exception); } - Slider slider = new Slider(length, height); + Slider slider = new Slider(length, height, plugin); Pane.load(slider, instance, element); Orientable.load(slider, element); @@ -145,4 +190,20 @@ public static Slider load(@NotNull Object instance, @NotNull Element element) { return slider; } + + /** + * Loads a percentage bar from a given element + * + * @param instance the instance class + * @param element the element + * @return the percentage bar + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Contract(pure = true) + @Deprecated + public static Slider load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(Slider.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index cd1c1bac3..bfb1aa83e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -9,6 +9,8 @@ import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.w3c.dom.Element; @@ -32,22 +34,31 @@ public class ToggleButton extends Pane { /** * Whether the button is enabled or disabled */ - private boolean enabled = false; + private boolean enabled; - public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority) { - this(x, y, length, height); + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param priority the priority + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, Priority, boolean) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled, + @NotNull Plugin plugin) { + super(length, height); - setPriority(priority); - } + setX(x); + setY(y); - public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled) { - this(x, y, length, height, priority); + setPriority(priority); this.enabled = enabled; - } - - public ToggleButton(int length, int height) { - super(length, height); this.enabledPane = new OutlinePane(this.x, this.y, length, height); this.enabledPane.addItem(new GuiItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE))); @@ -58,23 +69,102 @@ public ToggleButton(int length, int height) { this.disabledPane.setRepeat(true); } - public ToggleButton(int length, int height, boolean enabled) { - this(length, height); + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param priority the priority + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, Priority) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { + this(x, y, length, height, priority, false); + } - this.enabled = enabled; + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, boolean) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, boolean enabled, @NotNull Plugin plugin) { + this(x, y, length, height, Priority.NORMAL, enabled); } - public ToggleButton(int x, int y, int length, int height) { - this(length, height); + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, @NotNull Plugin plugin) { + this(x, y, length, height, false); + } - setX(x); - setY(y); + /** + * Creates a new toggle button + * + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, boolean) + * @since 0.10.8 + */ + public ToggleButton(int length, int height, boolean enabled, @NotNull Plugin plugin) { + this(0, 0, length, height, enabled); + } + + /** + * Creates a new toggle button + * + * @param length the length + * @param height the height + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int) + * @since 0.10.8 + */ + public ToggleButton(int length, int height, @NotNull Plugin plugin) { + this(length, height, false); + } + + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled) { + this(x, y, length, height, priority, enabled, JavaPlugin.getProvidingPlugin(ToggleButton.class)); + } + + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority) { + this(x, y, length, height, priority, false); } public ToggleButton(int x, int y, int length, int height, boolean enabled) { - this(x, y, length, height); + this(x, y, length, height, Priority.NORMAL, enabled); + } - this.enabled = enabled; + public ToggleButton(int x, int y, int length, int height) { + this(x, y, length, height, false); + } + + public ToggleButton(int length, int height, boolean enabled) { + this(0, 0, length, height, enabled); + } + + public ToggleButton(int length, int height) { + this(length, height, false); } @Override @@ -239,12 +329,13 @@ public void clear() {} * * @param instance the instance class * @param element the element + * @param plugin the plugin that will be the owner of the underlying items * @return the toggle button - * @since 0.5.0 + * @since 0.10.8 */ @NotNull @Contract(pure = true) - public static ToggleButton load(@NotNull Object instance, @NotNull Element element) { + public static ToggleButton load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { int length, height; try { @@ -255,10 +346,27 @@ public static ToggleButton load(@NotNull Object instance, @NotNull Element eleme } boolean enabled = element.hasAttribute("enabled") && Boolean.parseBoolean(element.getAttribute("enabled")); - ToggleButton toggleButton = new ToggleButton(length, height, enabled); + ToggleButton toggleButton = new ToggleButton(length, height, enabled, plugin); Pane.load(toggleButton, instance, element); return toggleButton; } + + /** + * Loads a toggle button from an XML element + * + * @param instance the instance class + * @param element the element + * @return the toggle button + * @since 0.5.0 + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Contract(pure = true) + @Deprecated + public static ToggleButton load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(ToggleButton.class)); + } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java index 01356cac4..7b24ca186 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java @@ -8,6 +8,8 @@ import com.github.stefvanschie.inventoryframework.pane.Pane; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -43,7 +45,32 @@ public abstract class VariableBar extends Pane implements Orientable, Flippable */ protected boolean flipHorizontally, flipVertically; - protected VariableBar(int length, int height) { + /** + * Creates a new variable bar + * + * @param length the length of the bar + * @param height the height of the bar + * @param plugin the plugin that will be the owner for this variable bar's items + * @see #VariableBar(int, int) + * @since 0.10.8 + */ + protected VariableBar(int length, int height, @NotNull Plugin plugin) { + this(0, 0, length, height, plugin); + } + + /** + * Creates a new variable bar + * + * @param x the x coordinate of the bar + * @param y the y coordinate of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param priority the priority of the bar + * @param plugin the plugin that will be the owner for this variable bar's items + * @see #VariableBar(int, int) + * @since 0.10.8 + */ + protected VariableBar(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { super(length, height); this.value = 0F; @@ -53,18 +80,14 @@ protected VariableBar(int length, int height) { this.backgroundPane = new OutlinePane(0, 0, length, height); this.fillPane.addItem(new GuiItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), - event -> event.setCancelled(true))); + event -> event.setCancelled(true), plugin)); this.backgroundPane.addItem(new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE), - event -> event.setCancelled(true))); + event -> event.setCancelled(true), plugin)); this.fillPane.setRepeat(true); this.backgroundPane.setRepeat(true); this.fillPane.setVisible(false); - } - - protected VariableBar(int x, int y, int length, int height, @NotNull Priority priority) { - this(length, height); setX(x); setY(y); @@ -72,6 +95,29 @@ protected VariableBar(int x, int y, int length, int height, @NotNull Priority pr setPriority(priority); } + /** + * Creates a new variable bar + * + * @param x the x coordinate of the bar + * @param y the y coordinate of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param plugin the plugin that will be the owner for this variable bar's items + * @see #VariableBar(int, int) + * @since 0.10.8 + */ + protected VariableBar(int x, int y, int length, int height, @NotNull Plugin plugin) { + this(x, y, length, height, Priority.NORMAL, plugin); + } + + protected VariableBar(int length, int height) { + this(0, 0, length, height); + } + + protected VariableBar(int x, int y, int length, int height, @NotNull Priority priority) { + this(x, y, length, height, priority, JavaPlugin.getProvidingPlugin(VariableBar.class)); + } + protected VariableBar(int x, int y, int length, int height) { this(x, y, length, height, Priority.NORMAL); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/TriFunction.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/TriFunction.java new file mode 100644 index 000000000..7ce718ca8 --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/TriFunction.java @@ -0,0 +1,25 @@ +package com.github.stefvanschie.inventoryframework.util; + +/** + * A function that takes three arguments and returns a result. + * + * @param the type of the first argument + * @param the type of the second argument + * @param the type of the third argument + * @param the type of the result + * @since 0.10.8 + */ +@FunctionalInterface +public interface TriFunction { + + /** + * Applies this function to the given arguments. + * + * @param a the first argument + * @param b the second argument + * @param c the third argument + * @return the result value + * @since 0.10.8 + */ + R apply(A a, B b, C c); +} From 8cc3ce68c9b100deb88ea9da58353984cb79d7be Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 20 Aug 2022 21:04:05 +0200 Subject: [PATCH 163/382] Add slots Allow you to specify positions via indexes --- .../inventoryframework/pane/MasonryPane.java | 53 ++++- .../inventoryframework/pane/OutlinePane.java | 52 ++++- .../pane/PaginatedPane.java | 53 ++++- .../inventoryframework/pane/Pane.java | 123 +++++++++-- .../inventoryframework/pane/PatternPane.java | 63 +++++- .../inventoryframework/pane/StaticPane.java | 129 ++++++++--- .../pane/component/CycleButton.java | 47 +++- .../pane/component/Label.java | 73 ++++++- .../pane/component/PercentageBar.java | 73 ++++++- .../pane/component/Slider.java | 72 +++++- .../pane/component/ToggleButton.java | 151 +++++++++++-- .../pane/component/util/VariableBar.java | 76 ++++++- .../inventoryframework/pane/util/Slot.java | 206 ++++++++++++++++++ 13 files changed, 1032 insertions(+), 139 deletions(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Slot.java diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java index f9a717135..8a0e168b7 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -39,10 +40,35 @@ public class MasonryPane extends Pane implements Orientable { @NotNull private Orientation orientation = Orientation.HORIZONTAL; + /** + * Creates a new masonry 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.8 + */ + public MasonryPane(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); + } + public MasonryPane(int x, int y, int length, int height, @NotNull Priority priority) { super(x, y, length, height, priority); } + /** + * Creates a new masonry 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.8 + */ + public MasonryPane(@NotNull Slot slot, int length, int height) { + super(slot, length, height); + } + public MasonryPane(int x, int y, int length, int height) { super(x, y, length, height); } @@ -99,8 +125,8 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs pane.display( inventoryComponent, - paneOffsetX + getX(), - paneOffsetY + getY(), + paneOffsetX + x, + paneOffsetY + y, Math.min(this.length, maxLength), Math.min(this.height, maxHeight) ); @@ -137,8 +163,8 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs pane.display( inventoryComponent, - paneOffsetX + getX(), - paneOffsetY + getY(), + paneOffsetX + x, + paneOffsetY + y, Math.min(this.length, maxLength), Math.min(this.height, maxHeight) ); @@ -157,10 +183,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + 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 % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; if (x < 0 || x >= length || y < 0 || y >= height) { return false; @@ -175,8 +208,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp continue; } - success = success || pane.click(gui, inventoryComponent, event, slot, paneOffsetX + getX(), - paneOffsetY + getY(), length, height); + success = success || pane.click(gui, inventoryComponent, event, slot, paneOffsetX + xPosition, + paneOffsetY + yPosition, length, height); } return success; @@ -186,7 +219,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Contract(pure = true) @Override public MasonryPane copy() { - MasonryPane masonryPane = new MasonryPane(x, y, length, height, getPriority()); + MasonryPane masonryPane = new MasonryPane(getSlot(), length, height, getPriority()); for (Pane pane : panes) { masonryPane.addPane(pane.copy()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java index 34fde4ea0..c1a8a0799 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java @@ -5,6 +5,7 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.pane.util.Mask; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import com.github.stefvanschie.inventoryframework.util.GeometryUtil; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; @@ -68,8 +69,17 @@ public class OutlinePane extends Pane implements Flippable, Orientable, Rotatabl @NotNull private Mask mask; - public OutlinePane(int x, int y, int length, int height, @NotNull Priority priority) { - super(x, y, length, height, priority); + /** + * Creates a new outline 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.8 + */ + public OutlinePane(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); this.items = new ArrayList<>(length * height); this.orientation = Orientation.HORIZONTAL; @@ -86,6 +96,23 @@ public OutlinePane(int x, int y, int length, int height, @NotNull Priority prior this.mask = new Mask(mask); } + public OutlinePane(int x, int y, int length, int height, @NotNull Priority priority) { + this(Slot.fromXY(x, y), length, height, priority); + } + + + /** + * Creates a new outline 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.8 + */ + public OutlinePane(@NotNull Slot slot, int length, int height) { + this(slot, length, height, Priority.NORMAL); + } + public OutlinePane(int x, int y, int length, int height) { this(x, y, length, height, Priority.NORMAL); } @@ -203,8 +230,10 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs y = coordinates.getValue(); if (x >= 0 && x < length && y >= 0 && y < height) { - int finalRow = getY() + y + paneOffsetY; - int finalColumn = getX() + x + paneOffsetX; + Slot slot = getSlot(); + + int finalRow = slot.getY(maxLength) + y + paneOffsetY; + int finalColumn = slot.getX(maxLength) + x + paneOffsetX; inventoryComponent.setItem(items[index], finalColumn, finalRow); } @@ -222,10 +251,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + 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 % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) { @@ -255,7 +291,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Contract(pure = true) @Override public OutlinePane copy() { - OutlinePane outlinePane = new OutlinePane(x, y, length, height, getPriority()); + OutlinePane outlinePane = new OutlinePane(getSlot(), length, height, getPriority()); for (GuiItem item : items) { outlinePane.addItem(item.copy()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index 99693d4a2..4c959ee90 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; @@ -37,8 +38,33 @@ public class PaginatedPane extends Pane { */ private int page; + /** + * Creates a new paginated 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.8 + */ + public PaginatedPane(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); + } + public PaginatedPane(int x, int y, int length, int height, @NotNull Priority priority) { - super(x, y, length, height, priority); + this(Slot.fromXY(x, y), length, height, priority); + } + + /** + * Creates a new paginated 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.8 + */ + public PaginatedPane(@NotNull Slot slot, int length, int height) { + this(slot, length, height, Priority.NORMAL); } public PaginatedPane(int x, int y, int length, int height) { @@ -222,8 +248,10 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs continue; } - int newPaneOffsetX = paneOffsetX + getX(); - int newPaneOffsetY = paneOffsetY + getY(); + Slot slot = getSlot(); + + int newPaneOffsetX = paneOffsetX + slot.getX(maxLength); + int newPaneOffsetY = paneOffsetY + slot.getY(maxLength); int newMaxLength = Math.min(length, maxLength); int newMaxHeight = Math.min(height, maxHeight); @@ -238,10 +266,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + 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 % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) { @@ -257,8 +292,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp continue; } - success = success || pane.click(gui, inventoryComponent, event, slot,paneOffsetX + getX(), - paneOffsetY + getY(), length, height); + success = success || pane.click(gui, inventoryComponent, event, slot,paneOffsetX + xPosition, + paneOffsetY + yPosition, length, height); } return success; @@ -268,7 +303,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Contract(pure = true) @Override public PaginatedPane copy() { - PaginatedPane paginatedPane = new PaginatedPane(x, y, length, height, getPriority()); + PaginatedPane paginatedPane = new PaginatedPane(getSlot(), length, height, getPriority()); for (Map.Entry> entry : panes.entrySet()) { for (Pane pane : entry.getValue()) { diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index f36e41ecc..7f60fb9df 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -7,6 +7,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.exception.XMLReflectionException; import com.github.stefvanschie.inventoryframework.pane.util.Mask; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import com.github.stefvanschie.inventoryframework.util.SkullUtil; import com.github.stefvanschie.inventoryframework.util.UUIDTagType; import com.github.stefvanschie.inventoryframework.util.XMLUtil; @@ -42,8 +43,15 @@ public abstract class Pane { /** * The starting position of this pane, which is 0 by default */ + @Deprecated protected int x = 0, y = 0; + /** + * The position of this pane, which is (0,0) by default + */ + @NotNull + protected Slot slot = Slot.fromXY(0, 0); + /** * Length is horizontal, height is vertical */ @@ -80,19 +88,18 @@ public abstract class Pane { /** * Constructs a new default pane * - * @param x the upper left x coordinate of the pane - * @param y the upper left y coordinate of the 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.8 */ - protected Pane(int x, int y, int length, int height, @NotNull Priority priority) { + protected Pane(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { if (length == 0 || height == 0) { throw new IllegalArgumentException("Length and height of pane must be greater than zero"); } - this.x = x; - this.y = y; + setSlot(slot); this.length = length; this.height = height; @@ -103,6 +110,19 @@ protected Pane(int x, int y, int length, int height, @NotNull Priority priority) this.uuid = UUID.randomUUID(); } + /** + * Constructs a new default pane + * + * @param x the upper left x coordinate of the pane + * @param y the upper left y coordinate of the pane + * @param length the length of the pane + * @param height the height of the pane + * @param priority the priority of the pane + */ + protected Pane(int x, int y, int length, int height, @NotNull Priority priority) { + this(Slot.fromXY(x, y), length, height, priority); + } + /** * Constructs a new default pane, with no position * @@ -123,6 +143,17 @@ protected Pane(int length, int height) { this.uuid = UUID.randomUUID(); } + /** + * Constructs a new default pane + * + * @param slot the slot of the pane + * @param length the length of the pane + * @param height the height of the pane + */ + protected Pane(Slot slot, int length, int height) { + this(slot, length, height, Priority.NORMAL); + } + /** * Constructs a new default pane * @@ -166,6 +197,20 @@ public void setHeight(int height) { this.height = height; } + /** + * Sets the slot of this pane. + * + * @param slot the slot + * @since 0.10.8 + */ + public void setSlot(@NotNull Slot slot) { + this.slot = slot; + + //the length should be the length of the parent container, but we don't have that, so just use one + this.x = slot.getX(1); + this.y = slot.getY(1); + } + /** * Set the x coordinate of this pane * @@ -173,6 +218,8 @@ public void setHeight(int height) { */ public void setX(int x) { this.x = x; + + this.slot = Slot.fromXY(x, getY()); } /** @@ -182,6 +229,8 @@ public void setX(int x) { */ public void setY(int y) { this.y = y; + + this.slot = Slot.fromXY(getX(), y); } /** @@ -216,12 +265,27 @@ public UUID getUUID() { return uuid; } + /** + * Gets the slot of the position of this pane + * + * @return the slot + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + public Slot getSlot() { + return this.slot; + } + /** * Gets the x coordinate of this pane * * @return the x coordinate + * @deprecated when the slot was specified as an indexed position, this may return the wrong value; + * {@link #getSlot()} should be used instead */ @Contract(pure = true) + @Deprecated public int getX() { return x; } @@ -230,8 +294,11 @@ public int getX() { * Gets the y coordinate of this pane * * @return the y coordinate + * @deprecated when the slot was specified as an indexed position, this may return the wrong value; + * {@link #getSlot()} should be used instead */ @Contract(pure = true) + @Deprecated public int getY() { return y; } @@ -512,13 +579,7 @@ public static GuiItem loadItem(@NotNull Object instance, @NotNull Element elemen } public static void load(@NotNull Pane pane, @NotNull Object instance, @NotNull Element element) { - if (element.hasAttribute("x")) { - pane.setX(Integer.parseInt(element.getAttribute("x"))); - } - - if (element.hasAttribute("y")) { - pane.setY(Integer.parseInt(element.getAttribute("y"))); - } + pane.setSlot(Slot.deserialize(element)); if (element.hasAttribute("priority")) pane.setPriority(Priority.valueOf(element.getAttribute("priority").toUpperCase())); @@ -643,14 +704,15 @@ protected void callOnClick(@NotNull InventoryClickEvent event) { if (onClick == null) { return; } - + + try { onClick.accept(event); } catch (Throwable t) { throw new RuntimeException( "Exception while handling click event in inventory '" + event.getView().getTitle() + "', slot=" + event.getSlot() + ", for " - + getClass().getSimpleName() + ", x=" + x + ", y=" + y + + getClass().getSimpleName() + ", x=" + getX() + ", y=" + getY() + ", length=" + length + ", height=" + height, t ); @@ -658,22 +720,21 @@ protected void callOnClick(@NotNull InventoryClickEvent event) { } /** - * Creates a pane which displays as a border around the outside of the pane consisting of the provided item. The x, - * y, length and height parameters are used for the respective properties of the pane. If either the length or + * Creates a pane which displays as a border around the outside of the pane consisting of the provided item. The + * slot, length and height parameters are used for the respective properties of the pane. If either the length or * height is negative an {@link IllegalArgumentException} will be thrown. * - * @param x the x coordinate of the pane - * @param y the y coordinate of the pane + * @param slot the slot of the pane * @param length the length of the pane * @param height the height of the pane * @param item the item of which the border is made * @return the created pane which displays a border - * @since 0.10.7 + * @since 0.10.8 * @throws IllegalArgumentException if length or height is negative */ @NotNull @Contract(pure = true) - public static Pane createBorder(int x, int y, int length, int height, @NotNull GuiItem item) { + public static Pane createBorder(Slot slot, int length, int height, @NotNull GuiItem item) { if (length < 0) { throw new IllegalArgumentException("Length should be non-negative"); } @@ -702,7 +763,7 @@ public static Pane createBorder(int x, int y, int length, int height, @NotNull G mask[yIndex] = builder.append('1').toString(); } - OutlinePane pane = new OutlinePane(x, y, length, height); + OutlinePane pane = new OutlinePane(slot, length, height); pane.applyMask(new Mask(mask)); pane.addItem(item); pane.setRepeat(true); @@ -710,6 +771,26 @@ public static Pane createBorder(int x, int y, int length, int height, @NotNull G return pane; } + /** + * Creates a pane which displays as a border around the outside of the pane consisting of the provided item. The x, + * y, length and height parameters are used for the respective properties of the pane. If either the length or + * height is negative an {@link IllegalArgumentException} will be thrown. + * + * @param x the x coordinate of the pane + * @param y the y coordinate of the pane + * @param length the length of the pane + * @param height the height of the pane + * @param item the item of which the border is made + * @return the created pane which displays a border + * @since 0.10.7 + * @throws IllegalArgumentException if length or height is negative + */ + @NotNull + @Contract(pure = true) + public static Pane createBorder(int x, int y, int length, int height, @NotNull GuiItem item) { + return createBorder(Slot.fromXY(x, y), length, height, item); + } + /** * Registers a property that can be used inside an XML file to add additional new properties. * The use of {@link Gui#registerProperty(String, Function)} is preferred over this method. diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java index 2d7670f6f..767e3b147 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java @@ -5,6 +5,7 @@ import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.util.Pattern; +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; @@ -56,27 +57,42 @@ public class PatternPane extends Pane implements Flippable, Rotatable { /** * Constructs a new pattern pane. * - * @param x the upper left x coordinate of the pane - * @param y the upper left y coordinate of the 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 * @param pattern the pattern of the pane * @throws IllegalArgumentException when the pane and pattern dimensions don't match - * @since 0.9.8 + * @since 0.10.8 */ - public PatternPane(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Pattern pattern) { - super(x, y, length, height, priority); + public PatternPane(@NotNull Slot slot, int length, int height, @NotNull Priority priority, @NotNull Pattern pattern) { + super(slot, length, height, priority); if (pattern.getLength() != length || pattern.getHeight() != height) { throw new IllegalArgumentException( - "Dimensions of the provided pattern do not match the dimensions of the pane" + "Dimensions of the provided pattern do not match the dimensions of the pane" ); } this.pattern = pattern; } + /** + * Constructs a new pattern pane. + * + * @param x the upper left x coordinate of the pane + * @param y the upper left y coordinate of the pane + * @param length the length of the pane + * @param height the height of the pane + * @param priority the priority of the pane + * @param pattern the pattern of the pane + * @throws IllegalArgumentException when the pane and pattern dimensions don't match + * @since 0.9.8 + */ + public PatternPane(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Pattern pattern) { + this(Slot.fromXY(x, y), length, height, priority, pattern); + } + /** * Constructs a new pattern pane, with no position. * @@ -90,6 +106,20 @@ public PatternPane(int length, int height, @NotNull Pattern pattern) { this(0, 0, length, height, pattern); } + /** + * Constructs a new pattern pane. + * + * @param slot the slot of the pane + * @param length the length of the pane + * @param height the height of the pane + * @param pattern the pattern of the pane + * @throws IllegalArgumentException when the pane and pattern dimensions don't match + * @since 0.10.8 + */ + public PatternPane(@NotNull Slot slot, int length, int height, @NotNull Pattern pattern) { + this(slot, length, height, Priority.NORMAL, pattern); + } + /** * Constructs a new pattern pane. * @@ -135,8 +165,10 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs newX = coordinates.getKey(); newY = coordinates.getValue(); - int finalRow = getY() + newY + paneOffsetY; - int finalColumn = getX() + newX + paneOffsetX; + Slot slot = getSlot(); + + int finalRow = slot.getY(maxLength) + newY + paneOffsetY; + int finalColumn = slot.getX(maxLength) + newX + paneOffsetX; inventoryComponent.setItem(item, finalColumn, finalRow); } @@ -150,10 +182,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + 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 % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) { @@ -183,7 +222,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Contract(pure = true) @Override public PatternPane copy() { - PatternPane patternPane = new PatternPane(getX(), getY(), getLength(), getHeight(), getPriority(), getPattern()); + PatternPane patternPane = new PatternPane(getSlot(), getLength(), getHeight(), getPriority(), getPattern()); patternPane.setVisible(isVisible()); patternPane.onClick = onClick; 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 faaa92a7d..ce3511da6 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 @@ -4,6 +4,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +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; @@ -21,6 +22,12 @@ /** * 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 StaticPane extends Pane implements Flippable, Rotatable { @@ -29,7 +36,7 @@ public class StaticPane extends Pane implements Flippable, Rotatable { * the key and the y coordinate is the value. */ @NotNull - private final Map, GuiItem> items; + private final Map items; /** * The clockwise rotation of this pane in degrees @@ -41,12 +48,37 @@ public class StaticPane extends Pane implements Flippable, Rotatable { */ private boolean flipHorizontally, flipVertically; - public StaticPane(int x, int y, int length, int height, @NotNull Priority priority) { - super(x, y, length, height, priority); + /** + * 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.8 + */ + public StaticPane(Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); this.items = new HashMap<>(length * height); } + public StaticPane(int x, int y, int length, int height, @NotNull Priority priority) { + this(Slot.fromXY(x, y), length, height, priority); + } + + /** + * 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 + * @since 0.10.8 + */ + public StaticPane(Slot slot, int length, int height) { + this(slot, length, height, Priority.NORMAL); + } + public StaticPane(int x, int y, int length, int height) { this(x, y, length, height, Priority.NORMAL); } @@ -55,6 +87,18 @@ public StaticPane(int length, int height) { this(0, 0, length, height); } + /** + * {@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) { @@ -62,9 +106,10 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs int height = Math.min(this.height, maxHeight); items.entrySet().stream().filter(entry -> entry.getValue().isVisible()).forEach(entry -> { - Map.Entry location = entry.getKey(); + Slot location = entry.getKey(); - int x = location.getKey(), y = location.getValue(); + int x = location.getX(getLength()); + int y = location.getY(getLength()); if (flipHorizontally) x = length - x - 1; @@ -84,27 +129,41 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs GuiItem item = entry.getValue(); - int finalRow = getY() + y + paneOffsetY; - int finalColumn = getX() + x + paneOffsetX; + Slot slot = getSlot(); + int finalRow = slot.getY(maxLength) + y + paneOffsetY; + int finalColumn = slot.getX(maxLength) + x + paneOffsetX; inventoryComponent.setItem(item, finalColumn, finalRow); }); } /** - * Adds a gui item at the specific spot in the pane. If the coordinates as specified by the x and y parameters is - * already occupied, that item will be replaced by the item parameter. + * Adds a gui item at the specific spot in the pane. If there is another item specified in terms of x and y + * coordinates that are equal to the coordinates of this item, the old item will be overwritten by this item. * * @param item the item to set * @param x the x coordinate of the position of the item * @param y the y coordinate of the position of the item */ public void addItem(@NotNull GuiItem item, int x, int y) { - items.keySet().removeIf(entry -> entry.getKey() == x && entry.getValue() == y); - - items.put(new AbstractMap.SimpleEntry<>(x, y), item); + addItem(item, Slot.fromXY(x, y)); } + /** + * Adds a gui item at the specific spot in the pane. If the slot is specified in terms of an x and y coordinate pair + * and this pane contains another item whose position is specified as such and these positions are equal, the old + * item will be overwritten by this item. If the slot is specified in terms of an index and this pane contains + * another item whose position is specified as such and these positions are equal, the old item will be overwritten + * by this item. + * + * @param item the item to set + * @param slot the position of the item + * @since 0.10.8 + */ + public void addItem(@NotNull GuiItem item, Slot slot) { + this.items.put(slot, item); + } + /** * Removes the specified item from the pane * @@ -116,14 +175,26 @@ public void removeItem(@NotNull GuiItem item) { } /** - * Removes the specified item from the pane + * Removes the specified item from the pane. This will only remove items whose slot was specified in terms of an x + * and y coordinate pair which matches the coordinate specified. * * @param x the x coordinate of the item to remove * @param y the y coordinate of the item to remove * @since 0.10.0 */ public void removeItem(int x, int y) { - items.remove(new AbstractMap.SimpleEntry<>(x, y)); + this.items.remove(Slot.fromXY(x, y)); + } + + /** + * Removes the specified item from the pane. This will only remove items whose slot was specified in the same way as + * the original slot and whose slot positions match. + * + * @param slot the slot of the item to remove + * @since 0.10.8 + */ + public void removeItem(@NotNull Slot slot) { + this.items.remove(slot); } @Override @@ -133,10 +204,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + Slot paneSlot = getSlot(); - int x = adjustedSlot % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + 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) { @@ -166,12 +244,10 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Contract(pure = true) @Override public StaticPane copy() { - StaticPane staticPane = new StaticPane(x, y, length, height, getPriority()); - - for (Map.Entry, GuiItem> entry : items.entrySet()) { - Map.Entry coordinates = entry.getKey(); + StaticPane staticPane = new StaticPane(getSlot(), length, height, getPriority()); - staticPane.addItem(entry.getValue().copy(), coordinates.getKey(), coordinates.getValue()); + for (Map.Entry entry : items.entrySet()) { + staticPane.addItem(entry.getValue().copy(), entry.getKey()); } staticPane.setVisible(isVisible()); @@ -210,14 +286,14 @@ public void setRotation(int rotation) { public void fillWith(@NotNull ItemStack itemStack, @Nullable Consumer action, @NotNull Plugin plugin) { //The non empty spots - Set> locations = this.items.keySet(); + Set locations = this.items.keySet(); for (int y = 0; y < this.getHeight(); y++) { for (int x = 0; x < this.getLength(); x++) { boolean found = false; - for (Map.Entry location : locations) { - if (location.getKey() == x && location.getValue() == y) { + for (Slot location : locations) { + if (location.getX(getLength()) == x && location.getY(getLength()) == y) { found = true; break; } @@ -332,8 +408,7 @@ public static StaticPane load(@NotNull Object instance, @NotNull Element element Element child = (Element) item; - staticPane.addItem(Pane.loadItem(instance, child), Integer.parseInt(child.getAttribute("x")), - Integer.parseInt(child.getAttribute("y"))); + staticPane.addItem(Pane.loadItem(instance, child), Slot.deserialize(child)); } return staticPane; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java index 3a186700a..dbe60c9e9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/CycleButton.java @@ -5,6 +5,7 @@ import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -34,10 +35,35 @@ public class CycleButton extends Pane { */ private int position = 0; + /** + * Creates a new cycle button + * + * @param slot the slot of the button + * @param length the length of the button + * @param height the height of the button + * @param priority the priority of the button + * @since 0.10.8 + */ + public CycleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); + } + public CycleButton(int x, int y, int length, int height, @NotNull Priority priority) { super(x, y, length, height, priority); } + /** + * Creates a new cycle button + * + * @param slot the slot of the button + * @param length the length of the button + * @param height the height of the button + * @since 0.10.8 + */ + public CycleButton(@NotNull Slot slot, int length, int height) { + super(slot, length, height); + } + public CycleButton(int x, int y, int length, int height) { super(x, y, length, height); } @@ -53,10 +79,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + Slot paneSlot = getSlot(); - int x = adjustedSlot % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + 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) { @@ -86,8 +119,10 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Override public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { - int newX = paneOffsetX + x; - int newY = paneOffsetY + y; + Slot slot = getSlot(); + + int newX = paneOffsetX + slot.getX(maxLength); + int newY = paneOffsetY + slot.getY(maxLength); int newMaxLength = Math.min(maxLength, length); int newMaxHeight = Math.min(maxHeight, height); @@ -99,7 +134,7 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs @Contract(pure = true) @Override public CycleButton copy() { - CycleButton cycleButton = new CycleButton(x, y, length, height, getPriority()); + CycleButton cycleButton = new CycleButton(getSlot(), length, height, getPriority()); for (Pane pane : panes) { cycleButton.addPane(pane); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java index 940ee93cb..fda4a04df 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Label.java @@ -6,6 +6,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.font.util.Font; import com.github.stefvanschie.inventoryframework.pane.*; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; @@ -44,8 +45,7 @@ public class Label extends OutlinePane { /** * Creates a new label * - * @param x the x coordinate - * @param y the y coordinate + * @param slot the slot * @param length the length * @param height the height * @param priority the priority @@ -54,12 +54,9 @@ public class Label extends OutlinePane { * @see #Label(int, int, int, int, Priority, Font) * @since 0.10.8 */ - public Label(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Font font, + public Label(@NotNull Slot slot, int length, int height, @NotNull Priority priority, @NotNull Font font, @NotNull Plugin plugin) { - super(length, height); - - this.x = x; - this.y = y; + super(slot, length, height); this.font = font; this.text = ""; @@ -69,6 +66,39 @@ public Label(int x, int y, int length, int height, @NotNull Priority priority, @ setPriority(priority); } + /** + * Creates a new label + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param priority the priority + * @param font the character set + * @param plugin the plugin that will be the owner for this label's items + * @see #Label(int, int, int, int, Priority, Font) + * @since 0.10.8 + */ + public Label(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Font font, + @NotNull Plugin plugin) { + this(Slot.fromXY(x, y), length, height, priority, font, plugin); + } + + /** + * Creates a new label + * + * @param slot the slot + * @param length the length + * @param height the height + * @param font the character set + * @param plugin the plugin that will be the owner for this label's items + * @see #Label(int, int, int, int, Font) + * @since 0.10.8 + */ + public Label(@NotNull Slot slot, int length, int height, @NotNull Font font, @NotNull Plugin plugin) { + this(slot, length, height, Priority.NORMAL, font, plugin); + } + /** * Creates a new label * @@ -99,6 +129,20 @@ public Label(int length, int height, @NotNull Font font, @NotNull Plugin plugin) this(0, 0, length, height, font, plugin); } + /** + * Creates a new label + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @param font the character set + * @since 0.10.8 + */ + public Label(@NotNull Slot slot, int length, int height, @NotNull Priority priority, @NotNull Font font) { + this(slot, length, height, priority, font, JavaPlugin.getProvidingPlugin(Label.class)); + } + /** * Creates a new label * @@ -114,6 +158,19 @@ public Label(int x, int y, int length, int height, @NotNull Priority priority, @ this(x, y, length, height, priority, font, JavaPlugin.getProvidingPlugin(Label.class)); } + /** + * Creates a new label + * + * @param slot the slot + * @param length the length + * @param height the height + * @param font the character set + * @since 0.10.8 + */ + public Label(@NotNull Slot slot, int length, int height, @NotNull Font font) { + this(slot, length, height, Priority.NORMAL, font); + } + /** * Creates a new label * @@ -191,7 +248,7 @@ public void setText(@NotNull String text) { @Contract(pure = true) @Override public Label copy() { - Label label = new Label(x, y, length, height, getPriority(), font, this.plugin); + Label label = new Label(getSlot(), length, height, getPriority(), font, this.plugin); for (GuiItem item : getItems()) { label.addItem(item.copy()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java index 5ecd8f0ee..b4729c885 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PercentageBar.java @@ -7,6 +7,7 @@ import com.github.stefvanschie.inventoryframework.pane.Orientable; import com.github.stefvanschie.inventoryframework.pane.Pane; import com.github.stefvanschie.inventoryframework.pane.component.util.VariableBar; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -21,6 +22,21 @@ */ public class PercentageBar extends VariableBar { + /** + * Creates a new percentage bar + * + * @param slot the slot of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param priority the priority of the bar + * @param plugin the plugin that will be the owner for this percentage bar's items + * @since 0.10.8 + */ + public PercentageBar(@NotNull Slot slot, int length, int height, @NotNull Priority priority, + @NotNull Plugin plugin) { + super(slot, length, height, priority, plugin); + } + /** * Creates a new percentage bar * @@ -36,6 +52,19 @@ public PercentageBar(int x, int y, int length, int height, @NotNull Priority pri super(x, y, length, height, priority, plugin); } + /** + * Creates a new percentage bar + * + * @param slot the slot of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param plugin the plugin that will be the owner for this percentage bar's items + * @since 0.10.8 + */ + public PercentageBar(@NotNull Slot slot, int length, int height, @NotNull Plugin plugin) { + super(slot, length, height, plugin); + } + /** * Creates a new percentage bar * @@ -62,10 +91,35 @@ public PercentageBar(int length, int height, @NotNull Plugin plugin) { super(length, height, plugin); } + /** + * Creates a new percentage bar + * + * @param slot the slot of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param priority the priority of the bar + * @since 0.10.8 + */ + public PercentageBar(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); + } + public PercentageBar(int x, int y, int length, int height, @NotNull Priority priority) { super(x, y, length, height, priority); } + /** + * Creates a new percentage bar + * + * @param slot the slot of the bar + * @param length the length of the bar + * @param height the height of the bar + * @since 0.10.8 + */ + public PercentageBar(@NotNull Slot slot, int length, int height) { + super(slot, length, height); + } + public PercentageBar(int x, int y, int length, int height) { super(x, y, length, height); } @@ -81,10 +135,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + 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 % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; if (x < 0 || x >= length || y < 0 || y >= height) { return false; @@ -94,8 +155,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp event.setCancelled(true); - int newPaneOffsetX = paneOffsetX + getX(); - int newPaneOffsetY = paneOffsetY + getY(); + int newPaneOffsetX = paneOffsetX + xPosition; + int newPaneOffsetY = paneOffsetY + yPosition; return this.fillPane.click( @@ -122,7 +183,7 @@ public void setPercentage(float percentage) { @Contract(pure = true) @Override public PercentageBar copy() { - PercentageBar percentageBar = new PercentageBar(x, y, length, height, getPriority()); + PercentageBar percentageBar = new PercentageBar(getSlot(), length, height, getPriority()); applyContents(percentageBar); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java index a439b336e..26c74e3d2 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/Slider.java @@ -7,6 +7,7 @@ import com.github.stefvanschie.inventoryframework.pane.Orientable; import com.github.stefvanschie.inventoryframework.pane.Pane; import com.github.stefvanschie.inventoryframework.pane.component.util.VariableBar; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -21,6 +22,20 @@ */ public class Slider extends VariableBar { + /** + * Creates a new slider + * + * @param slot the slot of the slider + * @param length the length of the slider + * @param height the height of the slider + * @param priority the priority of the slider + * @param plugin the plugin that will be the owner of the slider's items + * @since 0.10.8 + */ + public Slider(@NotNull Slot slot, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { + super(slot, length, height, priority, plugin); + } + /** * Creates a new slider * @@ -36,6 +51,19 @@ public Slider(int x, int y, int length, int height, @NotNull Priority priority, super(x, y, length, height, priority, plugin); } + /** + * Creates a new slider + * + * @param slot the slot of the slider + * @param length the length of the slider + * @param height the height of the slider + * @param plugin the plugin that will be the owner of the slider's items + * @since 0.10.8 + */ + public Slider(@NotNull Slot slot, int length, int height, @NotNull Plugin plugin) { + super(slot, length, height, plugin); + } + /** * Creates a new slider * @@ -62,10 +90,35 @@ public Slider(int length, int height, @NotNull Plugin plugin) { super(length, height, plugin); } + /** + * Creates a new slider + * + * @param slot the slot of the slider + * @param length the length of the slider + * @param height the height of the slider + * @param priority the priority of the slider + * @since 0.10.8 + */ + public Slider(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + super(slot, length, height, priority); + } + public Slider(int x, int y, int length, int height, @NotNull Priority priority) { super(x, y, length, height, priority); } + /** + * Creates a new slider + * + * @param slot the slot of the slider + * @param length the length of the slider + * @param height the height of the slider + * @since 0.10.8 + */ + public Slider(@NotNull Slot slot, int length, int height) { + super(slot, length, height); + } + public Slider(int x, int y, int length, int height) { super(x, y, length, height); } @@ -81,10 +134,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + 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 % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; if (x < 0 || x >= length || y < 0 || y >= height) { return false; @@ -100,8 +160,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp callOnClick(event); - int newPaneOffsetX = paneOffsetX + getX(); - int newPaneOffsetY = paneOffsetY + getY(); + int newPaneOffsetX = paneOffsetX + xPosition; + int newPaneOffsetY = paneOffsetY + yPosition; boolean success = this.fillPane.click( gui, inventoryComponent, event, slot, newPaneOffsetX, newPaneOffsetY, length, height @@ -131,7 +191,7 @@ public void setValue(float value) { @Contract(pure = true) @Override public Slider copy() { - Slider slider = new Slider(x, y, length, height, getPriority()); + Slider slider = new Slider(getSlot(), length, height, getPriority()); applyContents(slider); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index bfb1aa83e..8b6234d41 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -6,6 +6,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import com.github.stefvanschie.inventoryframework.pane.OutlinePane; import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; @@ -39,8 +40,7 @@ public class ToggleButton extends Pane { /** * Creates a new toggle button * - * @param x the x coordinate - * @param y the y coordinate + * @param slot the slot * @param length the length * @param height the height * @param priority the priority @@ -49,17 +49,14 @@ public class ToggleButton extends Pane { * @see #ToggleButton(int, int, int, int, Priority, boolean) * @since 0.10.8 */ - public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled, + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, boolean enabled, @NotNull Plugin plugin) { - super(length, height); - - setX(x); - setY(y); - - setPriority(priority); + super(slot, length, height, priority); this.enabled = enabled; + //TODO: don't know the positions of these panes, should be zero, though + this.enabledPane = new OutlinePane(this.x, this.y, length, height); this.enabledPane.addItem(new GuiItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE))); this.enabledPane.setRepeat(true); @@ -69,6 +66,40 @@ public ToggleButton(int x, int y, int length, int height, @NotNull Priority prio this.disabledPane.setRepeat(true); } + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param priority the priority + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, Priority, boolean) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled, + @NotNull Plugin plugin) { + this(Slot.fromXY(x, y), length, height, priority, enabled, plugin); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(Slot, int, int, Priority) + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, + @NotNull Plugin plugin) { + this(slot, length, height, priority, false, plugin); + } + /** * Creates a new toggle button * @@ -82,7 +113,22 @@ public ToggleButton(int x, int y, int length, int height, @NotNull Priority prio * @since 0.10.8 */ public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { - this(x, y, length, height, priority, false); + this(x, y, length, height, priority, false, plugin); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(Slot, int, int, boolean) + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, boolean enabled, @NotNull Plugin plugin) { + this(slot, length, height, Priority.NORMAL, enabled, plugin); } /** @@ -98,7 +144,21 @@ public ToggleButton(int x, int y, int length, int height, @NotNull Priority prio * @since 0.10.8 */ public ToggleButton(int x, int y, int length, int height, boolean enabled, @NotNull Plugin plugin) { - this(x, y, length, height, Priority.NORMAL, enabled); + this(x, y, length, height, Priority.NORMAL, enabled, plugin); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(Slot, int, int) + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Plugin plugin) { + this(slot, length, height, false, plugin); } /** @@ -113,7 +173,7 @@ public ToggleButton(int x, int y, int length, int height, boolean enabled, @NotN * @since 0.10.8 */ public ToggleButton(int x, int y, int length, int height, @NotNull Plugin plugin) { - this(x, y, length, height, false); + this(x, y, length, height, false, plugin); } /** @@ -143,18 +203,70 @@ public ToggleButton(int length, int height, @NotNull Plugin plugin) { this(length, height, false); } + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @param enabled whether the button should start in its enabled or disabled state + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, boolean enabled) { + this(slot, length, height, priority, enabled, JavaPlugin.getProvidingPlugin(ToggleButton.class)); + } + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled) { this(x, y, length, height, priority, enabled, JavaPlugin.getProvidingPlugin(ToggleButton.class)); } + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + this(slot, length, height, priority, false); + } + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority) { this(x, y, length, height, priority, false); } + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, boolean enabled) { + this(slot, length, height, Priority.NORMAL, enabled); + } + public ToggleButton(int x, int y, int length, int height, boolean enabled) { this(x, y, length, height, Priority.NORMAL, enabled); } + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height) { + this(slot, length, height, false); + } + public ToggleButton(int x, int y, int length, int height) { this(x, y, length, height, false); } @@ -187,10 +299,17 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); - int adjustedSlot = slot - (getX() + paneOffsetX) - inventoryComponent.getLength() * (getY() + paneOffsetY); + 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 % inventoryComponent.getLength(); - int y = adjustedSlot / inventoryComponent.getLength(); + int x = adjustedSlot % totalLength; + int y = adjustedSlot / totalLength; //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) { @@ -220,7 +339,7 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp @Contract(pure = true) @Override public ToggleButton copy() { - ToggleButton toggleButton = new ToggleButton(x, y, length, height, getPriority(), enabled); + ToggleButton toggleButton = new ToggleButton(getSlot(), length, height, getPriority(), enabled); toggleButton.setVisible(isVisible()); toggleButton.onClick = onClick; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java index 7b24ca186..e3a2d0507 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/util/VariableBar.java @@ -6,6 +6,7 @@ import com.github.stefvanschie.inventoryframework.pane.Orientable; import com.github.stefvanschie.inventoryframework.pane.OutlinePane; import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; @@ -61,17 +62,17 @@ protected VariableBar(int length, int height, @NotNull Plugin plugin) { /** * Creates a new variable bar * - * @param x the x coordinate of the bar - * @param y the y coordinate of the bar + * @param slot the slot of the bar * @param length the length of the bar * @param height the height of the bar * @param priority the priority of the bar * @param plugin the plugin that will be the owner for this variable bar's items - * @see #VariableBar(int, int) + * @see #VariableBar(Slot, int, int, Priority) * @since 0.10.8 */ - protected VariableBar(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { - super(length, height); + protected VariableBar(@NotNull Slot slot, int length, int height, @NotNull Priority priority, + @NotNull Plugin plugin) { + super(slot, length, height); this.value = 0F; this.orientation = Orientation.HORIZONTAL; @@ -89,12 +90,39 @@ protected VariableBar(int x, int y, int length, int height, @NotNull Priority pr this.fillPane.setVisible(false); - setX(x); - setY(y); - setPriority(priority); } + /** + * Creates a new variable bar + * + * @param x the x coordinate of the bar + * @param y the y coordinate of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param priority the priority of the bar + * @param plugin the plugin that will be the owner for this variable bar's items + * @see #VariableBar(int, int) + * @since 0.10.8 + */ + protected VariableBar(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { + this(Slot.fromXY(x, y), length, height, priority, plugin); + } + + /** + * Creates a new variable bar + * + * @param slot the slot of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param plugin the plugin that will be the owner for this variable bar's items + * @see #VariableBar(Slot, int, int) + * @since 0.10.8 + */ + protected VariableBar(@NotNull Slot slot, int length, int height, @NotNull Plugin plugin) { + this(slot, length, height, Priority.NORMAL, plugin); + } + /** * Creates a new variable bar * @@ -114,10 +142,35 @@ protected VariableBar(int length, int height) { this(0, 0, length, height); } + /** + * Creates a new variable bar + * + * @param slot the slot of the bar + * @param length the length of the bar + * @param height the height of the bar + * @param priority the priority of the bar + * @since 0.10.8 + */ + protected VariableBar(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + this(slot, length, height, priority, JavaPlugin.getProvidingPlugin(VariableBar.class)); + } + protected VariableBar(int x, int y, int length, int height, @NotNull Priority priority) { this(x, y, length, height, priority, JavaPlugin.getProvidingPlugin(VariableBar.class)); } + /** + * Creates a new variable bar + * + * @param slot the slot of the bar + * @param length the length of the bar + * @param height the height of the bar + * @since 0.10.8 + */ + protected VariableBar(@NotNull Slot slot, int length, int height) { + this(slot, length, height, Priority.NORMAL); + } + protected VariableBar(int x, int y, int length, int height) { this(x, y, length, height, Priority.NORMAL); } @@ -230,6 +283,7 @@ public void setHeight(int height) { protected void applyContents(@NotNull VariableBar copy) { copy.x = x; copy.y = y; + copy.slot = slot; copy.length = length; copy.height = height; copy.setPriority(getPriority()); @@ -282,8 +336,10 @@ public void setOrientation(@NotNull Orientation orientation) { @Override public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { - int newPaneOffsetX = paneOffsetX + getX(); - int newPaneOffsetY = paneOffsetY + getY(); + Slot slot = getSlot(); + + int newPaneOffsetX = paneOffsetX + slot.getX(maxLength); + int newPaneOffsetY = paneOffsetY + slot.getY(maxLength); int newMaxLength = Math.min(maxLength, getLength()); int newMaxHeight = Math.min(maxHeight, getHeight()); 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 new file mode 100644 index 000000000..7fc7bc144 --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/util/Slot.java @@ -0,0 +1,206 @@ +package com.github.stefvanschie.inventoryframework.pane.util; + +import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.Element; + +/** + * A slot represents a position in some type of container. Implementors of this class represent slots in different ways. + * + * @since 0.10.8 + */ +public interface Slot { + + /** + * Gets the x coordinate of this slot. + * + * @param length the length of the parent container + * @return the x coordinate of this slot + * @since 0.10.8 + */ + @Contract(pure = true) + int getX(int length); + + /** + * Gets the y coordinate of this slot. + * + * @param length the length of the parent container + * @return the y coordinate of this slot + * @since 0.10.8 + */ + @Contract(pure = true) + int getY(int length); + + /** + * Deserializes the slot from an element. The slot may either be provided as an (x, y) coordinate pair via the "x" + * and "y" attributes; or as an index via the "index" attribute. If both forms are present, an + * {@link XMLLoadException} will be thrown. If only the "x" or the "y" attribute is present, but not both, an + * {@link XMLLoadException} will be thrown. If none of the aforementioned attributes appear, an + * {@link XMLLoadException} will be thrown. If any of these attributes contain a value that is not an integer, an + * {@link XMLLoadException} will be thrown. Otherwise, this will return a slot based on the present attributes. + * + * @param element the element from which to retrieve the attributes for the slot + * @return the deserialized slot + * @throws XMLLoadException if "x", "y", and "index" attributes are present; if only an "x" attribute is present; if + * only a "y" attribute is present; if no "x", "y", or "index" attribute is present; or if + * the "x", "y", or "index" attribute contain a value that is not an integer. + */ + @NotNull + @Contract(value = "_ -> new", pure = true) + static Slot deserialize(@NotNull Element element) { + boolean hasX = element.hasAttribute("x"); + boolean hasY = element.hasAttribute("y"); + boolean hasIndex = element.hasAttribute("index"); + + if (hasX && hasY && !hasIndex) { + int x, y; + + try { + x = Integer.parseInt(element.getAttribute("x")); + y = Integer.parseInt(element.getAttribute("y")); + } catch (NumberFormatException exception) { + throw new XMLLoadException("The x or y attribute does not have an integer as value"); + } + + return Slot.fromXY(x, y); + } + + if (hasIndex && !hasX && !hasY) { + int index; + + try { + index = Integer.parseInt(element.getAttribute("index")); + } catch (NumberFormatException exception) { + throw new XMLLoadException("The index attribute does not have an integer as value"); + } + + return Slot.fromIndex(index); + } + + throw new XMLLoadException("The combination of x, y and index attributes is invalid"); + } + + /** + * Creates a new slot based on an (x, y) coordinate pair. + * + * @param x the x coordinate + * @param y the y coordinate + * @return the slot representing this position + * @since 0.10.8 + */ + @NotNull + @Contract(value = "_, _ -> new", pure = true) + static Slot fromXY(int x, int y) { + return new XY(x, y); + } + + /** + * Creates a new slot based on an index. This index is relative to the parent container this slot will be used in. + * + * @param index the index + * @return the slot representing this relative position + * @since 0.10.8 + */ + @NotNull + @Contract("_ -> new") + static Slot fromIndex(int index) { + return new Indexed(index); + } + + /** + * A class representing a slot based on an (x, y) coordinate pair. + * + * @since 0.10.8 + */ + class XY implements Slot { + + /** + * The (x, y) coordinate pair + */ + private final int x, y; + + /** + * Creates a new slot based on an (x, y) coordinate pair. + * + * @param x the x coordinate + * @param y the y coordinate + * @since 0.10.8 + */ + private XY(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public int getX(int length) { + return this.x; + } + + @Override + public int getY(int length) { + return this.y; + } + } + + /** + * A class representing a slot based on an index. + * + * @since 0.10.8 + */ + class Indexed implements Slot { + + /** + * The index of this slot. + */ + private final int index; + + /** + * Creates a new slot based on an index. + * + * @param index the index of this slot + * @since 0.10.8 + */ + private Indexed(int index) { + this.index = index; + } + + /** + * {@inheritDoc} + * + * If {@code length} is zero, this will throw an {@link IllegalArgumentException}. + * + * @param length {@inheritDoc} + * @return {@inheritDoc} + * @throws IllegalArgumentException when {@code length} is zero + */ + @Override + @Contract(pure = true) + public int getX(int length) { + if (length == 0) { + throw new IllegalArgumentException("Length may not be zero"); + } + + return this.index % length; + } + + /** + * {@inheritDoc} + * + * If {@code length} is zero, this will throw an {@link IllegalArgumentException}. + * + * @param length {@inheritDoc} + * @return {@inheritDoc} + * @throws IllegalArgumentException when {@code length} is zero + */ + @Override + @Contract(pure = true) + public int getY(int length) { + if (length == 0) { + throw new IllegalArgumentException("Length may not be zero"); + } + + return this.index / length; + } + } +} From cb3dc9792d52c5e35b929944505ca7815a4e4176 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 17 Sep 2022 20:21:01 +0200 Subject: [PATCH 164/382] Improve anvil gui handling Addresses #246 --- .../inventoryframework/gui/GuiListener.java | 3 +- .../inventoryframework/gui/type/AnvilGui.java | 7 +- .../nms/v1_14/AnvilInventoryImpl.java | 184 +++++++----------- .../nms/v1_15/AnvilInventoryImpl.java | 184 +++++++----------- .../nms/v1_16_1/AnvilInventoryImpl.java | 144 ++++++++------ .../nms/v1_16_2_3/AnvilInventoryImpl.java | 144 ++++++++------ .../nms/v1_16_4_5/AnvilInventoryImpl.java | 144 ++++++++------ nms/1_17_0/pom.xml | 2 +- .../nms/v1_17_0/AnvilInventoryImpl.java | 153 +++++++++------ nms/1_17_1/pom.xml | 2 +- .../nms/v1_17_1/AnvilInventoryImpl.java | 131 +++++++------ nms/1_18_0/pom.xml | 2 +- .../nms/v1_18_0/AnvilInventoryImpl.java | 131 +++++++------ nms/1_18_1/pom.xml | 2 +- .../nms/v1_18_1/AnvilInventoryImpl.java | 131 +++++++------ nms/1_18_2/pom.xml | 2 +- .../nms/v1_18_2/AnvilInventoryImpl.java | 131 +++++++------ nms/1_19_0/pom.xml | 2 +- .../nms/v1_19_0/AnvilInventoryImpl.java | 131 +++++++------ nms/1_19_1/pom.xml | 2 +- .../nms/v1_19_1/AnvilInventoryImpl.java | 131 +++++++------ nms/1_19_2/pom.xml | 2 +- .../nms/v1_19_2/AnvilInventoryImpl.java | 127 ++++++------ .../abstraction/AnvilInventory.java | 17 +- 24 files changed, 1033 insertions(+), 876 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index b2873fdb0..5fe916f4c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -97,8 +97,9 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { * * @param event the event fired * @since 0.8.0 + * @deprecated no longer used internally */ - @EventHandler(priority = EventPriority.HIGHEST) + @Deprecated public void resetItemsAnvil(@NotNull InventoryClickEvent event) { InventoryHolder holder = event.getInventory().getHolder(); 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 c1014f7c0..e337c985c 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 @@ -152,10 +152,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } - //also let Bukkit know that we opened an inventory - humanEntity.openInventory(getInventory()); + Inventory inventory = anvilInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); - anvilInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); + addInventory(inventory, this); this.viewers.add(humanEntity); } @@ -249,7 +248,9 @@ public List getViewers() { * * @param event the event to handle * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public void handleClickEvent(@NotNull InventoryClickEvent event) { int slot = event.getRawSlot(); Player player = (Player) event.getWhoClicked(); 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 index e2bdfe0f6..791d60c15 100644 --- 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 @@ -4,20 +4,17 @@ 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.Location; 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.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +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; - /** * Internal anvil inventory for 1.14 R1 * @@ -30,27 +27,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - entityPlayer.activeContainer = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerAnvil.windowId; IChatBaseComponent message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - sendItems(player, items); + int containerId = containerAnvil.getContainerId(); + + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); + entityPlayer.activeContainer = containerAnvil; + entityPlayer.syncInventory(); + + return inventory; } @Override @@ -109,7 +117,9 @@ public void clearCursor(@NotNull Player 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)); } @@ -120,7 +130,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack 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); @@ -133,8 +145,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @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; } @@ -145,9 +159,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -173,134 +189,84 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { private class ContainerAnvilImpl extends ContainerAnvil { /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the repair inventory field + * The index of the result slot */ - @NotNull - private final Field repairInventoryField; + private static final int RESULT_SLOT_INDEX = 2; /** - * Field for accessing the result inventory field + * The player for whom this container is */ @NotNull - private final Field resultInventoryField; - - /** - * Field for accessing the container access field - */ - @NotNull - private final Field containerAccessField; + private final EntityPlayer entityPlayer; /** * Creates a new custom anvil container for the specified player * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 + * @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, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); + ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.player = entityPlayer.getBukkitEntity(); + this.entityPlayer = entityPlayer; - try { - repairInventoryField = ContainerAnvil.class.getDeclaredField("repairInventory"); - repairInventoryField.setAccessible(true); + this.checkReachable = false; - resultInventoryField = ContainerAnvil.class.getDeclaredField("resultInventory"); - resultInventoryField.setAccessible(true); + setTitle(title); - containerAccessField = ContainerAnvil.class.getDeclaredField("containerAccess"); - containerAccessField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } + Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - getRepairInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getRepairInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + Slot newSlot = new Slot(originalSlot.inventory, originalSlot.index, originalSlot.e, originalSlot.f) { + @Override + public boolean isAllowed(ItemStack itemStack) { + return true; + } - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = getContainerAccess().getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, getRepairInventory(), getResultInventory(), - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + @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); } @Override public void a(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, getResultInventory().getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + this.entityPlayer.updateInventory(entityPlayer.activeContainer); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } + public void e() {} @Override - public void a(IInventory inventory) {} + public void b(EntityHuman entityHuman) {} @Override - public void b(EntityHuman entityhuman) {} + protected void a(EntityHuman entityHuman, World world, @NotNull IInventory inventory) {} - @NotNull - @Contract(pure = true) - private IInventory getRepairInventory() { - try { - return (IInventory) repairInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } + @Override + public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { + ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + //the client predicts the allowed movement of the item, so we broadcast the state again to override it + this.entityPlayer.updateInventory(entityPlayer.activeContainer); + + return itemStack; } - @NotNull - @Contract(pure = true) - private ContainerAccess getContainerAccess() { - try { - return (ContainerAccess) containerAccessField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.windowId; } } } 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 index 4addd1d7d..808ddc681 100644 --- 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 @@ -4,20 +4,17 @@ 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.Location; 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.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +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; - /** * Internal anvil inventory for 1.15 R1 * @@ -30,27 +27,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - entityPlayer.activeContainer = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerAnvil.windowId; IChatBaseComponent message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - sendItems(player, items); + int containerId = containerAnvil.getContainerId(); + + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); + entityPlayer.activeContainer = containerAnvil; + entityPlayer.syncInventory(); + + return inventory; } @Override @@ -109,7 +117,9 @@ public void clearCursor(@NotNull Player 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)); } @@ -120,7 +130,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack 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); @@ -133,8 +145,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @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; } @@ -145,9 +159,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -173,134 +189,84 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { private class ContainerAnvilImpl extends ContainerAnvil { /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the repair inventory field + * The index of the result slot */ - @NotNull - private final Field repairInventoryField; + private static final int RESULT_SLOT_INDEX = 2; /** - * Field for accessing the result inventory field + * The player for whom this container is */ @NotNull - private final Field resultInventoryField; - - /** - * Field for accessing the container access field - */ - @NotNull - private final Field containerAccessField; + private final EntityPlayer entityPlayer; /** * Creates a new custom anvil container for the specified player * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 + * @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, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); + ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.player = entityPlayer.getBukkitEntity(); + this.entityPlayer = entityPlayer; - try { - repairInventoryField = ContainerAnvil.class.getDeclaredField("repairInventory"); - repairInventoryField.setAccessible(true); + this.checkReachable = false; - resultInventoryField = ContainerAnvil.class.getDeclaredField("resultInventory"); - resultInventoryField.setAccessible(true); + setTitle(title); - containerAccessField = ContainerAnvil.class.getDeclaredField("containerAccess"); - containerAccessField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } + Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - getRepairInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getRepairInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + Slot newSlot = new Slot(originalSlot.inventory, originalSlot.index, originalSlot.e, originalSlot.f) { + @Override + public boolean isAllowed(ItemStack itemStack) { + return true; + } - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = getContainerAccess().getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, getRepairInventory(), getResultInventory(), - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + @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); } @Override public void a(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, getResultInventory().getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + this.entityPlayer.updateInventory(entityPlayer.activeContainer); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } + public void e() {} @Override - public void a(IInventory inventory) {} + public void b(EntityHuman entityHuman) {} @Override - public void b(EntityHuman entityhuman) {} + protected void a(EntityHuman entityHuman, World world, @NotNull IInventory inventory) {} - @NotNull - @Contract(pure = true) - private IInventory getRepairInventory() { - try { - return (IInventory) repairInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } + @Override + public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHuman entityhuman) { + ItemStack itemStack = super.a(i, j, inventoryclicktype, entityhuman); - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + //the client predicts the allowed movement of the item, so we broadcast the state again to override it + this.entityPlayer.updateInventory(entityPlayer.activeContainer); + + return itemStack; } - @NotNull - @Contract(pure = true) - private ContainerAccess getContainerAccess() { - try { - return (ContainerAccess) containerAccessField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.windowId; } } } 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 index aab6c707d..8564d1282 100644 --- 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 @@ -4,13 +4,12 @@ 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.Location; 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.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -28,27 +27,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - entityPlayer.activeContainer = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerAnvil.windowId; 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]); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + int containerId = containerAnvil.getContainerId(); - sendItems(player, items); + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); + entityPlayer.activeContainer = containerAnvil; + entityPlayer.syncInventory(); + + return inventory; } @Override @@ -107,7 +117,9 @@ public void clearCursor(@NotNull Player 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)); } @@ -118,7 +130,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack 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); @@ -131,8 +145,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @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; } @@ -143,9 +159,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -171,73 +189,89 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { private class ContainerAnvilImpl extends ContainerAnvil { /** - * The player for whom this anvil container is + * The index of the result slot */ - @NotNull - private final Player player; + private static final int RESULT_SLOT_INDEX = 2; /** - * The internal bukkit entity for this container anvil + * The player for whom this container is */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final EntityPlayer entityPlayer; /** * Creates a new custom anvil container for the specified player * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 + * @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, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); + ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.player = entityPlayer.getBukkitEntity(); + this.entityPlayer = entityPlayer; - repairInventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - repairInventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultInventory.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + this.checkReachable = false; - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = containerAccess.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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); } @Override public void a(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultInventory.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + this.entityPlayer.updateInventory(entityPlayer.activeContainer); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } + public void e() {} @Override - public void a(IInventory inventory) {} + public void b(EntityHuman entityHuman) {} @Override - public void b(EntityHuman entityhuman) {} + 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 + this.entityPlayer.updateInventory(entityPlayer.activeContainer); + + return itemStack; + } + + public int getContainerId() { + return this.windowId; + } } } 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 index 60ce9be2c..e0287ada8 100644 --- 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 @@ -4,13 +4,12 @@ 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.Location; import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -28,27 +27,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - entityPlayer.activeContainer = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerAnvil.windowId; 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]); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + int containerId = containerAnvil.getContainerId(); - sendItems(player, items); + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); + entityPlayer.activeContainer = containerAnvil; + entityPlayer.syncInventory(); + + return inventory; } @Override @@ -107,7 +117,9 @@ public void clearCursor(@NotNull Player 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)); } @@ -118,7 +130,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack 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); @@ -131,8 +145,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @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; } @@ -143,9 +159,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -171,73 +189,89 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { private class ContainerAnvilImpl extends ContainerAnvil { /** - * The player for whom this anvil container is + * The index of the result slot */ - @NotNull - private final Player player; + private static final int RESULT_SLOT_INDEX = 2; /** - * The internal bukkit entity for this container anvil + * The player for whom this container is */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final EntityPlayer entityPlayer; /** * Creates a new custom anvil container for the specified player * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 + * @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, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); + ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.player = entityPlayer.getBukkitEntity(); + this.entityPlayer = entityPlayer; - repairInventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - repairInventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultInventory.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + this.checkReachable = false; - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = containerAccess.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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); } @Override public void a(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultInventory.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + this.entityPlayer.updateInventory(entityPlayer.activeContainer); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } + public void e() {} @Override - public void a(IInventory inventory) {} + public void b(EntityHuman entityHuman) {} @Override - public void b(EntityHuman entityhuman) {} + 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 + this.entityPlayer.updateInventory(entityPlayer.activeContainer); + + return itemStack; + } + + public int getContainerId() { + return this.windowId; + } } } 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 index 257de5d3a..35bf2f5e1 100644 --- 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 @@ -4,13 +4,12 @@ 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.Location; 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.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -28,27 +27,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(entityPlayer, items); - entityPlayer.activeContainer = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerAnvil.windowId; 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]); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, message)); + int containerId = containerAnvil.getContainerId(); - sendItems(player, items); + entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, Containers.ANVIL, message)); + entityPlayer.activeContainer = containerAnvil; + entityPlayer.syncInventory(); + + return inventory; } @Override @@ -107,7 +117,9 @@ public void clearCursor(@NotNull Player 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)); } @@ -118,7 +130,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack 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); @@ -131,8 +145,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @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; } @@ -143,9 +159,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -171,73 +189,89 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { private class ContainerAnvilImpl extends ContainerAnvil { /** - * The player for whom this anvil container is + * The index of the result slot */ - @NotNull - private final Player player; + private static final int RESULT_SLOT_INDEX = 2; /** - * The internal bukkit entity for this container anvil + * The player for whom this container is */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final EntityPlayer entityPlayer; /** * Creates a new custom anvil container for the specified player * - * @param entityPlayer the player for who this anvil container is - * @since 0.8.0 + * @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, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBaseComponent title) { super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, - ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); + ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.player = entityPlayer.getBukkitEntity(); + this.entityPlayer = entityPlayer; - repairInventory.setItem(0, CraftItemStack.asNMSCopy(items[0])); - repairInventory.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultInventory.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + this.checkReachable = false; - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = containerAccess.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, repairInventory, resultInventory, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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); } @Override public void a(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultInventory.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + this.entityPlayer.updateInventory(entityPlayer.activeContainer); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { - return true; - } + public void e() {} @Override - public void a(IInventory inventory) {} + public void b(EntityHuman entityHuman) {} @Override - public void b(EntityHuman entityhuman) {} + 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 + this.entityPlayer.updateInventory(entityPlayer.activeContainer); + + return itemStack; + } + + public int getContainerId() { + return this.windowId; + } } } diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 95491d8e4..906a988cd 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.2.1 + 1.3 process-classes diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java index 9df96142f..831927fe6 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java @@ -2,8 +2,8 @@ import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_17_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -13,22 +13,26 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; import net.minecraft.world.Container; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.ContainerSynchronizer; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; + /** * Internal anvil inventory for 1.17 R1 * @@ -41,27 +45,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - sendItems(player, items); + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; } @Override @@ -119,7 +134,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.9.9 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { getPlayerConnection(getServerPlayer(player)).send(new ClientboundContainerSetSlotPacket(-1, -1, item)); } @@ -130,7 +147,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.9.9 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -144,8 +163,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.9.9 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -156,9 +177,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.9.9 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -181,76 +204,96 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.9.9 */ + @SuppressWarnings("JavaReflectionMemberAccess") private class ContainerAnvilImpl extends AnvilMenu { /** - * The player for whom this anvil container is + * The index of the result slot */ - @NotNull - private final Player player; + private static final int RESULT_SLOT_INDEX = 2; /** - * The internal bukkit entity for this container anvil + * A field that represents the synchronizer field */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final Field synchronizerField; /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.9.9 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), - ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } + Slot originalSlot = this.slots.get(RESULT_SLOT_INDEX); - return bukkitEntity; + Slot newSlot = new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }; + + this.slots.set(RESULT_SLOT_INDEX, newSlot); + + try { + this.synchronizerField = AbstractContainerMenu.class.getDeclaredField("v"); + } catch (NoSuchFieldException exception) { + throw new RuntimeException("Unable to access field", exception); + } } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; + + //the client predicts the output result, so we broadcast the state again to override it + ContainerSynchronizer synchronizer; + + try { + this.synchronizerField.setAccessible(true); - sendResultItem(player, resultSlots.getItem(0)); + synchronizer = (ContainerSynchronizer) this.synchronizerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException("Unable to access field", exception); + } + + synchronizer.sendSlotChange(this, RESULT_SLOT_INDEX, getSlot(RESULT_SLOT_INDEX).getItem()); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} @Override - public void slotsChanged(Container container) {} + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 376ac8dcc..9b5ef7c05 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.2.1 + 1.3 process-classes diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java index 85c734b01..1e96df189 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java @@ -16,14 +16,14 @@ import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,27 +41,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); - sendItems(player, items); + return inventory; } @Override @@ -125,7 +136,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.10.0 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int state = serverPlayer.containerMenu.incrementStateId(); @@ -139,7 +152,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.10.0 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -154,8 +169,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.10.0 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -166,9 +183,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.0 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -193,74 +212,64 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { */ private class ContainerAnvilImpl extends AnvilMenu { - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.10.0 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), - ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return originalSlot.mayPickup(playerEntity); + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultSlots.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void slotsChanged(Container container) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index bece017cf..909543a88 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.2.1 + 1.3 process-classes diff --git a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java index edb8cae9a..b1d07ae41 100644 --- a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java @@ -16,14 +16,14 @@ import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,27 +41,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); - sendItems(player, items); + return inventory; } @Override @@ -125,7 +136,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.10.4 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int state = serverPlayer.containerMenu.incrementStateId(); @@ -139,7 +152,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.10.4 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -154,8 +169,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.10.4 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -166,9 +183,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.4 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -193,74 +212,64 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { */ private class ContainerAnvilImpl extends AnvilMenu { - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.10.4 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), - ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return originalSlot.mayPickup(playerEntity); + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultSlots.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void slotsChanged(Container container) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index f79122953..bac64e45a 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.2.1 + 1.3 process-classes diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java index 6444cdac9..7ee6029f5 100644 --- a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java @@ -16,14 +16,14 @@ import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,27 +41,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); - sendItems(player, items); + return inventory; } @Override @@ -125,7 +136,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.10.4 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int state = serverPlayer.containerMenu.incrementStateId(); @@ -139,7 +152,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.10.4 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -154,8 +169,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.10.4 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -166,9 +183,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.4 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -193,74 +212,64 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { */ private class ContainerAnvilImpl extends AnvilMenu { - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.10.4 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), - ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return originalSlot.mayPickup(playerEntity); + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultSlots.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void slotsChanged(Container container) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 1f6b26b2f..d53c3c40d 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.2.1 + 1.3 process-classes diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java index fd6f703bb..1ae5300d2 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java @@ -16,14 +16,14 @@ import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,27 +41,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); - sendItems(player, items); + return inventory; } @Override @@ -125,7 +136,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.10.5 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int state = serverPlayer.containerMenu.incrementStateId(); @@ -139,7 +152,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.10.5 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -154,8 +169,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.10.5 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -166,9 +183,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.5 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -193,74 +212,64 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { */ private class ContainerAnvilImpl extends AnvilMenu { - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.10.5 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), - ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return originalSlot.mayPickup(playerEntity); + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultSlots.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void slotsChanged(Container container) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 92da38f26..ab5770f64 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.2.1 + 1.3 process-classes diff --git a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java index 2e72bf853..c9d82cb9c 100644 --- a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java @@ -16,14 +16,14 @@ import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,27 +41,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); - sendItems(player, items); + return inventory; } @Override @@ -125,7 +136,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.10.6 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int state = serverPlayer.containerMenu.incrementStateId(); @@ -139,7 +152,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.10.6 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -154,8 +169,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.10.6 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -166,9 +183,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.6 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -193,74 +212,64 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { */ private class ContainerAnvilImpl extends AnvilMenu { - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.10.6 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), - ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return originalSlot.mayPickup(playerEntity); + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultSlots.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void slotsChanged(Container container) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index a2f59c831..f71740e35 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.2.1 + 1.3 process-classes diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java index 0b4968c6d..9bb275df0 100644 --- a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java @@ -16,14 +16,14 @@ import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,27 +41,38 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + 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 + "'" + "The amount of items for an anvil should be 3, but is '" + itemAmount + "'" ); } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); - sendItems(player, items); + return inventory; } @Override @@ -125,7 +136,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.10.7 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int state = serverPlayer.containerMenu.incrementStateId(); @@ -139,7 +152,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.10.7 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -154,8 +169,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.10.7 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -166,9 +183,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.7 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -193,74 +212,64 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { */ private class ContainerAnvilImpl extends AnvilMenu { - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.10.7 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), - ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return originalSlot.mayPickup(playerEntity); + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultSlots.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void slotsChanged(Container container) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index c85013c96..b7b441c7f 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.2.1 + 1.3 process-classes diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java index 80fb89694..a5f5975b3 100644 --- a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java @@ -16,14 +16,14 @@ import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,8 +41,8 @@ public AnvilInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -52,16 +52,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, items); - serverPlayer.containerMenu = containerAnvil; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerAnvil.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, message); + + Inventory inventory = containerAnvil.getBukkitView().getTopInventory(); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ANVIL, message)); + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerAnvil.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); - sendItems(player, items); + return inventory; } @Override @@ -125,7 +136,9 @@ public void clearCursor(@NotNull Player player) { * @param player the player to set the cursor * @param item the item to set the cursor to * @since 0.10.7 + * @deprecated no longer used internally */ + @Deprecated private void setCursor(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int state = serverPlayer.containerMenu.incrementStateId(); @@ -139,7 +152,9 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * @param player the player to send the result item to * @param item the result item * @since 0.10.7 + * @deprecated no longer used internally */ + @Deprecated private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { ServerPlayer serverPlayer = getServerPlayer(player); int containerId = getContainerId(serverPlayer); @@ -154,8 +169,10 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * @param nmsPlayer the player to get the container id for * @return the container id * @since 0.10.7 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -166,9 +183,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.7 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -193,74 +212,64 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { */ private class ContainerAnvilImpl extends AnvilMenu { - /** - * The player for whom this anvil container is - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container anvil - */ - @Nullable - private CraftInventoryView bukkitEntity; - /** * Creates a new custom anvil container for the specified player * - * @param serverPlayer the player for who this anvil container is - * @since 0.10.7 + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 */ - public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); - this.player = serverPlayer.getBukkitEntity(); + this.checkReachable = false; - inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); - inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); - resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); - } + setTitle(title); - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - Location location = access.getLocation(); - CraftInventory inventory = new CraftInventoryAnvil(location, inputSlots, resultSlots, - this) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return originalSlot.mayPickup(playerEntity); + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); } @Override public void setItemName(@Nullable String name) { - text = name == null ? "" : name; + AnvilInventoryImpl.super.text = name == null ? "" : name; - sendResultItem(player, resultSlots.getItem(0)); + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); } - @Contract(pure = true, value = "_ -> true") @Override - public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { - return true; - } + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} @Override - public void slotsChanged(Container container) {} + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} @Override - public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } } } 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 f5762d4cf..9864a3dfe 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 @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Contract; @@ -50,7 +51,7 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ openInventory(player, StringHolder.of(title), items); } - public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); + public abstract Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. @@ -58,7 +59,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * @param player the player for which to open the anvil * @param items the items to send * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void sendItems(@NotNull Player player, @Nullable ItemStack[] items); /** @@ -67,7 +70,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * @param player the player to send the item to * @param item the item to send * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void sendResultItem(@NotNull Player player, @Nullable ItemStack item); /** @@ -76,7 +81,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * @param player the player to send the item to * @param item the item to send * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void sendFirstItem(@NotNull Player player, @Nullable ItemStack item); /** @@ -85,7 +92,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * @param player the player to send the item to * @param item the item to send * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void sendSecondItem(@NotNull Player player, @Nullable ItemStack item); /** @@ -94,7 +103,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * @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 public abstract void setCursor(@NotNull Player player, @NotNull ItemStack item); /** @@ -102,7 +113,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * * @param player the player to clear the cursor of * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void clearCursor(@NotNull Player player); /** @@ -110,7 +123,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * * @param player the player to clear the result item of * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void clearResultItem(@NotNull Player player); /** From 9297ec82aa26f247c21ec6adbe9d34a8e2a14773 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Aug 2022 05:16:15 +0000 Subject: [PATCH 165/382] Bump maven-javadoc-plugin from 3.4.0 to 3.4.1 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.0...maven-javadoc-plugin-3.4.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index b1c22d14e..4e03bb118 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -248,7 +248,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.0 + 3.4.1 attach-javadocs diff --git a/pom.xml b/pom.xml index c438a4bdb..f101f3ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -149,7 +149,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.0 + 3.4.1 attach-javadocs From d8c4dca883fd8cfc89c72d23faabfbd17320146b Mon Sep 17 00:00:00 2001 From: RobotHanzo Date: Thu, 25 Aug 2022 21:09:46 +0800 Subject: [PATCH 166/382] Respect visibility in OutlinePane --- .../stefvanschie/inventoryframework/pane/OutlinePane.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java index c1a8a0799..055b63818 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java @@ -235,7 +235,11 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs int finalRow = slot.getY(maxLength) + y + paneOffsetY; int finalColumn = slot.getX(maxLength) + x + paneOffsetX; - inventoryComponent.setItem(items[index], finalColumn, finalRow); + GuiItem item = items[index]; + if (!item.isVisible()) { + continue; + } + inventoryComponent.setItem(item, finalColumn, finalRow); } } From 20810213a7e075f11f30026f48526b7f1b4b17a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Sep 2022 05:18:39 +0000 Subject: [PATCH 167/382] Bump paper-nms-maven-plugin from 1.2.1 to 1.3 Bumps paper-nms-maven-plugin from 1.2.1 to 1.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- 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 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 95491d8e4..906a988cd 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.2.1 + 1.3 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 376ac8dcc..9b5ef7c05 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.2.1 + 1.3 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index bece017cf..909543a88 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.2.1 + 1.3 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index f79122953..bac64e45a 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.2.1 + 1.3 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 1f6b26b2f..d53c3c40d 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.2.1 + 1.3 process-classes diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 92da38f26..ab5770f64 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.2.1 + 1.3 process-classes diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index a2f59c831..f71740e35 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.2.1 + 1.3 process-classes diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index c85013c96..b7b441c7f 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.2.1 + 1.3 process-classes From 3b8489266adfa966cc214c65c031e209697d5f9d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Sep 2022 05:14:31 +0000 Subject: [PATCH 168/382] Bump maven-shade-plugin from 3.3.0 to 3.4.0 in /IF Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.3.0 to 3.4.0. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.3.0...maven-shade-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 4e03bb118..43c958d65 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -211,7 +211,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.3.0 + 3.4.0 package From 1b0afddf193a9464c6ce1962be74391f8a88ce86 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 18 Sep 2022 20:55:38 +0200 Subject: [PATCH 169/382] Add PaginatedPane#addPage Adds a pane to a new page after the current last page. --- .../pane/PaginatedPane.java | 37 ++++++++++++++ .../pane/PaginatedPaneTest.java | 49 +++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index 4c959ee90..f7b814312 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -92,6 +92,43 @@ public int getPage() { public int getPages() { return panes.size(); } + + /** + * Adds the specified pane to a new page. The new page will be at the index one after the highest indexed page + * currently in this paginated pane. If the highest index pane is {@code Integer.MAX_VALUE}, this method will throw + * an {@link ArithmeticException}. If this paginated pane has no pages, the index of the newly created page will + * be zero. + * + * @param pane the pane to add to a new page + * @since 0.10.8 + * @throws ArithmeticException if the highest indexed page is the maximum value + */ + public void addPage(@NotNull Pane pane) { + List list = new ArrayList<>(1); + + list.add(pane); + + if (this.panes.isEmpty()) { + this.panes.put(0, list); + + return; + } + + int highest = Integer.MIN_VALUE; + + for (int page : this.panes.keySet()) { + if (page > highest) { + highest = page; + } + } + + if (highest == Integer.MAX_VALUE) { + throw new ArithmeticException("Can't increment page index beyond its maximum value"); + } + + this.panes.put(highest + 1, list); + } + /** * Assigns a pane to a selected page * diff --git a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java index 559355f0e..af2c6b54e 100644 --- a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java +++ b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPaneTest.java @@ -2,10 +2,59 @@ import org.junit.jupiter.api.Test; +import java.util.Collection; + import static org.junit.jupiter.api.Assertions.*; public class PaginatedPaneTest { + @Test + void testAddPageEmpty() { + PaginatedPane paginatedPane = new PaginatedPane(0, 0, 1, 1); + + StaticPane staticPane = new StaticPane(0, 0, 1, 1); + + assertDoesNotThrow(() -> { + paginatedPane.addPage(staticPane); + + Collection panes = paginatedPane.getPanes(0); + + assertEquals(1, panes.size()); + assertSame(staticPane, panes.iterator().next()); + }); + } + + @Test + void testAddPageNotEmpty() { + PaginatedPane paginatedPane = new PaginatedPane(0, 0, 1, 1); + + StaticPane staticPane1 = new StaticPane(0, 0, 1, 1); + StaticPane staticPane2 = new StaticPane(0, 0, 1, 1); + + paginatedPane.addPane(0, staticPane1); + + assertDoesNotThrow(() -> { + paginatedPane.addPage(staticPane2); + + Collection panes = paginatedPane.getPanes(1); + + assertEquals(1, panes.size()); + assertSame(staticPane2, panes.iterator().next()); + }); + } + + @Test + void testAddPageException() { + PaginatedPane paginatedPane = new PaginatedPane(0, 0, 1, 1); + + StaticPane staticPane1 = new StaticPane(0, 0, 1, 1); + StaticPane staticPane2 = new StaticPane(0, 0, 1, 1); + + paginatedPane.addPane(Integer.MAX_VALUE, staticPane1); + + assertThrows(ArithmeticException.class, () -> paginatedPane.addPage(staticPane2)); + } + @Test void testCopy() { PaginatedPane original = new PaginatedPane(5, 5, 4, 1, Pane.Priority.NORMAL); From 14b27b06eea9a7933dd20ff5fa8dfbb3fede8af8 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 19 Sep 2022 21:13:58 +0200 Subject: [PATCH 170/382] Add ToggleButton#allowToggle Prevents players from toggling the toggle button. --- .../pane/component/ToggleButton.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index 8b6234d41..c7a937b9a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -37,6 +37,11 @@ public class ToggleButton extends Pane { */ private boolean enabled; + /** + * Whether this button can be toggled by a player + */ + private boolean allowToggle = true; + /** * Creates a new toggle button * @@ -316,15 +321,20 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp return false; } - toggle(); + if (this.allowToggle) { + toggle(); + } callOnClick(event); int newX = paneOffsetX + x; int newY = paneOffsetY + y; - //swap panes, since we will already have toggled the enabled state here - if (enabled) { + /* + Since we've toggled before, the click for the panes should be swapped around. If we haven't toggled due to + allowToggle being false, then we should click the pane corresponding to the current state. An XOR achieves this. + */ + if (enabled == this.allowToggle) { disabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); } else { enabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); @@ -341,6 +351,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp public ToggleButton copy() { ToggleButton toggleButton = new ToggleButton(getSlot(), length, height, getPriority(), enabled); + toggleButton.allowToggle = this.allowToggle; + toggleButton.setVisible(isVisible()); toggleButton.onClick = onClick; @@ -420,6 +432,17 @@ public Collection getPanes() { return Stream.of(enabledPane, disabledPane).collect(Collectors.toSet()); } + /** + * Sets whether this toggle button can be toggled. This only prevents players from toggling the button and does not + * prevent toggling the button programmatically with methods such as {@link #toggle()}. + * + * @param allowToggle whether this button can be toggled + * @since 0.10.8 + */ + public void allowToggle(boolean allowToggle) { + this.allowToggle = allowToggle; + } + /** * Gets whether this toggle button is currently enabled or disabled. * From 90ed5481739bff4f92c37428de127c500fe93ed2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:19:39 +0000 Subject: [PATCH 171/382] Bump junit-jupiter-engine from 5.9.0 to 5.9.1 in /IF Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.9.0 to 5.9.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.0...r5.9.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 43c958d65..3bb69f37f 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -204,7 +204,7 @@ org.junit.jupiter junit-jupiter-engine - 5.9.0 + 5.9.1 From 02d1899ce10a643451f40bc21f02d98bfb1240fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:19:58 +0000 Subject: [PATCH 172/382] Bump paper-nms-maven-plugin from 1.3 to 1.3.1 Bumps paper-nms-maven-plugin from 1.3 to 1.3.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- 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 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 906a988cd..4bba371eb 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.3 + 1.3.1 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 9b5ef7c05..6a87348cb 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.3 + 1.3.1 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 909543a88..c8c2f2ad3 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.3 + 1.3.1 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index bac64e45a..9930bc17e 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.3 + 1.3.1 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index d53c3c40d..710f8514d 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.3 + 1.3.1 process-classes diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index ab5770f64..5722604bd 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.3 + 1.3.1 process-classes diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index f71740e35..70cf454b1 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.3 + 1.3.1 process-classes diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index b7b441c7f..d4824f482 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.3 + 1.3.1 process-classes From 7abc25f4241aac75a8b6e45c8b81f4006f074a13 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:20:03 +0000 Subject: [PATCH 173/382] Bump junit-jupiter-api from 5.9.0 to 5.9.1 Bumps [junit-jupiter-api](https://github.com/junit-team/junit5) from 5.9.0 to 5.9.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.0...r5.9.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 3bb69f37f..5948f36a7 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -147,7 +147,7 @@ org.junit.jupiter junit-jupiter-api - 5.9.0 + 5.9.1 test From 5e3b3a125c093415dacedae26a9351125da70980 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:20:23 +0000 Subject: [PATCH 174/382] Bump junit-jupiter-engine from 5.9.0 to 5.9.1 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.9.0 to 5.9.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.0...r5.9.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f101f3ed6..e2e338db8 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ org.junit.jupiter junit-jupiter-engine - 5.9.0 + 5.9.1 From 567f483ced7d89fb6cc07b03db315cacc8df6873 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 1 Oct 2022 20:49:41 +0200 Subject: [PATCH 175/382] Cache .paper-nms --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 35cce1a8a..ae3b06aa6 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,6 +21,7 @@ jobs: uses: actions/cache@v2 with: path: | + .paper-nms build paperclip ~/.m2/repository/io/papermc/paper From 486105a0833f64549bfccd840745948deb423de5 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 1 Oct 2022 21:16:43 +0200 Subject: [PATCH 176/382] Add GuiItem#setItem(ItemStack) --- .../stefvanschie/inventoryframework/gui/GuiItem.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 20140dc22..732a3f77f 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 @@ -54,7 +54,7 @@ public class GuiItem { * The items shown */ @NotNull - private final ItemStack item; + private ItemStack item; /** * Whether this item is visible or not @@ -185,6 +185,16 @@ public void applyUUID() { } } + /** + * Overwrites the current item with the provided item. + * + * @param item the item to set + * @since 0.10.8 + */ + public void setItem(@NotNull ItemStack item) { + this.item = item; + } + /** * Sets the action to be executed when a human entity clicks on this item. * From 3b7a39fbe103fb8877cc761e9d4fe53bbe7ca9e1 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 6 Nov 2022 20:56:38 +0100 Subject: [PATCH 177/382] Add AnvilGui#setCost(short) Addresses #246 --- .../inventoryframework/gui/type/AnvilGui.java | 17 +++ .../nms/v1_14/AnvilInventoryImpl.java | 114 +++++++++++++++++- .../nms/v1_15/AnvilInventoryImpl.java | 114 +++++++++++++++++- .../nms/v1_16_1/AnvilInventoryImpl.java | 114 +++++++++++++++++- .../nms/v1_16_2_3/AnvilInventoryImpl.java | 114 +++++++++++++++++- .../nms/v1_16_4_5/AnvilInventoryImpl.java | 114 +++++++++++++++++- .../nms/v1_17_0/AnvilInventoryImpl.java | 1 + .../nms/v1_17_1/AnvilInventoryImpl.java | 3 +- .../nms/v1_18_0/AnvilInventoryImpl.java | 3 +- .../nms/v1_18_1/AnvilInventoryImpl.java | 3 +- .../nms/v1_18_2/AnvilInventoryImpl.java | 3 +- .../nms/v1_19_0/AnvilInventoryImpl.java | 3 +- .../nms/v1_19_1/AnvilInventoryImpl.java | 3 +- .../nms/v1_19_2/AnvilInventoryImpl.java | 3 +- .../abstraction/AnvilInventory.java | 22 ++++ 15 files changed, 594 insertions(+), 37 deletions(-) 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 e337c985c..30841324e 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 @@ -204,6 +204,23 @@ public Inventory getInventory() { return inventory; } + /** + * Sets the enchantment level cost for this anvil gui. Taking the item from the result slot will not actually remove + * these levels. Having a cost specified does not impede a player's ability to take the item in the result item, + * even if the player does not have the specified amount of levels. The cost must be a non-negative number. + * + * @param cost the cost + * @since 0.10.8 + * @throws IllegalArgumentException when the cost is less than zero + */ + public void setCost(short cost) { + if (cost < 0){ + throw new IllegalArgumentException("Cost must be non-negative"); + } + + this.anvilInventory.setCost(cost); + } + @NotNull @Contract(pure = true) @Override 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 index 791d60c15..890bc454f 100644 --- 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 @@ -15,6 +15,11 @@ 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 * @@ -194,10 +199,16 @@ private class ContainerAnvilImpl extends ContainerAnvil { private static final int RESULT_SLOT_INDEX = 2; /** - * The player for whom this container is + * A unique item + */ + @NotNull + private final ItemStack uniqueItem; + + /** + * The field containing the listeners for this container */ @NotNull - private final EntityPlayer entityPlayer; + private final Field listenersField; /** * Creates a new custom anvil container for the specified player @@ -210,10 +221,53 @@ public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBase super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.entityPlayer = entityPlayer; - 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); @@ -236,6 +290,19 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack 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 @@ -243,7 +310,7 @@ public void a(@Nullable String name) { AnvilInventoryImpl.super.text = name == null ? "" : name; //the client predicts the output result, so we broadcast the state again to override it - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); } @Override @@ -260,7 +327,7 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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 - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); return itemStack; } @@ -268,5 +335,40 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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/AnvilInventoryImpl.java b/nms/1_15/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_15/AnvilInventoryImpl.java index 808ddc681..7bb3be41d 100644 --- 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 @@ -15,6 +15,11 @@ 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 * @@ -194,10 +199,16 @@ private class ContainerAnvilImpl extends ContainerAnvil { private static final int RESULT_SLOT_INDEX = 2; /** - * The player for whom this container is + * A unique item + */ + @NotNull + private final ItemStack uniqueItem; + + /** + * The field containing the listeners for this container */ @NotNull - private final EntityPlayer entityPlayer; + private final Field listenersField; /** * Creates a new custom anvil container for the specified player @@ -210,10 +221,53 @@ public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBase super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.entityPlayer = entityPlayer; - 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); @@ -236,6 +290,19 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack 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 @@ -243,7 +310,7 @@ public void a(@Nullable String name) { AnvilInventoryImpl.super.text = name == null ? "" : name; //the client predicts the output result, so we broadcast the state again to override it - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); } @Override @@ -260,7 +327,7 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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 - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); return itemStack; } @@ -268,5 +335,40 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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/AnvilInventoryImpl.java b/nms/1_16_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java index 8564d1282..bd0ba56b4 100644 --- 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 @@ -15,6 +15,11 @@ 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 * @@ -194,10 +199,16 @@ private class ContainerAnvilImpl extends ContainerAnvil { private static final int RESULT_SLOT_INDEX = 2; /** - * The player for whom this container is + * A unique item + */ + @NotNull + private final ItemStack uniqueItem; + + /** + * The field containing the listeners for this container */ @NotNull - private final EntityPlayer entityPlayer; + private final Field listenersField; /** * Creates a new custom anvil container for the specified player @@ -210,10 +221,53 @@ public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBase super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.entityPlayer = entityPlayer; - 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); @@ -236,6 +290,19 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack 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 @@ -243,7 +310,7 @@ public void a(@Nullable String name) { AnvilInventoryImpl.super.text = name == null ? "" : name; //the client predicts the output result, so we broadcast the state again to override it - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); } @Override @@ -265,7 +332,7 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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 - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); return itemStack; } @@ -273,5 +340,40 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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); + + 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(); + } + } } } 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 index e0287ada8..bfe46ad3e 100644 --- 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 @@ -15,6 +15,11 @@ 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 * @@ -194,10 +199,16 @@ private class ContainerAnvilImpl extends ContainerAnvil { private static final int RESULT_SLOT_INDEX = 2; /** - * The player for whom this container is + * A unique item + */ + @NotNull + private final ItemStack uniqueItem; + + /** + * The field containing the listeners for this container */ @NotNull - private final EntityPlayer entityPlayer; + private final Field listenersField; /** * Creates a new custom anvil container for the specified player @@ -210,10 +221,53 @@ public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBase super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.entityPlayer = entityPlayer; - 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); @@ -236,6 +290,19 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack 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 @@ -243,7 +310,7 @@ public void a(@Nullable String name) { AnvilInventoryImpl.super.text = name == null ? "" : name; //the client predicts the output result, so we broadcast the state again to override it - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); } @Override @@ -265,7 +332,7 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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 - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); return itemStack; } @@ -273,5 +340,40 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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); + + 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(); + } + } } } 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 index 35bf2f5e1..110eee0b1 100644 --- 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 @@ -15,6 +15,11 @@ 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 * @@ -194,10 +199,16 @@ private class ContainerAnvilImpl extends ContainerAnvil { private static final int RESULT_SLOT_INDEX = 2; /** - * The player for whom this container is + * A unique item + */ + @NotNull + private final ItemStack uniqueItem; + + /** + * The field containing the listeners for this container */ @NotNull - private final EntityPlayer entityPlayer; + private final Field listenersField; /** * Creates a new custom anvil container for the specified player @@ -210,10 +221,53 @@ public ContainerAnvilImpl(@NotNull EntityPlayer entityPlayer, @NotNull IChatBase super(entityPlayer.nextContainerCounter(), entityPlayer.inventory, ContainerAccess.at(entityPlayer.getWorld(), new BlockPosition(0, 0, 0))); - this.entityPlayer = entityPlayer; - 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); @@ -236,6 +290,19 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack 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 @@ -243,7 +310,7 @@ public void a(@Nullable String name) { AnvilInventoryImpl.super.text = name == null ? "" : name; //the client predicts the output result, so we broadcast the state again to override it - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); } @Override @@ -265,7 +332,7 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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 - this.entityPlayer.updateInventory(entityPlayer.activeContainer); + forceUpdate(); return itemStack; } @@ -273,5 +340,40 @@ public ItemStack a(int i, int j, InventoryClickType inventoryclicktype, EntityHu 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); + + 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(); + } + } } } diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java index 831927fe6..fa6c79275 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java @@ -230,6 +230,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java index 1e96df189..fddec0f9e 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java @@ -224,6 +224,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); @@ -237,7 +238,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { @Override public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { - return originalSlot.mayPickup(playerEntity); + return true; } @Override diff --git a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java index b1d07ae41..1eb5270ac 100644 --- a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java @@ -224,6 +224,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); @@ -237,7 +238,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { @Override public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { - return originalSlot.mayPickup(playerEntity); + return true; } @Override diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java index 7ee6029f5..2b0e9d772 100644 --- a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java @@ -224,6 +224,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); @@ -237,7 +238,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { @Override public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { - return originalSlot.mayPickup(playerEntity); + return true; } @Override diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java index 1ae5300d2..e70641a96 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java @@ -224,6 +224,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); @@ -237,7 +238,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { @Override public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { - return originalSlot.mayPickup(playerEntity); + return true; } @Override diff --git a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java index c9d82cb9c..702b6c1c9 100644 --- a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java @@ -224,6 +224,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); @@ -237,7 +238,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { @Override public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { - return originalSlot.mayPickup(playerEntity); + return true; } @Override diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java index 9bb275df0..d5d0f07e0 100644 --- a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java @@ -224,6 +224,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); @@ -237,7 +238,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { @Override public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { - return originalSlot.mayPickup(playerEntity); + return true; } @Override diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java index a5f5975b3..2a0f4cb7d 100644 --- a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java @@ -224,6 +224,7 @@ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); setTitle(title); @@ -237,7 +238,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { @Override public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { - return originalSlot.mayPickup(playerEntity); + return true; } @Override 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 9864a3dfe..7af79cf88 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 @@ -29,6 +29,11 @@ public abstract class AnvilInventory { @NotNull protected String text = ""; + /** + * The enchantment cost displayed + */ + protected short cost; + /** * Creates a new anvil inventory for the specified inventory holder * @@ -39,6 +44,23 @@ public AnvilInventory(@NotNull InventoryHolder inventoryHolder) { this.inventoryHolder = inventoryHolder; } + /** + * Sets the enchantment level cost for this anvil gui. Taking the item from the result slot will not actually remove + * these levels. Having a cost specified does not impede a player's ability to take the item in the result item, + * even if the player does not have the specified amount of levels. The cost must be a non-negative number. + * + * @param cost the cost + * @since 0.10.8 + * @throws IllegalArgumentException when the cost is less than zero + */ + public void setCost(short cost) { + if (cost < 0){ + throw new IllegalArgumentException("Cost must be non-negative"); + } + + this.cost = cost; + } + /** * Opens the inventory for the specified player * From 4c06468d1ef26908a56968fa2b42f4c4b83c4063 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 5 Dec 2022 20:55:14 +0100 Subject: [PATCH 178/382] Fix grindstone inventories not behaving correctly Addresses #264 --- .../inventoryframework/gui/GuiListener.java | 3 +- .../gui/type/GrindstoneGui.java | 7 +- .../nms/v1_14/GrindstoneInventoryImpl.java | 209 +++++++++++------- .../nms/v1_15/GrindstoneInventoryImpl.java | 209 +++++++++++------- .../nms/v1_16_1/GrindstoneInventoryImpl.java | 205 ++++++++++------- .../v1_16_2_3/GrindstoneInventoryImpl.java | 205 ++++++++++------- .../v1_16_4_5/GrindstoneInventoryImpl.java | 205 ++++++++++------- .../nms/v1_17_0/GrindstoneInventoryImpl.java | 166 +++++--------- .../nms/v1_17_1/GrindstoneInventoryImpl.java | 165 +++++--------- .../nms/v1_18_0/GrindstoneInventoryImpl.java | 165 +++++--------- .../nms/v1_18_1/GrindstoneInventoryImpl.java | 165 +++++--------- .../nms/v1_18_2/GrindstoneInventoryImpl.java | 165 +++++--------- .../nms/v1_19_0/GrindstoneInventoryImpl.java | 165 +++++--------- .../nms/v1_19_1/GrindstoneInventoryImpl.java | 165 +++++--------- .../nms/v1_19_2/GrindstoneInventoryImpl.java | 163 +++++--------- .../abstraction/GrindstoneInventory.java | 11 +- 16 files changed, 1117 insertions(+), 1256 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index 5fe916f4c..92b0c94bc 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -166,8 +166,9 @@ public void resetItemsEnchantingTable(@NotNull InventoryClickEvent event) { * * @param event the event fired * @since 0.8.0 + * @deprecated no longer used internally */ - @EventHandler(priority = EventPriority.HIGHEST) + @Deprecated public void resetItemsGrindstone(@NotNull InventoryClickEvent event) { InventoryHolder holder = event.getInventory().getHolder(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index 82e6dc0ca..fd1a6d7b8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -136,10 +136,9 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } - //also let Bukkit know that we opened an inventory - humanEntity.openInventory(getInventory()); + Inventory inventory = grindstoneInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); - grindstoneInventory.openInventory((Player) humanEntity, getTitleHolder(), getTopItems()); + addInventory(inventory, this); } @NotNull @@ -202,7 +201,9 @@ public Inventory createInventory() { * * @param event the event to handle * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public void handleClickEvent(@NotNull InventoryClickEvent event) { int slot = event.getRawSlot(); Player player = (Player) event.getWhoClicked(); 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 index 72a292f87..8d5d0d72b 100644 --- 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 @@ -5,17 +5,20 @@ 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.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +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 @@ -29,8 +32,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -40,17 +43,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - entityPlayer.activeContainer = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerGrindstone.windowId; IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - entityPlayer.playerConnection.sendPacket(packet); + 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(); - sendItems(player, items, null); + return inventory; } @Override @@ -79,8 +92,10 @@ public void clearCursor(@NotNull Player player) { * @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; } @@ -91,9 +106,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -116,76 +133,128 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { * * @since 0.8.0 */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { + private static class ContainerGrindstoneImpl extends ContainerGrindstone { /** - * The player for this grindstone container + * A unique item */ @NotNull - private final Player player; + private final ItemStack uniqueItem; /** - * The internal bukkit entity for this container grindstone + * The field containing the listeners for this container */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final Field listenersField; /** - * Field for accessing the craft inventory field + * Creates a new grindstone container + * + * @param entityPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field craftInventoryField; + 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); + } /** - * Field for accessing the result inventory field + * Forcefully updates the client state, sending all items, container properties and the held item. + * + * @since 0.10.8 */ - @NotNull - private final Field resultInventoryField; + 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); - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + c(); - this.player = entityPlayer.getBukkitEntity(); + List listeners; try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); + //noinspection unchecked + listeners = (List) listenersField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException("Unable to access field 'listeners'", exception); } - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + for (ICrafting listener : listeners) { + if (!(listener instanceof EntityPlayer)) { + continue; + } - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + EntityPlayer player = (EntityPlayer) listener; + + player.e = false; + player.broadcastCarriedItem(); + } } - @NotNull @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } + 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 bukkitEntity; + return itemStack; } @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { + public boolean canUse(@Nullable EntityHuman entityHuman) { return true; } @@ -193,38 +262,10 @@ public boolean canUse(@Nullable EntityHuman entityhuman) { public void a(IInventory inventory) {} @Override - public void b(EntityHuman entityhuman) {} + public void b(EntityHuman entityHuman) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getWindowId() { + return this.windowId; } } } 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 index 1847edbed..ff9f5cf8a 100644 --- 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 @@ -5,17 +5,20 @@ 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.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +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 @@ -29,8 +32,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -40,17 +43,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - entityPlayer.activeContainer = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerGrindstone.windowId; IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - entityPlayer.playerConnection.sendPacket(packet); + 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(); - sendItems(player, items, null); + return inventory; } @Override @@ -79,8 +92,10 @@ public void clearCursor(@NotNull Player player) { * @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; } @@ -91,9 +106,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -116,76 +133,128 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { * * @since 0.8.0 */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { + private static class ContainerGrindstoneImpl extends ContainerGrindstone { /** - * The player for this grindstone container + * A unique item */ @NotNull - private final Player player; + private final ItemStack uniqueItem; /** - * The internal bukkit entity for this container grindstone + * The field containing the listeners for this container */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final Field listenersField; /** - * Field for accessing the craft inventory field + * Creates a new grindstone container + * + * @param entityPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field craftInventoryField; + 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); + } /** - * Field for accessing the result inventory field + * Forcefully updates the client state, sending all items, container properties and the held item. + * + * @since 0.10.8 */ - @NotNull - private final Field resultInventoryField; + 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); - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + c(); - this.player = entityPlayer.getBukkitEntity(); + List listeners; try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); + //noinspection unchecked + listeners = (List) listenersField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException("Unable to access field 'listeners'", exception); } - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + for (ICrafting listener : listeners) { + if (!(listener instanceof EntityPlayer)) { + continue; + } - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + EntityPlayer player = (EntityPlayer) listener; + + player.e = false; + player.broadcastCarriedItem(); + } } - @NotNull @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } + 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 bukkitEntity; + return itemStack; } @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { + public boolean canUse(@Nullable EntityHuman entityHuman) { return true; } @@ -193,38 +262,10 @@ public boolean canUse(@Nullable EntityHuman entityhuman) { public void a(IInventory inventory) {} @Override - public void b(EntityHuman entityhuman) {} + public void b(EntityHuman entityHuman) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getWindowId() { + return this.windowId; } } } 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 index fdbbb801a..619b8f447 100644 --- 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 @@ -5,17 +5,20 @@ 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.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +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 @@ -29,8 +32,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -40,17 +43,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - entityPlayer.activeContainer = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerGrindstone.windowId; IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - entityPlayer.playerConnection.sendPacket(packet); + 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(); - sendItems(player, items, null); + return inventory; } @Override @@ -116,76 +129,128 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { * * @since 0.8.0 */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { + private static class ContainerGrindstoneImpl extends ContainerGrindstone { /** - * The player for this grindstone container + * A unique item */ @NotNull - private final Player player; + private final ItemStack uniqueItem; /** - * The internal bukkit entity for this container grindstone + * The field containing the listeners for this container */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final Field listenersField; /** - * Field for accessing the craft inventory field + * Creates a new grindstone container + * + * @param entityPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field craftInventoryField; + 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); + } /** - * Field for accessing the result inventory field + * Forcefully updates the client state, sending all items, container properties and the held item. + * + * @since 0.10.8 */ - @NotNull - private final Field resultInventoryField; + 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); - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + notifyListeners(); - this.player = entityPlayer.getBukkitEntity(); + List listeners; try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); + //noinspection unchecked + listeners = (List) listenersField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException("Unable to access field 'listeners'", exception); } - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + for (ICrafting listener : listeners) { + if (!(listener instanceof EntityPlayer)) { + continue; + } - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + EntityPlayer player = (EntityPlayer) listener; + + player.e = false; + player.broadcastCarriedItem(); + } } - @NotNull @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } + 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 bukkitEntity; + return itemStack; } @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { + public boolean canUse(@Nullable EntityHuman entityHuman) { return true; } @@ -193,38 +258,10 @@ public boolean canUse(@Nullable EntityHuman entityhuman) { public void a(IInventory inventory) {} @Override - public void b(EntityHuman entityhuman) {} + public void b(EntityHuman entityHuman) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + 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/GrindstoneInventoryImpl.java b/nms/1_16_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_2_3/GrindstoneInventoryImpl.java index 4ba21f41d..4d0bd3f35 100644 --- 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 @@ -5,14 +5,20 @@ 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.event.inventory.InventoryCloseEvent; +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 @@ -26,8 +32,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -37,17 +43,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - entityPlayer.activeContainer = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerGrindstone.windowId; IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - entityPlayer.playerConnection.sendPacket(packet); + 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(); - sendItems(player, items, null); + return inventory; } @Override @@ -76,6 +92,7 @@ public void clearCursor(@NotNull Player player) { * @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) { @@ -88,9 +105,11 @@ private int getWindowId(@NotNull EntityPlayer entityPlayer) { * @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; } @@ -113,76 +132,128 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { * * @since 0.8.0 */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { + private static class ContainerGrindstoneImpl extends ContainerGrindstone { /** - * The player for this grindstone container + * A unique item */ @NotNull - private final Player player; + private final ItemStack uniqueItem; /** - * The internal bukkit entity for this container grindstone + * The field containing the listeners for this container */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final Field listenersField; /** - * Field for accessing the craft inventory field + * Creates a new grindstone container + * + * @param entityPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field craftInventoryField; + 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); + } /** - * Field for accessing the result inventory field + * Forcefully updates the client state, sending all items, container properties and the held item. + * + * @since 0.10.8 */ - @NotNull - private final Field resultInventoryField; + 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); - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + notifyListeners(); - this.player = entityPlayer.getBukkitEntity(); + List listeners; try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); + //noinspection unchecked + listeners = (List) listenersField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException("Unable to access field 'listeners'", exception); } - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + for (ICrafting listener : listeners) { + if (!(listener instanceof EntityPlayer)) { + continue; + } - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + EntityPlayer player = (EntityPlayer) listener; + + player.e = false; + player.broadcastCarriedItem(); + } } - @NotNull @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } + 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 bukkitEntity; + return itemStack; } @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { + public boolean canUse(@Nullable EntityHuman entityHuman) { return true; } @@ -190,38 +261,10 @@ public boolean canUse(@Nullable EntityHuman entityhuman) { public void a(IInventory inventory) {} @Override - public void b(EntityHuman entityhuman) {} + public void b(EntityHuman entityHuman) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + 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/GrindstoneInventoryImpl.java b/nms/1_16_4-5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_16_4_5/GrindstoneInventoryImpl.java index c10bb72bd..63846dcc4 100644 --- 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 @@ -5,17 +5,20 @@ 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.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; +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.event.inventory.InventoryCloseEvent; +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 @@ -29,8 +32,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -40,17 +43,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } EntityPlayer entityPlayer = getEntityPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer, items); - entityPlayer.activeContainer = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + entityPlayer.activeContainer = entityPlayer.defaultContainer; - int id = containerGrindstone.windowId; IChatBaseComponent message = TextHolderUtil.toComponent(title); - PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(id, Containers.GRINDSTONE, message); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(entityPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); - entityPlayer.playerConnection.sendPacket(packet); + 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(); - sendItems(player, items, null); + return inventory; } @Override @@ -116,76 +129,128 @@ private EntityPlayer getEntityPlayer(@NotNull Player player) { * * @since 0.8.0 */ - private class ContainerGrindstoneImpl extends ContainerGrindstone { + private static class ContainerGrindstoneImpl extends ContainerGrindstone { /** - * The player for this grindstone container + * A unique item */ @NotNull - private final Player player; + private final ItemStack uniqueItem; /** - * The internal bukkit entity for this container grindstone + * The field containing the listeners for this container */ - @Nullable - private CraftInventoryView bukkitEntity; + @NotNull + private final Field listenersField; /** - * Field for accessing the craft inventory field + * Creates a new grindstone container + * + * @param entityPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field craftInventoryField; + 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); + } /** - * Field for accessing the result inventory field + * Forcefully updates the client state, sending all items, container properties and the held item. + * + * @since 0.10.8 */ - @NotNull - private final Field resultInventoryField; + 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); - public ContainerGrindstoneImpl(@NotNull EntityPlayer entityPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { - super(entityPlayer.nextContainerCounter(), entityPlayer.inventory); + notifyListeners(); - this.player = entityPlayer.getBukkitEntity(); + List listeners; try { - this.craftInventoryField = ContainerGrindstone.class.getDeclaredField("craftInventory"); - this.craftInventoryField.setAccessible(true); - - this.resultInventoryField = ContainerGrindstone.class.getDeclaredField("resultInventory"); - this.resultInventoryField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); + //noinspection unchecked + listeners = (List) listenersField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException("Unable to access field 'listeners'", exception); } - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); + for (ICrafting listener : listeners) { + if (!(listener instanceof EntityPlayer)) { + continue; + } - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); + EntityPlayer player = (EntityPlayer) listener; + + player.e = false; + player.broadcastCarriedItem(); + } } - @NotNull @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } + 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 bukkitEntity; + return itemStack; } @Contract(pure = true, value = "_ -> true") @Override - public boolean canUse(@Nullable EntityHuman entityhuman) { + public boolean canUse(@Nullable EntityHuman entityHuman) { return true; } @@ -193,38 +258,10 @@ public boolean canUse(@Nullable EntityHuman entityhuman) { public void a(IInventory inventory) {} @Override - public void b(EntityHuman entityhuman) {} + public void b(EntityHuman entityHuman) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getCraftInventory() { - try { - return (IInventory) craftInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.8.0 - */ - @NotNull - @Contract(pure = true) - private IInventory getResultInventory() { - try { - return (IInventory) resultInventoryField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getWindowId() { + return this.windowId; } } } diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java index 2636ccc6f..431fa4829 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java @@ -14,20 +14,18 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.17 R1 * @@ -40,8 +38,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -51,16 +49,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, null); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -86,8 +95,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.9.9 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -98,9 +109,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.9.9 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -123,73 +136,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.9.9 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -204,36 +188,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.9.9 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.9.9 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java index 1ba46fc2f..920a0be85 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java @@ -14,20 +14,19 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.17 R1 * @@ -40,8 +39,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -51,16 +50,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, player.getItemOnCursor()); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -94,8 +104,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.10.0 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -106,9 +118,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.0 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -131,73 +145,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.10.0 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -212,36 +197,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.10.0 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java index ea056b769..1b39dde59 100644 --- a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java @@ -14,20 +14,19 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.18.0 * @@ -40,8 +39,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -51,16 +50,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, player.getItemOnCursor()); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -94,8 +104,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.10.4 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -106,9 +118,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.4 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -131,73 +145,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.10.4 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -212,36 +197,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.10.4 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.10.4 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java index 8f6331938..76dc73c5a 100644 --- a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java @@ -14,20 +14,19 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.18.1 * @@ -40,8 +39,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -51,16 +50,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, player.getItemOnCursor()); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -94,8 +104,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.10.4 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -106,9 +118,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.4 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -131,73 +145,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.10.4 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -212,36 +197,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.10.4 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.10.4 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java index 5c9c1b9aa..ad966c120 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java @@ -14,20 +14,19 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.18.2 * @@ -40,8 +39,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -51,16 +50,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, player.getItemOnCursor()); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -94,8 +104,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.10.5 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -106,9 +118,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.5 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -131,73 +145,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.10.5 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -212,36 +197,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.10.5 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.10.5 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java index 0ac7771ca..2bc3fea91 100644 --- a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java @@ -14,20 +14,19 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.19 * @@ -40,8 +39,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -51,16 +50,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, player.getItemOnCursor()); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -94,8 +104,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.10.6 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -106,9 +118,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.6 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -131,73 +145,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.10.6 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -212,36 +197,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.10.6 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.10.6 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java index a8dd8e091..169a5a436 100644 --- a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java @@ -14,20 +14,19 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.19.1 * @@ -40,8 +39,8 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -51,16 +50,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, player.getItemOnCursor()); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -94,8 +104,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.10.7 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -106,9 +118,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.7 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -131,73 +145,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.10.7 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -212,36 +197,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.10.7 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.10.7 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java index 2852d2928..3144a10c9 100644 --- a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java @@ -14,20 +14,19 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.GrindstoneMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryGrindstone; -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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; - /** * Internal grindstone inventory for 1.19.2 * @@ -40,7 +39,7 @@ public GrindstoneInventoryImpl(@NotNull InventoryHolder inventoryHolder) { } @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; @@ -51,16 +50,27 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, } ServerPlayer serverPlayer = getServerPlayer(player); - ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, items); - serverPlayer.containerMenu = containerGrindstone; + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; - int id = containerGrindstone.containerId; Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); - serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.GRINDSTONE, message)); + int containerId = containerGrindstone.getContainerId(); - sendItems(player, items, player.getItemOnCursor()); + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; } @Override @@ -94,8 +104,10 @@ public void clearCursor(@NotNull Player player) { * @param nmsPlayer the player to get the containerId id for * @return the containerId id * @since 0.10.7 + * @deprecated no longer used internally */ @Contract(pure = true) + @Deprecated private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { return nmsPlayer.containerMenu.containerId; } @@ -106,9 +118,11 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * @param serverPlayer the player to get the player connection from * @return the player connection * @since 0.10.7 + * @deprecated no longer used internally */ @NotNull @Contract(pure = true) + @Deprecated private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { return serverPlayer.connection; } @@ -131,73 +145,44 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @since 0.10.7 */ - private class ContainerGrindstoneImpl extends GrindstoneMenu { + private static class ContainerGrindstoneImpl extends GrindstoneMenu { /** - * The player for this grindstone container - */ - @NotNull - private final Player player; - - /** - * The internal bukkit entity for this container grindstone - */ - @Nullable - private CraftInventoryView bukkitEntity; - - /** - * Field for accessing the craft inventory field - */ - @NotNull - private final Field repairSlotsField; - - /** - * Field for accessing the result inventory field + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 */ - @NotNull - private final Field resultSlotsField; - - public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); - this.player = serverPlayer.getBukkitEntity(); - - try { - //noinspection JavaReflectionMemberAccess - this.repairSlotsField = GrindstoneMenu.class.getDeclaredField("t"); //repairSlots - this.repairSlotsField.setAccessible(true); - - //noinspection JavaReflectionMemberAccess - this.resultSlotsField = GrindstoneMenu.class.getDeclaredField("s"); //resultSlots - this.resultSlotsField.setAccessible(true); - } catch (NoSuchFieldException exception) { - throw new RuntimeException(exception); - } - - getCraftInventory().setItem(0, CraftItemStack.asNMSCopy(items[0])); - getCraftInventory().setItem(1, CraftItemStack.asNMSCopy(items[1])); - - getResultInventory().setItem(2, CraftItemStack.asNMSCopy(items[2])); - } - - @NotNull - @Override - public CraftInventoryView getBukkitView() { - if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryGrindstone(getCraftInventory(), getResultInventory()) { - @NotNull - @Contract(pure = true) - @Override - public InventoryHolder getHolder() { - return inventoryHolder; - } - }; - - bukkitEntity = new CraftInventoryView(player, inventory, this); - } - - return bukkitEntity; + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); } @Contract(pure = true, value = "_ -> true") @@ -212,36 +197,8 @@ public void slotsChanged(Container container) {} @Override public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} - /** - * Gets the craft inventory - * - * @return the craft inventory - * @since 0.10.7 - */ - @NotNull - @Contract(pure = true) - private Container getCraftInventory() { - try { - return (Container) repairSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } - } - - /** - * Gets the result inventory - * - * @return the result inventory - * @since 0.10.7 - */ - @NotNull - @Contract(pure = true) - private Container getResultInventory() { - try { - return (Container) resultSlotsField.get(this); - } catch (IllegalAccessException exception) { - throw new RuntimeException(exception); - } + public int getContainerId() { + return this.containerId; } } } diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java index 98c5bcfc5..e9b3571b3 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/GrindstoneInventory.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -39,11 +40,11 @@ public GrindstoneInventory(@NotNull InventoryHolder inventoryHolder) { * @param items the top items * @since 0.8.0 */ - public final void openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { - openInventory(player, StringHolder.of(title), items); + public final Inventory openInventory(@NotNull Player player, @NotNull String title, @Nullable ItemStack[] items) { + return openInventory(player, StringHolder.of(title), items); } - public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); + public abstract Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. @@ -52,7 +53,9 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * @param items the items to send * @param cursor the cursor item, this may be null on versions prior to 1.17.1 * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void sendItems(@NotNull Player player, @Nullable ItemStack[] items, @Nullable ItemStack cursor); /** @@ -60,6 +63,8 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ * * @param player the player to clear the cursor of * @since 0.8.0 + * @deprecated no longer used internally */ + @Deprecated public abstract void clearCursor(@NotNull Player player); } From 6a22ce6c6bd80a0ca1c7decae7b70d8ac06f3b66 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 19 Dec 2022 19:33:02 +0100 Subject: [PATCH 179/382] Add 1.19.3 support --- IF/pom.xml | 6 + .../util/version/Version.java | 11 +- .../util/version/VersionMatcher.java | 16 + nms/1_19_3/pom.xml | 58 ++++ .../nms/v1_19_3/AnvilInventoryImpl.java | 276 ++++++++++++++++++ .../nms/v1_19_3/BeaconInventoryImpl.java | 199 +++++++++++++ .../CartographyTableInventoryImpl.java | 213 ++++++++++++++ .../v1_19_3/EnchantingTableInventoryImpl.java | 213 ++++++++++++++ .../nms/v1_19_3/GrindstoneInventoryImpl.java | 204 +++++++++++++ .../nms/v1_19_3/MerchantInventoryImpl.java | 97 ++++++ .../v1_19_3/SmithingTableInventoryImpl.java | 251 ++++++++++++++++ .../nms/v1_19_3/StonecutterInventoryImpl.java | 219 ++++++++++++++ .../nms/v1_19_3/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_19_3/util/TextHolderUtil.java | 65 +++++ pom.xml | 1 + 15 files changed, 1869 insertions(+), 1 deletion(-) create mode 100644 nms/1_19_3/pom.xml create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/BeaconInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/CartographyTableInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/EnchantingTableInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/MerchantInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/StonecutterInventoryImpl.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/CustomInventoryUtil.java create mode 100644 nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index 4e03bb118..aa8f4b1bd 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -118,6 +118,12 @@ ${project.version} compile
+ + com.github.stefvanschie.inventoryframework + 1_19_3 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 7a3c9918a..4f77f9592 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -101,7 +101,14 @@ public enum Version { * * @since 0.10.7 */ - V1_19_2; + V1_19_2, + + /** + * Version 1.19.3 + * + * @since 0.10.8 + */ + V1_19_3; /** * Gets the version currently being used. If the used version is not supported, an @@ -150,6 +157,8 @@ public static Version getVersion() { return V1_19_1; case "1.19.2": return V1_19_2; + case "1.19.3": + return V1_19_3; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 7d78c3481..1a6e646af 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 @@ -258,6 +258,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -286,6 +288,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -314,6 +318,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -342,6 +348,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -370,6 +378,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -398,6 +408,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -422,6 +434,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.SmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -450,5 +464,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_1.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_19_3, + com.github.stefvanschie.inventoryframework.nms.v1_19_3.StonecutterInventoryImpl.class); } } diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml new file mode 100644 index 000000000..93131d6fe --- /dev/null +++ b/nms/1_19_3/pom.xml @@ -0,0 +1,58 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.7 + ../../pom.xml + + 4.0.0 + + 1_19_3 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.19.3-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.3 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java new file mode 100644 index 000000000..324f1f4fe --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java @@ -0,0 +1,276 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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 anvil inventory for 1.19.3 + * + * @since 0.10.8 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.8 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.8 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.8 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.8 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.8 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.8 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public void setItemName(@Nullable String name) { + AnvilInventoryImpl.super.text = name == null ? "" : name; + + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/BeaconInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/BeaconInventoryImpl.java new file mode 100644 index 000000000..52488aab0 --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R2.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.19.3 + * + * @since 0.10.8 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.8 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.8 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/CartographyTableInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..d0edc3de7 --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R2.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.19.3 + * + * @since 0.10.8 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.8 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.8 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/EnchantingTableInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..667957135 --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R2.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.19.3 + * + * @since 0.10.8 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.8 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.8 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..b8a00356e --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java @@ -0,0 +1,204 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryCloseEvent; +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 grindstone inventory for 1.19.3 + * + * @since 0.10.8 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.8 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.8 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.8 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.8 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/MerchantInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/MerchantInventoryImpl.java new file mode 100644 index 000000000..7dcb9dda0 --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_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.19.3 + * + * @since 0.10.8 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.8 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..afc55c6ac --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java @@ -0,0 +1,251 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R2.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; + +/** + * Internal smithing table inventory for 1.19.3 + * + * @since 0.10.8 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@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 smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.8 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.8 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.8 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.8 + */ + private class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/StonecutterInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/StonecutterInventoryImpl.java new file mode 100644 index 000000000..9a124704e --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_R2.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.19.3 + * + * @since 0.10.8 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.8 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.8 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/CustomInventoryUtil.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/CustomInventoryUtil.java new file mode 100644 index 000000000..7cd7b7f91 --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_3.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.8 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/TextHolderUtil.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/TextHolderUtil.java new file mode 100644 index 000000000..6508159e0 --- /dev/null +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_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.network.chat.Component; +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.8 + */ +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.8 + */ + @NotNull + @Contract(pure = true) + public static Component 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.8 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.8 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index f101f3ed6..3beec1859 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_19_3 nms/1_19_2 nms/1_19_1 nms/1_19_0 From 0cdbca0b3b316dca83327ddc4f2226f8fa63071e Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 19 Dec 2022 19:43:32 +0100 Subject: [PATCH 180/382] Add 1.19.3 initialization to workflow --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ae3b06aa6..56cf819bc 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -75,5 +75,6 @@ jobs: 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 - name: Build with Maven run: mvn -B package --file pom.xml From 563cc2e37c12b4fec8363a3d3d4d5e5d86cd9750 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 19 Dec 2022 21:00:26 +0100 Subject: [PATCH 181/382] V 0.10.8 --- IF/pom.xml | 2 +- README.md | 5 +++-- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/abstraction/pom.xml | 2 +- pom.xml | 2 +- 19 files changed, 21 insertions(+), 20 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 18a9c88c3..a329c7f09 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 4.0.0 diff --git a/README.md b/README.md index bcaa98e81..fabf0ed47 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.7 + 0.10.8 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.7' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.8' // ... } ``` @@ -134,6 +134,7 @@ 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 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 19ff541db..9d3dc1443 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index ed2acc715..2d8c2831e 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 4ee5a055e..345cb2cb8 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index ca352c750..450dad765 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index e7de2bc17..08c99ca4f 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 6638da999..52be9deb3 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 4bba371eb..a7c1a4bb1 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 6a87348cb..c532210bb 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index c8c2f2ad3..0182cbc73 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 9930bc17e..5011a08ae 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 710f8514d..7312d2673 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 5722604bd..94c247800 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 70cf454b1..dd4555cdb 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index d4824f482..372df458f 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 93131d6fe..8af5c2daa 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 457b0e556..f1044479a 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.7 + 0.10.8 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index e9d781ccc..ce84aca89 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.7 + 0.10.8 pom IF From 80b2de7c14deb9b3fae754d09286ff78cbda7c46 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 7 Jan 2023 19:13:35 +0100 Subject: [PATCH 182/382] Update paper-nms maven plugin (#275) --- 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 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index a7c1a4bb1..c90e82b17 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.3.1 + 1.3.2 process-classes diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index c532210bb..84e840dce 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.3.1 + 1.3.2 process-classes diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 0182cbc73..71be50d86 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.3.1 + 1.3.2 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 5011a08ae..6f23b2a14 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.3.1 + 1.3.2 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 7312d2673..3a6556ce2 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.3.1 + 1.3.2 process-classes diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 94c247800..e5fa0e476 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.3.1 + 1.3.2 process-classes diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index dd4555cdb..dda107336 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.3.1 + 1.3.2 process-classes diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 372df458f..26a00f829 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.3.1 + 1.3.2 process-classes From 090e22e3eb7288958a2487013a914ea5c500b882 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Oct 2022 05:18:27 +0000 Subject: [PATCH 183/382] Bump maven-shade-plugin from 3.4.0 to 3.4.1 in /IF Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.0...maven-shade-plugin-3.4.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index a329c7f09..c20a6ce8a 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -217,7 +217,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.4.0 + 3.4.1 package From 5fd25569f355ca3e2e7a709a983010b38112cbbb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Nov 2022 05:04:54 +0000 Subject: [PATCH 184/382] Bump adventure-api from 4.11.0 to 4.12.0 Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.11.0 to 4.12.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.11.0...v4.12.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ce84aca89..debda8272 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 1.8 true UTF-8 - 4.11.0 + 4.12.0
com.github.stefvanschie.inventoryframework From 595d89463397bfbe5e5f01abe33111051c17621b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 5 Feb 2023 19:54:12 +0100 Subject: [PATCH 185/382] Set up auto deployment --- .github/deployment/deploy.sh | 27 +++++++++++ .github/deployment/settings.xml | 9 ++++ .github/workflows/auto-deploy.yml | 79 +++++++++++++++++++++++++++++++ IF/pom.xml | 3 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/abstraction/pom.xml | 2 +- pom.xml | 2 +- 21 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 .github/deployment/deploy.sh create mode 100644 .github/deployment/settings.xml create mode 100644 .github/workflows/auto-deploy.yml diff --git a/.github/deployment/deploy.sh b/.github/deployment/deploy.sh new file mode 100644 index 000000000..b59735a9a --- /dev/null +++ b/.github/deployment/deploy.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +PARENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -pl :IF-parent -q -DforceStdout) +BASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -pl :IF -q -DforceStdout) + +if [[ $PARENT_VERSION != "$BASE_VERSION" ]]; then + echo "IF-parent and IF versions mismatch" + exit 1 +fi + +if [[ $PARENT_VERSION != *-SNAPSHOT ]]; then + exit 0 +fi + +if ! mvn clean install -B; then + echo "Unable to build IF" + exit 1 +fi + +if ! mvn deploy -N -pl :IF-parent -P deploy -s ./.github/deployment/settings.xml -B -Dgpg.passphrase="$1" -Ddeploy.password="$2"; 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.password="$2"; then + echo "Unable to deploy IF" +fi diff --git a/.github/deployment/settings.xml b/.github/deployment/settings.xml new file mode 100644 index 000000000..b6734a58c --- /dev/null +++ b/.github/deployment/settings.xml @@ -0,0 +1,9 @@ + + + + ossrh + stefvanschie + ${deploy.password} + + + \ No newline at end of file diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml new file mode 100644 index 000000000..68d0e4f26 --- /dev/null +++ b/.github/workflows/auto-deploy.yml @@ -0,0 +1,79 @@ +name: Automatically deploy the project + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: ubuntu-latest + name: 'Deploy' + 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 + - uses: actions/checkout@v2 + name: Checkout code + - 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 + - name: Setup GPG keys + run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import + - name: Automatically deploy the project + env: + gpg_secret: ${{ secrets.GPG_PASSPHRASE }} + deploy_password: ${{ secrets.DEPLOY_PASSWORD }} + run: bash ./.github/deployment/deploy.sh '$gpg_passphrase' '$deploy_password' diff --git a/IF/pom.xml b/IF/pom.xml index c20a6ce8a..df1fc14bf 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,8 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT + ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 9d3dc1443..8276f3efe 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 2d8c2831e..023aa5a1f 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 345cb2cb8..3bfb130fa 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 450dad765..c59ae81d5 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 08c99ca4f..d0e8592eb 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 52be9deb3..b2f12cf3e 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index c90e82b17..9af8b279c 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 84e840dce..89edc560a 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 71be50d86..514aa0ba0 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 6f23b2a14..2c3a8dc8c 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 3a6556ce2..cdafaf063 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index e5fa0e476..c9f2a41d6 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index dda107336..5e4d048bc 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 26a00f829..5e292ca0e 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 8af5c2daa..ea03564c3 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index f1044479a..6cc79805b 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.8 + 0.10.9-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index debda8272..2379eeb1f 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.8 + 0.10.9-SNAPSHOT pom IF From 97848804551b5f6908c42af0ee9ac15f00aa0286 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 5 Feb 2023 20:42:52 +0100 Subject: [PATCH 186/382] Fix typo --- .github/workflows/auto-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 68d0e4f26..c1696e53b 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -74,6 +74,6 @@ jobs: run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import - name: Automatically deploy the project env: - gpg_secret: ${{ secrets.GPG_PASSPHRASE }} + gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} deploy_password: ${{ secrets.DEPLOY_PASSWORD }} run: bash ./.github/deployment/deploy.sh '$gpg_passphrase' '$deploy_password' From ee3ae467e68341b9352749b9063f37a9bd0731ce Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 5 Feb 2023 21:04:04 +0100 Subject: [PATCH 187/382] Use double quotes for command --- .github/workflows/auto-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index c1696e53b..8a46cc9c9 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -76,4 +76,4 @@ jobs: env: gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} deploy_password: ${{ secrets.DEPLOY_PASSWORD }} - run: bash ./.github/deployment/deploy.sh '$gpg_passphrase' '$deploy_password' + run: bash ./.github/deployment/deploy.sh "$gpg_passphrase" "$deploy_password" From f6d771d3bbe626277cd36b1a78fb9588dd86bfcc Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 13 Mar 2023 20:07:40 +0100 Subject: [PATCH 188/382] Fix StaticPane#addItem not overwriting already set items in the same position --- .../inventoryframework/pane/util/Slot.java | 43 +++++++++++++++++++ .../pane/util/SlotTest.java | 23 ++++++++++ 2 files changed, 66 insertions(+) create mode 100644 IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/SlotTest.java 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 7fc7bc144..d1306fe42 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 @@ -3,8 +3,11 @@ import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.w3c.dom.Element; +import java.util.Objects; + /** * A slot represents a position in some type of container. Implementors of this class represent slots in different ways. * @@ -141,6 +144,26 @@ public int getX(int length) { public int getY(int length) { return this.y; } + + @Override + public boolean equals(@Nullable Object object) { + if (this == object) { + return true; + } + + if (object == null || getClass() != object.getClass()) { + return false; + } + + XY xy = (XY) object; + + return x == xy.x && y == xy.y; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } } /** @@ -202,5 +225,25 @@ public int getY(int length) { return this.index / length; } + + @Override + public boolean equals(@Nullable Object object) { + if (this == object) { + return true; + } + + if (object == null || getClass() != object.getClass()) { + return false; + } + + Indexed indexed = (Indexed) object; + + return index == indexed.index; + } + + @Override + public int hashCode() { + return index; + } } } diff --git a/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/SlotTest.java b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/SlotTest.java new file mode 100644 index 000000000..2ad037ef8 --- /dev/null +++ b/IF/src/test/java/com/github/stefvanschie/inventoryframework/pane/util/SlotTest.java @@ -0,0 +1,23 @@ +package com.github.stefvanschie.inventoryframework.pane.util; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class SlotTest { + + @Test + void testEquals() { + assertEquals(Slot.fromXY(0, 0), Slot.fromXY(0, 0)); + assertNotEquals(Slot.fromXY(0, 1), Slot.fromXY(1, 0)); + + assertEquals(Slot.fromIndex(0), Slot.fromIndex(0)); + assertNotEquals(Slot.fromIndex(0), Slot.fromIndex(1)); + } + + @Test + void testHashCode() { + assertEquals(Slot.fromXY(0, 0).hashCode(), Slot.fromXY(0, 0).hashCode()); + assertEquals(Slot.fromIndex(0).hashCode(), Slot.fromIndex(0).hashCode()); + } +} From e3c600eea88f281e3722137fc3d5608572bf6ba5 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 17 Mar 2023 21:35:35 +0100 Subject: [PATCH 189/382] Fix anvil and grindstone gui not working on Spigot --- .../inventoryframework/nms/v1_14/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_14/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_15/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_15/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_16_1/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_16_1/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_16_2_3/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_16_2_3/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_16_4_5/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_16_4_5/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_17_0/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_17_1/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_18_0/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_18_1/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_18_2/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_19_0/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_19_1/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_19_2/GrindstoneInventoryImpl.java | 5 +++-- .../inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java | 5 +++-- .../nms/v1_19_3/GrindstoneInventoryImpl.java | 5 +++-- 28 files changed, 84 insertions(+), 56 deletions(-) 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 index 890bc454f..a8e19a890 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index 8d5d0d72b..f382990ab 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index 7bb3be41d..4cd004986 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index ff9f5cf8a..e34d4fbdd 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index bd0ba56b4..30ac098da 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index 619b8f447..c349af46c 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index bfe46ad3e..b3705dec9 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index 4d0bd3f35..0950c0553 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index 110eee0b1..f103c04ad 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; 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 index 63846dcc4..0ce518a25 100644 --- 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 @@ -8,7 +8,6 @@ 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.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -44,7 +43,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title EntityPlayer entityPlayer = getEntityPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(entityPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(entityPlayer); entityPlayer.activeContainer = entityPlayer.defaultContainer; diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java index fa6c79275..10282bef6 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java @@ -24,7 +24,6 @@ import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -57,7 +56,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java index 431fa4829..cc6f1af40 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/GrindstoneInventoryImpl.java @@ -19,7 +19,6 @@ import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -50,7 +49,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java index fddec0f9e..42086f682 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java index 920a0be85..0bc3de75d 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java index 1eb5270ac..90b7f3378 100644 --- a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java index 1b39dde59..771ccf841 100644 --- a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java index 2b0e9d772..6cd837f36 100644 --- a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java index 76dc73c5a..f8b13b2f9 100644 --- a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_18_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java index e70641a96..6b30a4940 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java index ad966c120..1dbb1be6a 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java index 702b6c1c9..73f4bf64d 100644 --- a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java index 2bc3fea91..6795a9358 100644 --- a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java index d5d0f07e0..e5b5d17c3 100644 --- a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java index 169a5a436..b89208af6 100644 --- a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java index 2a0f4cb7d..87a523cce 100644 --- a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java index 3144a10c9..bcf8715e4 100644 --- a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java index 324f1f4fe..a736dd7bf 100644 --- a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java @@ -22,7 +22,6 @@ import org.bukkit.craftbukkit.v1_19_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -53,7 +52,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java index b8a00356e..f1a75f995 100644 --- a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/GrindstoneInventoryImpl.java @@ -20,7 +20,6 @@ import org.bukkit.craftbukkit.v1_19_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -51,7 +50,9 @@ public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title ServerPlayer serverPlayer = getServerPlayer(player); - CraftEventFactory.handleInventoryCloseEvent(serverPlayer, InventoryCloseEvent.Reason.OPEN_NEW); + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); serverPlayer.containerMenu = serverPlayer.inventoryMenu; From 2c4c6145a639ba3e152fae16c3a6f2985aa4a886 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 27 Mar 2023 19:58:35 +0200 Subject: [PATCH 190/382] Add 1.19.4 support --- .github/dependabot.yml | 32 ++ .github/workflows/auto-deploy.yml | 1 + .github/workflows/maven.yml | 1 + IF/pom.xml | 8 +- .../inventoryframework/gui/GuiListener.java | 2 + .../gui/type/ModernSmithingTableGui.java | 404 ++++++++++++++++++ .../gui/type/SmithingTableGui.java | 4 +- .../inventoryframework/util/CSVUtil.java | 5 +- .../util/version/Version.java | 11 +- .../util/version/VersionMatcher.java | 85 +++- README.md | 1 + .../v1_16_1/SmithingTableInventoryImpl.java | 8 +- .../v1_16_2_3/SmithingTableInventoryImpl.java | 8 +- .../v1_16_4_5/SmithingTableInventoryImpl.java | 8 +- .../v1_17_0/SmithingTableInventoryImpl.java | 8 +- .../v1_17_1/SmithingTableInventoryImpl.java | 8 +- .../v1_18_0/SmithingTableInventoryImpl.java | 8 +- .../v1_18_1/SmithingTableInventoryImpl.java | 8 +- .../v1_18_2/SmithingTableInventoryImpl.java | 8 +- .../v1_19_0/SmithingTableInventoryImpl.java | 8 +- .../v1_19_1/SmithingTableInventoryImpl.java | 8 +- .../v1_19_2/SmithingTableInventoryImpl.java | 8 +- .../v1_19_3/SmithingTableInventoryImpl.java | 8 +- nms/1_19_4/pom.xml | 58 +++ .../nms/v1_19_4/AnvilInventoryImpl.java | 277 ++++++++++++ .../nms/v1_19_4/BeaconInventoryImpl.java | 199 +++++++++ .../CartographyTableInventoryImpl.java | 213 +++++++++ .../v1_19_4/EnchantingTableInventoryImpl.java | 213 +++++++++ .../nms/v1_19_4/GrindstoneInventoryImpl.java | 205 +++++++++ .../LegacySmithingTableInventoryImpl.java | 257 +++++++++++ .../nms/v1_19_4/MerchantInventoryImpl.java | 97 +++++ .../v1_19_4/SmithingTableInventoryImpl.java | 335 +++++++++++++++ .../nms/v1_19_4/StonecutterInventoryImpl.java | 219 ++++++++++ .../nms/v1_19_4/util/CustomInventoryUtil.java | 41 ++ .../nms/v1_19_4/util/TextHolderUtil.java | 65 +++ .../abstraction/SmithingTableInventory.java | 14 +- pom.xml | 1 + 37 files changed, 2797 insertions(+), 47 deletions(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java create mode 100644 nms/1_19_4/pom.xml create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/AnvilInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/BeaconInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/CartographyTableInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/EnchantingTableInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/GrindstoneInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/LegacySmithingTableInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/MerchantInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/SmithingTableInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/StonecutterInventoryImpl.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/CustomInventoryUtil.java create mode 100644 nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/TextHolderUtil.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d2f8803b0..509114481 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -40,6 +40,38 @@ updates: directory: "/nms/1_17_1" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_18_0" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_18_1" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_18_2" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_19_0" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_19_1" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_19_2" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_19_3" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_19_4" + schedule: + interval: "daily" - package-ecosystem: "maven" directory: "/nms/abstraction" schedule: diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 8a46cc9c9..151011321 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -70,6 +70,7 @@ jobs: 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 - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import - name: Automatically deploy the project diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 56cf819bc..9f9ab98dc 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -76,5 +76,6 @@ jobs: 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 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index df1fc14bf..dccfe881e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -125,10 +125,16 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_19_4 + ${project.version} + compile + org.spigotmc spigot-api - 1.17.1-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT provided diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index 92b0c94bc..cfaaf9a53 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -372,6 +372,8 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { ((AnvilGui) gui).handleClose(humanEntity); } else if (gui instanceof MerchantGui) { ((MerchantGui) gui).handleClose(humanEntity); + } else if (gui instanceof ModernSmithingTableGui) { + ((ModernSmithingTableGui) gui).handleClose(humanEntity); } }); } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java new file mode 100644 index 000000000..7ad929fcf --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java @@ -0,0 +1,404 @@ +package com.github.stefvanschie.inventoryframework.gui.type; + +import com.github.stefvanschie.inventoryframework.HumanEntityCache; +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; +import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; +import com.github.stefvanschie.inventoryframework.util.version.Version; +import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +/** + * Represents a gui in the form of a smithing table. This is the modern variant with three input slots, available in + * from Minecraft 1.19.4. + * + * @since 0.10.9 + */ +public class ModernSmithingTableGui extends NamedGui implements InventoryBased { + + /** + * Represents the inventory component for the input + */ + @NotNull + private InventoryComponent inputComponent = new InventoryComponent(3, 1); + + /** + * Represents the inventory component for the result + */ + @NotNull + private InventoryComponent resultComponent = new InventoryComponent(1, 1); + + /** + * Represents the inventory component for the player inventory + */ + @NotNull + private InventoryComponent playerInventoryComponent = new InventoryComponent(9, 4); + + /** + * An internal smithing inventory + */ + @NotNull + private final SmithingTableInventory smithingTableInventory = VersionMatcher.newModernSmithingTableInventory( + Version.getVersion(), this + ); + + /** + * The viewers of this gui + */ + @NotNull + private final Collection viewers = new HashSet<>(); + + /** + * Constructs a new GUI. + * + * @param title the title/name of this gui. + * @since 0.10.9 + */ + public ModernSmithingTableGui(@NotNull String title) { + super(title); + } + + /** + * Constructs a new GUI. + * + * @param title the title/name of this gui. + * @since 0.10.9 + */ + public ModernSmithingTableGui(@NotNull TextHolder title) { + super(title); + } + + /** + * Constructs a new smithing table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #ModernSmithingTableGui(String) + * @since 0.10.9 + */ + public ModernSmithingTableGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new smithing table gui for the given {@code plugin}. + * + * @param title the title/name of this gui. + * @param plugin the owning plugin of this gui + * @see #ModernSmithingTableGui(TextHolder) + * @since 0.10.9 + */ + public ModernSmithingTableGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + + @Override + public void show(@NotNull HumanEntity humanEntity) { + if (!(humanEntity instanceof Player)) { + throw new IllegalArgumentException("Smithing tables can only be opened by players"); + } + + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + + getInventory().clear(); + + getInputComponent().display(getInventory(), 0); + getResultComponent().display(getInventory(), 3); + getPlayerInventoryComponent().display(); + + if (getPlayerInventoryComponent().hasItem()) { + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } + + getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); + } + + Inventory inventory = smithingTableInventory.openInventory((Player) humanEntity, getTitleHolder(), + getTopItems()); + + addInventory(inventory, this); + + this.viewers.add(humanEntity); + } + + @NotNull + @Contract(pure = true) + @Override + public ModernSmithingTableGui copy() { + ModernSmithingTableGui gui = new ModernSmithingTableGui(getTitleHolder(), super.plugin); + + gui.inputComponent = inputComponent.copy(); + gui.resultComponent = resultComponent.copy(); + gui.playerInventoryComponent = playerInventoryComponent.copy(); + + gui.setOnTopClick(this.onTopClick); + gui.setOnBottomClick(this.onBottomClick); + gui.setOnGlobalClick(this.onGlobalClick); + gui.setOnOutsideClick(this.onOutsideClick); + gui.setOnClose(this.onClose); + + return gui; + } + + @Override + public void click(@NotNull InventoryClickEvent event) { + int rawSlot = event.getRawSlot(); + + if (rawSlot >= 0 && rawSlot <= 2) { + getInputComponent().click(this, event, rawSlot); + } else if (rawSlot == 3) { + getResultComponent().click(this, event, 0); + } else { + getPlayerInventoryComponent().click(this, event, rawSlot - 4); + } + } + + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + + @Contract(pure = true) + @Override + public boolean isPlayerInventoryUsed() { + return getPlayerInventoryComponent().hasItem(); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory createInventory() { + return getTitleHolder().asInventoryTitle(this, InventoryType.SMITHING_NEW); + } + + /** + * Handles a human entity closing this gui. + * + * @param humanEntity the human entity closing the gui + * @since 0.10.9 + */ + public void handleClose(@NotNull HumanEntity humanEntity) { + this.viewers.remove(humanEntity); + } + + @Contract(pure = true) + @Override + public int getViewerCount() { + return this.viewers.size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(this.viewers); + } + + /** + * Gets the inventory component representing the input items + * + * @return the input component + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + public InventoryComponent getInputComponent() { + return inputComponent; + } + + /** + * Gets the inventory component representing the result + * + * @return the result component + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + public InventoryComponent getResultComponent() { + return resultComponent; + } + + /** + * Gets the inventory component representing the player inventory + * + * @return the player inventory component + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + public InventoryComponent getPlayerInventoryComponent() { + return playerInventoryComponent; + } + + /** + * Gets the top items + * + * @return the top items + * @since 0.10.9 + */ + @Nullable + @Contract(pure = true) + private ItemStack[] getTopItems() { + return new ItemStack[] { + getInputComponent().getItem(0, 0), + getInputComponent().getItem(1, 0), + getInputComponent().getItem(2, 0), + getResultComponent().getItem(0, 0) + }; + } + + /** + * Loads a smithing table gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui + * @return the loaded smithing table gui + * @see #load(Object, InputStream) + * @since 0.10.9 + */ + @Nullable + @Contract(pure = true) + public static ModernSmithingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { + try { + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); + Element documentElement = document.getDocumentElement(); + + documentElement.normalize(); + + return load(instance, documentElement, plugin); + } catch (SAXException | ParserConfigurationException | IOException e) { + e.printStackTrace(); + return null; + } + } + + /** + * Loads a smithing table gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui + * @return the loaded smithing table gui + * @since 0.10.9 + */ + @NotNull + public static ModernSmithingTableGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { + if (!element.hasAttribute("title")) { + throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); + } + + ModernSmithingTableGui smithingTableGui = new ModernSmithingTableGui(element.getAttribute("title"), plugin); + smithingTableGui.initializeOrThrow(instance, element); + + if (element.hasAttribute("populate")) { + return smithingTableGui; + } + + NodeList childNodes = element.getChildNodes(); + + for (int index = 0; index < childNodes.getLength(); index++) { + Node item = childNodes.item(index); + + if (item.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + Element componentElement = (Element) item; + + if (!componentElement.getTagName().equalsIgnoreCase("component")) { + throw new XMLLoadException("Gui element contains non-component tags"); + } + + if (!componentElement.hasAttribute("name")) { + throw new XMLLoadException("Component tag does not have a name specified"); + } + + InventoryComponent component; + + switch (componentElement.getAttribute("name")) { + case "input": + component = smithingTableGui.getInputComponent(); + break; + case "result": + component = smithingTableGui.getResultComponent(); + break; + case "player-inventory": + component = smithingTableGui.getPlayerInventoryComponent(); + break; + default: + throw new XMLLoadException("Unknown component name"); + } + + component.load(instance, componentElement); + } + + return smithingTableGui; + } + + /** + * Loads a smithing table gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded smithing table gui + * @since 0.10.9 + */ + @Nullable + @Contract(pure = true) + public static ModernSmithingTableGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(ModernSmithingTableGui.class)); + } + + /** + * Loads a smithing table gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded smithing table gui + * @since 0.10.9 + */ + @NotNull + public static ModernSmithingTableGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(ModernSmithingTableGui.class)); + } +} diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 0c39e80c9..9821788f3 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -34,10 +34,12 @@ import java.util.List; /** - * Represents a gui in the form of a smithing table + * Represents a gui in the form of a smithing table. This is the ;egacy variant with two input slots, available prior to + * Minecraft 1.20. * * @since 0.8.0 */ +@Deprecated public class SmithingTableGui extends NamedGui implements InventoryBased { /** diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/CSVUtil.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/CSVUtil.java index 1f2b75797..89d05da5f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/CSVUtil.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/CSVUtil.java @@ -1,6 +1,5 @@ package com.github.stefvanschie.inventoryframework.util; -import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import java.io.BufferedReader; @@ -72,9 +71,7 @@ public static List readAll(@NotNull InputStream inputStream) throws IO array[i] = array[i].substring(1, array[i].length() - 1); } - array[i] = StringUtils.replace(array[i], "\"\"", "\""); - //Restore original code (array[i] = array[i].replace("\"\"", "\"")) - //once we update to Java 11, where it receives the current, faster implementation + array[i] = array[i].replace("\"\"", "\""); //replace unicode characters Matcher matcher = UNICODE_CHARACTER_PATTERN.matcher(array[i]); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 4f77f9592..50d857322 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -108,7 +108,14 @@ public enum Version { * * @since 0.10.8 */ - V1_19_3; + V1_19_3, + + /** + * Version 1.19.4 + * + * @since 0.10.9 + */ + V1_19_4; /** * Gets the version currently being used. If the used version is not supported, an @@ -159,6 +166,8 @@ public static Version getVersion() { return V1_19_2; case "1.19.3": return V1_19_3; + case "1.19.4": + return V1_19_4; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 1a6e646af..114a8b93a 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 @@ -2,6 +2,7 @@ import com.github.stefvanschie.inventoryframework.abstraction.*; import com.github.stefvanschie.inventoryframework.exception.UnsupportedVersionException; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.LegacySmithingTableInventoryImpl; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -51,6 +52,11 @@ public class VersionMatcher { */ private static final EnumMap> SMITHING_TABLE_INVENTORIES; + /** + * The different legacy smithing table inventories for different versions + */ + private static final EnumMap> LEGACY_SMITHING_TABLE_INVENTORIES; + /** * The different stonecutter inventories for different versions */ @@ -187,23 +193,52 @@ public static MerchantInventory newMerchantInventory(@NotNull Version version) { * @param version the version to get the inventory of * @param inventoryHolder the inventory holder * @return the smithing table inventory + * @since 0.10.9 + * @throws UnsupportedVersionException when a smithing table is requested on a version without smithing tables + */ + @NotNull + @Contract(pure = true) + public static SmithingTableInventory newModernSmithingTableInventory(@NotNull Version version, + @NotNull InventoryHolder inventoryHolder) { + if (version != Version.V1_19_4) { + throw new UnsupportedVersionException("Modern smithing tables didn't exist in version " + version); + } + + try { + Class clazz = SMITHING_TABLE_INVENTORIES.get(version); + + return clazz.getConstructor(InventoryHolder.class).newInstance(inventoryHolder); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException exception) { + throw new IllegalStateException(exception); + } + } + + /** + * Gets a new legacy smithing table inventory for the specified version of the specified inventory holder. If a + * smithing table is requested for a version that does not have smithing tables, an + * {@link UnsupportedVersionException} is thrown. + * + * @param version the version to get the inventory of + * @param inventoryHolder the inventory holder + * @return the smithing table inventory * @since 0.8.0 * @throws UnsupportedVersionException when a smithing table is requested on a version without smithing tables */ @NotNull @Contract(pure = true) public static SmithingTableInventory newSmithingTableInventory(@NotNull Version version, - @NotNull InventoryHolder inventoryHolder) { + @NotNull InventoryHolder inventoryHolder) { if (version == Version.V1_14 || version == Version.V1_15) { throw new UnsupportedVersionException("Smithing tables didn't exist in version " + version); } try { - Class clazz = SMITHING_TABLE_INVENTORIES.get(version); + Class clazz = LEGACY_SMITHING_TABLE_INVENTORIES.get(version); return clazz.getConstructor(InventoryHolder.class).newInstance(inventoryHolder); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | - NoSuchMethodException exception) { + NoSuchMethodException exception) { throw new IllegalStateException(exception); } } @@ -260,6 +295,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_2.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -290,6 +327,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_2.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -320,6 +359,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_2.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -350,6 +391,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_2.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -380,6 +423,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_2.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -410,32 +455,40 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_2.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, + SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.SmithingTableInventoryImpl.class); + + LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, com.github.stefvanschie.inventoryframework.nms.v1_16_1.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_16_2_3, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_2_3, com.github.stefvanschie.inventoryframework.nms.v1_16_2_3.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_16_4_5, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_4_5, com.github.stefvanschie.inventoryframework.nms.v1_16_4_5.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_17_0, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_17_0, com.github.stefvanschie.inventoryframework.nms.v1_17_0.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_17_1, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_17_1, com.github.stefvanschie.inventoryframework.nms.v1_17_1.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_18_0, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_18_0, com.github.stefvanschie.inventoryframework.nms.v1_18_0.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_18_1, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_18_1, com.github.stefvanschie.inventoryframework.nms.v1_18_1.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_18_2, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_18_2, com.github.stefvanschie.inventoryframework.nms.v1_18_2.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_19_0, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_19_0, com.github.stefvanschie.inventoryframework.nms.v1_19_0.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_19_1, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_19_1, com.github.stefvanschie.inventoryframework.nms.v1_19_1.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_19_2, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_19_2, com.github.stefvanschie.inventoryframework.nms.v1_19_2.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_19_3, + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.SmithingTableInventoryImpl.class); + LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, + LegacySmithingTableInventoryImpl.class); STONECUTTER_INVENTORIES = new EnumMap<>(Version.class); STONECUTTER_INVENTORIES.put(Version.V1_14, @@ -466,5 +519,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_2.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_19_3, com.github.stefvanschie.inventoryframework.nms.v1_19_3.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_19_4, + com.github.stefvanschie.inventoryframework.nms.v1_19_4.StonecutterInventoryImpl.class); } } diff --git a/README.md b/README.md index fabf0ed47..44f4c7974 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ 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 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. 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 index a8a5df0da..d662e556c 100644 --- 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 @@ -10,6 +10,7 @@ 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; @@ -26,9 +27,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -49,6 +51,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); sendItems(player, items, null); + + return null; } @Override 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 index f89ee345d..18dad0415 100644 --- 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 @@ -7,6 +7,7 @@ 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; @@ -23,9 +24,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -46,6 +48,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); sendItems(player, items, null); + + return null; } @Override 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 index 2fb7fe694..a1d178405 100644 --- 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 @@ -10,6 +10,7 @@ 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; @@ -26,9 +27,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -49,6 +51,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, entityPlayer.playerConnection.sendPacket(packet); sendItems(player, items, null); + + return null; } @Override diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java index e51b8dde3..80045c6ff 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_17_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, null); + + return null; } @Override diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java index 4ada319ad..ae263134c 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_17_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/SmithingTableInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/SmithingTableInventoryImpl.java index 35e7f24fe..c8fd9cf7f 100644 --- a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/SmithingTableInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_18_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java index f34ce72b2..0de583897 100644 --- a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_18_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java index c9a1895d3..d2776935f 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_18_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/SmithingTableInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/SmithingTableInventoryImpl.java index 809fc2996..f393093a2 100644 --- a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/SmithingTableInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_19_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java index 91d88f77b..1c346d14c 100644 --- a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_19_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java index 0af9f0071..3f30ef670 100644 --- a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_19_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java index afc55c6ac..da99add0b 100644 --- a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/SmithingTableInventoryImpl.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_19_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; @@ -39,9 +40,10 @@ public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { super(inventoryHolder); } + @Nullable @Override - public void openInventory(@NotNull Player player, @NotNull TextHolder title, - @Nullable org.bukkit.inventory.ItemStack[] items) { + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { int itemAmount = items.length; if (itemAmount != 3) { @@ -61,6 +63,8 @@ public void openInventory(@NotNull Player player, @NotNull TextHolder title, serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.SMITHING, message)); sendItems(player, items, player.getItemOnCursor()); + + return null; } @Override diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml new file mode 100644 index 000000000..bed7084e9 --- /dev/null +++ b/nms/1_19_4/pom.xml @@ -0,0 +1,58 @@ + + + + IF-parent + com.github.stefvanschie.inventoryframework + 0.10.9-SNAPSHOT + ../../pom.xml + + 4.0.0 + + 1_19_4 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.19.4-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.3 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file 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 new file mode 100644 index 000000000..742b0e4af --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/AnvilInventoryImpl.java @@ -0,0 +1,277 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_19_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 anvil inventory for 1.19.4 + * + * @since 0.10.9 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.9 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.9 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.9 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10. + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.9 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.9 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public void setItemName(@Nullable String name) { + AnvilInventoryImpl.super.text = name == null ? "" : name; + + //the client predicts the output result, so we broadcast the state again to override it + broadcastFullState(); + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/BeaconInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/BeaconInventoryImpl.java new file mode 100644 index 000000000..c3359e7f0 --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/BeaconInventoryImpl.java @@ -0,0 +1,199 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.4 + * + * @since 0.10.9 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.9 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/CartographyTableInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..3cbef8b2d --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/CartographyTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.4 + * + * @since 0.10.9 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.9 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/EnchantingTableInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..bc95beaaf --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/EnchantingTableInventoryImpl.java @@ -0,0 +1,213 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.4 + * + * @since 0.10.9 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.9 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/GrindstoneInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..20288623b --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/GrindstoneInventoryImpl.java @@ -0,0 +1,205 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_19_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 grindstone inventory for 1.19.4 + * + * @since 0.10.9 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.9 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.9 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.9 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @since 0.10.9 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/LegacySmithingTableInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/LegacySmithingTableInventoryImpl.java new file mode 100644 index 000000000..d4232dd49 --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/LegacySmithingTableInventoryImpl.java @@ -0,0 +1,257 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.LegacySmithingMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventorySmithing; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.4. This smithing table is for prior to Minecraft 1.20. + * + * @since 0.10.9 + * @deprecated this type of smithing table will be removed in Minecraft 1.20 + */ +@Deprecated +public class LegacySmithingTableInventoryImpl extends SmithingTableInventory { + + public LegacySmithingTableInventoryImpl(@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 legacy smithing table should be 3, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerSmithingTable; + + int id = containerSmithingTable.containerId; + Component message = TextHolderUtil.toComponent(title); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.LEGACY_SMITHING, message)); + + sendItems(player, items, player.getItemOnCursor()); + + return null; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.9 + */ + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.9 + */ + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.9 + */ + private class ContainerSmithingTableImpl extends LegacySmithingMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.player = serverPlayer.getBukkitEntity(); + + inputSlots.setItem(0, CraftItemStack.asNMSCopy(items[0])); + inputSlots.setItem(1, CraftItemStack.asNMSCopy(items[1])); + resultSlots.setItem(0, CraftItemStack.asNMSCopy(items[2])); + } + + @NotNull + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity == null) { + CraftInventory inventory = new CraftInventorySmithing(access.getLocation(), inputSlots, resultSlots) { + @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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/MerchantInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/MerchantInventoryImpl.java new file mode 100644 index 000000000..b1a0b13ab --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_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.19.4 + * + * @since 0.10.9 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/SmithingTableInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..a3dc68a37 --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_19_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.19.4. This smithing table is for Minecraft 1.19.4 or higher. + * + * @since 0.10.9 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.9 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.9 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.9 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.9 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.9 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.9 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/StonecutterInventoryImpl.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/StonecutterInventoryImpl.java new file mode 100644 index 000000000..ba23f087b --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/StonecutterInventoryImpl.java @@ -0,0 +1,219 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_19_4.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_19_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.19.4 + * + * @since 0.10.9 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + Component message = TextHolderUtil.toComponent(title); + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.9 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.9 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/CustomInventoryUtil.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/CustomInventoryUtil.java new file mode 100644 index 000000000..317736273 --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10. + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.9 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/TextHolderUtil.java b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/TextHolderUtil.java new file mode 100644 index 000000000..bf999b34d --- /dev/null +++ b/nms/1_19_4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_4/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_19_4.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.network.chat.Component; +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.9 + */ +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.9 + */ + @NotNull + @Contract(pure = true) + public static Component 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.9 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.9 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java index 8490598b7..267d73a01 100644 --- a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/SmithingTableInventory.java @@ -3,6 +3,7 @@ import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -43,7 +44,18 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ openInventory(player, StringHolder.of(title), items); } - public abstract void openInventory(@NotNull Player player, @NotNull TextHolder title, @Nullable ItemStack[] items); + /** + * Opens the inventory for the specified player + * + * @param player the player to open the inventory for + * @param title the title of the inventory + * @param items the top items + * @return the opened inventory + * @since 0.10.9 + */ + @Nullable + public abstract Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable ItemStack[] items); /** * Sends the top items to the inventory for the specified player. diff --git a/pom.xml b/pom.xml index 2379eeb1f..4f0ad2707 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_19_4 nms/1_19_3 nms/1_19_2 nms/1_19_1 From 27a4c083b9e834bb90420570d0996a1acf0035f1 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 27 Mar 2023 20:54:55 +0200 Subject: [PATCH 191/382] V 0.10.9 --- IF/pom.xml | 2 +- README.md | 4 ++-- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/abstraction/pom.xml | 2 +- pom.xml | 2 +- 20 files changed, 21 insertions(+), 21 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index dccfe881e..77d4000c5 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index 44f4c7974..9ce7c0b4d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.8 + 0.10.9 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.8' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.9' // ... } ``` diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 8276f3efe..fa736654b 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 023aa5a1f..5f284e665 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 3bfb130fa..70de60310 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index c59ae81d5..213f9ebbd 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index d0e8592eb..657c89c2d 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index b2f12cf3e..098eba654 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 9af8b279c..160e08d56 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 89edc560a..a13dd6cae 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 514aa0ba0..1a251ca4e 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 2c3a8dc8c..d25275ff7 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index cdafaf063..48c724300 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index c9f2a41d6..8c94fd544 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 5e4d048bc..99fc00547 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 5e292ca0e..a76f3d3e2 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index ea03564c3..dd453fa0d 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index bed7084e9..05aa0aed2 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 6cc79805b..2e921e425 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9-SNAPSHOT + 0.10.9 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 4f0ad2707..cdbc9f2e8 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.9-SNAPSHOT + 0.10.9 pom IF From c3ea2b2616ff125003e81bd55980674c9b44aa9c Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 8 Apr 2023 21:14:35 +0200 Subject: [PATCH 192/382] Bump to 0.10.10-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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/abstraction/pom.xml | 2 +- pom.xml | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 77d4000c5..6b391dfd2 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index fa736654b..f0eb300f1 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 5f284e665..0ad887169 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 70de60310..aa36d4b0a 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 213f9ebbd..f91e31746 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 657c89c2d..b2e76cdda 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 098eba654..3abedad0c 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 160e08d56..2be35874e 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index a13dd6cae..a8163b82a 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 1a251ca4e..1f77dd014 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index d25275ff7..b4938f5e7 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 48c724300..4434fc753 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 8c94fd544..4d5365aaf 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 99fc00547..01d60011d 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index a76f3d3e2..082147742 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index dd453fa0d..dc96e2804 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 05aa0aed2..7d8643c54 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 2e921e425..3e7d2a3cd 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.9 + 0.10.10-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index cdbc9f2e8..17b0dd05a 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.9 + 0.10.10-SNAPSHOT pom IF From 5b054b54f7118dff8cb0e4a3f16d5d9f0bc869e8 Mon Sep 17 00:00:00 2001 From: RobotHanzo Date: Mon, 2 Jan 2023 22:39:12 +0800 Subject: [PATCH 193/382] An attempt to fix hidden items breaking everything after it in OutlinePane --- .../stefvanschie/inventoryframework/pane/OutlinePane.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java index 055b63818..205cdf0cf 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java @@ -236,10 +236,9 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs int finalColumn = slot.getX(maxLength) + x + paneOffsetX; GuiItem item = items[index]; - if (!item.isVisible()) { - continue; + if (item.isVisible()) { + inventoryComponent.setItem(item, finalColumn, finalRow); } - inventoryComponent.setItem(item, finalColumn, finalRow); } } From 4ae6fb47bd308859e4ec698ccc7dc018d138d5ba Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 25 May 2023 19:56:29 +0200 Subject: [PATCH 194/382] Add #285 Adds a callback for anvil guis that is fired whenever the name input changes --- .../inventoryframework/gui/type/AnvilGui.java | 45 +++++++++++ .../nms/v1_14/AnvilInventoryImpl.java | 8 +- .../nms/v1_15/AnvilInventoryImpl.java | 8 +- .../nms/v1_16_1/AnvilInventoryImpl.java | 10 ++- .../nms/v1_16_2_3/AnvilInventoryImpl.java | 10 ++- .../nms/v1_16_4_5/AnvilInventoryImpl.java | 10 ++- .../nms/v1_17_0/AnvilInventoryImpl.java | 8 +- .../nms/v1_17_1/AnvilInventoryImpl.java | 8 +- .../nms/v1_18_0/AnvilInventoryImpl.java | 8 +- .../nms/v1_18_1/AnvilInventoryImpl.java | 8 +- .../nms/v1_18_2/AnvilInventoryImpl.java | 8 +- .../nms/v1_19_0/AnvilInventoryImpl.java | 8 +- .../nms/v1_19_1/AnvilInventoryImpl.java | 8 +- .../nms/v1_19_2/AnvilInventoryImpl.java | 8 +- .../nms/v1_19_3/AnvilInventoryImpl.java | 8 +- .../nms/v1_19_4/AnvilInventoryImpl.java | 8 +- .../abstraction/AnvilInventory.java | 28 +++++++ .../abstraction/util/ObservableValue.java | 80 +++++++++++++++++++ 18 files changed, 261 insertions(+), 18 deletions(-) create mode 100644 nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/util/ObservableValue.java 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 30841324e..32a968edd 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 @@ -34,6 +34,8 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.function.Consumer; +import java.util.logging.Level; /** * Represents a gui in the form of an anvil @@ -42,6 +44,12 @@ */ public class AnvilGui extends NamedGui implements InventoryBased { + /** + * Called whenever the name input is changed. + */ + @NotNull + private Consumer onNameInputChanged = (name) -> {}; + /** * Represents the inventory component for the first item */ @@ -87,6 +95,8 @@ public class AnvilGui extends NamedGui implements InventoryBased { */ public AnvilGui(@NotNull String title) { super(title); + + this.anvilInventory.subscribeToNameInputChanges(this::callOnRename); } /** @@ -97,6 +107,8 @@ public AnvilGui(@NotNull String title) { */ public AnvilGui(@NotNull TextHolder title) { super(title); + + this.anvilInventory.subscribeToNameInputChanges(this::callOnRename); } /** @@ -109,6 +121,8 @@ public AnvilGui(@NotNull TextHolder title) { */ public AnvilGui(@NotNull String title, @NotNull Plugin plugin) { super(title, plugin); + + this.anvilInventory.subscribeToNameInputChanges(this::callOnRename); } /** @@ -121,6 +135,8 @@ public AnvilGui(@NotNull String title, @NotNull Plugin plugin) { */ public AnvilGui(@NotNull TextHolder title, @NotNull Plugin plugin) { super(title, plugin); + + this.anvilInventory.subscribeToNameInputChanges(this::callOnRename); } @Override @@ -307,6 +323,35 @@ public void handleClose(@NotNull HumanEntity humanEntity) { this.viewers.remove(humanEntity); } + /** + * Sets the consumer that should be called whenever the name input is changed. The argument is the new input. When + * this consumer is invoked, the value as returned by {@link #getRenameText()} will not have updated yet, hence + * allowing you to see the old value via that. + * + * @param onNameInputChanged the consumer to call when the rename input is changed + * @since 0.10.10 + */ + public void setOnNameInputChanged(@NotNull Consumer onNameInputChanged) { + this.onNameInputChanged = onNameInputChanged; + } + + /** + * Calls the consumer that was specified using {@link #setOnNameInputChanged(Consumer)}, so the consumer that should + * be called whenever the rename input is changed. Catches and logs all exceptions the consumer might throw. + * + * @param newInput the new rename input + * @since 0.10.10 + */ + private void callOnRename(@NotNull String newInput) { + try { + this.onNameInputChanged.accept(newInput); + } catch (Throwable throwable) { + String message = "Exception while handling onRename, newInput='" + newInput + "'"; + + this.plugin.getLogger().log(Level.SEVERE, message, throwable); + } + } + /** * Gets the inventory component representing the first item * 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 index a8e19a890..9b30ed8bc 100644 --- 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 @@ -308,7 +308,13 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { @Override public void a(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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(); 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 index 4cd004986..aff83a514 100644 --- 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 @@ -308,7 +308,13 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { @Override public void a(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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(); 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 index 30ac098da..098c90241 100644 --- 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 @@ -308,7 +308,13 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { @Override public void a(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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(); @@ -354,7 +360,7 @@ public void forceUpdate() { */ Collections.fill(this.items, this.uniqueItem); - notifyListeners(); + c(); List listeners; 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 index b3705dec9..83b57373d 100644 --- 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 @@ -308,7 +308,13 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { @Override public void a(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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(); @@ -354,7 +360,7 @@ public void forceUpdate() { */ Collections.fill(this.items, this.uniqueItem); - notifyListeners(); + c(); List listeners; 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 index f103c04ad..99f65b47e 100644 --- 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 @@ -308,7 +308,13 @@ public ItemStack a(EntityHuman entityHuman, @NotNull ItemStack itemStack) { @Override public void a(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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(); @@ -354,7 +360,7 @@ public void forceUpdate() { */ Collections.fill(this.items, this.uniqueItem); - notifyListeners(); + c(); List listeners; diff --git a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java index 10282bef6..48e5975e0 100644 --- a/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java +++ b/nms/1_17_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_0/AnvilInventoryImpl.java @@ -265,7 +265,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 ContainerSynchronizer synchronizer; diff --git a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java index 42086f682..8c93a9ec9 100644 --- a/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java +++ b/nms/1_17_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_17_1/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); diff --git a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java index 90b7f3378..4fb3e2bda 100644 --- a/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java +++ b/nms/1_18_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_0/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); diff --git a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java index 6cd837f36..143dca697 100644 --- a/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java +++ b/nms/1_18_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_1/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); diff --git a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java index 6b30a4940..c12daf435 100644 --- a/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java +++ b/nms/1_18_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_18_2/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); diff --git a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java index 73f4bf64d..dc578277a 100644 --- a/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java +++ b/nms/1_19_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_0/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); diff --git a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java index e5b5d17c3..aefaaa939 100644 --- a/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java +++ b/nms/1_19_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_1/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); diff --git a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java index 87a523cce..e06ee5772 100644 --- a/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java +++ b/nms/1_19_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_2/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); diff --git a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java index a736dd7bf..62af7ade7 100644 --- a/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java +++ b/nms/1_19_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_19_3/AnvilInventoryImpl.java @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); 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 742b0e4af..877668403 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 @@ -251,7 +251,13 @@ public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @No @Override public void setItemName(@Nullable String name) { - AnvilInventoryImpl.super.text = name == null ? "" : 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 broadcastFullState(); 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 7af79cf88..44f5bfb7b 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 @@ -1,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.abstraction; +import com.github.stefvanschie.inventoryframework.abstraction.util.ObservableValue; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import org.bukkit.entity.Player; @@ -10,6 +11,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Consumer; + /** * An anvil inventory * @@ -25,10 +28,19 @@ public abstract class AnvilInventory { /** * The rename text + * + * @deprecated Superseded by {@link #observableText} */ @NotNull + @Deprecated protected String text = ""; + /** + * The name input text. + */ + @NotNull + protected final ObservableValue<@NotNull String> observableText = new ObservableValue<>(""); + /** * The enchantment cost displayed */ @@ -159,6 +171,22 @@ public final void openInventory(@NotNull Player player, @NotNull String title, @ @NotNull @Contract(pure = true) public String getRenameText() { + String text = observableText.get(); + + if (text == null) { + throw new IllegalStateException("Rename text is null"); + } + return text; } + + /** + * Subscribes to changes of the name input. + * + * @param onNameInputChanged the consumer to call when the name input changes + * @since 0.10.10 + */ + public void subscribeToNameInputChanges(@NotNull Consumer onNameInputChanged) { + this.observableText.subscribe(onNameInputChanged); + } } diff --git a/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/util/ObservableValue.java b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/util/ObservableValue.java new file mode 100644 index 000000000..c0d5309f9 --- /dev/null +++ b/nms/abstraction/src/main/java/com/github/stefvanschie/inventoryframework/abstraction/util/ObservableValue.java @@ -0,0 +1,80 @@ +package com.github.stefvanschie.inventoryframework.abstraction.util; + +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.HashSet; +import java.util.function.Consumer; + +/** + * A value whose modifications can be observed. + * + * @param the type of value to store + * @since 0.10.10 + */ +public class ObservableValue { + + /** + * A collection of subscribers that should be notified on updates. + */ + @NotNull + private final Collection> subscribers = new HashSet<>(); + + /** + * The current value + */ + @Nullable + private T value; + + /** + * Creates a new observable value with the given default value. + * + * @param defaultValue the default value + * @since 0.10.10 + */ + public ObservableValue(@Nullable T defaultValue) { + this.value = defaultValue; + } + + /** + * Updates the old value to the given new value. This will notify all the subscribers before updating the new value. + * Subscribers may observe the old value by using {@link #get()}. This will always notify the subscribers, even if + * the new value is the same as the old value. + * + * @param newValue the new value + * @since 0.10.10 + */ + public void set(T newValue) { + for (Consumer subscriber : this.subscribers) { + subscriber.accept(newValue); + } + + this.value = newValue; + } + + /** + * Subscribes to modifications of this value. The provided consumer will be called every time this value changes. + * + * @param consumer the consumer to call upon updates of this value + * @since 0.10.10 + */ + public void subscribe(@NotNull Consumer consumer) { + this.subscribers.add(consumer); + } + + /** + * Gets the current value of this item. If this is called from within a subscriber, then this is the value from + * before the current in-progress update. + * + * @return the current value + * @since 0.10.10 + */ + @Nullable + @Contract(pure = true) + public T get() { + return this.value; + } + +} From fdc17fe19e7ecd337374f3731d01719bc0da222a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Feb 2023 05:58:25 +0000 Subject: [PATCH 195/382] Bump maven-javadoc-plugin from 3.4.1 to 3.5.0 in /nms/1_14 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.1 to 3.5.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.1...maven-javadoc-plugin-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 17b0dd05a..40b3d14b5 100644 --- a/pom.xml +++ b/pom.xml @@ -151,7 +151,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.1 + 3.5.0 attach-javadocs From 5e454da7bbeae8898cb8847bbec6439bc8fa58a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Feb 2023 05:58:46 +0000 Subject: [PATCH 196/382] Bump maven-javadoc-plugin from 3.4.1 to 3.5.0 Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.1 to 3.5.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.1...maven-javadoc-plugin-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 6b391dfd2..bcd5e2518 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -261,7 +261,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.1 + 3.5.0 attach-javadocs From 5b23ebc2a3e3ba955a3635f9d3aa10ae99e8a267 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 30 May 2023 20:50:20 +0200 Subject: [PATCH 197/382] Fix #323 Also fix the same issue for CartographyTableGui. --- .../inventoryframework/gui/GuiItem.java | 41 ++++++++++++------- .../gui/type/CartographyTableGui.java | 2 +- 2 files changed, 28 insertions(+), 15 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 732a3f77f..4b7773bd3 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 @@ -29,14 +29,14 @@ public class GuiItem { * The logger to log errors with */ @NotNull - private Logger logger; + private final Logger logger; /** * The {@link NamespacedKey} that specifies the location of the (internal) {@link UUID} in {@link PersistentDataContainer}s. * The {@link PersistentDataType} that should be used is {@link UUIDTagType}. */ @NotNull - private NamespacedKey keyUUID; + private final NamespacedKey keyUUID; /** * An action for the inventory @@ -77,15 +77,7 @@ public class GuiItem { * @since 0.10.8 */ public GuiItem(@NotNull ItemStack item, @Nullable Consumer action, @NotNull Plugin plugin) { - this.logger = plugin.getLogger(); - this.keyUUID = new NamespacedKey(plugin, "IF-uuid"); - this.action = action; - this.visible = true; - this.properties = new ArrayList<>(); - this.item = item; - - //remove this call after the removal of InventoryComponent#setItem(ItemStack, int, int) - applyUUID(); + this(item, action, plugin.getLogger(), new NamespacedKey(plugin, "IF-uuid")); } /** @@ -119,6 +111,29 @@ public GuiItem(@NotNull ItemStack item) { this(item, event -> {}); } + /** + * Creates a new gui item based on the given item, action, logger, and key. The logger will be used for logging + * exceptions and the key is used for identification of this item. + * + * @param item the item stack + * @param action the action called whenever an interaction with this item happens + * @param logger the logger used for logging exceptions + * @param key the key to identify this item with + * @since 0.10.10 + */ + private GuiItem(@NotNull ItemStack item, @Nullable Consumer action, @NotNull Logger logger, + @NotNull NamespacedKey key) { + this.logger = logger; + this.keyUUID = key; + this.action = action; + this.visible = true; + this.properties = new ArrayList<>(); + this.item = item; + + //remove this call after the removal of InventoryComponent#setItem(ItemStack, int, int) + applyUUID(); + } + /** * Makes a copy of this gui item and returns it. This makes a deep copy of the gui item. This entails that the * underlying item will be copied as per their {@link ItemStack#clone()} and miscellaneous data will be copied in @@ -130,10 +145,8 @@ public GuiItem(@NotNull ItemStack item) { @NotNull @Contract(pure = true) public GuiItem copy() { - GuiItem guiItem = new GuiItem(item.clone(), action); + GuiItem guiItem = new GuiItem(item.clone(), action, this.logger, this.keyUUID); - guiItem.logger = this.logger; - guiItem.keyUUID = this.keyUUID; guiItem.visible = visible; guiItem.uuid = uuid; guiItem.properties = new ArrayList<>(properties); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 53c7c705c..1c324acee 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -155,7 +155,7 @@ public void show(@NotNull HumanEntity humanEntity) { @Contract(pure = true) @Override public CartographyTableGui copy() { - CartographyTableGui gui = new CartographyTableGui(getTitleHolder()); + CartographyTableGui gui = new CartographyTableGui(getTitleHolder(), super.plugin); gui.mapComponent = mapComponent.copy(); gui.paperComponent = paperComponent.copy(); From 5b917edfe1bf20c4a3f29ded8a9849b2ba963e36 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 Mar 2023 05:58:54 +0000 Subject: [PATCH 198/382] Bump annotations from 23.0.0 to 24.0.1 in /IF Bumps [annotations](https://github.com/JetBrains/java-annotations) from 23.0.0 to 24.0.1. - [Release notes](https://github.com/JetBrains/java-annotations/releases) - [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md) - [Commits](https://github.com/JetBrains/java-annotations/commits) --- updated-dependencies: - dependency-name: org.jetbrains:annotations dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 40b3d14b5..3090a77dd 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ org.jetbrains annotations - 23.0.0 + 24.0.1 provided From 21161f4388783c388d1efe26963f27d5833f520b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jun 2023 20:59:33 +0200 Subject: [PATCH 199/382] Add support for Minecraft 1.20 --- .github/dependabot.yml | 4 + .github/workflows/auto-deploy.yml | 1 + .github/workflows/maven.yml | 1 + IF/pom.xml | 6 + .../inventoryframework/gui/GuiListener.java | 27 +- .../util/version/Version.java | 40 ++- .../util/version/VersionMatcher.java | 28 +- nms/1_20/pom.xml | 58 +++ .../nms/v1_20/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_20/BeaconInventoryImpl.java | 200 +++++++++++ .../v1_20/CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_20/EnchantingTableInventoryImpl.java | 218 ++++++++++++ .../nms/v1_20/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_20/MerchantInventoryImpl.java | 97 +++++ .../nms/v1_20/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_20/StonecutterInventoryImpl.java | 221 ++++++++++++ .../nms/v1_20/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_20/util/TextHolderUtil.java | 65 ++++ pom.xml | 1 + 19 files changed, 2036 insertions(+), 17 deletions(-) create mode 100644 nms/1_20/pom.xml create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/AnvilInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/BeaconInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/CartographyTableInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/EnchantingTableInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/GrindstoneInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/MerchantInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/SmithingTableInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/StonecutterInventoryImpl.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/CustomInventoryUtil.java create mode 100644 nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/TextHolderUtil.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 509114481..c5fcaa429 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -72,6 +72,10 @@ updates: directory: "/nms/1_19_4" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_20" + schedule: + interval: "daily" - package-ecosystem: "maven" directory: "/nms/abstraction" schedule: diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 151011321..c6cc10730 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -71,6 +71,7 @@ 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 - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import - name: Automatically deploy the project diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9f9ab98dc..fbd9b627c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -77,5 +77,6 @@ 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 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index bcd5e2518..7b386e54f 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -131,6 +131,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_20 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index cfaaf9a53..e2efce85e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -360,22 +360,21 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { } }); - //delay because merchants put items in slots back in the player inventory - Bukkit.getScheduler().runTask(this.plugin, () -> { - gui.getHumanEntityCache().restoreAndForget(humanEntity); + event.getInventory().clear(); //clear inventory to prevent items being put back - if (gui.getViewerCount() == 1) { - activeGuiInstances.remove(gui); - } + gui.getHumanEntityCache().restoreAndForget(humanEntity); - if (gui instanceof AnvilGui) { - ((AnvilGui) gui).handleClose(humanEntity); - } else if (gui instanceof MerchantGui) { - ((MerchantGui) gui).handleClose(humanEntity); - } else if (gui instanceof ModernSmithingTableGui) { - ((ModernSmithingTableGui) gui).handleClose(humanEntity); - } - }); + if (gui.getViewerCount() == 1) { + activeGuiInstances.remove(gui); + } + + if (gui instanceof AnvilGui) { + ((AnvilGui) gui).handleClose(humanEntity); + } else if (gui instanceof MerchantGui) { + ((MerchantGui) gui).handleClose(humanEntity); + } else if (gui instanceof ModernSmithingTableGui) { + ((ModernSmithingTableGui) gui).handleClose(humanEntity); + } } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 50d857322..97d6db328 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -5,6 +5,9 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.util.Collection; +import java.util.EnumSet; + /** * The different supported NMS versions * @@ -115,7 +118,40 @@ public enum Version { * * @since 0.10.9 */ - V1_19_4; + V1_19_4, + + /** + * Version 1.20 + * + * @since 0.10.10 + */ + V1_20; + + /** + * A collection of versions on which modern smithing tables are available. + */ + private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of(V1_19_4, V1_20); + + /** + * Checks whether modern smithing tables exist on this version. Returns true if they do, otherwise false. + * + * @return true if modern smithing tables are available + * @since 0.10.10 + */ + boolean existsModernSmithingTable() { + return MODERN_SMITHING_TABLE_VERSIONS.contains(this); + } + + /** + * Checks whether legacy smithing tables exist on this version. Returns true if they do, otherwise false. + * + * @return true if legacy smithing tables are available + * @since 0.10.10 + */ + @Contract(pure = true) + boolean existsLegacySmithingTable() { + return this != V1_20; + } /** * Gets the version currently being used. If the used version is not supported, an @@ -168,6 +204,8 @@ public static Version getVersion() { return V1_19_3; case "1.19.4": return V1_19_4; + case "1.20": + return V1_20; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 114a8b93a..0241096c5 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 @@ -200,7 +200,11 @@ public static MerchantInventory newMerchantInventory(@NotNull Version version) { @Contract(pure = true) public static SmithingTableInventory newModernSmithingTableInventory(@NotNull Version version, @NotNull InventoryHolder inventoryHolder) { - if (version != Version.V1_19_4) { + if (!version.existsModernSmithingTable() && !version.existsLegacySmithingTable()) { + throw new UnsupportedVersionException("Smithing tables didn't exist in version " + version); + } + + if (!version.existsModernSmithingTable()) { throw new UnsupportedVersionException("Modern smithing tables didn't exist in version " + version); } @@ -229,10 +233,14 @@ public static SmithingTableInventory newModernSmithingTableInventory(@NotNull Ve @Contract(pure = true) public static SmithingTableInventory newSmithingTableInventory(@NotNull Version version, @NotNull InventoryHolder inventoryHolder) { - if (version == Version.V1_14 || version == Version.V1_15) { + if (!version.existsModernSmithingTable() && !version.existsLegacySmithingTable()) { throw new UnsupportedVersionException("Smithing tables didn't exist in version " + version); } + if (!version.existsLegacySmithingTable()) { + throw new UnsupportedVersionException("Legacy smithing tables don't exist in version " + version); + } + try { Class clazz = LEGACY_SMITHING_TABLE_INVENTORIES.get(version); @@ -297,6 +305,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -329,6 +339,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -361,6 +373,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -393,6 +407,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -425,6 +441,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -457,10 +475,14 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -521,5 +543,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20, + com.github.stefvanschie.inventoryframework.nms.v1_20.StonecutterInventoryImpl.class); } } diff --git a/nms/1_20/pom.xml b/nms/1_20/pom.xml new file mode 100644 index 000000000..9f374534f --- /dev/null +++ b/nms/1_20/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.10-SNAPSHOT + ../../pom.xml + + + 1_20 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.20-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.3 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/AnvilInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/AnvilInventoryImpl.java new file mode 100644 index 000000000..366009293 --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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 anvil inventory for 1.20 + * + * @since 0.10.10 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.10 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.10 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.10 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.10 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.10 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.10 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/BeaconInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/BeaconInventoryImpl.java new file mode 100644 index 000000000..7a473807e --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/BeaconInventoryImpl.java @@ -0,0 +1,200 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20 + * + * @since 0.10.10 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.10 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.10 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/CartographyTableInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..25a539e7e --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20 + * + * @since 0.10.10 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.10 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.10 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/EnchantingTableInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..2a0d9cfe8 --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/EnchantingTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20 + * + * @since 0.10.10 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.10 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.10 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/GrindstoneInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..170bf7a3a --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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 grindstone inventory for 1.20 + * + * @since 0.10.10 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.10 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.10 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.10 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.10 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/MerchantInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/MerchantInventoryImpl.java new file mode 100644 index 000000000..e90734ae8 --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_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.20 + * + * @since 0.10.10 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.10 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/SmithingTableInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..ee6be3325 --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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.20. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.10 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.10 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.10 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.10 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.10 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.10 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.10 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/StonecutterInventoryImpl.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/StonecutterInventoryImpl.java new file mode 100644 index 000000000..cc39b3641 --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/StonecutterInventoryImpl.java @@ -0,0 +1,221 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20 + * + * @since 0.10.10 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.10 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.10 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/CustomInventoryUtil.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/CustomInventoryUtil.java new file mode 100644 index 000000000..c67c18099 --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.10 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.10 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/TextHolderUtil.java b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/TextHolderUtil.java new file mode 100644 index 000000000..da626ee4f --- /dev/null +++ b/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20.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.network.chat.Component; +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.10 + */ +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.10 + */ + @NotNull + @Contract(pure = true) + public static Component 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.10 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.10 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 40b3d14b5..8fc914e68 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,7 @@ nms/1_15 nms/1_14 adventure-support + nms/1_20 From f0d0a544fd067fd01c1280210b629aa9fb382a28 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 9 Jun 2023 22:04:27 +0200 Subject: [PATCH 200/382] V 0.10.10 --- IF/pom.xml | 2 +- README.md | 7 ++++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 21 files changed, 24 insertions(+), 23 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 7b386e54f..a1a2e5fc0 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index 9ce7c0b4d..01d64b0d4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IF Discord guild -*This framework works for Minecraft versions 1.14-1.19* +*This framework works for Minecraft versions 1.14-1.20* An inventory framework for managing GUIs @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.9 + 0.10.10 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.9' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.10' // ... } ``` @@ -136,6 +136,7 @@ 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 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index f0eb300f1..48c68697e 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 0ad887169..60c997e6b 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index aa36d4b0a..c66947ff9 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index f91e31746..b3bf60de0 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index b2e76cdda..98c280aa4 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 3abedad0c..d21723559 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 2be35874e..6c0a8821e 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index a8163b82a..a0ade4e70 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 1f77dd014..8df6a9f95 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index b4938f5e7..0eab58d7d 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 4434fc753..42d580a70 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 4d5365aaf..13f4913ab 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 01d60011d..194b8783d 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 082147742..f88aad112 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index dc96e2804..be9691cc1 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 7d8643c54..1f406838a 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/nms/1_20/pom.xml b/nms/1_20/pom.xml index 9f374534f..b9a7702bf 100644 --- a/nms/1_20/pom.xml +++ b/nms/1_20/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 3e7d2a3cd..f369a2703 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10-SNAPSHOT + 0.10.10 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index dc7033246..d4d137144 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.10-SNAPSHOT + 0.10.10 pom IF From fefb749466c637066ba53a20d98680249f94d179 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 23 Jun 2023 20:48:49 +0200 Subject: [PATCH 201/382] Bump to 0.10.11-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index a1a2e5fc0..aa89e2082 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 48c68697e..f8d78e0b1 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 60c997e6b..457bc7e62 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index c66947ff9..6963ddfe7 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index b3bf60de0..565be55b8 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 98c280aa4..31b078118 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index d21723559..1a2523749 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 6c0a8821e..0a79678d3 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index a0ade4e70..afefb4a2b 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 8df6a9f95..2b89eb3c2 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 0eab58d7d..38d4fe419 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 42d580a70..4307b1911 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 13f4913ab..fa0ba5bce 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 194b8783d..bd482fa23 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index f88aad112..2f655d6cb 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index be9691cc1..5ccc7745e 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 1f406838a..57d2b63df 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20/pom.xml b/nms/1_20/pom.xml index b9a7702bf..5bd427cb5 100644 --- a/nms/1_20/pom.xml +++ b/nms/1_20/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index f369a2703..ec228cd1f 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.10 + 0.10.11-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index d4d137144..2395aa9e5 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.10 + 0.10.11-SNAPSHOT pom IF From 02988bf77c437963fce9939f43badc23a5154014 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 23 Jun 2023 21:11:18 +0200 Subject: [PATCH 202/382] Add 1.20.1 support --- .../stefvanschie/inventoryframework/util/version/Version.java | 1 + 1 file changed, 1 insertion(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 97d6db328..c7e658baf 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -205,6 +205,7 @@ public static Version getVersion() { case "1.19.4": return V1_19_4; case "1.20": + case "1.20.1": return V1_20; default: throw new UnsupportedVersionException("The server version provided is not supported"); From c0999c059792c42ceed35f635c23e2dd39a62bb7 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 24 Jun 2023 20:18:54 +0200 Subject: [PATCH 203/382] V 0.10.11 --- IF/pom.xml | 2 +- README.md | 4 ++-- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 21 files changed, 22 insertions(+), 22 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index aa89e2082..abbd44d0e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index 01d64b0d4..5402db49d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.10 + 0.10.11 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.10' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.11' // ... } ``` diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index f8d78e0b1..f1333f63e 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 457bc7e62..2ff2d5aa6 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 6963ddfe7..daf67c9ca 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 565be55b8..479cf0594 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 31b078118..338f9b9c4 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 1a2523749..a15806fde 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 0a79678d3..195d7d0e5 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index afefb4a2b..f00b06405 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 2b89eb3c2..b16accebb 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 38d4fe419..47dc01cb2 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 4307b1911..b3ca2e69e 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index fa0ba5bce..e42693b25 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index bd482fa23..e0f31f4b1 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 2f655d6cb..12bfe5e4f 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 5ccc7745e..45123d3fb 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 57d2b63df..e3ca8b80b 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/nms/1_20/pom.xml b/nms/1_20/pom.xml index 5bd427cb5..ec1d03547 100644 --- a/nms/1_20/pom.xml +++ b/nms/1_20/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index ec228cd1f..54654fbfb 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11-SNAPSHOT + 0.10.11 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 2395aa9e5..2fcc00ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.11-SNAPSHOT + 0.10.11 pom IF From 5b9f637f744b7881f49582bfbd082524609ae26e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Mar 2023 18:00:24 +0000 Subject: [PATCH 204/382] Bump paper-nms-maven-plugin from 1.3 to 1.3.2 in /nms/1_19_3 Bumps paper-nms-maven-plugin from 1.3 to 1.3.2. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 45123d3fb..63da8f98e 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.3 + 1.3.2 process-classes From 73d5d76c96c680281d4351bf6208113b4b00a6aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Mar 2023 18:00:33 +0000 Subject: [PATCH 205/382] Bump paper-nms-maven-plugin from 1.3 to 1.3.2 in /nms/1_19_4 Bumps paper-nms-maven-plugin from 1.3 to 1.3.2. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index e3ca8b80b..573a1ff4c 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.3 + 1.3.2 process-classes From 7b729b4a306b4ab8acb495fa1c42f9438cba98ef Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 6 Jul 2023 20:30:18 +0200 Subject: [PATCH 206/382] Bump to 0.10.12-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index abbd44d0e..3b954ef87 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index f1333f63e..58aaed12f 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 2ff2d5aa6..0002dac07 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index daf67c9ca..27d754fc4 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 479cf0594..2d63747e7 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 338f9b9c4..1d10dd5a3 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index a15806fde..2fde710dd 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 195d7d0e5..ddafa0bd8 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index f00b06405..af62af186 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index b16accebb..b089dd394 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 47dc01cb2..329c64b1b 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index b3ca2e69e..5280a9632 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index e42693b25..f9ee45538 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index e0f31f4b1..a0908474c 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 12bfe5e4f..bc90c27ce 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 63da8f98e..87beeced1 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 573a1ff4c..495e7a6d3 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20/pom.xml b/nms/1_20/pom.xml index ec1d03547..4e444f33a 100644 --- a/nms/1_20/pom.xml +++ b/nms/1_20/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 54654fbfb..7b6a0c75a 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.11 + 0.10.12-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 2fcc00ed6..06ab7b016 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.11 + 0.10.12-SNAPSHOT pom IF From 20a483c8597c21b647c0e35a2b7f703f6e2adad3 Mon Sep 17 00:00:00 2001 From: Janet Blackquill Date: Sun, 22 Jan 2023 16:46:32 -0500 Subject: [PATCH 207/382] Fix inverted logic for XML onClick bindings The code should check that the property is assignable to the parameter, not that the parameter is assignable to the property. --- .../com/github/stefvanschie/inventoryframework/pane/Pane.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 7f60fb9df..e927a28f7 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -522,8 +522,8 @@ else if (parameterCount == properties.size() + 1) { Object attribute = properties.get(i); if (!(parameterTypes[1 + i].isPrimitive() && - Primitives.unwrap(attribute.getClass()).isAssignableFrom(parameterTypes[1 + i])) && - !attribute.getClass().isAssignableFrom(parameterTypes[1 + i])) + parameterTypes[1 + i].isAssignableFrom(Primitives.unwrap(attribute.getClass()))) && + !parameterTypes[1 + i].isAssignableFrom(attribute.getClass())) correct = false; } From a9d30b892020e61dc307a2c8d9e30d047d2b2228 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Apr 2023 05:58:09 +0000 Subject: [PATCH 208/382] Bump junit-jupiter-engine from 5.9.1 to 5.9.3 in /nms/1_16_2-3 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.9.1 to 5.9.3. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.1...r5.9.3) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 06ab7b016..739c55da6 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ org.junit.jupiter junit-jupiter-engine - 5.9.1 + 5.9.3 From 7602f0f64656c93e48fff0985c67be3a4a7c99e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Apr 2023 05:58:13 +0000 Subject: [PATCH 209/382] Bump junit-jupiter-engine from 5.9.1 to 5.9.3 in /IF Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.9.1 to 5.9.3. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.1...r5.9.3) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 3b954ef87..352395a4a 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -223,7 +223,7 @@ org.junit.jupiter junit-jupiter-engine - 5.9.1 + 5.9.3 From 198f3918318b1346f91f06ab05fab3a6fb557cb5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Apr 2023 05:58:19 +0000 Subject: [PATCH 210/382] Bump junit-jupiter-api from 5.9.1 to 5.9.3 in /IF Bumps [junit-jupiter-api](https://github.com/junit-team/junit5) from 5.9.1 to 5.9.3. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.1...r5.9.3) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 352395a4a..8015090c9 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -166,7 +166,7 @@ org.junit.jupiter junit-jupiter-api - 5.9.1 + 5.9.3 test From adfd3822b1ac8a35b71888a54d45dac5b69b08fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 May 2023 05:58:12 +0000 Subject: [PATCH 211/382] Bump maven-gpg-plugin from 3.0.1 to 3.1.0 in /nms/1_17_1 Bumps [maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.0.1 to 3.1.0. - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.0.1...maven-gpg-plugin-3.1.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 739c55da6..bd9e5ca59 100644 --- a/pom.xml +++ b/pom.xml @@ -90,7 +90,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.1.0 sign-artifacts From a3778f9210f6975a473be96c56ea3a9fd54cc93f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 05:57:58 +0000 Subject: [PATCH 212/382] Bump maven-source-plugin from 3.2.1 to 3.3.0 Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.1 to 3.3.0. - [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.1...maven-source-plugin-3.3.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-source-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 8015090c9..121118be4 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -254,7 +254,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 attach-sources diff --git a/pom.xml b/pom.xml index bd9e5ca59..2f47d64a9 100644 --- a/pom.xml +++ b/pom.xml @@ -139,7 +139,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 attach-sources From cb1b60656508ecd4ec1a21b6c087119d76bed2f5 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 13 Jul 2023 21:14:16 +0200 Subject: [PATCH 213/382] Fix toggle buttons not working in masonry panes Fixes #322 --- .../pane/component/ToggleButton.java | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index c7a937b9a..d88b0eb7d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -60,13 +60,11 @@ public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priorit this.enabled = enabled; - //TODO: don't know the positions of these panes, should be zero, though - - this.enabledPane = new OutlinePane(this.x, this.y, length, height); + this.enabledPane = new OutlinePane(length, height); this.enabledPane.addItem(new GuiItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE))); this.enabledPane.setRepeat(true); - this.disabledPane = new OutlinePane(this.x, this.y, length, height); + this.disabledPane = new OutlinePane(length, height); this.disabledPane.addItem(new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE))); this.disabledPane.setRepeat(true); } @@ -380,22 +378,6 @@ public void setHeight(int height) { this.enabledPane.setHeight(height); } - @Override - public void setX(int x) { - super.setX(x); - - this.disabledPane.setX(x); - this.enabledPane.setX(x); - } - - @Override - public void setY(int y) { - super.setY(y); - - this.disabledPane.setY(y); - this.enabledPane.setY(y); - } - /** * Sets the item to use when the button is set to disabled * From ceeec7b993aa4256c9597c4faa0c193f86b129de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 05:58:06 +0000 Subject: [PATCH 214/382] Bump maven-gpg-plugin from 3.0.1 to 3.1.0 Bumps [maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.0.1 to 3.1.0. - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.0.1...maven-gpg-plugin-3.1.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 121118be4..cbfb14cca 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -190,7 +190,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.1.0 sign-artifacts From caa50e51bc92399320cc7ad5595e9f8e53ccd7b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jul 2023 20:45:28 +0200 Subject: [PATCH 215/382] Bump maven-surefire-plugin from 2.22.2 to 3.1.2 in /nms/1_17_0 (#454) * Bump maven-surefire-plugin from 2.22.2 to 3.1.2 in /nms/1_17_0 Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 2.22.2 to 3.1.2. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-2.22.2...surefire-3.1.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * Fix maven-surefire-plugin breaking on version 3.1.2 --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: stefvanschie --- IF/pom.xml | 8 ++++---- pom.xml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index cbfb14cca..0f240de0c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -213,12 +213,12 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.1.2 - org.junit.platform - junit-platform-surefire-provider - 1.3.2 + org.apache.maven.surefire + surefire-junit-platform + 3.1.2 org.junit.jupiter diff --git a/pom.xml b/pom.xml index 2f47d64a9..9e0d46ab1 100644 --- a/pom.xml +++ b/pom.xml @@ -111,12 +111,12 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.1.2 - org.junit.platform - junit-platform-surefire-provider - 1.3.2 + org.apache.maven.surefire + surefire-junit-platform + 3.1.2 org.junit.jupiter From e2827d37cb7c3ebcd00e644400c2770ab4d90466 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Jun 2023 05:58:18 +0000 Subject: [PATCH 216/382] Bump adventure-api from 4.12.0 to 4.14.0 in /IF Bumps [adventure-api](https://github.com/KyoriPowered/adventure) from 4.12.0 to 4.14.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.12.0...v4.14.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9e0d46ab1..b4f82677c 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 1.8 true UTF-8 - 4.12.0 + 4.14.0 com.github.stefvanschie.inventoryframework From 2409542b6a36f29905fe141d96bcb48413d2d9e4 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 19 Jul 2023 20:57:14 +0200 Subject: [PATCH 217/382] Fix crafting table gui not displaying items Fixes #481 --- .../inventoryframework/gui/type/CraftingTableGui.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index 8e2df39c0..eae560d4b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -120,9 +120,6 @@ public void show(@NotNull HumanEntity humanEntity) { getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); } - //also let Bukkit know that we opened an inventory - humanEntity.openInventory(getInventory()); - humanEntity.openInventory(getInventory()); } From 1af1805db213f7d83b483f0f92db029ec5376f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Stefa=C5=84czyk?= Date: Tue, 20 Jun 2023 00:30:02 +0200 Subject: [PATCH 218/382] Pass owning plugin down to panes --- .../gui/InventoryComponent.java | 17 ++++++++++++++++- .../inventoryframework/gui/type/ChestGui.java | 4 ++-- 2 files changed, 18 insertions(+), 3 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 159a5d5f2..a40367b3e 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 @@ -7,6 +7,8 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -300,6 +302,19 @@ public InventoryComponent excludeRows(int from, int end) { * @since 0.8.0 */ public void load(@NotNull Object instance, @NotNull Element element) { + load(instance, element, JavaPlugin.getProvidingPlugin(InventoryComponent.class)); + } + + /** + * Loads the provided element's child panes onto this component. If the element contains any child panes, this will + * 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 + * @since 0.10.11 + */ + public void load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { NodeList childNodes = element.getChildNodes(); for (int innerIndex = 0; innerIndex < childNodes.getLength(); innerIndex++) { @@ -309,7 +324,7 @@ public void load(@NotNull Object instance, @NotNull Element element) { continue; } - addPane(Gui.loadPane(instance, innerItem)); + addPane(Gui.loadPane(instance, innerItem, plugin)); } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java index db5c0d6b0..9647388bd 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ChestGui.java @@ -331,9 +331,9 @@ public static ChestGui load(@NotNull Object instance, @NotNull Element element, InventoryComponent inventoryComponent = chestGui.getInventoryComponent(); if (componentElement.getTagName().equalsIgnoreCase("component")) { - inventoryComponent.load(instance, componentElement); + inventoryComponent.load(instance, componentElement, plugin); } else { - inventoryComponent.load(instance, element); + inventoryComponent.load(instance, element, plugin); } break; From 9e4e159bb587f70ca66305612c87179fa50f5725 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 26 Jul 2023 19:22:11 +0200 Subject: [PATCH 219/382] Fix plugin not being passed to all gui types and some panes --- .../inventoryframework/gui/InventoryComponent.java | 4 +++- .../stefvanschie/inventoryframework/gui/type/AnvilGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/BarrelGui.java | 4 ++-- .../stefvanschie/inventoryframework/gui/type/BeaconGui.java | 2 +- .../inventoryframework/gui/type/BlastFurnaceGui.java | 2 +- .../inventoryframework/gui/type/BrewingStandGui.java | 2 +- .../inventoryframework/gui/type/CartographyTableGui.java | 2 +- .../inventoryframework/gui/type/CraftingTableGui.java | 2 +- .../inventoryframework/gui/type/DispenserGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/DropperGui.java | 2 +- .../inventoryframework/gui/type/EnchantingTableGui.java | 2 +- .../inventoryframework/gui/type/EnderChestGui.java | 4 ++-- .../stefvanschie/inventoryframework/gui/type/FurnaceGui.java | 2 +- .../inventoryframework/gui/type/GrindstoneGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/HopperGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/MerchantGui.java | 2 +- .../inventoryframework/gui/type/ModernSmithingTableGui.java | 2 +- .../inventoryframework/gui/type/ShulkerBoxGui.java | 4 ++-- .../inventoryframework/gui/type/SmithingTableGui.java | 2 +- .../stefvanschie/inventoryframework/gui/type/SmokerGui.java | 2 +- .../inventoryframework/gui/type/StonecutterGui.java | 2 +- .../stefvanschie/inventoryframework/pane/OutlinePane.java | 2 +- .../stefvanschie/inventoryframework/pane/PatternPane.java | 2 +- .../stefvanschie/inventoryframework/pane/StaticPane.java | 2 +- 24 files changed, 29 insertions(+), 27 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 a40367b3e..fa23496f5 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 @@ -300,7 +300,9 @@ public InventoryComponent excludeRows(int from, int end) { * @param instance the instance to apply field and method references on * @param element the element to load * @since 0.8.0 + * @deprecated superseded by {@link #load(Object, Element, Plugin)} */ + @Deprecated public void load(@NotNull Object instance, @NotNull Element element) { load(instance, element, JavaPlugin.getProvidingPlugin(InventoryComponent.class)); } @@ -312,7 +314,7 @@ public void load(@NotNull Object instance, @NotNull Element element) { * @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 - * @since 0.10.11 + * @since 0.10.12 */ public void load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { NodeList childNodes = element.getChildNodes(); 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 32a968edd..7a8e875dc 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 @@ -503,7 +503,7 @@ public static AnvilGui load(@NotNull Object instance, @NotNull Element element, throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return anvilGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java index cefc4de2d..894f189d9 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BarrelGui.java @@ -267,9 +267,9 @@ public static BarrelGui load(@NotNull Object instance, @NotNull Element element, InventoryComponent inventoryComponent = barrelGui.getInventoryComponent(); if (componentElement.getTagName().equalsIgnoreCase("component")) { - inventoryComponent.load(instance, componentElement); + inventoryComponent.load(instance, componentElement, plugin); } else { - inventoryComponent.load(instance, element); + inventoryComponent.load(instance, element, plugin); } break; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java index dbe19ef54..72ed653ae 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BeaconGui.java @@ -294,7 +294,7 @@ public static BeaconGui load(@NotNull Object instance, @NotNull Element element, throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return beaconGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java index 8a21c61e3..a9f274b60 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BlastFurnaceGui.java @@ -337,7 +337,7 @@ public static BlastFurnaceGui load(@NotNull Object instance, @NotNull Element el throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return blastFurnaceGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java index 8a6b85dec..2bd166e5c 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/BrewingStandGui.java @@ -391,7 +391,7 @@ public static BrewingStandGui load(@NotNull Object instance, @NotNull Element el throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return brewingStandGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java index 1c324acee..84c547042 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CartographyTableGui.java @@ -397,7 +397,7 @@ public static CartographyTableGui load(@NotNull Object instance, @NotNull Elemen throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return cartographyTableGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java index eae560d4b..6082f4f00 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CraftingTableGui.java @@ -311,7 +311,7 @@ public static CraftingTableGui load(@NotNull Object instance, @NotNull Element e throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return craftingTableGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java index afe5ab6fa..1a306f76e 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DispenserGui.java @@ -291,7 +291,7 @@ public static DispenserGui load(@NotNull Object instance, @NotNull Element eleme throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return dispenserGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java index 0107982d0..9d45d08da 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/DropperGui.java @@ -290,7 +290,7 @@ public static DropperGui load(@NotNull Object instance, @NotNull Element element throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return dropperGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java index 879d5c76c..a49473c4f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnchantingTableGui.java @@ -340,7 +340,7 @@ public static EnchantingTableGui load(@NotNull Object instance, @NotNull Element throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return enchantingTableGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java index dab9c634c..9e4a91835 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/EnderChestGui.java @@ -268,9 +268,9 @@ public static EnderChestGui load(@NotNull Object instance, @NotNull Element elem InventoryComponent inventoryComponent = enderChestGui.getInventoryComponent(); if (componentElement.getTagName().equalsIgnoreCase("component")) { - inventoryComponent.load(instance, componentElement); + inventoryComponent.load(instance, componentElement, plugin); } else { - inventoryComponent.load(instance, element); + inventoryComponent.load(instance, element, plugin); } break; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java index cc90a4f1b..d079e2628 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/FurnaceGui.java @@ -340,7 +340,7 @@ public static FurnaceGui load(@NotNull Object instance, @NotNull Element element throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return furnaceGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java index fd1a6d7b8..b5be1f137 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/GrindstoneGui.java @@ -369,7 +369,7 @@ public static GrindstoneGui load(@NotNull Object instance, @NotNull Element elem throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return grindstoneGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java index 01f10d1b5..8136f9328 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/HopperGui.java @@ -290,7 +290,7 @@ public static HopperGui load(@NotNull Object instance, @NotNull Element element, throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return hopperGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index fbde4b5d9..5e0ee3582 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -487,7 +487,7 @@ public static MerchantGui load(@NotNull Object instance, @NotNull Element elemen throw new XMLLoadException("Unknown component name"); } - component.load(instance, nestedElement); + component.load(instance, nestedElement, plugin); } else if (tagName.equalsIgnoreCase("trade")) { NodeList tradeNodes = nestedElement.getChildNodes(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java index 7ad929fcf..f0d85a7a0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ModernSmithingTableGui.java @@ -369,7 +369,7 @@ public static ModernSmithingTableGui load(@NotNull Object instance, @NotNull Ele throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return smithingTableGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java index 9d0733a77..3bdb3f473 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/ShulkerBoxGui.java @@ -267,9 +267,9 @@ public static ShulkerBoxGui load(@NotNull Object instance, @NotNull Element elem InventoryComponent inventoryComponent = shulkerBoxGui.getInventoryComponent(); if (componentElement.getTagName().equalsIgnoreCase("component")) { - inventoryComponent.load(instance, componentElement); + inventoryComponent.load(instance, componentElement, plugin); } else { - inventoryComponent.load(instance, element); + inventoryComponent.load(instance, element, plugin); } break; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java index 9821788f3..48fdcd783 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmithingTableGui.java @@ -409,7 +409,7 @@ public static SmithingTableGui load(@NotNull Object instance, @NotNull Element e throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return smithingTableGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java index b54dea119..f77ede998 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/SmokerGui.java @@ -336,7 +336,7 @@ public static SmokerGui load(@NotNull Object instance, @NotNull Element element, throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return smokerGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java index 8f25e24b6..80359c618 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/StonecutterGui.java @@ -368,7 +368,7 @@ public static StonecutterGui load(@NotNull Object instance, @NotNull Element ele throw new XMLLoadException("Unknown component name"); } - component.load(instance, componentElement); + component.load(instance, componentElement, plugin); } return stonecutterGui; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java index 205cdf0cf..90fd53f71 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/OutlinePane.java @@ -570,7 +570,7 @@ public static OutlinePane load(@NotNull Object instance, @NotNull Element elemen if (item.getNodeName().equals("empty")) outlinePane.addItem(new GuiItem(new ItemStack(Material.AIR), plugin)); else - outlinePane.addItem(Pane.loadItem(instance, (Element) item)); + outlinePane.addItem(Pane.loadItem(instance, (Element) item, plugin)); } return outlinePane; diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java index 767e3b147..1f52f07e1 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java @@ -430,7 +430,7 @@ public static PatternPane load(@NotNull Object instance, @NotNull Element elemen throw new XMLLoadException("Binding has multiple inner tags, one expected"); } - guiItem = Pane.loadItem(instance, (Element) guiItemNode); + guiItem = Pane.loadItem(instance, (Element) guiItemNode, plugin); } //guaranteed to only be a single code point 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 ce3511da6..1661708a0 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 @@ -408,7 +408,7 @@ public static StaticPane load(@NotNull Object instance, @NotNull Element element Element child = (Element) item; - staticPane.addItem(Pane.loadItem(instance, child), Slot.deserialize(child)); + staticPane.addItem(Pane.loadItem(instance, child, plugin), Slot.deserialize(child)); } return staticPane; From d2c35afab93dc94747e7040a3e4d81a796481c95 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 05:44:09 +0000 Subject: [PATCH 220/382] Bump maven-shade-plugin from 3.4.1 to 3.5.0 in /IF Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.1 to 3.5.0. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.1...maven-shade-plugin-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 0f240de0c..0841b1ddd 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -230,7 +230,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.4.1 + 3.5.0 package From b772656a64a4609e4f2012b5ba3755ad8d93ab10 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 27 Jul 2023 17:29:14 +0200 Subject: [PATCH 221/382] Fix setting cursor in close event not working Fixes #512 --- .../inventoryframework/gui/GuiListener.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index e2efce85e..0acf686e3 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -351,14 +351,8 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { //due to a client issue off-hand items appear as ghost items, this updates the off-hand correctly client-side playerInventory.setItemInOffHand(playerInventory.getItemInOffHand()); - if (!gui.isUpdating()) {//this is a hack to remove items correctly when players press the x button in a beacon - Bukkit.getScheduler().runTask(this.plugin, () -> { - gui.callOnClose(event); - - if (humanEntity.getOpenInventory().getTopInventory() instanceof PlayerInventory) { - humanEntity.closeInventory(); - } - }); + if (!gui.isUpdating()) { + gui.callOnClose(event); event.getInventory().clear(); //clear inventory to prevent items being put back From 88a31623d361124c17fb3523d9409017a9d069a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:12:10 +0000 Subject: [PATCH 222/382] Bump paper-nms-maven-plugin from 1.3.2 to 1.4.1 in /nms/1_19_3 Bumps paper-nms-maven-plugin from 1.3.2 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_19_3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 87beeced1..511b4bf79 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.3.2 + 1.4.1 process-classes From e740e483ba93ef4249f925c5cde9c3cbec0603b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:12:38 +0000 Subject: [PATCH 223/382] Bump paper-nms-maven-plugin from 1.3.2 to 1.4.1 in /nms/1_18_1 Bumps paper-nms-maven-plugin from 1.3.2 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_18_1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 329c64b1b..5b258a71d 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.3.2 + 1.4.1 process-classes From 0eae7b6011f6a094dd2d6e2c9658c28033bd70f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:23:18 +0000 Subject: [PATCH 224/382] Bump paper-nms-maven-plugin from 1.3.2 to 1.4.1 in /nms/1_17_1 Bumps paper-nms-maven-plugin from 1.3.2 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_17_1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index af62af186..99a543afe 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.3.2 + 1.4.1 process-classes From 89c606232a60ccdb1906dd3981a9060dd76e5011 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:27:36 +0000 Subject: [PATCH 225/382] Bump paper-nms-maven-plugin from 1.3.2 to 1.4.1 in /nms/1_17_0 Bumps paper-nms-maven-plugin from 1.3.2 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_17_0/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index ddafa0bd8..629c471c9 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.3.2 + 1.4.1 process-classes From 6a550bd652ccc84173ccb4328db5a6483c616116 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:37:16 +0000 Subject: [PATCH 226/382] Bump paper-nms-maven-plugin from 1.3.2 to 1.4.1 in /nms/1_18_2 Bumps paper-nms-maven-plugin from 1.3.2 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_18_2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 5280a9632..9d40f2898 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.3.2 + 1.4.1 process-classes From 769ab8f3ebea11a166f0a4f410cf61572909ada4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:44:17 +0000 Subject: [PATCH 227/382] Bump paper-nms-maven-plugin from 1.3 to 1.4.1 in /nms/1_20 Bumps paper-nms-maven-plugin from 1.3 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_20/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20/pom.xml b/nms/1_20/pom.xml index 4e444f33a..4971afa5d 100644 --- a/nms/1_20/pom.xml +++ b/nms/1_20/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.3 + 1.4.1 process-classes From 88560a5eb491e3130c17ca766d1993628da2db7c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:45:49 +0000 Subject: [PATCH 228/382] Bump paper-nms-maven-plugin from 1.3.2 to 1.4.1 in /nms/1_19_0 Bumps paper-nms-maven-plugin from 1.3.2 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_19_0/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index f9ee45538..5a10a9f0a 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.3.2 + 1.4.1 process-classes From 5ddbcac877eb56542af041640576576698669212 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 05:46:48 +0000 Subject: [PATCH 229/382] Bump paper-nms-maven-plugin from 1.3 to 1.4.1 Bumps paper-nms-maven-plugin from 1.3 to 1.4.1. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_18_0/pom.xml | 2 +- nms/1_19_1/pom.xml | 2 +- nms/1_19_2/pom.xml | 2 +- nms/1_19_4/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index b089dd394..5518d0086 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.3.2 + 1.4.1 process-classes diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index a0908474c..d26681873 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.3.2 + 1.4.1 process-classes diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index bc90c27ce..4a93f0eb3 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.3.2 + 1.4.1 process-classes diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 495e7a6d3..8b823d780 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.3.2 + 1.4.1 process-classes From 6234456c7b4e8104b6d34192511d559e0b5e9425 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 18 Aug 2023 20:37:21 +0200 Subject: [PATCH 230/382] Fix toggle button click handlers not always firing Fixes #322 --- .../inventoryframework/pane/component/ToggleButton.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index d88b0eb7d..39b47c538 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -325,8 +325,8 @@ public boolean click(@NotNull Gui gui, @NotNull InventoryComponent inventoryComp callOnClick(event); - int newX = paneOffsetX + x; - int newY = paneOffsetY + y; + int newX = paneOffsetX + xPosition; + int newY = paneOffsetY + yPosition; /* Since we've toggled before, the click for the panes should be swapped around. If we haven't toggled due to From 2148ac93370335277d1c96ff56f73ff6db1b5425 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jul 2023 05:08:55 +0000 Subject: [PATCH 231/382] Bump org.junit.jupiter:junit-jupiter-engine in /nms/1_19_0 Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.9.3 to 5.10.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.3...r5.10.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b4f82677c..9503bddb2 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ org.junit.jupiter junit-jupiter-engine - 5.9.3 + 5.10.0 From 6cd6dd5f6067e4861eea4e3b89fd85bf397eceb1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jul 2023 05:15:07 +0000 Subject: [PATCH 232/382] Bump org.junit.jupiter:junit-jupiter-engine from 5.9.3 to 5.10.0 in /IF Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.9.3 to 5.10.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.3...r5.10.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 0841b1ddd..5c826cf86 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -223,7 +223,7 @@ org.junit.jupiter junit-jupiter-engine - 5.9.3 + 5.10.0 From b70f3902f26eee2d671fea54df8748dde34e5bb3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 9 Sep 2023 20:03:54 +0200 Subject: [PATCH 233/382] Match junit api version --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 5c826cf86..72e26171e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -166,7 +166,7 @@ org.junit.jupiter junit-jupiter-api - 5.9.3 + 5.10.0 test From 3140721b2456a2fa2566f64fd2a86ba7a1c57d52 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 24 Oct 2023 20:21:58 +0200 Subject: [PATCH 234/382] Add version 1.20.2 support --- IF/pom.xml | 8 +- .../util/version/Version.java | 32 +- .../util/version/VersionMatcher.java | 48 ++- nms/{1_20 => 1_20_0-1}/pom.xml | 2 +- .../nms/v1_20_0_1}/AnvilInventoryImpl.java | 6 +- .../nms/v1_20_0_1}/BeaconInventoryImpl.java | 2 +- .../CartographyTableInventoryImpl.java | 6 +- .../EnchantingTableInventoryImpl.java | 4 +- .../v1_20_0_1}/GrindstoneInventoryImpl.java | 6 +- .../nms/v1_20_0_1}/MerchantInventoryImpl.java | 2 +- .../SmithingTableInventoryImpl.java | 6 +- .../v1_20_0_1}/StonecutterInventoryImpl.java | 4 +- .../v1_20_0_1}/util/CustomInventoryUtil.java | 2 +- .../nms/v1_20_0_1}/util/TextHolderUtil.java | 2 +- nms/1_20_2/pom.xml | 59 +++ .../nms/v1_20_2/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_20_2/BeaconInventoryImpl.java | 200 +++++++++++ .../CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_20_2/EnchantingTableInventoryImpl.java | 218 ++++++++++++ .../nms/v1_20_2/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_20_2/MerchantInventoryImpl.java | 97 +++++ .../v1_20_2/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_20_2/StonecutterInventoryImpl.java | 221 ++++++++++++ .../nms/v1_20_2/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_20_2/util/TextHolderUtil.java | 65 ++++ pom.xml | 3 +- 26 files changed, 2035 insertions(+), 44 deletions(-) rename nms/{1_20 => 1_20_0-1}/pom.xml (98%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/AnvilInventoryImpl.java (97%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/BeaconInventoryImpl.java (99%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/CartographyTableInventoryImpl.java (96%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/EnchantingTableInventoryImpl.java (98%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/GrindstoneInventoryImpl.java (96%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/MerchantInventoryImpl.java (98%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/SmithingTableInventoryImpl.java (98%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/StonecutterInventoryImpl.java (98%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/util/CustomInventoryUtil.java (94%) rename nms/{1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20 => 1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1}/util/TextHolderUtil.java (96%) create mode 100644 nms/1_20_2/pom.xml create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/AnvilInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/BeaconInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/CartographyTableInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/EnchantingTableInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/GrindstoneInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/MerchantInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/SmithingTableInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/StonecutterInventoryImpl.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/CustomInventoryUtil.java create mode 100644 nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index 72e26171e..027821de8 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -133,7 +133,13 @@ com.github.stefvanschie.inventoryframework - 1_20 + 1_20_0-1 + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + 1_20_2 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index c7e658baf..1761085cc 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -121,16 +121,36 @@ public enum Version { V1_19_4, /** - * Version 1.20 + * Version 1.20.0 - 1.20.1 * * @since 0.10.10 */ - V1_20; + V1_20_0_1, + + /** + * Version 1.20.2 + * + * @since 0.10.12 + */ + V1_20_2; /** * A collection of versions on which modern smithing tables are available. */ - private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of(V1_19_4, V1_20); + private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of(V1_19_4, V1_20_0_1, V1_20_2); + + /** + * A collection of versions on which legacy smithing tables ae available. + */ + @NotNull + private static final Collection<@NotNull Version> LEGACY_SMITHING_TABLE_VERSIONS = EnumSet.of( + V1_14, + V1_15, + V1_16_1, V1_16_2_3, V1_16_4_5, + V1_17_0, V1_17_1, + V1_18_0, V1_18_1, V1_18_2, + V1_19_0, V1_19_1, V1_19_2, V1_19_3, V1_19_4 + ); /** * Checks whether modern smithing tables exist on this version. Returns true if they do, otherwise false. @@ -150,7 +170,7 @@ boolean existsModernSmithingTable() { */ @Contract(pure = true) boolean existsLegacySmithingTable() { - return this != V1_20; + return LEGACY_SMITHING_TABLE_VERSIONS.contains(this); } /** @@ -206,7 +226,9 @@ public static Version getVersion() { return V1_19_4; case "1.20": case "1.20.1": - return V1_20; + return V1_20_0_1; + case "1.20.2": + return V1_20_2; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 0241096c5..490b3ebb0 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 @@ -305,8 +305,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -339,8 +341,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -373,8 +377,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -407,8 +413,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -441,8 +449,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -475,14 +485,18 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.MerchantInventoryImpl.class); - MERCHANT_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -543,7 +557,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_20, - com.github.stefvanschie.inventoryframework.nms.v1_20.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20_0_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20_2, + com.github.stefvanschie.inventoryframework.nms.v1_20_2.StonecutterInventoryImpl.class); } } diff --git a/nms/1_20/pom.xml b/nms/1_20_0-1/pom.xml similarity index 98% rename from nms/1_20/pom.xml rename to nms/1_20_0-1/pom.xml index 4971afa5d..7adb9c057 100644 --- a/nms/1_20/pom.xml +++ b/nms/1_20_0-1/pom.xml @@ -10,7 +10,7 @@ ../../pom.xml - 1_20 + 1_20_0-1 true diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/AnvilInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/AnvilInventoryImpl.java similarity index 97% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/AnvilInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/AnvilInventoryImpl.java index 366009293..e43effd2f 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/AnvilInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/AnvilInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/BeaconInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/BeaconInventoryImpl.java similarity index 99% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/BeaconInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/BeaconInventoryImpl.java index 7a473807e..d201fbb12 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/BeaconInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/BeaconInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import net.minecraft.core.NonNullList; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/CartographyTableInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/CartographyTableInventoryImpl.java similarity index 96% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/CartographyTableInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/CartographyTableInventoryImpl.java index 25a539e7e..7b0d190a5 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/CartographyTableInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/CartographyTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/EnchantingTableInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/EnchantingTableInventoryImpl.java similarity index 98% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/EnchantingTableInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/EnchantingTableInventoryImpl.java index 2a0d9cfe8..e24ad5b1c 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/EnchantingTableInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/EnchantingTableInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/GrindstoneInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/GrindstoneInventoryImpl.java similarity index 96% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/GrindstoneInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/GrindstoneInventoryImpl.java index 170bf7a3a..29a424b86 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/GrindstoneInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/GrindstoneInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/MerchantInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/MerchantInventoryImpl.java similarity index 98% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/MerchantInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/MerchantInventoryImpl.java index e90734ae8..096076cd3 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/MerchantInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/MerchantInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import net.minecraft.server.level.ServerPlayer; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/SmithingTableInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/SmithingTableInventoryImpl.java similarity index 98% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/SmithingTableInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/SmithingTableInventoryImpl.java index ee6be3325..534c50780 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/SmithingTableInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/SmithingTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/StonecutterInventoryImpl.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/StonecutterInventoryImpl.java similarity index 98% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/StonecutterInventoryImpl.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/StonecutterInventoryImpl.java index cc39b3641..d74c6de38 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/StonecutterInventoryImpl.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/StonecutterInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/CustomInventoryUtil.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/CustomInventoryUtil.java similarity index 94% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/CustomInventoryUtil.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/CustomInventoryUtil.java index c67c18099..0cae2b267 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/CustomInventoryUtil.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/CustomInventoryUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20.util; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; diff --git a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/TextHolderUtil.java b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/TextHolderUtil.java similarity index 96% rename from nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/TextHolderUtil.java rename to nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/TextHolderUtil.java index da626ee4f..c99a391ea 100644 --- a/nms/1_20/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20/util/TextHolderUtil.java +++ b/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20.util; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml new file mode 100644 index 000000000..fb773b0f2 --- /dev/null +++ b/nms/1_20_2/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.12-SNAPSHOT + ../../pom.xml + + + 1_20_2 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.20.2-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.1 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + \ No newline at end of file diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/AnvilInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/AnvilInventoryImpl.java new file mode 100644 index 000000000..75581419a --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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; + +/** + * Internal anvil inventory for 1.20.2 + * + * @since 0.10.12 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.12 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.12 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.12 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.12 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.12 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.12 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/BeaconInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/BeaconInventoryImpl.java new file mode 100644 index 000000000..601e1f310 --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/BeaconInventoryImpl.java @@ -0,0 +1,200 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R2.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.20.2 + * + * @since 0.10.12 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.12 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.12 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("s"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/CartographyTableInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..a8362db7b --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R2.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.20.2 + * + * @since 0.10.12 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.12 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.12 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/EnchantingTableInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..2191c7b2e --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/EnchantingTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R2.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.20.2 + * + * @since 0.10.12 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.12 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.12 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("o"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/GrindstoneInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..c915baccb --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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; + +/** + * Internal grindstone inventory for 1.20.2 + * + * @since 0.10.12 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.12 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.12 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.12 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.12 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/MerchantInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/MerchantInventoryImpl.java new file mode 100644 index 000000000..5302ffaff --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_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.20.2 + * + * @since 0.10.12 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.12 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/SmithingTableInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..73e6ce304 --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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; + +/** + * Internal smithing table inventory for 1.20.2. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.12 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.12 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.12 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.12 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.12 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.12 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.12 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/StonecutterInventoryImpl.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/StonecutterInventoryImpl.java new file mode 100644 index 000000000..46f13264b --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/StonecutterInventoryImpl.java @@ -0,0 +1,221 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R2.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.20.2 + * + * @since 0.10.12 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.12 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.12 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/CustomInventoryUtil.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/CustomInventoryUtil.java new file mode 100644 index 000000000..66f18dbff --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.12 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.12 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/TextHolderUtil.java b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/TextHolderUtil.java new file mode 100644 index 000000000..d1bc6fe98 --- /dev/null +++ b/nms/1_20_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_2/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_2.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.network.chat.Component; +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.12 + */ +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.12 + */ + @NotNull + @Contract(pure = true) + public static Component 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.12 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.12 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 9503bddb2..4eafd918e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,8 @@ IF nms/abstraction + nms/1_20_2 + nms/1_20_0-1 nms/1_19_4 nms/1_19_3 nms/1_19_2 @@ -23,7 +25,6 @@ nms/1_15 nms/1_14 adventure-support - nms/1_20 From a16e56593effc809ceb0009622d46c4582f4c1a1 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 24 Oct 2023 20:46:38 +0200 Subject: [PATCH 235/382] V 0.10.12 --- .github/dependabot.yml | 6 +++++- .github/workflows/auto-deploy.yml | 3 ++- .github/workflows/maven.yml | 3 ++- IF/pom.xml | 2 +- README.md | 7 ++++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0-1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 25 files changed, 34 insertions(+), 27 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c5fcaa429..f7f6bb734 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -73,7 +73,11 @@ updates: schedule: interval: "daily" - package-ecosystem: "maven" - directory: "/nms/1_20" + directory: "/nms/1_20_0-1" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_20_2" schedule: interval: "daily" - package-ecosystem: "maven" diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index c6cc10730..7194aefdc 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -71,7 +71,8 @@ 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-1 + mvn paper-nms:init -pl nms/1_20_2 - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import - name: Automatically deploy the project diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fbd9b627c..a18d167e1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -77,6 +77,7 @@ 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-1 + mvn paper-nms:init -pl nms/1_20_2 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 027821de8..eaef30f2c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index 5402db49d..f3df45043 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.11 + 0.10.12 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.11' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.12' // ... } ``` @@ -136,7 +136,8 @@ 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 +mvn paper-nms:init -pl nms/1_20_0-1 +mvn paper-nms:init -pl nms/1_20_2 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 58aaed12f..9a9b7b67d 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 0002dac07..ef280314f 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 27d754fc4..9f9cf68fb 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 2d63747e7..1c8ad4cc8 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 1d10dd5a3..335872722 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 2fde710dd..61b244c46 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 629c471c9..1f1b7d7ef 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 99a543afe..f7d51390c 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 5518d0086..c9776c1b9 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 5b258a71d..9f911b82a 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 9d40f2898..85b859b8b 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 5a10a9f0a..bc82b2122 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index d26681873..e9a16ff40 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 4a93f0eb3..cc9ce3f31 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 511b4bf79..1aa6a5678 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 8b823d780..2269dcfa3 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/nms/1_20_0-1/pom.xml b/nms/1_20_0-1/pom.xml index 7adb9c057..acfde03c1 100644 --- a/nms/1_20_0-1/pom.xml +++ b/nms/1_20_0-1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index fb773b0f2..b19377cd3 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 7b6a0c75a..a77d626c9 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12-SNAPSHOT + 0.10.12 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 4eafd918e..719e9b8d0 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12-SNAPSHOT + 0.10.12 pom IF From f001da253a3af069684ecbb62f325cb2a2cf16a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 05:02:30 +0000 Subject: [PATCH 236/382] Bump org.apache.maven.plugins:maven-javadoc-plugin in /nms/1_14 Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.5.0 to 3.6.3. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.5.0...maven-javadoc-plugin-3.6.3) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 719e9b8d0..5154bfe16 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 + 3.6.3 attach-javadocs From 0acc2359950d41b5fdc9cd72226e76fa11e1fddf Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 11 Dec 2023 20:38:43 +0100 Subject: [PATCH 237/382] Bump to 0.10.13-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0-1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index eaef30f2c..c27aef2f3 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 9a9b7b67d..e2f332519 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index ef280314f..78db7c895 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 9f9cf68fb..9c6c66d92 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 1c8ad4cc8..9f43755b6 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 335872722..56c4e3202 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 61b244c46..1a4071e5d 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 1f1b7d7ef..15b9d01af 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index f7d51390c..e7aa94cab 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index c9776c1b9..fd2160dfd 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 9f911b82a..333f03717 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 85b859b8b..48fcec2c9 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index bc82b2122..fca44cad1 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index e9a16ff40..3c8255a16 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index cc9ce3f31..7438bc921 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 1aa6a5678..cb6539c2d 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 2269dcfa3..10693d95c 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20_0-1/pom.xml b/nms/1_20_0-1/pom.xml index acfde03c1..91fa043ab 100644 --- a/nms/1_20_0-1/pom.xml +++ b/nms/1_20_0-1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index b19377cd3..e818dc51e 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index a77d626c9..2d1cf424f 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 From 11564e707c3d81b2cf3a22dfa223b0aa51f6c05b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 11 Dec 2023 20:38:43 +0100 Subject: [PATCH 238/382] Bump to 0.10.13-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0-1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index eaef30f2c..c27aef2f3 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 9a9b7b67d..e2f332519 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index ef280314f..78db7c895 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 9f9cf68fb..9c6c66d92 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 1c8ad4cc8..9f43755b6 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 335872722..56c4e3202 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 61b244c46..1a4071e5d 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 1f1b7d7ef..15b9d01af 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index f7d51390c..e7aa94cab 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index c9776c1b9..fd2160dfd 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 9f911b82a..333f03717 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 85b859b8b..48fcec2c9 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index bc82b2122..fca44cad1 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index e9a16ff40..3c8255a16 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index cc9ce3f31..7438bc921 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 1aa6a5678..cb6539c2d 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 2269dcfa3..10693d95c 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20_0-1/pom.xml b/nms/1_20_0-1/pom.xml index acfde03c1..91fa043ab 100644 --- a/nms/1_20_0-1/pom.xml +++ b/nms/1_20_0-1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index b19377cd3..e818dc51e 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index a77d626c9..2d1cf424f 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.12 + 0.10.13-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 719e9b8d0..741e21b0b 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.12 + 0.10.13-SNAPSHOT pom IF From 076a9816750a5cab03b94d69e582f5aa6aa687ce Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 21 Dec 2023 20:31:44 +0100 Subject: [PATCH 239/382] Add 1.20.3 support --- .github/dependabot.yml | 4 + .github/workflows/auto-deploy.yml | 1 + .github/workflows/maven.yml | 1 + IF/pom.xml | 6 + .../util/version/Version.java | 16 +- .../util/version/VersionMatcher.java | 16 + nms/1_20_3/pom.xml | 67 ++++ .../nms/v1_20_3/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_20_3/BeaconInventoryImpl.java | 200 +++++++++++ .../CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_20_3/EnchantingTableInventoryImpl.java | 218 ++++++++++++ .../nms/v1_20_3/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_20_3/MerchantInventoryImpl.java | 97 +++++ .../v1_20_3/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_20_3/StonecutterInventoryImpl.java | 221 ++++++++++++ .../nms/v1_20_3/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_20_3/util/TextHolderUtil.java | 65 ++++ pom.xml | 1 + 18 files changed, 1997 insertions(+), 2 deletions(-) create mode 100644 nms/1_20_3/pom.xml create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java create mode 100644 nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f7f6bb734..ac3ce90e6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -80,6 +80,10 @@ updates: directory: "/nms/1_20_2" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_20_3" + schedule: + interval: "daily" - package-ecosystem: "maven" directory: "/nms/abstraction" schedule: diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 7194aefdc..d6ac6e767 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -73,6 +73,7 @@ jobs: mvn paper-nms:init -pl nms/1_19_4 mvn paper-nms:init -pl nms/1_20_0-1 mvn paper-nms:init -pl nms/1_20_2 + mvn paper-nms:init -pl nms/1_20_3 - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import - name: Automatically deploy the project diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a18d167e1..0ff2564d0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -79,5 +79,6 @@ jobs: mvn paper-nms:init -pl nms/1_19_4 mvn paper-nms:init -pl nms/1_20_0-1 mvn paper-nms:init -pl nms/1_20_2 + mvn paper-nms:init -pl nms/1_20_3 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index c27aef2f3..28c7f840c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -143,6 +143,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_20_3 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 1761085cc..56d54efab 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -132,12 +132,22 @@ public enum Version { * * @since 0.10.12 */ - V1_20_2; + V1_20_2, + + /** + * Version 1.20.3 + * + * @since 0.10.13 + */ + V1_20_3; /** * A collection of versions on which modern smithing tables are available. */ - private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of(V1_19_4, V1_20_0_1, V1_20_2); + private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( + V1_19_4, + V1_20_0_1, V1_20_2, V1_20_3 + ); /** * A collection of versions on which legacy smithing tables ae available. @@ -229,6 +239,8 @@ public static Version getVersion() { return V1_20_0_1; case "1.20.2": return V1_20_2; + case "1.20.3": + return V1_20_3; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 490b3ebb0..7cd5015a8 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 @@ -309,6 +309,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -345,6 +347,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -381,6 +385,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -417,6 +423,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -453,6 +461,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -489,6 +499,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, @@ -497,6 +509,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -561,5 +575,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20_3, + com.github.stefvanschie.inventoryframework.nms.v1_20_3.StonecutterInventoryImpl.class); } } diff --git a/nms/1_20_3/pom.xml b/nms/1_20_3/pom.xml new file mode 100644 index 000000000..c44e8825f --- /dev/null +++ b/nms/1_20_3/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.13-SNAPSHOT + ../../pom.xml + + + 1_20_3 + + + true + + + + + + sonatype-oss-snapshots1 + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.20.3-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.1 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + \ No newline at end of file diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java new file mode 100644 index 000000000..9f5691dce --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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 anvil inventory for 1.20.3 + * + * @since 0.10.13 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.13 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.13 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.13 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.13 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.13 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.13 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java new file mode 100644 index 000000000..154a99f41 --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java @@ -0,0 +1,200 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.3 + * + * @since 0.10.13 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.13 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.13 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("s"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..db1f66cca --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.3 + * + * @since 0.10.13 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.13 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.13 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..7f536a9de --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.3 + * + * @since 0.10.13 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.13 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.13 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("o"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..f109eb023 --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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 grindstone inventory for 1.20.3 + * + * @since 0.10.13 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.13 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.13 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.13 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.13 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java new file mode 100644 index 000000000..da6be654d --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_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.20.3 + * + * @since 0.10.13 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.13 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..3513d80a3 --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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.20.3. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.13 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.13 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.13 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.13 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.13 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.13 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.13 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java new file mode 100644 index 000000000..eef0dc207 --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java @@ -0,0 +1,221 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_3.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.3 + * + * @since 0.10.13 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.13 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.13 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java new file mode 100644 index 000000000..3a6cdb8d1 --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_3.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.13 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java new file mode 100644 index 000000000..f5cbc26ee --- /dev/null +++ b/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_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.network.chat.Component; +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.13 + */ +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.13 + */ + @NotNull + @Contract(pure = true) + public static Component 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.13 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.13 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 741e21b0b..b9dc16ee0 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_20_3 nms/1_20_2 nms/1_20_0-1 nms/1_19_4 From 5f98903e7bc2a43bd4834d44b67f545c4dd25036 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:34:52 +0000 Subject: [PATCH 240/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_20_3 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.1.2 to 3.2.3. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b9dc16ee0..9f7be6497 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.1.2 + 3.2.3 org.junit.jupiter From abb0be9d8b951f9891bc2ee1603b1ac7ecd16f6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:35:03 +0000 Subject: [PATCH 241/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_20_3 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.2 to 3.2.3. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.2...surefire-3.2.3) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b9dc16ee0..c62dbfb02 100644 --- a/pom.xml +++ b/pom.xml @@ -113,12 +113,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.3 org.apache.maven.surefire surefire-junit-platform - 3.1.2 + 3.2.3 org.junit.jupiter From a70a62cbfec39231f2f3c1ed4d8dd805ebc5d685 Mon Sep 17 00:00:00 2001 From: Gregor Suurvarik <55884713+GregorSomething@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:01:25 +0200 Subject: [PATCH 242/382] Update SkullUtil.java - Minecraft 1.20.2 "Profile name must not be null" --- .../github/stefvanschie/inventoryframework/util/SkullUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b28b82bc4..880ec0fe5 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 @@ -51,7 +51,7 @@ 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(), null); + GameProfile profile = new GameProfile(UUID.randomUUID(), "RandomName"); // Name is not null to avoid errors. 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))); From 950ea5a154099859fa2e7516b374827be31ff377 Mon Sep 17 00:00:00 2001 From: Gregor Suurvarik <55884713+GregorSomething@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:02:21 +0200 Subject: [PATCH 243/382] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f3df45043..1bcdcb5dc 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ 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_0-1 mvn paper-nms:init -pl nms/1_20_2 +mvn paper-nms:init -pl nms/1_20_3 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. From 287c93bc1828d58fad453bd8564bd1d4b5e9e092 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 4 Jan 2024 21:10:56 +0100 Subject: [PATCH 244/382] Add crafter gui --- IF/pom.xml | 2 +- .../gui/type/CrafterGui.java | 326 ++++++++++++++++++ 2 files changed, 327 insertions(+), 1 deletion(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CrafterGui.java diff --git a/IF/pom.xml b/IF/pom.xml index 28c7f840c..a57f7e582 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -152,7 +152,7 @@ org.spigotmc spigot-api - 1.19.4-R0.1-SNAPSHOT + 1.20.3-R0.1-SNAPSHOT provided diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CrafterGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CrafterGui.java new file mode 100644 index 000000000..f661d6880 --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/CrafterGui.java @@ -0,0 +1,326 @@ +package com.github.stefvanschie.inventoryframework.gui.type; + +import com.github.stefvanschie.inventoryframework.HumanEntityCache; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.InventoryBased; +import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; +import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * Represents a gui in the form of a crafter. + * + * @since 0.10.13 + */ +public class CrafterGui extends NamedGui implements InventoryBased { + + /** + * Represents the inventory component for the input + */ + @NotNull + private InventoryComponent inputComponent = new InventoryComponent(3, 3); + + /** + * Represents the inventory component for the player inventory + */ + @NotNull + private InventoryComponent playerInventoryComponent = new InventoryComponent(9, 4); + + /** + * Constructs a new crafter gui. + * + * @param title the title/name of this gui + * @since 0.10.13 + */ + public CrafterGui(@NotNull String title) { + super(title); + } + + /** + * Constructs a new crafter gui. + * + * @param title the title/name of this gui + * @since 0.10.13 + */ + public CrafterGui(@NotNull TextHolder title) { + super(title); + } + + /** + * Constructs a new crafter gui for the given {@code plugin}. + * + * @param title the title/name of this gui + * @param plugin the owning plugin of this gui + * @see #CrafterGui(String) + * @since 0.10.13 + */ + public CrafterGui(@NotNull String title, @NotNull Plugin plugin) { + super(title, plugin); + } + + /** + * Constructs a new crafter gui for the given {@code plugin}. + * + * @param title the title/name of this gui + * @param plugin the owning plugin of this gui + * @see #CrafterGui(TextHolder) + * @since 0.10.13 + */ + public CrafterGui(@NotNull TextHolder title, @NotNull Plugin plugin) { + super(title, plugin); + } + + @Override + public void show(@NotNull HumanEntity humanEntity) { + if (isDirty()) { + this.inventory = createInventory(); + markChanges(); + } + + getInventory().clear(); + + getInputComponent().display(getInventory(), 0); + getPlayerInventoryComponent().display(); + + if (getPlayerInventoryComponent().hasItem()) { + HumanEntityCache humanEntityCache = getHumanEntityCache(); + + if (!humanEntityCache.contains(humanEntity)) { + humanEntityCache.storeAndClear(humanEntity); + } + + getPlayerInventoryComponent().placeItems(humanEntity.getInventory(), 0); + } + + humanEntity.openInventory(getInventory()); + } + + @NotNull + @Contract(pure = true) + @Override + public CrafterGui copy() { + CrafterGui gui = new CrafterGui(getTitleHolder(), super.plugin); + + gui.inputComponent = inputComponent.copy(); + gui.playerInventoryComponent = playerInventoryComponent.copy(); + + gui.setOnTopClick(this.onTopClick); + gui.setOnBottomClick(this.onBottomClick); + gui.setOnGlobalClick(this.onGlobalClick); + gui.setOnOutsideClick(this.onOutsideClick); + gui.setOnClose(this.onClose); + + return gui; + } + + @Override + public void click(@NotNull InventoryClickEvent event) { + int rawSlot = event.getRawSlot(); + + if (rawSlot >= 0 && rawSlot <= 8) { + getInputComponent().click(this, event, rawSlot); + } else { + getPlayerInventoryComponent().click(this, event, rawSlot - 9); + } + } + + @NotNull + @Override + public Inventory getInventory() { + if (this.inventory == null) { + this.inventory = createInventory(); + } + + return inventory; + } + + @Contract(pure = true) + @Override + public boolean isPlayerInventoryUsed() { + return getPlayerInventoryComponent().hasItem(); + } + + @NotNull + @Contract(pure = true) + @Override + public Inventory createInventory() { + //noinspection UnstableApiUsage + Inventory inventory = getTitleHolder().asInventoryTitle(this, InventoryType.CRAFTER); + + addInventory(inventory, this); + + return inventory; + } + + @Contract(pure = true) + @Override + public int getViewerCount() { + return getInventory().getViewers().size(); + } + + @NotNull + @Contract(pure = true) + @Override + public List getViewers() { + return new ArrayList<>(getInventory().getViewers()); + } + + /** + * Gets the inventory component representing the input. + * + * @return the input component + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + public InventoryComponent getInputComponent() { + return inputComponent; + } + + /** + * Gets the inventory component representing the player inventory. + * + * @return the player inventory component + * @since 0.10.13 + */ + @NotNull + @Contract(pure = true) + public InventoryComponent getPlayerInventoryComponent() { + return playerInventoryComponent; + } + + /** + * Loads a crafter gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @param plugin the plugin that will be the owner of the created gui + * @return the loaded crafter gui + * @see #load(Object, InputStream) + * @since 0.10.13 + */ + @Nullable + @Contract(pure = true) + public static CrafterGui load(@NotNull Object instance, @NotNull InputStream inputStream, + @NotNull Plugin plugin) { + try { + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); + Element documentElement = document.getDocumentElement(); + + documentElement.normalize(); + + return load(instance, documentElement, plugin); + } catch (SAXException | ParserConfigurationException | IOException e) { + e.printStackTrace(); + return null; + } + } + + /** + * Loads a crafter gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @param plugin the plugin that will be the owner of the created gui + * @return the loaded crafter gui + * @since 0.10.13 + */ + @NotNull + public static CrafterGui load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { + if (!element.hasAttribute("title")) { + throw new XMLLoadException("Provided XML element's gui tag doesn't have the mandatory title attribute set"); + } + + CrafterGui crafterGui = new CrafterGui(element.getAttribute("title"), plugin); + crafterGui.initializeOrThrow(instance, element); + + if (element.hasAttribute("populate")) { + return crafterGui; + } + + NodeList childNodes = element.getChildNodes(); + + for (int index = 0; index < childNodes.getLength(); index++) { + Node item = childNodes.item(index); + + if (item.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + Element componentElement = (Element) item; + + if (!componentElement.getTagName().equalsIgnoreCase("component")) { + throw new XMLLoadException("Gui element contains non-component tags"); + } + + if (!componentElement.hasAttribute("name")) { + throw new XMLLoadException("Component tag does not have a name specified"); + } + + InventoryComponent component; + + switch (componentElement.getAttribute("name")) { + case "input": + component = crafterGui.getInputComponent(); + break; + case "player-inventory": + component = crafterGui.getPlayerInventoryComponent(); + break; + default: + throw new XMLLoadException("Unknown component name"); + } + + component.load(instance, componentElement, plugin); + } + + return crafterGui; + } + + /** + * Loads a crafter gui from an XML file. + * + * @param instance the instance on which to reference fields and methods + * @param inputStream the input stream containing the XML data + * @return the loaded crafter gui + * @since 0.10.13 + */ + @Nullable + @Contract(pure = true) + public static CrafterGui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(CrafterGui.class)); + } + + /** + * Loads a crafter gui from the specified element, applying code references to the provided instance. + * + * @param instance the instance on which to reference fields and methods + * @param element the element to load the gui from + * @return the loaded crafting table gui + * @since 0.10.13 + */ + @NotNull + public static CrafterGui load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(CrafterGui.class)); + } +} From 3ba855838ddc9a0745e579516c416c481078d68d Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 5 Jan 2024 21:05:45 +0100 Subject: [PATCH 245/382] Add 1.20.4 support --- IF/pom.xml | 2 +- .../inventoryframework/util/version/Version.java | 9 +++++---- .../util/version/VersionMatcher.java | 16 ++++++++-------- nms/{1_20_3 => 1_20_3-4}/pom.xml | 2 +- .../nms/v1_20_3/AnvilInventoryImpl.java | 0 .../nms/v1_20_3/BeaconInventoryImpl.java | 0 .../v1_20_3/CartographyTableInventoryImpl.java | 0 .../v1_20_3/EnchantingTableInventoryImpl.java | 0 .../nms/v1_20_3/GrindstoneInventoryImpl.java | 0 .../nms/v1_20_3/MerchantInventoryImpl.java | 0 .../nms/v1_20_3/SmithingTableInventoryImpl.java | 0 .../nms/v1_20_3/StonecutterInventoryImpl.java | 0 .../nms/v1_20_3/util/CustomInventoryUtil.java | 0 .../nms/v1_20_3/util/TextHolderUtil.java | 0 pom.xml | 2 +- 15 files changed, 16 insertions(+), 15 deletions(-) rename nms/{1_20_3 => 1_20_3-4}/pom.xml (98%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java (100%) rename nms/{1_20_3 => 1_20_3-4}/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java (100%) diff --git a/IF/pom.xml b/IF/pom.xml index a57f7e582..31e020bd5 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -145,7 +145,7 @@ com.github.stefvanschie.inventoryframework - 1_20_3 + 1_20_3-4 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 56d54efab..1c5ba69d0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -135,18 +135,18 @@ public enum Version { V1_20_2, /** - * Version 1.20.3 + * Version 1.20.3 - 1.20.4 * * @since 0.10.13 */ - V1_20_3; + V1_20_3_4; /** * A collection of versions on which modern smithing tables are available. */ private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, - V1_20_0_1, V1_20_2, V1_20_3 + V1_20_0_1, V1_20_2, V1_20_3_4 ); /** @@ -240,7 +240,8 @@ public static Version getVersion() { case "1.20.2": return V1_20_2; case "1.20.3": - return V1_20_3; + case "1.20.4": + return V1_20_3_4; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 7cd5015a8..8b6eae337 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 @@ -309,7 +309,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_20_3, + ANVIL_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); @@ -347,7 +347,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_20_3, + BEACON_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); @@ -385,7 +385,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_3, + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); @@ -423,7 +423,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_3, + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); @@ -461,7 +461,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_20_3, + GRINDSTONE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); @@ -499,7 +499,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.MerchantInventoryImpl.class); - MERCHANT_INVENTORIES.put(Version.V1_20_3, + MERCHANT_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); @@ -509,7 +509,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_20_3, + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); @@ -575,7 +575,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_20_3, + STONECUTTER_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.StonecutterInventoryImpl.class); } } diff --git a/nms/1_20_3/pom.xml b/nms/1_20_3-4/pom.xml similarity index 98% rename from nms/1_20_3/pom.xml rename to nms/1_20_3-4/pom.xml index c44e8825f..eb34aa23c 100644 --- a/nms/1_20_3/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -10,7 +10,7 @@ ../../pom.xml - 1_20_3 + 1_20_3-4 true diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/AnvilInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/BeaconInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/CartographyTableInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/EnchantingTableInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/GrindstoneInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/MerchantInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/SmithingTableInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/StonecutterInventoryImpl.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/CustomInventoryUtil.java diff --git a/nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java b/nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java similarity index 100% rename from nms/1_20_3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java rename to nms/1_20_3-4/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_3/util/TextHolderUtil.java diff --git a/pom.xml b/pom.xml index b9dc16ee0..35edd4ea8 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ IF nms/abstraction - nms/1_20_3 + nms/1_20_3-4 nms/1_20_2 nms/1_20_0-1 nms/1_19_4 From ade2a327f9acfea622835de3a161f964de6d292e Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 6 Jan 2024 00:43:39 +0100 Subject: [PATCH 246/382] V 0.10.13 --- .github/dependabot.yml | 2 +- .github/workflows/auto-deploy.yml | 2 +- .github/workflows/maven.yml | 2 +- IF/pom.xml | 2 +- README.md | 5 +++-- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0-1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 26 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ac3ce90e6..c4bd20453 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -81,7 +81,7 @@ updates: schedule: interval: "daily" - package-ecosystem: "maven" - directory: "/nms/1_20_3" + directory: "/nms/1_20_3-4" schedule: interval: "daily" - package-ecosystem: "maven" diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index d6ac6e767..bb550f67b 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -73,7 +73,7 @@ jobs: mvn paper-nms:init -pl nms/1_19_4 mvn paper-nms:init -pl nms/1_20_0-1 mvn paper-nms:init -pl nms/1_20_2 - mvn paper-nms:init -pl nms/1_20_3 + mvn paper-nms:init -pl nms/1_20_3-4 - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import - name: Automatically deploy the project diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0ff2564d0..a8ec0d451 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -79,6 +79,6 @@ jobs: mvn paper-nms:init -pl nms/1_19_4 mvn paper-nms:init -pl nms/1_20_0-1 mvn paper-nms:init -pl nms/1_20_2 - mvn paper-nms:init -pl nms/1_20_3 + mvn paper-nms:init -pl nms/1_20_3-4 - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 31e020bd5..407485860 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index f3df45043..b15d6a4fe 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.12 + 0.10.13 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.12' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.13' // ... } ``` @@ -138,6 +138,7 @@ 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_0-1 mvn paper-nms:init -pl nms/1_20_2 +mvn paper-nms:init -pl nms/1_20_3-4 ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index e2f332519..0eaa8fe03 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 78db7c895..81f335d7a 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 9c6c66d92..e87164320 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 9f43755b6..ae0aceddf 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 56c4e3202..0c7d3e6d2 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 1a4071e5d..5c7cf7640 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 15b9d01af..a877f40d1 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index e7aa94cab..3761397bf 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index fd2160dfd..db4162435 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 333f03717..3a4bd13ad 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 48fcec2c9..e03fe5bcf 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index fca44cad1..31c8b88b4 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 3c8255a16..1b9d3a780 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 7438bc921..10462bf58 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index cb6539c2d..4eb8669d5 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 10693d95c..a5404afc8 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/nms/1_20_0-1/pom.xml b/nms/1_20_0-1/pom.xml index 91fa043ab..ae3c730bc 100644 --- a/nms/1_20_0-1/pom.xml +++ b/nms/1_20_0-1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index e818dc51e..dea07b187 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index eb34aa23c..d6648cf0b 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 2d1cf424f..2b4a15686 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13-SNAPSHOT + 0.10.13 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 35edd4ea8..8f7b4faeb 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13-SNAPSHOT + 0.10.13 pom IF From 322a8d735817d76711c0253c7fa477fc8fc09fac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 05:16:38 +0000 Subject: [PATCH 247/382] Bump org.apache.maven.plugins:maven-javadoc-plugin in /nms/1_19_2 Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.5.0 to 3.6.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.5.0...maven-javadoc-plugin-3.6.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8f7b4faeb..4ee25ede7 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 + 3.6.0 attach-javadocs From 23d8cb34a16b9fc9e669fe62ba27d50a6cfe2852 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Sep 2023 05:34:24 +0000 Subject: [PATCH 248/382] Bump org.apache.maven.plugins:maven-shade-plugin in /IF Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.0 to 3.5.1. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.0...maven-shade-plugin-3.5.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 407485860..a5e350cfd 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -242,7 +242,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.0 + 3.5.1 package From f67167767f91b7b3d6f9006a5427db5e5472f0a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:13:11 +0000 Subject: [PATCH 249/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_19_1 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 1b9d3a780..3a88544da 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.3 process-classes From ea0644cf45fe4557489a8c64af98342affbf19c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:22:27 +0000 Subject: [PATCH 250/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_18_1 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_18_1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 3a4bd13ad..91a185308 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.3 process-classes From 6b32e7d536051a22969a9f8098a23600f1035f8b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:22:52 +0000 Subject: [PATCH 251/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_18_0 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_18_0/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index db4162435..83f7b44ae 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.3 process-classes From 7477dab1805eeb9eac9c61a427a7dbc955aef892 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:28:43 +0000 Subject: [PATCH 252/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_17_0 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_17_0/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index a877f40d1..d9e58a009 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.3 process-classes From e57f129add2034fc25746804d7c999256c915f30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:31:14 +0000 Subject: [PATCH 253/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_17_1 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_17_1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 3761397bf..11bd1141f 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.3 process-classes From ff29a670059f18508a4069c3bbf552348cffc0b2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:36:34 +0000 Subject: [PATCH 254/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_19_0 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_0/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 31c8b88b4..64e131830 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.3 process-classes From f8a3b0678e88ff0ebdf7c3918e1defed51e3d09d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:40:00 +0000 Subject: [PATCH 255/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_19_2 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 10462bf58..a0f693a97 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.3 process-classes From 3f39017626bce6b2700f62e90e42f309fc2ad506 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 05:54:44 +0000 Subject: [PATCH 256/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_18_2 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_18_2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index e03fe5bcf..2f4e36d2e 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.3 process-classes From ab637d37d03f49149268fa24d4d345c26392fe55 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 06:00:55 +0000 Subject: [PATCH 257/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_19_3 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_3/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 4eb8669d5..f329e8dd5 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.3 process-classes From 90b5085b27b33a66d903232050276b0cd1669b6a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Oct 2023 06:05:19 +0000 Subject: [PATCH 258/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_19_4 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index a5404afc8..708de7a6a 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.3 process-classes From 195a061d48d5d7d1b12421d2a60047e19a93c91a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 05:56:53 +0000 Subject: [PATCH 259/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_20 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.1.2 to 3.2.1. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4ee25ede7..5f66bef8f 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.1.2 + 3.2.1 org.junit.jupiter From 99da127e976c80a6d31b96940f8a90e1394b7cae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 05:56:57 +0000 Subject: [PATCH 260/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_20 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.2 to 3.2.1. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.2...surefire-3.2.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5f66bef8f..bcce48412 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.1 org.apache.maven.surefire From 183a895586984ce3e4acd475157d264e5089178f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:24:49 +0000 Subject: [PATCH 261/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_20_0-1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nms/1_20_0-1/pom.xml b/nms/1_20_0-1/pom.xml index ae3c730bc..6e0a78462 100644 --- a/nms/1_20_0-1/pom.xml +++ b/nms/1_20_0-1/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.3 process-classes diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index dea07b187..dc257e204 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.3 process-classes From e803e7cdcaf2c2337523bd9fb9d735ede4a1ba3f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 05:08:17 +0000 Subject: [PATCH 262/382] Bump org.junit.jupiter:junit-jupiter-engine in /nms/1_18_0 Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.10.0 to 5.10.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.0...r5.10.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bcce48412..e16836bca 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ org.junit.jupiter junit-jupiter-engine - 5.10.0 + 5.10.1 From 29be1640d15f829513dbf07081242ff4937cc059 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 05:29:24 +0000 Subject: [PATCH 263/382] Bump org.junit.jupiter:junit-jupiter-engine from 5.10.0 to 5.10.1 in /IF Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.10.0 to 5.10.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.0...r5.10.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index a5e350cfd..ded896d6b 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -235,7 +235,7 @@ org.junit.jupiter junit-jupiter-engine - 5.10.0 + 5.10.1 From 42dd534e56d4ca9373be9aaf2af981df5a1d502e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Nov 2023 05:13:49 +0000 Subject: [PATCH 264/382] Bump org.jetbrains:annotations in /adventure-support Bumps [org.jetbrains:annotations](https://github.com/JetBrains/java-annotations) from 24.0.1 to 24.1.0. - [Release notes](https://github.com/JetBrains/java-annotations/releases) - [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md) - [Commits](https://github.com/JetBrains/java-annotations/compare/24.0.1...24.1.0) --- updated-dependencies: - dependency-name: org.jetbrains:annotations dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e16836bca..a44b0591f 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ org.jetbrains annotations - 24.0.1 + 24.1.0 provided From 504dd967f67e19983b86eb26e272b65307329933 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 05:07:33 +0000 Subject: [PATCH 265/382] Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.5.0 to 3.6.3 Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.5.0 to 3.6.3. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.5.0...maven-javadoc-plugin-3.6.3) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index ded896d6b..631116e83 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -279,7 +279,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 + 3.6.3 attach-javadocs From efe26341f8ea53ac17174c9554f1b08879908473 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 19:27:32 +0000 Subject: [PATCH 266/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /IF Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.2 to 3.2.5. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.2...surefire-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 4 ++-- pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 631116e83..41f9b1f51 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -225,12 +225,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.5 org.apache.maven.surefire surefire-junit-platform - 3.1.2 + 3.2.5 org.junit.jupiter diff --git a/pom.xml b/pom.xml index 8951390e3..a1be18d2a 100644 --- a/pom.xml +++ b/pom.xml @@ -113,12 +113,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.3 + 3.2.5 org.apache.maven.surefire surefire-junit-platform - 3.2.3 + 3.2.5 org.junit.jupiter From c4326a42b51764fd6209bdb20a7142b4986d4f55 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jan 2024 23:45:13 +0000 Subject: [PATCH 267/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3 in /nms/1_20_3-4 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.1 to 1.4.3. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_20_3-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index d6648cf0b..9f4b18870 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -44,7 +44,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.1 + 1.4.3 process-classes From 2e2abe8abd2304adaf74004c646d6618d68553db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:13:25 +0000 Subject: [PATCH 268/382] Bump org.apache.maven.surefire:surefire-junit-platform Bumps org.apache.maven.surefire:surefire-junit-platform from 3.1.2 to 3.2.5. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8951390e3..86d0121f0 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.2.3 + 3.2.5 org.junit.jupiter From 88b12916cdc79589f56bddcc33fd0ed20579374a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:14:00 +0000 Subject: [PATCH 269/382] Bump org.apache.maven.surefire:surefire-junit-platform Bumps org.apache.maven.surefire:surefire-junit-platform from 3.1.2 to 3.2.5. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 631116e83..fca53cf7c 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -230,7 +230,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.1.2 + 3.2.5 org.junit.jupiter From 4cc4037a60087fe80e71161bab01227d29c3f9f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 19:28:44 +0000 Subject: [PATCH 270/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_20_3-4 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.1.2 to 3.2.5. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.1.2...surefire-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 86d0121f0..a1be18d2a 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.3 + 3.2.5 org.apache.maven.surefire From 088f3ed7dec859df9a55b32e7cce98715f01db30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 05:10:06 +0000 Subject: [PATCH 271/382] Bump net.kyori:adventure-api from 4.14.0 to 4.15.0 Bumps [net.kyori:adventure-api](https://github.com/KyoriPowered/adventure) from 4.14.0 to 4.15.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.14.0...v4.15.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a1be18d2a..1658686b0 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 1.8 true UTF-8 - 4.14.0 + 4.15.0 com.github.stefvanschie.inventoryframework From 2512ec91e5108cf47543e94249903ab6c949d7f7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 05:28:18 +0000 Subject: [PATCH 272/382] Bump org.junit.jupiter:junit-jupiter-api from 5.10.0 to 5.10.1 in /IF Bumps [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) from 5.10.0 to 5.10.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.0...r5.10.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index fca53cf7c..ad7983236 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -178,7 +178,7 @@ org.junit.jupiter junit-jupiter-api - 5.10.0 + 5.10.1 test From 748c81231d9b964e84c257a825b9d97e0124c762 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 31 Jan 2024 22:11:31 +0100 Subject: [PATCH 273/382] Fix failing tests --- IF/pom.xml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 41f9b1f51..bbef0ab54 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -177,8 +177,8 @@ org.junit.jupiter - junit-jupiter-api - 5.10.0 + junit-jupiter-engine + 5.10.1 test @@ -232,11 +232,6 @@ surefire-junit-platform 3.2.5 - - org.junit.jupiter - junit-jupiter-engine - 5.10.1 - From 7c08d51f3369a4dea6482ee8a140922cb454376f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 05:09:32 +0000 Subject: [PATCH 274/382] Bump org.junit.jupiter:junit-jupiter-engine in /nms/1_20_0-1 Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.10.1 to 5.10.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.1...r5.10.2) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1658686b0..1c81a581b 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ org.junit.jupiter junit-jupiter-engine - 5.10.1 + 5.10.2 From b474d3ebad5ff4e74dce312e4fc8b38db6970ac0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 05:15:49 +0000 Subject: [PATCH 275/382] Bump org.junit.jupiter:junit-jupiter-engine from 5.10.1 to 5.10.2 Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.10.1 to 5.10.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.1...r5.10.2) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index bbef0ab54..1d03fafce 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -178,7 +178,7 @@ org.junit.jupiter junit-jupiter-engine - 5.10.1 + 5.10.2 test From 859f69bcad54a34a2e5418f32692b5d292584aaa Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 5 Feb 2024 21:28:24 +0100 Subject: [PATCH 276/382] Bump to 0.10.14-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0-1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index bbef0ab54..3c2508c0e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 0eaa8fe03..a16f0ac97 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 81f335d7a..87396e593 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index e87164320..361ee78f8 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index ae0aceddf..b9f694024 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 0c7d3e6d2..af25bc11d 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 5c7cf7640..af0736fea 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index d9e58a009..a86864d35 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 11bd1141f..5f81939a0 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 83f7b44ae..a8cf8c2d8 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 91a185308..e6dddaf56 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 2f4e36d2e..5ac5240db 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 64e131830..74eb07cf2 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 3a88544da..13027a11b 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index a0f693a97..cfacaf06a 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index f329e8dd5..2ef834583 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 708de7a6a..9a6b0f564 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20_0-1/pom.xml b/nms/1_20_0-1/pom.xml index 6e0a78462..982c3ecba 100644 --- a/nms/1_20_0-1/pom.xml +++ b/nms/1_20_0-1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index dc257e204..57bec5a06 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 9f4b18870..ebb7e8435 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 2b4a15686..d973ad639 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.13 + 0.10.14-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 1658686b0..a14dcceba 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.13 + 0.10.14-SNAPSHOT pom IF From 2418ed6fbce540f2c297cfb6505e6366d448e322 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 14 Feb 2024 21:10:42 +0100 Subject: [PATCH 277/382] Fix plugin instance for toggle button Toggle buttons wouldn't provide the correct plugin instance to their gui items when a specific one was specified. --- .../pane/component/ToggleButton.java | 992 +++++++++--------- 1 file changed, 496 insertions(+), 496 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index 39b47c538..ce418078f 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -1,496 +1,496 @@ -package com.github.stefvanschie.inventoryframework.pane.component; - -import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; -import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; -import com.github.stefvanschie.inventoryframework.gui.GuiItem; -import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; -import com.github.stefvanschie.inventoryframework.pane.OutlinePane; -import com.github.stefvanschie.inventoryframework.pane.Pane; -import com.github.stefvanschie.inventoryframework.pane.util.Slot; -import org.bukkit.Material; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Element; - -import java.util.Collection; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * A button that toggles between an enabled and disabled state. - * - * @since 0.5.0 - */ -public class ToggleButton extends Pane { - - /** - * The panes used for showing the enabled and disabled states - */ - private final OutlinePane enabledPane, disabledPane; - - /** - * Whether the button is enabled or disabled - */ - private boolean enabled; - - /** - * Whether this button can be toggled by a player - */ - private boolean allowToggle = true; - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @param priority the priority - * @param enabled whether the button should start in its enabled or disabled state - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(int, int, int, int, Priority, boolean) - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, boolean enabled, - @NotNull Plugin plugin) { - super(slot, length, height, priority); - - this.enabled = enabled; - - this.enabledPane = new OutlinePane(length, height); - this.enabledPane.addItem(new GuiItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE))); - this.enabledPane.setRepeat(true); - - this.disabledPane = new OutlinePane(length, height); - this.disabledPane.addItem(new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE))); - this.disabledPane.setRepeat(true); - } - - /** - * Creates a new toggle button - * - * @param x the x coordinate - * @param y the y coordinate - * @param length the length - * @param height the height - * @param priority the priority - * @param enabled whether the button should start in its enabled or disabled state - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(int, int, int, int, Priority, boolean) - * @since 0.10.8 - */ - public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled, - @NotNull Plugin plugin) { - this(Slot.fromXY(x, y), length, height, priority, enabled, plugin); - } - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @param priority the priority - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(Slot, int, int, Priority) - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, - @NotNull Plugin plugin) { - this(slot, length, height, priority, false, plugin); - } - - /** - * Creates a new toggle button - * - * @param x the x coordinate - * @param y the y coordinate - * @param length the length - * @param height the height - * @param priority the priority - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(int, int, int, int, Priority) - * @since 0.10.8 - */ - public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { - this(x, y, length, height, priority, false, plugin); - } - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @param enabled whether the button should start in its enabled or disabled state - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(Slot, int, int, boolean) - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height, boolean enabled, @NotNull Plugin plugin) { - this(slot, length, height, Priority.NORMAL, enabled, plugin); - } - - /** - * Creates a new toggle button - * - * @param x the x coordinate - * @param y the y coordinate - * @param length the length - * @param height the height - * @param enabled whether the button should start in its enabled or disabled state - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(int, int, int, int, boolean) - * @since 0.10.8 - */ - public ToggleButton(int x, int y, int length, int height, boolean enabled, @NotNull Plugin plugin) { - this(x, y, length, height, Priority.NORMAL, enabled, plugin); - } - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(Slot, int, int) - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Plugin plugin) { - this(slot, length, height, false, plugin); - } - - /** - * Creates a new toggle button - * - * @param x the x coordinate - * @param y the y coordinate - * @param length the length - * @param height the height - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(int, int, int, int) - * @since 0.10.8 - */ - public ToggleButton(int x, int y, int length, int height, @NotNull Plugin plugin) { - this(x, y, length, height, false, plugin); - } - - /** - * Creates a new toggle button - * - * @param length the length - * @param height the height - * @param enabled whether the button should start in its enabled or disabled state - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(int, int, boolean) - * @since 0.10.8 - */ - public ToggleButton(int length, int height, boolean enabled, @NotNull Plugin plugin) { - this(0, 0, length, height, enabled); - } - - /** - * Creates a new toggle button - * - * @param length the length - * @param height the height - * @param plugin the plugin that will be the owner of this button's items - * @see #ToggleButton(int, int) - * @since 0.10.8 - */ - public ToggleButton(int length, int height, @NotNull Plugin plugin) { - this(length, height, false); - } - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @param priority the priority - * @param enabled whether the button should start in its enabled or disabled state - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, boolean enabled) { - this(slot, length, height, priority, enabled, JavaPlugin.getProvidingPlugin(ToggleButton.class)); - } - - public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled) { - this(x, y, length, height, priority, enabled, JavaPlugin.getProvidingPlugin(ToggleButton.class)); - } - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @param priority the priority - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { - this(slot, length, height, priority, false); - } - - public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority) { - this(x, y, length, height, priority, false); - } - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @param enabled whether the button should start in its enabled or disabled state - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height, boolean enabled) { - this(slot, length, height, Priority.NORMAL, enabled); - } - - public ToggleButton(int x, int y, int length, int height, boolean enabled) { - this(x, y, length, height, Priority.NORMAL, enabled); - } - - /** - * Creates a new toggle button - * - * @param slot the slot - * @param length the length - * @param height the height - * @since 0.10.8 - */ - public ToggleButton(@NotNull Slot slot, int length, int height) { - this(slot, length, height, false); - } - - public ToggleButton(int x, int y, int length, int height) { - this(x, y, length, height, false); - } - - public ToggleButton(int length, int height, boolean enabled) { - this(0, 0, length, height, enabled); - } - - public ToggleButton(int length, int height) { - this(length, height, false); - } - - @Override - public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, - int maxHeight) { - int newMaxLength = Math.min(maxLength, length); - int newMaxHeight = Math.min(maxHeight, height); - - if (enabled) { - this.enabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); - } else { - this.disabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); - } - } - - @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; - } - - if (this.allowToggle) { - toggle(); - } - - callOnClick(event); - - int newX = paneOffsetX + xPosition; - int newY = paneOffsetY + yPosition; - - /* - Since we've toggled before, the click for the panes should be swapped around. If we haven't toggled due to - allowToggle being false, then we should click the pane corresponding to the current state. An XOR achieves this. - */ - if (enabled == this.allowToggle) { - disabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); - } else { - enabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); - } - - gui.update(); - - return true; - } - - @NotNull - @Contract(pure = true) - @Override - public ToggleButton copy() { - ToggleButton toggleButton = new ToggleButton(getSlot(), length, height, getPriority(), enabled); - - toggleButton.allowToggle = this.allowToggle; - - toggleButton.setVisible(isVisible()); - toggleButton.onClick = onClick; - - toggleButton.uuid = uuid; - - toggleButton.setEnabledItem(enabledPane.getItems().get(0).copy()); - toggleButton.setDisabledItem(disabledPane.getItems().get(0).copy()); - - return toggleButton; - } - - @Override - public void setLength(int length) { - super.setLength(length); - - this.disabledPane.setLength(length); - this.enabledPane.setLength(length); - } - - @Override - public void setHeight(int height) { - super.setHeight(height); - - this.disabledPane.setHeight(height); - this.enabledPane.setHeight(height); - } - - /** - * Sets the item to use when the button is set to disabled - * - * @param item the disabled item - * @since 0.5.0 - */ - public void setDisabledItem(@NotNull GuiItem item) { - disabledPane.clear(); - - disabledPane.addItem(item); - } - - /** - * Sets the item to use when the button is set to enabled - * - * @param item the enabled item - * @since 0.5.0 - */ - public void setEnabledItem(@NotNull GuiItem item) { - enabledPane.clear(); - - enabledPane.addItem(item); - } - - @NotNull - @Override - public Collection getItems() { - return getPanes().stream().flatMap(pane -> pane.getItems().stream()).collect(Collectors.toSet()); - } - - @NotNull - @Override - public Collection getPanes() { - return Stream.of(enabledPane, disabledPane).collect(Collectors.toSet()); - } - - /** - * Sets whether this toggle button can be toggled. This only prevents players from toggling the button and does not - * prevent toggling the button programmatically with methods such as {@link #toggle()}. - * - * @param allowToggle whether this button can be toggled - * @since 0.10.8 - */ - public void allowToggle(boolean allowToggle) { - this.allowToggle = allowToggle; - } - - /** - * Gets whether this toggle button is currently enabled or disabled. - * - * @return whether the button is enabled or disabled - * @since 0.9.6 - */ - @Contract(pure = true) - public boolean isEnabled() { - return enabled; - } - - /** - * Toggles between the enabled and disabled states - * - * @since 0.5.0 - */ - public void toggle() { - enabled = !enabled; - } - - @Override - public void clear() {} - - /** - * Loads a toggle button from an XML element - * - * @param instance the instance class - * @param element the element - * @param plugin the plugin that will be the owner of the underlying items - * @return the toggle button - * @since 0.10.8 - */ - @NotNull - @Contract(pure = true) - public static ToggleButton load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { - int length, height; - - try { - length = Integer.parseInt(element.getAttribute("length")); - height = Integer.parseInt(element.getAttribute("height")); - } catch (NumberFormatException exception) { - throw new XMLLoadException(exception); - } - - boolean enabled = element.hasAttribute("enabled") && Boolean.parseBoolean(element.getAttribute("enabled")); - ToggleButton toggleButton = new ToggleButton(length, height, enabled, plugin); - - Pane.load(toggleButton, instance, element); - - return toggleButton; - } - - /** - * Loads a toggle button from an XML element - * - * @param instance the instance class - * @param element the element - * @return the toggle button - * @since 0.5.0 - * @deprecated this method is no longer used internally and has been superseded by - * {@link #load(Object, Element, Plugin)} - */ - @NotNull - @Contract(pure = true) - @Deprecated - public static ToggleButton load(@NotNull Object instance, @NotNull Element element) { - return load(instance, element, JavaPlugin.getProvidingPlugin(ToggleButton.class)); - } -} +package com.github.stefvanschie.inventoryframework.pane.component; + +import com.github.stefvanschie.inventoryframework.gui.InventoryComponent; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; +import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import com.github.stefvanschie.inventoryframework.pane.OutlinePane; +import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.Element; + +import java.util.Collection; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * A button that toggles between an enabled and disabled state. + * + * @since 0.5.0 + */ +public class ToggleButton extends Pane { + + /** + * The panes used for showing the enabled and disabled states + */ + private final OutlinePane enabledPane, disabledPane; + + /** + * Whether the button is enabled or disabled + */ + private boolean enabled; + + /** + * Whether this button can be toggled by a player + */ + private boolean allowToggle = true; + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, Priority, boolean) + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, boolean enabled, + @NotNull Plugin plugin) { + super(slot, length, height, priority); + + this.enabled = enabled; + + this.enabledPane = new OutlinePane(length, height); + this.enabledPane.addItem(new GuiItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), plugin)); + this.enabledPane.setRepeat(true); + + this.disabledPane = new OutlinePane(length, height); + this.disabledPane.addItem(new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE), plugin)); + this.disabledPane.setRepeat(true); + } + + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param priority the priority + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, Priority, boolean) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled, + @NotNull Plugin plugin) { + this(Slot.fromXY(x, y), length, height, priority, enabled, plugin); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(Slot, int, int, Priority) + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, + @NotNull Plugin plugin) { + this(slot, length, height, priority, false, plugin); + } + + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param priority the priority + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, Priority) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, @NotNull Plugin plugin) { + this(x, y, length, height, priority, false, plugin); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(Slot, int, int, boolean) + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, boolean enabled, @NotNull Plugin plugin) { + this(slot, length, height, Priority.NORMAL, enabled, plugin); + } + + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int, boolean) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, boolean enabled, @NotNull Plugin plugin) { + this(x, y, length, height, Priority.NORMAL, enabled, plugin); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(Slot, int, int) + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Plugin plugin) { + this(slot, length, height, false, plugin); + } + + /** + * Creates a new toggle button + * + * @param x the x coordinate + * @param y the y coordinate + * @param length the length + * @param height the height + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, int, int) + * @since 0.10.8 + */ + public ToggleButton(int x, int y, int length, int height, @NotNull Plugin plugin) { + this(x, y, length, height, false, plugin); + } + + /** + * Creates a new toggle button + * + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int, boolean) + * @since 0.10.8 + */ + public ToggleButton(int length, int height, boolean enabled, @NotNull Plugin plugin) { + this(0, 0, length, height, enabled); + } + + /** + * Creates a new toggle button + * + * @param length the length + * @param height the height + * @param plugin the plugin that will be the owner of this button's items + * @see #ToggleButton(int, int) + * @since 0.10.8 + */ + public ToggleButton(int length, int height, @NotNull Plugin plugin) { + this(length, height, false); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @param enabled whether the button should start in its enabled or disabled state + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority, boolean enabled) { + this(slot, length, height, priority, enabled, JavaPlugin.getProvidingPlugin(ToggleButton.class)); + } + + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority, boolean enabled) { + this(x, y, length, height, priority, enabled, JavaPlugin.getProvidingPlugin(ToggleButton.class)); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param priority the priority + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, @NotNull Priority priority) { + this(slot, length, height, priority, false); + } + + public ToggleButton(int x, int y, int length, int height, @NotNull Priority priority) { + this(x, y, length, height, priority, false); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @param enabled whether the button should start in its enabled or disabled state + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height, boolean enabled) { + this(slot, length, height, Priority.NORMAL, enabled); + } + + public ToggleButton(int x, int y, int length, int height, boolean enabled) { + this(x, y, length, height, Priority.NORMAL, enabled); + } + + /** + * Creates a new toggle button + * + * @param slot the slot + * @param length the length + * @param height the height + * @since 0.10.8 + */ + public ToggleButton(@NotNull Slot slot, int length, int height) { + this(slot, length, height, false); + } + + public ToggleButton(int x, int y, int length, int height) { + this(x, y, length, height, false); + } + + public ToggleButton(int length, int height, boolean enabled) { + this(0, 0, length, height, enabled); + } + + public ToggleButton(int length, int height) { + this(length, height, false); + } + + @Override + public void display(@NotNull InventoryComponent inventoryComponent, int paneOffsetX, int paneOffsetY, int maxLength, + int maxHeight) { + int newMaxLength = Math.min(maxLength, length); + int newMaxHeight = Math.min(maxHeight, height); + + if (enabled) { + this.enabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); + } else { + this.disabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); + } + } + + @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; + } + + if (this.allowToggle) { + toggle(); + } + + callOnClick(event); + + int newX = paneOffsetX + xPosition; + int newY = paneOffsetY + yPosition; + + /* + Since we've toggled before, the click for the panes should be swapped around. If we haven't toggled due to + allowToggle being false, then we should click the pane corresponding to the current state. An XOR achieves this. + */ + if (enabled == this.allowToggle) { + disabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); + } else { + enabledPane.click(gui, inventoryComponent, event, slot, newX, newY, length, height); + } + + gui.update(); + + return true; + } + + @NotNull + @Contract(pure = true) + @Override + public ToggleButton copy() { + ToggleButton toggleButton = new ToggleButton(getSlot(), length, height, getPriority(), enabled); + + toggleButton.allowToggle = this.allowToggle; + + toggleButton.setVisible(isVisible()); + toggleButton.onClick = onClick; + + toggleButton.uuid = uuid; + + toggleButton.setEnabledItem(enabledPane.getItems().get(0).copy()); + toggleButton.setDisabledItem(disabledPane.getItems().get(0).copy()); + + return toggleButton; + } + + @Override + public void setLength(int length) { + super.setLength(length); + + this.disabledPane.setLength(length); + this.enabledPane.setLength(length); + } + + @Override + public void setHeight(int height) { + super.setHeight(height); + + this.disabledPane.setHeight(height); + this.enabledPane.setHeight(height); + } + + /** + * Sets the item to use when the button is set to disabled + * + * @param item the disabled item + * @since 0.5.0 + */ + public void setDisabledItem(@NotNull GuiItem item) { + disabledPane.clear(); + + disabledPane.addItem(item); + } + + /** + * Sets the item to use when the button is set to enabled + * + * @param item the enabled item + * @since 0.5.0 + */ + public void setEnabledItem(@NotNull GuiItem item) { + enabledPane.clear(); + + enabledPane.addItem(item); + } + + @NotNull + @Override + public Collection getItems() { + return getPanes().stream().flatMap(pane -> pane.getItems().stream()).collect(Collectors.toSet()); + } + + @NotNull + @Override + public Collection getPanes() { + return Stream.of(enabledPane, disabledPane).collect(Collectors.toSet()); + } + + /** + * Sets whether this toggle button can be toggled. This only prevents players from toggling the button and does not + * prevent toggling the button programmatically with methods such as {@link #toggle()}. + * + * @param allowToggle whether this button can be toggled + * @since 0.10.8 + */ + public void allowToggle(boolean allowToggle) { + this.allowToggle = allowToggle; + } + + /** + * Gets whether this toggle button is currently enabled or disabled. + * + * @return whether the button is enabled or disabled + * @since 0.9.6 + */ + @Contract(pure = true) + public boolean isEnabled() { + return enabled; + } + + /** + * Toggles between the enabled and disabled states + * + * @since 0.5.0 + */ + public void toggle() { + enabled = !enabled; + } + + @Override + public void clear() {} + + /** + * Loads a toggle button from an XML element + * + * @param instance the instance class + * @param element the element + * @param plugin the plugin that will be the owner of the underlying items + * @return the toggle button + * @since 0.10.8 + */ + @NotNull + @Contract(pure = true) + public static ToggleButton load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { + int length, height; + + try { + length = Integer.parseInt(element.getAttribute("length")); + height = Integer.parseInt(element.getAttribute("height")); + } catch (NumberFormatException exception) { + throw new XMLLoadException(exception); + } + + boolean enabled = element.hasAttribute("enabled") && Boolean.parseBoolean(element.getAttribute("enabled")); + ToggleButton toggleButton = new ToggleButton(length, height, enabled, plugin); + + Pane.load(toggleButton, instance, element); + + return toggleButton; + } + + /** + * Loads a toggle button from an XML element + * + * @param instance the instance class + * @param element the element + * @return the toggle button + * @since 0.5.0 + * @deprecated this method is no longer used internally and has been superseded by + * {@link #load(Object, Element, Plugin)} + */ + @NotNull + @Contract(pure = true) + @Deprecated + public static ToggleButton load(@NotNull Object instance, @NotNull Element element) { + return load(instance, element, JavaPlugin.getProvidingPlugin(ToggleButton.class)); + } +} From 28d4a92f2559493f8fda3d53ff808a1a7042d79c Mon Sep 17 00:00:00 2001 From: VyperzDev Date: Wed, 14 Feb 2024 18:47:39 -0600 Subject: [PATCH 278/382] Update PatternPain --- .../stefvanschie/inventoryframework/pane/PatternPane.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java index 1f52f07e1..86a02db3a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PatternPane.java @@ -229,9 +229,9 @@ public PatternPane copy() { patternPane.uuid = uuid; - patternPane.setRotation(getRotation()); - patternPane.flipHorizontally(isFlippedHorizontally()); - patternPane.flipVertically(isFlippedVertically()); + patternPane.rotation = rotation; + patternPane.flippedHorizontally = flippedHorizontally; + patternPane.flippedVertically = flippedVertically; return patternPane; } From fa7c12094ed4adbcd0ec5abb9f4e7b16de285c7e Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 16 Feb 2024 21:32:28 +0100 Subject: [PATCH 279/382] Fix toggle buttons appearing in the wrong place Addresses #589 --- .../inventoryframework/pane/component/ToggleButton.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java index ce418078f..6ff5bd43a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/ToggleButton.java @@ -288,10 +288,13 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs int newMaxLength = Math.min(maxLength, length); int newMaxHeight = Math.min(maxHeight, height); + int newPaneOffsetX = this.slot.getX(newMaxLength) + paneOffsetX; + int newPaneOffsetY = this.slot.getY(newMaxHeight) + paneOffsetY; + if (enabled) { - this.enabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); + this.enabledPane.display(inventoryComponent, newPaneOffsetX, newPaneOffsetY, newMaxLength, newMaxHeight); } else { - this.disabledPane.display(inventoryComponent, paneOffsetX, paneOffsetY, newMaxLength, newMaxHeight); + this.disabledPane.display(inventoryComponent, newPaneOffsetX, newPaneOffsetY, newMaxLength, newMaxHeight); } } From 569b2cf61d53c563ae020e5c77092aad12338619 Mon Sep 17 00:00:00 2001 From: Mastermori Date: Sat, 17 Feb 2024 20:08:45 +0100 Subject: [PATCH 280/382] Used slot position to calculate offset instead of pane position --- .../stefvanschie/inventoryframework/pane/MasonryPane.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java index 8a0e168b7..894e87daf 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/MasonryPane.java @@ -125,8 +125,8 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs pane.display( inventoryComponent, - paneOffsetX + x, - paneOffsetY + y, + paneOffsetX + getSlot().getX(length), + paneOffsetY + getSlot().getY(length), Math.min(this.length, maxLength), Math.min(this.height, maxHeight) ); @@ -163,8 +163,8 @@ public void display(@NotNull InventoryComponent inventoryComponent, int paneOffs pane.display( inventoryComponent, - paneOffsetX + x, - paneOffsetY + y, + paneOffsetX + getSlot().getX(length), + paneOffsetY + getSlot().getY(length), Math.min(this.length, maxLength), Math.min(this.height, maxHeight) ); From 3595fed9147fb3fd5e3903e1ab4ac50c1abd20f9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 05:13:03 +0000 Subject: [PATCH 281/382] Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.1 to 3.5.2 Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.1 to 3.5.2. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.1...maven-shade-plugin-3.5.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 212e2d458..5eaaaa7c3 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -237,7 +237,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.1 + 3.5.2 package From 4d306e5926d58083fdb87ca78191536d56c0179c Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 1 Mar 2024 21:27:07 +0100 Subject: [PATCH 282/382] Update shade plugin version in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b15d6a4fe..71e46aa66 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Now in order to shade the project into your project, add the following to your p org.apache.maven.plugins maven-shade-plugin - 3.2.4 + 3.5.2 ${project.build.directory}/dependency-reduced-pom.xml From 2099c2e5b5c8100ff8b5d568933445969549359b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 05:13:24 +0000 Subject: [PATCH 283/382] Bump net.kyori:adventure-api from 4.15.0 to 4.16.0 Bumps [net.kyori:adventure-api](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.16.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.16.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2e034a6d9..4959afdfe 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 1.8 true UTF-8 - 4.15.0 + 4.16.0 com.github.stefvanschie.inventoryframework From e350697bd7475acd849fcc732297aa5c95387f1b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 3 Mar 2024 20:50:40 +0100 Subject: [PATCH 284/382] Fix 1.20.1 not working Addresses #653 --- IF/pom.xml | 8 +- .../util/version/Version.java | 18 +- .../util/version/VersionMatcher.java | 48 ++- nms/{1_20_0-1 => 1_20_0}/pom.xml | 2 +- .../nms/v1_20_0}/AnvilInventoryImpl.java | 24 +- .../nms/v1_20_0}/BeaconInventoryImpl.java | 14 +- .../CartographyTableInventoryImpl.java | 18 +- .../EnchantingTableInventoryImpl.java | 16 +- .../nms/v1_20_0}/GrindstoneInventoryImpl.java | 20 +- .../nms/v1_20_0}/MerchantInventoryImpl.java | 10 +- .../v1_20_0}/SmithingTableInventoryImpl.java | 24 +- .../v1_20_0}/StonecutterInventoryImpl.java | 18 +- .../v1_20_0}/util/CustomInventoryUtil.java | 6 +- .../nms/v1_20_0}/util/TextHolderUtil.java | 10 +- nms/1_20_1/pom.xml | 58 +++ .../nms/v1_20_1/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_20_1/BeaconInventoryImpl.java | 200 +++++++++++ .../CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_20_1/EnchantingTableInventoryImpl.java | 218 ++++++++++++ .../nms/v1_20_1/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_20_1/MerchantInventoryImpl.java | 97 +++++ .../v1_20_1/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_20_1/StonecutterInventoryImpl.java | 221 ++++++++++++ .../nms/v1_20_1/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_20_1/util/TextHolderUtil.java | 65 ++++ pom.xml | 3 +- 26 files changed, 2080 insertions(+), 104 deletions(-) rename nms/{1_20_0-1 => 1_20_0}/pom.xml (98%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/AnvilInventoryImpl.java (95%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/BeaconInventoryImpl.java (97%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/CartographyTableInventoryImpl.java (95%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/EnchantingTableInventoryImpl.java (96%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/GrindstoneInventoryImpl.java (94%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/MerchantInventoryImpl.java (95%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/SmithingTableInventoryImpl.java (95%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/StonecutterInventoryImpl.java (95%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/util/CustomInventoryUtil.java (91%) rename nms/{1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1 => 1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0}/util/TextHolderUtil.java (92%) create mode 100644 nms/1_20_1/pom.xml create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/AnvilInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/BeaconInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/CartographyTableInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/EnchantingTableInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/GrindstoneInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/MerchantInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/SmithingTableInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/StonecutterInventoryImpl.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/CustomInventoryUtil.java create mode 100644 nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index 5eaaaa7c3..686d8ada8 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -133,7 +133,13 @@ com.github.stefvanschie.inventoryframework - 1_20_0-1 + 1_20_0 + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + 1_20_1 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 1c5ba69d0..734e663fc 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -121,11 +121,18 @@ public enum Version { V1_19_4, /** - * Version 1.20.0 - 1.20.1 + * Version 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 + */ + V1_20_0, + + /** + * Version 1.20.1 + * + * @since 0.10.14 */ - V1_20_0_1, + V1_20_1, /** * Version 1.20.2 @@ -146,7 +153,7 @@ public enum Version { */ private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, - V1_20_0_1, V1_20_2, V1_20_3_4 + V1_20_0, V1_20_1, V1_20_2, V1_20_3_4 ); /** @@ -235,8 +242,9 @@ public static Version getVersion() { case "1.19.4": return V1_19_4; case "1.20": + return V1_20_0; case "1.20.1": - return V1_20_0_1; + return V1_20_1; case "1.20.2": return V1_20_2; case "1.20.3": 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 8b6eae337..e138a29d8 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 @@ -305,8 +305,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_3_4, @@ -343,8 +345,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_3_4, @@ -381,8 +385,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_3_4, @@ -419,8 +425,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_3_4, @@ -457,8 +465,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_3_4, @@ -495,8 +505,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.MerchantInventoryImpl.class); - MERCHANT_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_3_4, @@ -505,8 +517,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_3_4, @@ -571,8 +585,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_19_3.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_19_4, com.github.stefvanschie.inventoryframework.nms.v1_19_4.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_20_0_1, - com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20_0, + com.github.stefvanschie.inventoryframework.nms.v1_20_0.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20_1, + com.github.stefvanschie.inventoryframework.nms.v1_20_1.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_2, com.github.stefvanschie.inventoryframework.nms.v1_20_2.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_3_4, diff --git a/nms/1_20_0-1/pom.xml b/nms/1_20_0/pom.xml similarity index 98% rename from nms/1_20_0-1/pom.xml rename to nms/1_20_0/pom.xml index 982c3ecba..29b5e7af2 100644 --- a/nms/1_20_0-1/pom.xml +++ b/nms/1_20_0/pom.xml @@ -10,7 +10,7 @@ ../../pom.xml - 1_20_0-1 + 1_20_0 true diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/AnvilInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/AnvilInventoryImpl.java similarity index 95% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/AnvilInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/AnvilInventoryImpl.java index e43effd2f..1507fe2ed 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/AnvilInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/AnvilInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -29,9 +29,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal anvil inventory for 1.20 + * Internal anvil inventory for 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 */ public class AnvilInventoryImpl extends AnvilInventory { @@ -136,7 +136,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @Deprecated @@ -152,7 +152,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @Deprecated @@ -169,7 +169,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @Contract(pure = true) @@ -183,7 +183,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @NotNull @@ -198,7 +198,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -209,7 +209,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container anvil for responding to item renaming * - * @since 0.10.10 + * @since 0.10.14 */ private class ContainerAnvilImpl extends AnvilMenu { @@ -218,7 +218,7 @@ private class ContainerAnvilImpl extends AnvilMenu { * * @param serverPlayer the player for whom this anvil container is * @param title the title of the inventory - * @since 0.10.10 + * @since 0.10.14 */ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/BeaconInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/BeaconInventoryImpl.java similarity index 97% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/BeaconInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/BeaconInventoryImpl.java index d201fbb12..da29ddbfd 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/BeaconInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/BeaconInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import net.minecraft.core.NonNullList; @@ -26,9 +26,9 @@ import java.lang.reflect.Field; /** - * Internal beacon inventory for 1.20 + * Internal beacon inventory for 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 */ public class BeaconInventoryImpl extends BeaconInventory { @@ -80,7 +80,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.10 + * @since 0.10.14 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -92,7 +92,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -105,7 +105,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -116,7 +116,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container beacon * - * @since 0.10.10 + * @since 0.10.14 */ private class ContainerBeaconImpl extends BeaconMenu { diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/CartographyTableInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/CartographyTableInventoryImpl.java similarity index 95% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/CartographyTableInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/CartographyTableInventoryImpl.java index 7b0d190a5..6cc1af680 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/CartographyTableInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/CartographyTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -29,9 +29,9 @@ import java.lang.reflect.Field; /** - * Internal cartography table inventory for 1.20 + * Internal cartography table inventory for 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 */ public class CartographyTableInventoryImpl extends CartographyTableInventory { @@ -92,7 +92,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.10 + * @since 0.10.14 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -104,7 +104,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -117,7 +117,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -128,7 +128,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container cartography table * - * @since 0.10.10 + * @since 0.10.14 */ private class ContainerCartographyTableImpl extends CartographyTableMenu { diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/EnchantingTableInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/EnchantingTableInventoryImpl.java similarity index 96% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/EnchantingTableInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/EnchantingTableInventoryImpl.java index e24ad5b1c..0bb826224 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/EnchantingTableInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/EnchantingTableInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal enchanting table inventory for 1.20 + * Internal enchanting table inventory for 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 */ public class EnchantingTableInventoryImpl extends EnchantingTableInventory { @@ -94,7 +94,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.10 + * @since 0.10.14 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -106,7 +106,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -119,7 +119,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -130,7 +130,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.10 + * @since 0.10.14 */ private class ContainerEnchantingTableImpl extends EnchantmentMenu { diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/GrindstoneInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/GrindstoneInventoryImpl.java similarity index 94% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/GrindstoneInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/GrindstoneInventoryImpl.java index 29a424b86..842fcc910 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/GrindstoneInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/GrindstoneInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -27,9 +27,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal grindstone inventory for 1.20 + * Internal grindstone inventory for 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 */ public class GrindstoneInventoryImpl extends GrindstoneInventory { @@ -104,7 +104,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @Contract(pure = true) @@ -118,7 +118,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @NotNull @@ -133,7 +133,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -144,7 +144,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container grindstone * - * @since 0.10.10 + * @since 0.10.14 */ private static class ContainerGrindstoneImpl extends GrindstoneMenu { @@ -153,7 +153,7 @@ private static class ContainerGrindstoneImpl extends GrindstoneMenu { * * @param serverPlayer the player for whom this container should be opened * @param title the title of the gui - * @since 0.10.10 + * @since 0.10.14 */ public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/MerchantInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/MerchantInventoryImpl.java similarity index 95% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/MerchantInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/MerchantInventoryImpl.java index 096076cd3..9eb421d0e 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/MerchantInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/MerchantInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import net.minecraft.server.level.ServerPlayer; @@ -16,9 +16,9 @@ import java.util.Map; /** - * Internal merchant inventory for 1.20 + * Internal merchant inventory for 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 */ public class MerchantInventoryImpl extends MerchantInventory { @@ -75,7 +75,7 @@ public void sendMerchantOffers(@NotNull Player player, * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -88,7 +88,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.10 + * @since 0.10.14 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/SmithingTableInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/SmithingTableInventoryImpl.java similarity index 95% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/SmithingTableInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/SmithingTableInventoryImpl.java index 534c50780..82fd2df81 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/SmithingTableInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/SmithingTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -29,9 +29,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal smithing table inventory for 1.20. This is only available for Minecraft 1.20 and higher. + * Internal smithing table inventory for 1.20.0. This is only available for Minecraft 1.20 and higher. * - * @since 0.10.10 + * @since 0.10.14 */ public class SmithingTableInventoryImpl extends SmithingTableInventory { @@ -139,7 +139,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @Deprecated @@ -155,7 +155,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @Deprecated @@ -172,7 +172,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @Contract(pure = true) @@ -186,7 +186,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.10 + * @since 0.10.14 * @deprecated no longer used internally */ @NotNull @@ -201,7 +201,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -212,7 +212,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container smithing table * - * @since 0.10.10 + * @since 0.10.14 */ private static class ContainerSmithingTableImpl extends SmithingMenu { @@ -221,7 +221,7 @@ private static class ContainerSmithingTableImpl extends SmithingMenu { * * @param serverPlayer the player for whom this anvil container is * @param title the title of the inventory - * @since 0.10.10 + * @since 0.10.14 */ public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/StonecutterInventoryImpl.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/StonecutterInventoryImpl.java similarity index 95% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/StonecutterInventoryImpl.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/StonecutterInventoryImpl.java index d74c6de38..6bfdb19d8 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/StonecutterInventoryImpl.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/StonecutterInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal stonecutter inventory for 1.20 + * Internal stonecutter inventory for 1.20.0 * - * @since 0.10.10 + * @since 0.10.14 */ public class StonecutterInventoryImpl extends StonecutterInventory { @@ -93,7 +93,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.10 + * @since 0.10.14 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -105,7 +105,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -118,7 +118,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -129,7 +129,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.10 + * @since 0.10.14 */ private class ContainerStonecutterImpl extends StonecutterMenu { @@ -206,7 +206,7 @@ public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} * Gets the result inventory * * @return the result inventory - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/CustomInventoryUtil.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/util/CustomInventoryUtil.java similarity index 91% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/CustomInventoryUtil.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/util/CustomInventoryUtil.java index 0cae2b267..5050a7885 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/CustomInventoryUtil.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/util/CustomInventoryUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; @@ -10,7 +10,7 @@ /** * A utility class for custom inventories * - * @since 0.10.10 + * @since 0.10.14 */ public final class CustomInventoryUtil { @@ -25,7 +25,7 @@ private CustomInventoryUtil() {} * * @param items the items to convert * @return a list of converted items - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) diff --git a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/TextHolderUtil.java b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/util/TextHolderUtil.java similarity index 92% rename from nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/TextHolderUtil.java rename to nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/util/TextHolderUtil.java index c99a391ea..ef64afcc5 100644 --- a/nms/1_20_0-1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0_1/util/TextHolderUtil.java +++ b/nms/1_20_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_0/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_20_0_1.util; +package com.github.stefvanschie.inventoryframework.nms.v1_20_0.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; @@ -12,7 +12,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since 0.10.10 + * @since 0.10.14 */ public final class TextHolderUtil { @@ -25,7 +25,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -42,7 +42,7 @@ public static Component toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) @@ -55,7 +55,7 @@ private static Component toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.10 + * @since 0.10.14 */ @NotNull @Contract(pure = true) diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml new file mode 100644 index 000000000..8e6f3ef74 --- /dev/null +++ b/nms/1_20_1/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.14-SNAPSHOT + ../../pom.xml + + + 1_20_1 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + ca.bkaw + paper-nms + 1.20.1-SNAPSHOT + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.3 + + + process-classes + + remap + + + + + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + \ No newline at end of file diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/AnvilInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/AnvilInventoryImpl.java new file mode 100644 index 000000000..ec4284832 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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 anvil inventory for 1.20.1 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.14 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.14 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/BeaconInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/BeaconInventoryImpl.java new file mode 100644 index 000000000..ecbae2c22 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/BeaconInventoryImpl.java @@ -0,0 +1,200 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.1 + * + * @since 0.10.14 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.14 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("r"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/CartographyTableInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..6d3f7af35 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.1 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.14 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/EnchantingTableInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..c16480009 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/EnchantingTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.1 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.14 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("n"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/GrindstoneInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..35bd3c5d1 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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 grindstone inventory for 1.20.1 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.14 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.14 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/MerchantInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/MerchantInventoryImpl.java new file mode 100644 index 000000000..687afca70 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/MerchantInventoryImpl.java @@ -0,0 +1,97 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_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.20.1 + * + * @since 0.10.14 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.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(); + + MerchantOffer merchantOffer = new MerchantOffer( + nmsItemA, nmsItemB, nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/SmithingTableInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..30be2e530 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_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.20.1. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.14 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.14 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.14 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/StonecutterInventoryImpl.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/StonecutterInventoryImpl.java new file mode 100644 index 000000000..53d96f9c5 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/StonecutterInventoryImpl.java @@ -0,0 +1,221 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_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.20.1 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.14 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/CustomInventoryUtil.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/CustomInventoryUtil.java new file mode 100644 index 000000000..ed08ff8f4 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_1.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.14 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/TextHolderUtil.java b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/TextHolderUtil.java new file mode 100644 index 000000000..3438bb279 --- /dev/null +++ b/nms/1_20_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_1/util/TextHolderUtil.java @@ -0,0 +1,65 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_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.network.chat.Component; +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.14 + */ +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.14 + */ + @NotNull + @Contract(pure = true) + public static Component 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.14 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.14 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson())); + } +} diff --git a/pom.xml b/pom.xml index 4959afdfe..83f902304 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,8 @@ nms/abstraction nms/1_20_3-4 nms/1_20_2 - nms/1_20_0-1 + nms/1_20_1 + nms/1_20_0 nms/1_19_4 nms/1_19_3 nms/1_19_2 From 485267eea355d6fc24d42ba6e859bbc5dfe12953 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 3 Mar 2024 20:57:18 +0100 Subject: [PATCH 285/382] Fix CI --- .github/dependabot.yml | 6 +++++- .github/workflows/auto-deploy.yml | 3 ++- .github/workflows/maven.yml | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c4bd20453..50b16e349 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -73,7 +73,11 @@ updates: schedule: interval: "daily" - package-ecosystem: "maven" - directory: "/nms/1_20_0-1" + directory: "/nms/1_20_0" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_20_1" schedule: interval: "daily" - package-ecosystem: "maven" diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index bb550f67b..43d5b625b 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -71,7 +71,8 @@ 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_0-1 + 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: Setup GPG keys diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a8ec0d451..f4b77daf8 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -77,7 +77,8 @@ 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_0-1 + 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: Build with Maven From d156525c4f186517fe1243fd421477745578a6de Mon Sep 17 00:00:00 2001 From: Gregor Suurvarik <55884713+GregorSomething@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:35:54 +0200 Subject: [PATCH 286/382] Update SkullUtil.java --- .../stefvanschie/inventoryframework/util/SkullUtil.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 880ec0fe5..5bf584bfc 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 @@ -51,15 +51,18 @@ 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(), "RandomName"); // Name is not null to avoid errors. + 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(); try { Field profileField = meta.getClass().getDeclaredField("profile"); profileField.setAccessible(true); profileField.set(meta, profile); + + meta.setDisplayName(itemDisplayName); } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) { throw new RuntimeException(e); } From 3f0df57dbd8aa7c278edd8abd55676f0d14089b9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 05:04:08 +0000 Subject: [PATCH 287/382] Bump org.apache.maven.plugins:maven-gpg-plugin in /nms/abstraction Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.1.0...maven-gpg-plugin-3.2.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 83f902304..ebfdf8f5f 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.1.0 + 3.2.0 sign-artifacts From e6aeafaf921421fd8df2e799b7ad73d44e010dcc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 05:37:25 +0000 Subject: [PATCH 288/382] Bump org.apache.maven.plugins:maven-gpg-plugin in /IF Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.1.0...maven-gpg-plugin-3.2.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 686d8ada8..a17cd0a93 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -208,7 +208,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.1.0 + 3.2.0 sign-artifacts From 1f0a18fce994a4d2fa22d62a1ed2cabe49d2c399 Mon Sep 17 00:00:00 2001 From: Gregor Suurvarik <55884713+GregorSomething@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:01:50 +0200 Subject: [PATCH 289/382] Update SkullUtil.java --- .../inventoryframework/util/SkullUtil.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 5bf584bfc..47e62f15b 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 @@ -63,8 +63,15 @@ public static void setSkull(@NotNull ItemMeta meta, @NotNull String id) { profileField.set(meta, profile); meta.setDisplayName(itemDisplayName); - } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) { + + // 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) {} } } From b07309a5ada3fcc13f82f9c5c5ea486fb3f57dab Mon Sep 17 00:00:00 2001 From: Gregor Suurvarik <55884713+GregorSomething@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:46:15 +0200 Subject: [PATCH 290/382] Update SkullUtil.java --- .../github/stefvanschie/inventoryframework/util/SkullUtil.java | 2 ++ 1 file changed, 2 insertions(+) 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 47e62f15b..1537767dc 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 @@ -8,6 +8,8 @@ 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.util.Objects; import java.util.UUID; From f41c85a83fb17842e2950c63b6a7286ed665f673 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 05:06:56 +0000 Subject: [PATCH 291/382] Bump org.apache.maven.plugins:maven-gpg-plugin in /IF Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.0 to 3.2.1. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.0...maven-gpg-plugin-3.2.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index a17cd0a93..1cb51844f 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -208,7 +208,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.0 + 3.2.1 sign-artifacts diff --git a/pom.xml b/pom.xml index ebfdf8f5f..cf3168cad 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.0 + 3.2.1 sign-artifacts From 3b6bb0bec3e4d225c9a501b292d3a4d5cc050a03 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 19 Mar 2024 21:24:36 +0100 Subject: [PATCH 292/382] Add PagingButtons --- .../inventoryframework/gui/type/util/Gui.java | 1 + .../pane/PaginatedPane.java | 5 + .../inventoryframework/pane/Pane.java | 32 +- .../pane/component/PagingButtons.java | 395 ++++++++++++++++++ 4 files changed, 424 insertions(+), 9 deletions(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PagingButtons.java 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..6ef314fae 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 @@ -719,6 +719,7 @@ public static Pane loadPane(@NotNull Object instance, @NotNull Node node) { (TriFunction) CycleButton::load); registerPane("label", (TriFunction) Label::load); + registerPane("pagingbuttons", PagingButtons::load); registerPane("percentagebar", (TriFunction) PercentageBar::load); registerPane("slider", diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index f7b814312..c3778e757 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -461,6 +461,11 @@ public static PaginatedPane load(@NotNull Object instance, @NotNull Element elem if (element.hasAttribute("populate")) return paginatedPane; + if (element.hasAttribute("id")) { + element.setIdAttribute("id", true); + element.setUserData("pane", paginatedPane, null); + } + int pageCount = 0; NodeList childNodes = element.getChildNodes(); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index e927a28f7..9a44511f5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -609,6 +609,28 @@ public static void load(@NotNull Pane pane, @NotNull Object instance, @NotNull E } } + /** + * Checks whether a {@link GuiItem} is the same item as the given {@link ItemStack}. The item will be compared using + * internal data. When the item does not have this data, this method will return false. If the item does have such + * data, but its value does not match, false is also returned. This method will not mutate any of the provided + * arguments. + * + * @param guiItem the gui item to check + * @param item the item which the gui item should be checked against + * @return true if the {@link GuiItem} matches the {@link ItemStack}, false otherwise + * @since 0.10.14 + */ + @Contract(pure = true) + protected static boolean matchesItem(@NotNull GuiItem guiItem, @NotNull ItemStack item) { + ItemMeta meta = item.getItemMeta(); + + if (meta == null) { + return false; + } + + return guiItem.getUUID().equals(meta.getPersistentDataContainer().get(guiItem.getKey(), UUIDTagType.INSTANCE)); + } + /** * Finds a type of {@link GuiItem} from the provided collection of items based on the provided {@link ItemStack}. * The items will be compared using internal data. When the item does not have this data, this method will return @@ -628,15 +650,7 @@ public static void load(@NotNull Pane pane, @NotNull Object instance, @NotNull E @Contract(pure = true) protected static T findMatchingItem(@NotNull Collection items, @NotNull ItemStack item) { for (T guiItem : items) { - ItemMeta meta = item.getItemMeta(); - - if (meta == null) { - return null; - } - - UUID uuid = meta.getPersistentDataContainer().get(guiItem.getKey(), UUIDTagType.INSTANCE); - - if (guiItem.getUUID().equals(uuid)) { + if (matchesItem(guiItem, item)) { return guiItem; } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PagingButtons.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PagingButtons.java new file mode 100644 index 000000000..7458b5999 --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/component/PagingButtons.java @@ -0,0 +1,395 @@ +package com.github.stefvanschie.inventoryframework.pane.component; + +import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +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.PaginatedPane; +import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.pane.util.Slot; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.w3c.dom.Element; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; + +/** + * An interface for interacting with {@link PaginatedPane}s. This gives two buttons for navigating backwards and + * forwards through the pages of the {@link PaginatedPane}. The backward button will be displayed at (0, 0) of this pane + * and the forward button will be displayed at (length - 1, 0) of this pane. If the paginated pane is at the first page + * or the last page, the backwards respectively the forward button will not show. This does not display the + * {@link PaginatedPane} itself, but is merely an interface for interacting with it. + * + * @since 0.10.14 + */ +public class PagingButtons extends Pane { + + /** + * The paginated pane. + */ + @NotNull + private final PaginatedPane pages; + + /** + * The backwards button. + */ + @NotNull + private GuiItem backwardButton; + + /** + * The forwards button. + */ + @NotNull + private GuiItem forwardButton; + + /** + * The plugin with which the items were created. + */ + @NotNull + private final Plugin plugin; + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param slot the position of this interface + * @param length the length of this interface + * @param priority the priority of this interface + * @param pages the pages to interact with + * @param plugin the plugin that will be the owner of this interface's items + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons( + @NotNull Slot slot, + int length, + @NotNull Priority priority, + @NotNull PaginatedPane pages, + @NotNull Plugin plugin + ) { + super(slot, length, 1, priority); + + if (length < 2) { + throw new IllegalArgumentException("Length of paging buttons must be at least 2"); + } + + this.pages = pages; + this.plugin = plugin; + + this.backwardButton = new GuiItem(new ItemStack(Material.ARROW), plugin); + this.forwardButton = new GuiItem(new ItemStack(Material.ARROW), plugin); + } + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param slot the position of this interface + * @param length the length of this interface + * @param priority the priority of this interface + * @param pages the pages to interact with + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons(@NotNull Slot slot, int length, @NotNull Priority priority, @NotNull PaginatedPane pages) { + this(slot, length, priority, pages, JavaPlugin.getProvidingPlugin(PagingButtons.class)); + } + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param slot the position of this interface + * @param length the length of this interface + * @param pages the pages to interact with + * @param plugin the plugin that will be the owner of this interface's items + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons(@NotNull Slot slot, int length, @NotNull PaginatedPane pages, @NotNull Plugin plugin) { + this(slot, length, Priority.NORMAL, pages, plugin); + } + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param slot the position of this interface + * @param length the length of this interface + * @param pages the pages to interact with + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons(@NotNull Slot slot, int length, @NotNull PaginatedPane pages) { + this(slot, length, Priority.NORMAL, pages); + } + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param length the length of this interface + * @param priority the priority of this interface + * @param pages the pages to interact with + * @param plugin the plugin that will be the owner of this interface's items + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons(int length, @NotNull Priority priority, @NotNull PaginatedPane pages, @NotNull Plugin plugin) { + this(Slot.fromXY(0, 0), length, priority, pages, plugin); + } + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param length the length of this interface + * @param priority the priority of this interface + * @param pages the pages to interact with + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons(int length, @NotNull Priority priority, @NotNull PaginatedPane pages) { + this(Slot.fromXY(0, 0), length, priority, pages, JavaPlugin.getProvidingPlugin(PagingButtons.class)); + } + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param length the length of this interface + * @param pages the pages to interact with + * @param plugin the plugin that will be the owner of this interface's items + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons(int length, @NotNull PaginatedPane pages, @NotNull Plugin plugin) { + this(Slot.fromXY(0, 0), length, Priority.NORMAL, pages, plugin); + } + + /** + * Creates a new PagingButtons instance, which controls the provided {@link PaginatedPane}. The backward and forward + * item will be an arrow. If the length provided is less than 2, this will throw an + * {@link IllegalArgumentException}. + * + * @param length the length of this interface + * @param pages the pages to interact with + * @since 0.10.14 + * @throws IllegalArgumentException if the length is less than 2 + */ + public PagingButtons(int length, @NotNull PaginatedPane pages) { + this(Slot.fromXY(0, 0), length, Priority.NORMAL, pages); + } + + @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); + + ItemStack itemStack = event.getCurrentItem(); + + if (itemStack == null) { + return false; + } + + if (matchesItem(this.backwardButton, itemStack)) { + this.pages.setPage(this.pages.getPage() - 1); + + this.backwardButton.callAction(event); + + gui.update(); + + return true; + } + + if (matchesItem(this.forwardButton, itemStack)) { + this.pages.setPage(this.pages.getPage() + 1); + + this.forwardButton.callAction(event); + + gui.update(); + + return true; + } + + return false; + } + + @Override + public void display( + @NotNull InventoryComponent inventoryComponent, + int paneOffsetX, + int paneOffsetY, + int maxLength, + int maxHeight + ) { + int length = Math.min(getLength(), maxLength); + + int x = super.slot.getX(length) + paneOffsetX; + int y = super.slot.getY(length) + paneOffsetY; + + if (this.pages.getPage() > 0) { + inventoryComponent.setItem(this.backwardButton, x, y); + } + + if (this.pages.getPage() < this.pages.getPages() - 1) { + inventoryComponent.setItem(this.forwardButton, x + length - 1, y); + } + } + + /** + * {@inheritDoc} + * + * This does not make a copy of the {@link PaginatedPane} that is being controlled by this interface. + */ + @NotNull + @Contract(pure = true) + @Override + public PagingButtons copy() { + PagingButtons pagingButtons = new PagingButtons(getSlot(), getLength(), getPriority(), this.pages, this.plugin); + + pagingButtons.setVisible(isVisible()); + pagingButtons.onClick = super.onClick; + + pagingButtons.uuid = super.uuid; + + pagingButtons.backwardButton = this.backwardButton.copy(); + pagingButtons.forwardButton = this.forwardButton.copy(); + + return pagingButtons; + } + + @NotNull + @Contract(pure = true) + @Override + public Collection getItems() { + Collection items = new HashSet<>(); + + items.add(this.backwardButton); + items.add(this.forwardButton); + + return Collections.unmodifiableCollection(items); + } + + /** + * Sets the item to be used for navigating backwards. If an event is attached to the item, this event will be called + * after the page has been changed. + * + * @param item the new backward item + * @since 0.10.14 + */ + public void setBackwardButton(@NotNull GuiItem item) { + this.backwardButton = item; + } + + /** + * Sets the item to be used for navigating forwards. If an event is attached to the item, this event will be called + * after the page has been changed. + * + * @param item the new forward item + * @since 0.10.14 + */ + public void setForwardButton(@NotNull GuiItem item) { + this.forwardButton = item; + } + + @NotNull + @Contract(pure = true) + @Override + public Collection getPanes() { + return Collections.emptySet(); + } + + /** + * This is a no-op. + * + * @since 0.10.14 + */ + @Override + public void clear() {} + + /** + * Loads a paging buttons pane from an XML element. + * + * @param instance the instance class + * @param element the element + * @param plugin the plugin that will be the owner of the underlying items + * @return the paging buttons pane + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + public static PagingButtons load(@NotNull Object instance, @NotNull Element element, @NotNull Plugin plugin) { + int length; + + try { + length = Integer.parseInt(element.getAttribute("length")); + } catch (NumberFormatException exception) { + throw new XMLLoadException(exception); + } + + if (!element.hasAttribute("pages")) { + throw new XMLLoadException("Paging buttons does not have pages attribute"); + } + + Element paginatedPaneElement = element.getOwnerDocument().getElementById(element.getAttribute("pages")); + + if (paginatedPaneElement == null) { + throw new XMLLoadException("Paging buttons pages reference is invalid"); + } + + Object paginatedPane = paginatedPaneElement.getUserData("pane"); + + if (!(paginatedPane instanceof PaginatedPane)) { + throw new XMLLoadException("Retrieved data is not a paginated pane"); + } + + PagingButtons pagingButtons = new PagingButtons(length, (PaginatedPane) paginatedPane); + + Pane.load(pagingButtons, instance, element); + + return pagingButtons; + } +} From 0c4b3ef905d530975a75ced7870089bf4f009e7c Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 26 Mar 2024 21:51:39 +0100 Subject: [PATCH 293/382] Add Gui#setParent --- .../inventoryframework/gui/GuiListener.java | 3 + .../inventoryframework/gui/type/util/Gui.java | 1576 +++++++++-------- 2 files changed, 808 insertions(+), 771 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index 0acf686e3..56524dd6d 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -369,6 +369,9 @@ public void onInventoryClose(@NotNull InventoryCloseEvent event) { } else if (gui instanceof ModernSmithingTableGui) { ((ModernSmithingTableGui) gui).handleClose(humanEntity); } + + //Bukkit doesn't like it if you open an inventory while the previous one is being closed + Bukkit.getScheduler().runTask(this.plugin, () -> gui.navigateToParent(humanEntity)); } } 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 6ef314fae..d354f4b57 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 @@ -1,771 +1,805 @@ -package com.github.stefvanschie.inventoryframework.gui.type.util; - -import com.github.stefvanschie.inventoryframework.HumanEntityCache; -import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; -import com.github.stefvanschie.inventoryframework.gui.GuiListener; -import com.github.stefvanschie.inventoryframework.gui.type.*; -import com.github.stefvanschie.inventoryframework.pane.*; -import com.github.stefvanschie.inventoryframework.pane.component.*; -import com.github.stefvanschie.inventoryframework.util.TriFunction; -import com.github.stefvanschie.inventoryframework.util.XMLUtil; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.HumanEntity; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.logging.Level; - -/** - * The base class of all GUIs - */ -public abstract class Gui { - - /** - * The plugin that owns this gui - */ - @NotNull - protected final Plugin plugin; - - /** - * The inventory of this gui - */ - protected Inventory inventory; - - /** - * A player cache for storing player's inventories - */ - @NotNull - protected final HumanEntityCache humanEntityCache = new HumanEntityCache(); - - /** - * The consumer that will be called once a players clicks in the top-half of the gui - */ - @Nullable - protected Consumer onTopClick; - - /** - * The consumer that will be called once a players clicks in the bottom-half of the gui - */ - @Nullable - protected Consumer onBottomClick; - - /** - * The consumer that will be called once a players clicks in the gui or in their inventory - */ - @Nullable - protected Consumer onGlobalClick; - - /** - * The consumer that will be called once a player clicks outside of the gui screen - */ - @Nullable - protected Consumer onOutsideClick; - - /** - * The consumer that will be called once a player drags in the top-half of the gui - */ - @Nullable - protected Consumer onTopDrag; - - /** - * The consumer that will be called once a player drags in the bottom-half of the gui - */ - @Nullable - protected Consumer onBottomDrag; - - /** - * The consumer that will be called once a player drags in the gui or their inventory - */ - @Nullable - protected Consumer onGlobalDrag; - - /** - * The consumer that will be called once a player closes the gui - */ - @Nullable - protected Consumer onClose; - - /** - * Whether this gui is updating (as invoked by {@link #update()}), true if this is the case, false otherwise. This - * is used to indicate that inventory close events due to updating should be ignored. - */ - boolean updating = false; - - /** - * The pane mapping which will allow users to register their own panes to be used in XML files - */ - @NotNull - private static final Map> - PANE_MAPPINGS = new HashMap<>(); - - /** - * The gui mappings which determine which gui type belongs to which identifier - */ - @NotNull - private static final Map> - GUI_MAPPINGS = new HashMap<>(); - - /** - * A map containing the relations between inventories and their respective gui. This is needed because Bukkit and - * Spigot ignore inventory holders for beacons, brewing stands, dispensers, droppers, furnaces and hoppers. The - * inventory holder for beacons is already being set properly via NMS, but this contains the other inventory types. - */ - @NotNull - private static final Map GUI_INVENTORIES = new WeakHashMap<>(); - - /** - * Whether listeners have ben registered by some gui - */ - private static boolean hasRegisteredListeners; - - /** - * Constructs a new gui with the provided plugin. - * - * @param plugin the plugin - * @since 0.10.8 - */ - public Gui(@NotNull Plugin plugin) { - this.plugin = plugin; - - if (!hasRegisteredListeners) { - Bukkit.getPluginManager().registerEvents(new GuiListener(plugin), plugin); - - hasRegisteredListeners = true; - } - } - - /** - * Shows a gui to a player - * - * @param humanEntity the human entity to show the gui to - */ - public abstract void show(@NotNull HumanEntity humanEntity); - - /** - * Makes a copy of this gui and returns it. This makes a deep copy of the gui. This entails that the underlying - * panes will be copied as per their {@link Pane#copy} and miscellaneous data will be copied. The copy of this gui, - * will however have no viewers even if this gui currently has viewers. With this, cache data for viewers will also - * be non-existent for the copied gui. The original owning plugin of the gui is preserved, but the plugin will not - * be deeply copied. The returned gui will never be reference equal to the current gui. - * - * @return a copy of the gui - * @since 0.6.2 - */ - @NotNull - @Contract(pure = true) - public abstract Gui copy(); - - /** - * This should delegate the provided inventory click event to the right pane, which can then handle this click event - * further. This should not call any internal click handlers, since those will already have been activated. - * - * @param event the event to delegate - * @since 0.8.0 - */ - public abstract void click(@NotNull InventoryClickEvent event); - - /** - * Gets whether the player inventory is currently in use. This means whether the player inventory currently has an - * item in it. - * - * @return true if the player inventory is occupied, false otherwise - * @since 0.8.0 - */ - public abstract boolean isPlayerInventoryUsed(); - - /** - * Gets the count of {@link HumanEntity} instances that are currently viewing this GUI. - * - * @return the count of viewers - * @since 0.5.19 - */ - @Contract(pure = true) - public abstract int getViewerCount(); - - /** - * Gets a mutable snapshot of the current {@link HumanEntity} viewers of this GUI. - * This is a snapshot (copy) and not a view, therefore modifications aren't visible. - * - * @return a snapshot of the current viewers - * @see #getViewerCount() - * @since 0.5.19 - */ - @NotNull - @Contract(pure = true) - public abstract List getViewers(); - - /** - * Update the gui for everyone - */ - public void update() { - updating = true; - - for (HumanEntity viewer : getViewers()) { - ItemStack cursor = viewer.getItemOnCursor(); - viewer.setItemOnCursor(new ItemStack(Material.AIR)); - - show(viewer); - - viewer.setItemOnCursor(cursor); - } - - if (!updating) - throw new AssertionError("Gui#isUpdating became false before Gui#update finished"); - - updating = false; - } - - /** - * Adds the specified inventory and gui, so we can properly intercept clicks. - * - * @param inventory the inventory for the specified gui - * @param gui the gui belonging to the specified inventory - * @since 0.8.1 - */ - protected void addInventory(@NotNull Inventory inventory, @NotNull Gui gui) { - GUI_INVENTORIES.put(inventory, gui); - } - - /** - * Gets a gui from the specified inventory. Only guis of type beacon, brewing stand, dispenser, dropper, furnace and - * hopper can be retrieved. - * - * @param inventory the inventory to get the gui from - * @return the gui or null if the inventory doesn't have an accompanying gui - * @since 0.8.1 - */ - @Nullable - @Contract(pure = true) - public static Gui getGui(@NotNull Inventory inventory) { - return GUI_INVENTORIES.get(inventory); - } - - /** - * Gets the human entity cache used for this gui - * - * @return the human entity cache - * @see HumanEntityCache - * @since 0.5.4 - */ - @NotNull - @Contract(pure = true) - public HumanEntityCache getHumanEntityCache() { - return humanEntityCache; - } - - /** - * Loads a Gui from a given input stream. - * - * @param instance the class instance for all reflection lookups - * @param inputStream the file - * @return the gui or null if the loading failed - * @throws XMLLoadException if loading could not finish successfully, due to e.g., a malformed file - * @see #load(Object, InputStream) - * @since 0.10.8 - */ - @Nullable - public static Gui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { - try { - Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); - Element documentElement = document.getDocumentElement(); - - documentElement.normalize(); - - if (!documentElement.hasAttribute("type")) { - throw new XMLLoadException("Type attribute must be specified when loading via Gui.load"); - } - - String type = documentElement.getAttribute("type"); - TriFunction mapping = GUI_MAPPINGS - .get(type); - - if (mapping == null) { - throw new XMLLoadException("Type attribute '" + type + "' is invalid"); - } - - return mapping.apply(instance, documentElement, plugin); - } catch (SAXException | ParserConfigurationException | IOException e) { - e.printStackTrace(); - return null; - } - } - - /** - * Loads a Gui from a given input stream. - * Returns null instead of throwing an exception in case of a failure. - * - * @param instance the class instance for all reflection lookups - * @param inputStream the file - * @return the gui or null if the loading failed - * @throws XMLLoadException if loading could not finish successfully, due to e.g., a malformed file - */ - @Nullable - public static Gui load(@NotNull Object instance, @NotNull InputStream inputStream) { - return load(instance, inputStream, JavaPlugin.getProvidingPlugin(Gui.class)); - } - - /** - * Initializes standard fields from a Gui from a given input stream. - * Throws a {@link RuntimeException} instead of returning null in case of a failure. - * - * @param instance the class instance for all reflection lookups - * @param element the gui element - * @see #load(Object, InputStream) - */ - protected void initializeOrThrow(@NotNull Object instance, @NotNull Element element) { - if (element.hasAttribute("field")) - XMLUtil.loadFieldAttribute(instance, element, this); - - if (element.hasAttribute("onTopClick")) { - setOnTopClick(XMLUtil.loadOnEventAttribute(instance, - element, InventoryClickEvent.class, "onTopClick")); - } - - if (element.hasAttribute("onBottomClick")) { - setOnBottomClick(XMLUtil.loadOnEventAttribute(instance, - element, InventoryClickEvent.class, "onBottomClick")); - } - - if (element.hasAttribute("onGlobalClick")) { - setOnGlobalClick(XMLUtil.loadOnEventAttribute(instance, - element, InventoryClickEvent.class, "onGlobalClick")); - } - - if (element.hasAttribute("onOutsideClick")) { - setOnOutsideClick(XMLUtil.loadOnEventAttribute(instance, - element, InventoryClickEvent.class, "onOutsideClick")); - } - - if (element.hasAttribute("onTopDrag")) { - setOnTopDrag(XMLUtil.loadOnEventAttribute(instance, - element, InventoryDragEvent.class, "onTopDrag")); - } - - if (element.hasAttribute("onBottomDrag")) { - setOnBottomDrag(XMLUtil.loadOnEventAttribute(instance, - element, InventoryDragEvent.class, "onBottomDrag")); - } - - if (element.hasAttribute("onGlobalDrag")) { - setOnGlobalDrag(XMLUtil.loadOnEventAttribute(instance, - element, InventoryDragEvent.class, "onGlobalDrag")); - } - - if (element.hasAttribute("onClose")) { - setOnClose(XMLUtil.loadOnEventAttribute(instance, - element, InventoryCloseEvent.class, "onClose")); - } - - if (element.hasAttribute("populate")) { - XMLUtil.invokeMethod(instance, element.getAttribute("populate"), this, Gui.class); - } - } - - /** - * Set the consumer that should be called whenever this gui is clicked in. - * - * @param onTopClick the consumer that gets called - */ - public void setOnTopClick(@Nullable Consumer onTopClick) { - this.onTopClick = onTopClick; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnTopClick(Consumer)}, - * so the consumer that should be called whenever this gui is clicked in. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.6.0 - */ - public void callOnTopClick(@NotNull InventoryClickEvent event) { - callCallback(onTopClick, event, "onTopClick"); - } - - /** - * Set the consumer that should be called whenever the inventory is clicked in. - * - * @param onBottomClick the consumer that gets called - */ - public void setOnBottomClick(@Nullable Consumer onBottomClick) { - this.onBottomClick = onBottomClick; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnBottomClick(Consumer)}, - * so the consumer that should be called whenever the inventory is clicked in. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.6.0 - */ - public void callOnBottomClick(@NotNull InventoryClickEvent event) { - callCallback(onBottomClick, event, "onBottomClick"); - } - - /** - * Set the consumer that should be called whenever this gui or inventory is clicked in. - * - * @param onGlobalClick the consumer that gets called - */ - public void setOnGlobalClick(@Nullable Consumer onGlobalClick) { - this.onGlobalClick = onGlobalClick; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnGlobalClick(Consumer)}, - * so the consumer that should be called whenever this gui or inventory is clicked in. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.6.0 - */ - public void callOnGlobalClick(@NotNull InventoryClickEvent event) { - callCallback(onGlobalClick, event, "onGlobalClick"); - } - - /** - * Set the consumer that should be called whenever a player clicks outside the gui. - * - * @param onOutsideClick the consumer that gets called - * @since 0.5.7 - */ - public void setOnOutsideClick(@Nullable Consumer onOutsideClick) { - this.onOutsideClick = onOutsideClick; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnOutsideClick(Consumer)}, - * so the consumer that should be called whenever a player clicks outside the gui. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.6.0 - */ - public void callOnOutsideClick(@NotNull InventoryClickEvent event) { - callCallback(onOutsideClick, event, "onOutsideClick"); - } - - /** - * Set the consumer that should be called whenever this gui's top half is dragged in. - * - * @param onTopDrag the consumer that gets called - * @since 0.9.0 - */ - public void setOnTopDrag(@Nullable Consumer onTopDrag) { - this.onTopDrag = onTopDrag; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnTopDrag(Consumer)}, - * so the consumer that should be called whenever this gui's top half is dragged in. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.9.0 - */ - public void callOnTopDrag(@NotNull InventoryDragEvent event) { - callCallback(onTopDrag, event, "onTopDrag"); - } - - /** - * Set the consumer that should be called whenever the inventory is dragged in. - * - * @param onBottomDrag the consumer that gets called - * @since 0.9.0 - */ - public void setOnBottomDrag(@Nullable Consumer onBottomDrag) { - this.onBottomDrag = onBottomDrag; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnBottomDrag(Consumer)}, - * so the consumer that should be called whenever the inventory is dragged in. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.9.0 - */ - public void callOnBottomDrag(@NotNull InventoryDragEvent event) { - callCallback(onBottomDrag, event, "onBottomDrag"); - } - - /** - * Set the consumer that should be called whenever this gui or inventory is dragged in. - * - * @param onGlobalDrag the consumer that gets called - * @since 0.9.0 - */ - public void setOnGlobalDrag(@Nullable Consumer onGlobalDrag) { - this.onGlobalDrag = onGlobalDrag; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnGlobalDrag(Consumer)}, - * so the consumer that should be called whenever this gui or inventory is dragged in. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.6.0 - */ - public void callOnGlobalDrag(@NotNull InventoryDragEvent event) { - callCallback(onGlobalDrag, event, "onGlobalDrag"); - } - - /** - * Set the consumer that should be called whenever this gui is closed. - * - * @param onClose the consumer that gets called - */ - public void setOnClose(@Nullable Consumer onClose) { - this.onClose = onClose; - } - - /** - * Calls the consumer (if it's not null) that was specified using {@link #setOnClose(Consumer)}, - * so the consumer that should be called whenever this gui is closed. - * Catches and logs all exceptions the consumer might throw. - * - * @param event the event to handle - * @since 0.6.0 - */ - public void callOnClose(@NotNull InventoryCloseEvent event) { - callCallback(onClose, event, "onClose"); - } - - /** - * Calls the specified consumer (if it's not null) with the specified parameter, - * catching and logging all exceptions it might throw. - * - * @param callback the consumer to call if it isn't null - * @param event the value the consumer should accept - * @param callbackName the name of the action, used for logging - * @param the type of the value the consumer is accepting - */ - protected void callCallback(@Nullable Consumer callback, - @NotNull T event, @NotNull String callbackName) { - if (callback == null) { - return; - } - - try { - callback.accept(event); - } catch (Throwable t) { - String message = "Exception while handling " + callbackName; - if (event instanceof InventoryClickEvent) { - InventoryClickEvent clickEvent = (InventoryClickEvent) event; - message += ", slot=" + clickEvent.getSlot(); - } - - this.plugin.getLogger().log(Level.SEVERE, message, t); - } - } - - /** - * Gets whether this gui is being updated, as invoked by {@link #update()}. This returns true if this is the case - * and false otherwise. - * - * @return whether this gui is being updated - * @since 0.5.15 - */ - @Contract(pure = true) - public boolean isUpdating() { - return updating; - } - - /** - * Registers a property that can be used inside an XML file to add additional new properties. - * - * @param attributeName the name of the property. This is the same name you'll be using to specify the property - * type in the XML file. - * @param function how the property should be processed. This converts the raw text input from the XML node value - * into the correct object type. - * @throws IllegalArgumentException when a property with this name is already registered. - */ - public static void registerProperty(@NotNull String attributeName, @NotNull Function function) { - Pane.registerProperty(attributeName, function); - } - - /** - * Registers a name that can be used inside an XML file to add custom panes - * - * @param name the name of the pane to be used in the XML file - * @param triFunction how the pane loading should be processed - * @throws IllegalArgumentException when a pane with this name is already registered - * @see #registerPane(String, BiFunction) - * @since 0.10.8 - */ - public static void registerPane(@NotNull String name, - @NotNull TriFunction triFunction) { - if (PANE_MAPPINGS.containsKey(name)) { - throw new IllegalArgumentException("pane name '" + name + "' is already registered"); - } - - PANE_MAPPINGS.put(name, triFunction); - } - - /** - * Registers a name that can be used inside an XML file to add custom panes - * - * @param name the name of the pane to be used in the XML file - * @param biFunction how the pane loading should be processed - * @throws IllegalArgumentException when a pane with this name is already registered - */ - public static void registerPane(@NotNull String name, @NotNull BiFunction biFunction) { - registerPane(name, (object, element, plugin) -> biFunction.apply(object, element)); - } - - /** - * Registers a type that can be used inside an XML file to specify the gui type - * - * @param name the name of the type of gui to be used in an XML file - * @param triFunction how the gui creation should be processed - * @throws IllegalArgumentException when a gui type with this name is already registered - * @since 0.10.8 - */ - public static void registerGui(@NotNull String name, - @NotNull TriFunction triFunction) { - if (GUI_MAPPINGS.containsKey(name)) { - throw new IllegalArgumentException("Gui name '" + name + "' is already registered"); - } - - GUI_MAPPINGS.put(name, triFunction); - } - - /** - * Registers a type that can be used inside an XML file to specify the gui type - * - * @param name the name of the type of gui to be used in an XML file - * @param biFunction how the gui creation should be processed - * @throws IllegalArgumentException when a gui type with this name is already registered - * @deprecated this method is no longer used internally and has been superseded by - * {@link #registerPane(String, TriFunction)} - */ - @Deprecated - public static void registerGui(@NotNull String name, - @NotNull BiFunction biFunction) { - registerGui(name, (object, element, plugin) -> biFunction.apply(object, element)); - } - - /** - * Loads a pane by the given instance and node - * - * @param instance the instance - * @param node the node - * @param plugin the plugin to load the pane with - * @return the pane - * @throws XMLLoadException if the name of the node does not correspond to a valid pane. - * @since 0.10.8 - */ - @NotNull - public static Pane loadPane(@NotNull Object instance, @NotNull Node node, @NotNull Plugin plugin) { - String name = node.getNodeName(); - TriFunction mapping = PANE_MAPPINGS.get(name); - - if (mapping == null) { - throw new XMLLoadException("Pane '" + name + "' is not registered or does not exist"); - } - - return mapping.apply(instance, (Element) node, plugin); - } - - /** - * Loads a pane by the given instance and node - * - * @param instance the instance - * @param node the node - * @return the pane - */ - @NotNull - public static Pane loadPane(@NotNull Object instance, @NotNull Node node) { - return loadPane(instance, node, JavaPlugin.getProvidingPlugin(Gui.class)); - } - - static { - registerPane("masonrypane", - (TriFunction) MasonryPane::load); - registerPane("outlinepane", - (TriFunction) OutlinePane::load); - registerPane("paginatedpane", - (TriFunction) PaginatedPane::load); - registerPane("patternpane", - (TriFunction) PatternPane::load); - registerPane("staticpane", - (TriFunction) StaticPane::load); - - registerPane("cyclebutton", - (TriFunction) CycleButton::load); - registerPane("label", - (TriFunction) Label::load); - registerPane("pagingbuttons", PagingButtons::load); - registerPane("percentagebar", - (TriFunction) PercentageBar::load); - registerPane("slider", - (TriFunction) Slider::load); - registerPane("togglebutton", - (TriFunction) ToggleButton::load); - - registerGui("anvil", - (TriFunction) AnvilGui::load); - registerGui("barrel", - (TriFunction) BarrelGui::load); - registerGui("beacon", - (TriFunction) BeaconGui::load); - registerGui("blast-furnace", - (TriFunction) BlastFurnaceGui::load); - registerGui("brewing-stand", - (TriFunction) BrewingStandGui::load); - registerGui("cartography-table", - (TriFunction) CartographyTableGui::load); - registerGui("chest", - (TriFunction) ChestGui::load); - registerGui("crafting-table", - (TriFunction) CraftingTableGui::load); - registerGui("dispenser", - (TriFunction) DispenserGui::load); - registerGui("dropper", - (TriFunction) DropperGui::load); - registerGui("enchanting-table", - (TriFunction) EnchantingTableGui::load); - registerGui("ender-chest", - (TriFunction) EnderChestGui::load); - registerGui("furnace", - (TriFunction) FurnaceGui::load); - registerGui("grindstone", - (TriFunction) GrindstoneGui::load); - registerGui("hopper", - (TriFunction) HopperGui::load); - registerGui("merchant", - (TriFunction) MerchantGui::load); - registerGui("shulker-box", - (TriFunction) ShulkerBoxGui::load); - registerGui("smithing-table", - (TriFunction) SmithingTableGui::load); - registerGui("smoker", - (TriFunction) SmokerGui::load); - registerGui("stonecutter", - (TriFunction) StonecutterGui::load); - } -} +package com.github.stefvanschie.inventoryframework.gui.type.util; + +import com.github.stefvanschie.inventoryframework.HumanEntityCache; +import com.github.stefvanschie.inventoryframework.exception.XMLLoadException; +import com.github.stefvanschie.inventoryframework.gui.GuiListener; +import com.github.stefvanschie.inventoryframework.gui.type.*; +import com.github.stefvanschie.inventoryframework.pane.*; +import com.github.stefvanschie.inventoryframework.pane.component.*; +import com.github.stefvanschie.inventoryframework.util.TriFunction; +import com.github.stefvanschie.inventoryframework.util.XMLUtil; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.inventory.InventoryEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.logging.Level; + +/** + * The base class of all GUIs + */ +public abstract class Gui { + + /** + * The plugin that owns this gui + */ + @NotNull + protected final Plugin plugin; + + /** + * The inventory of this gui + */ + protected Inventory inventory; + + /** + * A player cache for storing player's inventories + */ + @NotNull + protected final HumanEntityCache humanEntityCache = new HumanEntityCache(); + + /** + * The consumer that will be called once a players clicks in the top-half of the gui + */ + @Nullable + protected Consumer onTopClick; + + /** + * The consumer that will be called once a players clicks in the bottom-half of the gui + */ + @Nullable + protected Consumer onBottomClick; + + /** + * The consumer that will be called once a players clicks in the gui or in their inventory + */ + @Nullable + protected Consumer onGlobalClick; + + /** + * The consumer that will be called once a player clicks outside of the gui screen + */ + @Nullable + protected Consumer onOutsideClick; + + /** + * The consumer that will be called once a player drags in the top-half of the gui + */ + @Nullable + protected Consumer onTopDrag; + + /** + * The consumer that will be called once a player drags in the bottom-half of the gui + */ + @Nullable + protected Consumer onBottomDrag; + + /** + * The consumer that will be called once a player drags in the gui or their inventory + */ + @Nullable + protected Consumer onGlobalDrag; + + /** + * The consumer that will be called once a player closes the gui + */ + @Nullable + protected Consumer onClose; + + /** + * Whether this gui is updating (as invoked by {@link #update()}), true if this is the case, false otherwise. This + * is used to indicate that inventory close events due to updating should be ignored. + */ + boolean updating = false; + + /** + * The parent gui. This gui will be navigated to once a player closes this gui. If this is null, the player will not + * be redirected to another gui once they close this gui. + */ + @Nullable + private Gui parent; + + /** + * The pane mapping which will allow users to register their own panes to be used in XML files + */ + @NotNull + private static final Map> + PANE_MAPPINGS = new HashMap<>(); + + /** + * The gui mappings which determine which gui type belongs to which identifier + */ + @NotNull + private static final Map> + GUI_MAPPINGS = new HashMap<>(); + + /** + * A map containing the relations between inventories and their respective gui. This is needed because Bukkit and + * Spigot ignore inventory holders for beacons, brewing stands, dispensers, droppers, furnaces and hoppers. The + * inventory holder for beacons is already being set properly via NMS, but this contains the other inventory types. + */ + @NotNull + private static final Map GUI_INVENTORIES = new WeakHashMap<>(); + + /** + * Whether listeners have ben registered by some gui + */ + private static boolean hasRegisteredListeners; + + /** + * Constructs a new gui with the provided plugin. + * + * @param plugin the plugin + * @since 0.10.8 + */ + public Gui(@NotNull Plugin plugin) { + this.plugin = plugin; + + if (!hasRegisteredListeners) { + Bukkit.getPluginManager().registerEvents(new GuiListener(plugin), plugin); + + hasRegisteredListeners = true; + } + } + + /** + * Shows a gui to a player + * + * @param humanEntity the human entity to show the gui to + */ + public abstract void show(@NotNull HumanEntity humanEntity); + + /** + * Makes a copy of this gui and returns it. This makes a deep copy of the gui. This entails that the underlying + * panes will be copied as per their {@link Pane#copy} and miscellaneous data will be copied. The copy of this gui, + * will however have no viewers even if this gui currently has viewers. With this, cache data for viewers will also + * be non-existent for the copied gui. The original owning plugin of the gui is preserved, but the plugin will not + * be deeply copied. The returned gui will never be reference equal to the current gui. + * + * @return a copy of the gui + * @since 0.6.2 + */ + @NotNull + @Contract(pure = true) + public abstract Gui copy(); + + /** + * This should delegate the provided inventory click event to the right pane, which can then handle this click event + * further. This should not call any internal click handlers, since those will already have been activated. + * + * @param event the event to delegate + * @since 0.8.0 + */ + public abstract void click(@NotNull InventoryClickEvent event); + + /** + * Gets whether the player inventory is currently in use. This means whether the player inventory currently has an + * item in it. + * + * @return true if the player inventory is occupied, false otherwise + * @since 0.8.0 + */ + public abstract boolean isPlayerInventoryUsed(); + + /** + * Gets the count of {@link HumanEntity} instances that are currently viewing this GUI. + * + * @return the count of viewers + * @since 0.5.19 + */ + @Contract(pure = true) + public abstract int getViewerCount(); + + /** + * Gets a mutable snapshot of the current {@link HumanEntity} viewers of this GUI. + * This is a snapshot (copy) and not a view, therefore modifications aren't visible. + * + * @return a snapshot of the current viewers + * @see #getViewerCount() + * @since 0.5.19 + */ + @NotNull + @Contract(pure = true) + public abstract List getViewers(); + + /** + * Update the gui for everyone + */ + public void update() { + updating = true; + + for (HumanEntity viewer : getViewers()) { + ItemStack cursor = viewer.getItemOnCursor(); + viewer.setItemOnCursor(new ItemStack(Material.AIR)); + + show(viewer); + + viewer.setItemOnCursor(cursor); + } + + if (!updating) + throw new AssertionError("Gui#isUpdating became false before Gui#update finished"); + + updating = false; + } + + /** + * Adds the specified inventory and gui, so we can properly intercept clicks. + * + * @param inventory the inventory for the specified gui + * @param gui the gui belonging to the specified inventory + * @since 0.8.1 + */ + protected void addInventory(@NotNull Inventory inventory, @NotNull Gui gui) { + GUI_INVENTORIES.put(inventory, gui); + } + + /** + * Gets a gui from the specified inventory. Only guis of type beacon, brewing stand, dispenser, dropper, furnace and + * hopper can be retrieved. + * + * @param inventory the inventory to get the gui from + * @return the gui or null if the inventory doesn't have an accompanying gui + * @since 0.8.1 + */ + @Nullable + @Contract(pure = true) + public static Gui getGui(@NotNull Inventory inventory) { + return GUI_INVENTORIES.get(inventory); + } + + /** + * Gets the human entity cache used for this gui + * + * @return the human entity cache + * @see HumanEntityCache + * @since 0.5.4 + */ + @NotNull + @Contract(pure = true) + public HumanEntityCache getHumanEntityCache() { + return humanEntityCache; + } + + /** + * Loads a Gui from a given input stream. + * + * @param instance the class instance for all reflection lookups + * @param inputStream the file + * @return the gui or null if the loading failed + * @throws XMLLoadException if loading could not finish successfully, due to e.g., a malformed file + * @see #load(Object, InputStream) + * @since 0.10.8 + */ + @Nullable + public static Gui load(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) { + try { + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); + Element documentElement = document.getDocumentElement(); + + documentElement.normalize(); + + if (!documentElement.hasAttribute("type")) { + throw new XMLLoadException("Type attribute must be specified when loading via Gui.load"); + } + + String type = documentElement.getAttribute("type"); + TriFunction mapping = GUI_MAPPINGS + .get(type); + + if (mapping == null) { + throw new XMLLoadException("Type attribute '" + type + "' is invalid"); + } + + return mapping.apply(instance, documentElement, plugin); + } catch (SAXException | ParserConfigurationException | IOException e) { + e.printStackTrace(); + return null; + } + } + + /** + * Loads a Gui from a given input stream. + * Returns null instead of throwing an exception in case of a failure. + * + * @param instance the class instance for all reflection lookups + * @param inputStream the file + * @return the gui or null if the loading failed + * @throws XMLLoadException if loading could not finish successfully, due to e.g., a malformed file + */ + @Nullable + public static Gui load(@NotNull Object instance, @NotNull InputStream inputStream) { + return load(instance, inputStream, JavaPlugin.getProvidingPlugin(Gui.class)); + } + + /** + * Initializes standard fields from a Gui from a given input stream. + * Throws a {@link RuntimeException} instead of returning null in case of a failure. + * + * @param instance the class instance for all reflection lookups + * @param element the gui element + * @see #load(Object, InputStream) + */ + protected void initializeOrThrow(@NotNull Object instance, @NotNull Element element) { + if (element.hasAttribute("field")) + XMLUtil.loadFieldAttribute(instance, element, this); + + if (element.hasAttribute("onTopClick")) { + setOnTopClick(XMLUtil.loadOnEventAttribute(instance, + element, InventoryClickEvent.class, "onTopClick")); + } + + if (element.hasAttribute("onBottomClick")) { + setOnBottomClick(XMLUtil.loadOnEventAttribute(instance, + element, InventoryClickEvent.class, "onBottomClick")); + } + + if (element.hasAttribute("onGlobalClick")) { + setOnGlobalClick(XMLUtil.loadOnEventAttribute(instance, + element, InventoryClickEvent.class, "onGlobalClick")); + } + + if (element.hasAttribute("onOutsideClick")) { + setOnOutsideClick(XMLUtil.loadOnEventAttribute(instance, + element, InventoryClickEvent.class, "onOutsideClick")); + } + + if (element.hasAttribute("onTopDrag")) { + setOnTopDrag(XMLUtil.loadOnEventAttribute(instance, + element, InventoryDragEvent.class, "onTopDrag")); + } + + if (element.hasAttribute("onBottomDrag")) { + setOnBottomDrag(XMLUtil.loadOnEventAttribute(instance, + element, InventoryDragEvent.class, "onBottomDrag")); + } + + if (element.hasAttribute("onGlobalDrag")) { + setOnGlobalDrag(XMLUtil.loadOnEventAttribute(instance, + element, InventoryDragEvent.class, "onGlobalDrag")); + } + + if (element.hasAttribute("onClose")) { + setOnClose(XMLUtil.loadOnEventAttribute(instance, + element, InventoryCloseEvent.class, "onClose")); + } + + if (element.hasAttribute("populate")) { + XMLUtil.invokeMethod(instance, element.getAttribute("populate"), this, Gui.class); + } + } + + /** + * Set the consumer that should be called whenever this gui is clicked in. + * + * @param onTopClick the consumer that gets called + */ + public void setOnTopClick(@Nullable Consumer onTopClick) { + this.onTopClick = onTopClick; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnTopClick(Consumer)}, + * so the consumer that should be called whenever this gui is clicked in. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.6.0 + */ + public void callOnTopClick(@NotNull InventoryClickEvent event) { + callCallback(onTopClick, event, "onTopClick"); + } + + /** + * Set the consumer that should be called whenever the inventory is clicked in. + * + * @param onBottomClick the consumer that gets called + */ + public void setOnBottomClick(@Nullable Consumer onBottomClick) { + this.onBottomClick = onBottomClick; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnBottomClick(Consumer)}, + * so the consumer that should be called whenever the inventory is clicked in. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.6.0 + */ + public void callOnBottomClick(@NotNull InventoryClickEvent event) { + callCallback(onBottomClick, event, "onBottomClick"); + } + + /** + * Set the consumer that should be called whenever this gui or inventory is clicked in. + * + * @param onGlobalClick the consumer that gets called + */ + public void setOnGlobalClick(@Nullable Consumer onGlobalClick) { + this.onGlobalClick = onGlobalClick; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnGlobalClick(Consumer)}, + * so the consumer that should be called whenever this gui or inventory is clicked in. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.6.0 + */ + public void callOnGlobalClick(@NotNull InventoryClickEvent event) { + callCallback(onGlobalClick, event, "onGlobalClick"); + } + + /** + * Set the consumer that should be called whenever a player clicks outside the gui. + * + * @param onOutsideClick the consumer that gets called + * @since 0.5.7 + */ + public void setOnOutsideClick(@Nullable Consumer onOutsideClick) { + this.onOutsideClick = onOutsideClick; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnOutsideClick(Consumer)}, + * so the consumer that should be called whenever a player clicks outside the gui. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.6.0 + */ + public void callOnOutsideClick(@NotNull InventoryClickEvent event) { + callCallback(onOutsideClick, event, "onOutsideClick"); + } + + /** + * Set the consumer that should be called whenever this gui's top half is dragged in. + * + * @param onTopDrag the consumer that gets called + * @since 0.9.0 + */ + public void setOnTopDrag(@Nullable Consumer onTopDrag) { + this.onTopDrag = onTopDrag; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnTopDrag(Consumer)}, + * so the consumer that should be called whenever this gui's top half is dragged in. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.9.0 + */ + public void callOnTopDrag(@NotNull InventoryDragEvent event) { + callCallback(onTopDrag, event, "onTopDrag"); + } + + /** + * Set the consumer that should be called whenever the inventory is dragged in. + * + * @param onBottomDrag the consumer that gets called + * @since 0.9.0 + */ + public void setOnBottomDrag(@Nullable Consumer onBottomDrag) { + this.onBottomDrag = onBottomDrag; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnBottomDrag(Consumer)}, + * so the consumer that should be called whenever the inventory is dragged in. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.9.0 + */ + public void callOnBottomDrag(@NotNull InventoryDragEvent event) { + callCallback(onBottomDrag, event, "onBottomDrag"); + } + + /** + * Set the consumer that should be called whenever this gui or inventory is dragged in. + * + * @param onGlobalDrag the consumer that gets called + * @since 0.9.0 + */ + public void setOnGlobalDrag(@Nullable Consumer onGlobalDrag) { + this.onGlobalDrag = onGlobalDrag; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnGlobalDrag(Consumer)}, + * so the consumer that should be called whenever this gui or inventory is dragged in. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.6.0 + */ + public void callOnGlobalDrag(@NotNull InventoryDragEvent event) { + callCallback(onGlobalDrag, event, "onGlobalDrag"); + } + + /** + * Set the consumer that should be called whenever this gui is closed. + * + * @param onClose the consumer that gets called + */ + public void setOnClose(@Nullable Consumer onClose) { + this.onClose = onClose; + } + + /** + * Calls the consumer (if it's not null) that was specified using {@link #setOnClose(Consumer)}, + * so the consumer that should be called whenever this gui is closed. + * Catches and logs all exceptions the consumer might throw. + * + * @param event the event to handle + * @since 0.6.0 + */ + public void callOnClose(@NotNull InventoryCloseEvent event) { + callCallback(onClose, event, "onClose"); + } + + /** + * Calls the specified consumer (if it's not null) with the specified parameter, + * catching and logging all exceptions it might throw. + * + * @param callback the consumer to call if it isn't null + * @param event the value the consumer should accept + * @param callbackName the name of the action, used for logging + * @param the type of the value the consumer is accepting + */ + protected void callCallback(@Nullable Consumer callback, + @NotNull T event, @NotNull String callbackName) { + if (callback == null) { + return; + } + + try { + callback.accept(event); + } catch (Throwable t) { + String message = "Exception while handling " + callbackName; + if (event instanceof InventoryClickEvent) { + InventoryClickEvent clickEvent = (InventoryClickEvent) event; + message += ", slot=" + clickEvent.getSlot(); + } + + this.plugin.getLogger().log(Level.SEVERE, message, t); + } + } + + /** + * The parent gui will be shown to the specified {@link HumanEntity}. If no parent gui is set, then this method will + * silently do nothing. + * + * @param humanEntity the human entity to redirect + * @since 0.10.14 + */ + public void navigateToParent(@NotNull HumanEntity humanEntity) { + if (this.parent == null) { + return; + } + + this.parent.show(humanEntity); + } + + /** + * Sets the parent gui to the provided gui. This is the gui that a player will be navigated to once they close this + * gui. The navigation will occur after the close event handler, set by {@link #setOnClose(Consumer)}, is called. If + * there was already a previous parent set, the provided gui will override the previous one. + * + * @param gui the new parent gui + * @since 0.10.14 + */ + public void setParent(@NotNull Gui gui) { + this.parent = gui; + } + + /** + * Gets whether this gui is being updated, as invoked by {@link #update()}. This returns true if this is the case + * and false otherwise. + * + * @return whether this gui is being updated + * @since 0.5.15 + */ + @Contract(pure = true) + public boolean isUpdating() { + return updating; + } + + /** + * Registers a property that can be used inside an XML file to add additional new properties. + * + * @param attributeName the name of the property. This is the same name you'll be using to specify the property + * type in the XML file. + * @param function how the property should be processed. This converts the raw text input from the XML node value + * into the correct object type. + * @throws IllegalArgumentException when a property with this name is already registered. + */ + public static void registerProperty(@NotNull String attributeName, @NotNull Function function) { + Pane.registerProperty(attributeName, function); + } + + /** + * Registers a name that can be used inside an XML file to add custom panes + * + * @param name the name of the pane to be used in the XML file + * @param triFunction how the pane loading should be processed + * @throws IllegalArgumentException when a pane with this name is already registered + * @see #registerPane(String, BiFunction) + * @since 0.10.8 + */ + public static void registerPane(@NotNull String name, + @NotNull TriFunction triFunction) { + if (PANE_MAPPINGS.containsKey(name)) { + throw new IllegalArgumentException("pane name '" + name + "' is already registered"); + } + + PANE_MAPPINGS.put(name, triFunction); + } + + /** + * Registers a name that can be used inside an XML file to add custom panes + * + * @param name the name of the pane to be used in the XML file + * @param biFunction how the pane loading should be processed + * @throws IllegalArgumentException when a pane with this name is already registered + */ + public static void registerPane(@NotNull String name, @NotNull BiFunction biFunction) { + registerPane(name, (object, element, plugin) -> biFunction.apply(object, element)); + } + + /** + * Registers a type that can be used inside an XML file to specify the gui type + * + * @param name the name of the type of gui to be used in an XML file + * @param triFunction how the gui creation should be processed + * @throws IllegalArgumentException when a gui type with this name is already registered + * @since 0.10.8 + */ + public static void registerGui(@NotNull String name, + @NotNull TriFunction triFunction) { + if (GUI_MAPPINGS.containsKey(name)) { + throw new IllegalArgumentException("Gui name '" + name + "' is already registered"); + } + + GUI_MAPPINGS.put(name, triFunction); + } + + /** + * Registers a type that can be used inside an XML file to specify the gui type + * + * @param name the name of the type of gui to be used in an XML file + * @param biFunction how the gui creation should be processed + * @throws IllegalArgumentException when a gui type with this name is already registered + * @deprecated this method is no longer used internally and has been superseded by + * {@link #registerPane(String, TriFunction)} + */ + @Deprecated + public static void registerGui(@NotNull String name, + @NotNull BiFunction biFunction) { + registerGui(name, (object, element, plugin) -> biFunction.apply(object, element)); + } + + /** + * Loads a pane by the given instance and node + * + * @param instance the instance + * @param node the node + * @param plugin the plugin to load the pane with + * @return the pane + * @throws XMLLoadException if the name of the node does not correspond to a valid pane. + * @since 0.10.8 + */ + @NotNull + public static Pane loadPane(@NotNull Object instance, @NotNull Node node, @NotNull Plugin plugin) { + String name = node.getNodeName(); + TriFunction mapping = PANE_MAPPINGS.get(name); + + if (mapping == null) { + throw new XMLLoadException("Pane '" + name + "' is not registered or does not exist"); + } + + return mapping.apply(instance, (Element) node, plugin); + } + + /** + * Loads a pane by the given instance and node + * + * @param instance the instance + * @param node the node + * @return the pane + */ + @NotNull + public static Pane loadPane(@NotNull Object instance, @NotNull Node node) { + return loadPane(instance, node, JavaPlugin.getProvidingPlugin(Gui.class)); + } + + static { + registerPane("masonrypane", + (TriFunction) MasonryPane::load); + registerPane("outlinepane", + (TriFunction) OutlinePane::load); + registerPane("paginatedpane", + (TriFunction) PaginatedPane::load); + registerPane("patternpane", + (TriFunction) PatternPane::load); + registerPane("staticpane", + (TriFunction) StaticPane::load); + + registerPane("cyclebutton", + (TriFunction) CycleButton::load); + registerPane("label", + (TriFunction) Label::load); + registerPane("pagingbuttons", PagingButtons::load); + registerPane("percentagebar", + (TriFunction) PercentageBar::load); + registerPane("slider", + (TriFunction) Slider::load); + registerPane("togglebutton", + (TriFunction) ToggleButton::load); + + registerGui("anvil", + (TriFunction) AnvilGui::load); + registerGui("barrel", + (TriFunction) BarrelGui::load); + registerGui("beacon", + (TriFunction) BeaconGui::load); + registerGui("blast-furnace", + (TriFunction) BlastFurnaceGui::load); + registerGui("brewing-stand", + (TriFunction) BrewingStandGui::load); + registerGui("cartography-table", + (TriFunction) CartographyTableGui::load); + registerGui("chest", + (TriFunction) ChestGui::load); + registerGui("crafting-table", + (TriFunction) CraftingTableGui::load); + registerGui("dispenser", + (TriFunction) DispenserGui::load); + registerGui("dropper", + (TriFunction) DropperGui::load); + registerGui("enchanting-table", + (TriFunction) EnchantingTableGui::load); + registerGui("ender-chest", + (TriFunction) EnderChestGui::load); + registerGui("furnace", + (TriFunction) FurnaceGui::load); + registerGui("grindstone", + (TriFunction) GrindstoneGui::load); + registerGui("hopper", + (TriFunction) HopperGui::load); + registerGui("merchant", + (TriFunction) MerchantGui::load); + registerGui("shulker-box", + (TriFunction) ShulkerBoxGui::load); + registerGui("smithing-table", + (TriFunction) SmithingTableGui::load); + registerGui("smoker", + (TriFunction) SmokerGui::load); + registerGui("stonecutter", + (TriFunction) StonecutterGui::load); + } +} From c6140b6b6994a92a9b175bcc87537c380aeb846e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 05:14:12 +0000 Subject: [PATCH 294/382] Bump org.apache.maven.plugins:maven-gpg-plugin in /nms/1_19_4 Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.1 to 3.2.2. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.1...maven-gpg-plugin-3.2.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cf3168cad..efe7711c7 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.1 + 3.2.2 sign-artifacts From 0dfb6b84c523455a55ec8fec9adf81c4cf466adc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 05:35:55 +0000 Subject: [PATCH 295/382] Bump org.apache.maven.plugins:maven-gpg-plugin in /IF Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.1 to 3.2.2. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.1...maven-gpg-plugin-3.2.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 1cb51844f..55dd5e5be 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -208,7 +208,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.1 + 3.2.2 sign-artifacts From 5ea1db2409e9cf7470193214ac923a3ed7312764 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Apr 2024 05:04:40 +0000 Subject: [PATCH 296/382] Bump org.apache.maven.plugins:maven-source-plugin in /nms/1_17_0 Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.3.0 to 3.3.1. - [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.3.0...maven-source-plugin-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-source-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index efe7711c7..f9f4c3beb 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ org.apache.maven.plugins maven-source-plugin - 3.3.0 + 3.3.1 attach-sources From 276860833378e4a28706083ca8301271ca2f0960 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Apr 2024 05:49:36 +0000 Subject: [PATCH 297/382] Bump org.apache.maven.plugins:maven-source-plugin in /IF Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.3.0 to 3.3.1. - [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.3.0...maven-source-plugin-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-source-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 55dd5e5be..73877052d 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -267,7 +267,7 @@ org.apache.maven.plugins maven-source-plugin - 3.3.0 + 3.3.1 attach-sources From a68f50dc8d9ccb9a442ff74ef406fa8c466f7d51 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 9 May 2024 22:00:34 +0200 Subject: [PATCH 298/382] Add 1.20.5 support --- .github/dependabot.yml | 4 + .github/workflows/auto-deploy.yml | 29 ++ .github/workflows/maven.yml | 29 ++ IF/pom.xml | 6 + .../util/version/Version.java | 13 +- .../util/version/VersionMatcher.java | 16 + nms/1_20_5/pom.xml | 73 ++++ .../nms/v1_20_5/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_20_5/BeaconInventoryImpl.java | 200 +++++++++++ .../CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_20_5/EnchantingTableInventoryImpl.java | 218 ++++++++++++ .../nms/v1_20_5/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_20_5/MerchantInventoryImpl.java | 119 +++++++ .../v1_20_5/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_20_5/StonecutterInventoryImpl.java | 221 ++++++++++++ .../nms/v1_20_5/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_20_5/util/TextHolderUtil.java | 67 ++++ pom.xml | 1 + 18 files changed, 2080 insertions(+), 2 deletions(-) create mode 100644 nms/1_20_5/pom.xml create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/AnvilInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/BeaconInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/CartographyTableInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/EnchantingTableInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/GrindstoneInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/MerchantInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/SmithingTableInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/StonecutterInventoryImpl.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/CustomInventoryUtil.java create mode 100644 nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/TextHolderUtil.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 50b16e349..671a75356 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -88,6 +88,10 @@ updates: directory: "/nms/1_20_3-4" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_20_5" + schedule: + interval: "daily" - package-ecosystem: "maven" directory: "/nms/abstraction" schedule: diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 43d5b625b..a5ecec683 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -75,6 +75,35 @@ 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: Run BuildTools 1.20.5 + 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 + cd ../ - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import - name: Automatically deploy the project diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f4b77daf8..eff4dce3f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -81,5 +81,34 @@ 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: Run BuildTools 1.20.5 + 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 + cd ../ - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 73877052d..158faa0eb 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -155,6 +155,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_20_5 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 734e663fc..32ce41d7b 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -146,14 +146,21 @@ public enum Version { * * @since 0.10.13 */ - V1_20_3_4; + V1_20_3_4, + + /** + * Version 1.20.5 + * + * @since 0.10.14 + */ + V1_20_5; /** * A collection of versions on which modern smithing tables are available. */ private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, - V1_20_0, V1_20_1, V1_20_2, V1_20_3_4 + V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5 ); /** @@ -250,6 +257,8 @@ public static Version getVersion() { case "1.20.3": case "1.20.4": return V1_20_3_4; + case "1.20.5": + return V1_20_5; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 e138a29d8..396068004 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 @@ -313,6 +313,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -353,6 +355,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -393,6 +397,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -433,6 +439,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -473,6 +481,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -513,6 +523,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, @@ -525,6 +537,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -593,5 +607,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_2.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_3_4, com.github.stefvanschie.inventoryframework.nms.v1_20_3.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20_5, + com.github.stefvanschie.inventoryframework.nms.v1_20_5.StonecutterInventoryImpl.class); } } diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml new file mode 100644 index 000000000..c08b3cec2 --- /dev/null +++ b/nms/1_20_5/pom.xml @@ -0,0 +1,73 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.14-SNAPSHOT + ../../pom.xml + + + 1_20_5 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.20.5-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.20.5-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.20.5-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/AnvilInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/AnvilInventoryImpl.java new file mode 100644 index 000000000..ac1a3ceec --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_R4.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 anvil inventory for 1.20.5 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.14 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.14 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/BeaconInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/BeaconInventoryImpl.java new file mode 100644 index 000000000..b5c91dfd9 --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/BeaconInventoryImpl.java @@ -0,0 +1,200 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.5 + * + * @since 0.10.14 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.14 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("s"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/CartographyTableInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..e7c4d926d --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.5 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.14 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/EnchantingTableInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..b6a9c4eba --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/EnchantingTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.5 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.14 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("o"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/GrindstoneInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..b53b79b6f --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_R4.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 grindstone inventory for 1.20.5 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.14 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.14 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/MerchantInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/MerchantInventoryImpl.java new file mode 100644 index 000000000..e655a9e19 --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/MerchantInventoryImpl.java @@ -0,0 +1,119 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.trading.ItemCost; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.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; +import java.util.Optional; + +/** + * Internal merchant inventory for 1.20.5 + * + * @since 0.10.14 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); + + if (itemB != null) { + nmsItemB = CraftItemStack.asNMSCopy(itemB); + } + + ItemCost itemCostA = convertItemStackToItemCost(nmsItemA); + ItemCost itemCostB = convertItemStackToItemCost(nmsItemB); + + int uses = recipe.getUses(); + int maxUses = recipe.getMaxUses(); + int exp = recipe.getVillagerExperience(); + float multiplier = recipe.getPriceMultiplier(); + + MerchantOffer merchantOffer = new MerchantOffer( + itemCostA, Optional.of(itemCostB), nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Converts an NMS item stack to an item cost. + * + * @param itemStack the item stack to convert + * @return the item cost + * @since 0.10.14 + */ + @NotNull + @Contract(value = "_ -> new", pure = true) + private ItemCost convertItemStackToItemCost(@NotNull net.minecraft.world.item.ItemStack itemStack) { + DataComponentPredicate predicate = DataComponentPredicate.allOf(itemStack.getComponents()); + + return new ItemCost(itemStack.getItemHolder(), itemStack.getCount(), predicate, itemStack); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/SmithingTableInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..44710f594 --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_R4.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.20.5. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.14 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.14 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.14 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/StonecutterInventoryImpl.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/StonecutterInventoryImpl.java new file mode 100644 index 000000000..698b5fb36 --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/StonecutterInventoryImpl.java @@ -0,0 +1,221 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_5.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.5 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.14 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/CustomInventoryUtil.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/CustomInventoryUtil.java new file mode 100644 index 000000000..b735c1655 --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_5.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.14 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/TextHolderUtil.java b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/TextHolderUtil.java new file mode 100644 index 000000000..9f8bce785 --- /dev/null +++ b/nms/1_20_5/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_5/util/TextHolderUtil.java @@ -0,0 +1,67 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_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.core.HolderLookup; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.stream.Stream; + +/** + * A utility class for adding {@link TextHolder} support. + * + * @since 0.10.14 + */ +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.14 + */ + @NotNull + @Contract(pure = true) + public static Component 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.14 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.14 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson(), HolderLookup.Provider.create(Stream.empty()))); + } +} diff --git a/pom.xml b/pom.xml index f9f4c3beb..6bd6e3eca 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_20_5 nms/1_20_3-4 nms/1_20_2 nms/1_20_1 From a16602931cb768ba4b74483528a5d866a24f5078 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 10 May 2024 21:08:50 +0200 Subject: [PATCH 299/382] CI: Update Java version to 21 --- .github/workflows/auto-deploy.yml | 4 ++-- .github/workflows/maven.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index a5ecec683..0eda366cb 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -52,10 +52,10 @@ jobs: 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 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - uses: actions/checkout@v2 name: Checkout code - name: Run paper-nms init diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index eff4dce3f..e5ee2553f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -58,10 +58,10 @@ jobs: 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 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - uses: actions/checkout@v2 name: Checkout code - name: Run paper-nms init From 92c2e92ca066f4367e4cb3d5679cc3088dd795a9 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 13 May 2024 22:15:49 +0200 Subject: [PATCH 300/382] Add 1.20.6 support --- .github/dependabot.yml | 4 + .github/workflows/auto-deploy.yml | 3 +- .github/workflows/maven.yml | 3 +- IF/pom.xml | 6 + .../util/version/Version.java | 13 +- .../util/version/VersionMatcher.java | 16 + nms/1_20_6/pom.xml | 73 ++++ .../nms/v1_20_6/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_20_6/BeaconInventoryImpl.java | 200 +++++++++++ .../CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_20_6/EnchantingTableInventoryImpl.java | 218 ++++++++++++ .../nms/v1_20_6/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_20_6/MerchantInventoryImpl.java | 118 ++++++ .../v1_20_6/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_20_6/StonecutterInventoryImpl.java | 221 ++++++++++++ .../nms/v1_20_6/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_20_6/util/TextHolderUtil.java | 67 ++++ pom.xml | 1 + 18 files changed, 2025 insertions(+), 4 deletions(-) create mode 100644 nms/1_20_6/pom.xml create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/AnvilInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/BeaconInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/CartographyTableInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/EnchantingTableInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/GrindstoneInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/MerchantInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/SmithingTableInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/StonecutterInventoryImpl.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/CustomInventoryUtil.java create mode 100644 nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/TextHolderUtil.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 671a75356..fc422adf2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -92,6 +92,10 @@ updates: directory: "/nms/1_20_5" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_20_6" + schedule: + interval: "daily" - package-ecosystem: "maven" directory: "/nms/abstraction" schedule: diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 0eda366cb..07a0ae635 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -75,7 +75,7 @@ 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: Run BuildTools 1.20.5 + - name: 'Run BuildTools 1.20.5 & 1.20.6' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -103,6 +103,7 @@ jobs: cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update + java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check cd ../ - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e5ee2553f..3ece93647 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -81,7 +81,7 @@ 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: Run BuildTools 1.20.5 + - name: 'Run BuildTools 1.20.5 & 1.20.6' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -109,6 +109,7 @@ jobs: cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update + java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check cd ../ - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 158faa0eb..1ef5bdd1a 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -161,6 +161,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_20_6 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 32ce41d7b..64568eaed 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -153,14 +153,21 @@ public enum Version { * * @since 0.10.14 */ - V1_20_5; + V1_20_5, + + /** + * Version 1.20.6 + * + * @since 0.10.14 + */ + V1_20_6; /** * A collection of versions on which modern smithing tables are available. */ private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, - V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5 + V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5, V1_20_6 ); /** @@ -259,6 +266,8 @@ public static Version getVersion() { return V1_20_3_4; case "1.20.5": return V1_20_5; + case "1.20.6": + return V1_20_6; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 396068004..f793eea1d 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 @@ -315,6 +315,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -357,6 +359,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -399,6 +403,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -441,6 +447,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -483,6 +491,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -525,6 +535,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, @@ -539,6 +551,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -609,5 +623,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_3.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_5, com.github.stefvanschie.inventoryframework.nms.v1_20_5.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_20_6, + com.github.stefvanschie.inventoryframework.nms.v1_20_6.StonecutterInventoryImpl.class); } } diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml new file mode 100644 index 000000000..c5dd0062e --- /dev/null +++ b/nms/1_20_6/pom.xml @@ -0,0 +1,73 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.14-SNAPSHOT + ../../pom.xml + + + 1_20_6 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.20.6-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/AnvilInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/AnvilInventoryImpl.java new file mode 100644 index 000000000..65cfec658 --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_R4.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 anvil inventory for 1.20.6 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.14 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.14 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/BeaconInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/BeaconInventoryImpl.java new file mode 100644 index 000000000..8d2b3914a --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/BeaconInventoryImpl.java @@ -0,0 +1,200 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.6 + * + * @since 0.10.14 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.14 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("s"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/CartographyTableInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..0e9624f28 --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.6 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.14 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/EnchantingTableInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..d3a65c70c --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/EnchantingTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.6 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.14 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("o"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/GrindstoneInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..04f79f892 --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_R4.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 grindstone inventory for 1.20.6 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.14 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.14 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/MerchantInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/MerchantInventoryImpl.java new file mode 100644 index 000000000..4ec8a905b --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/MerchantInventoryImpl.java @@ -0,0 +1,118 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.ItemCost; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.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; +import java.util.Optional; + +/** + * Internal merchant inventory for 1.20.6 + * + * @since 0.10.14 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); + + if (itemB != null) { + nmsItemB = CraftItemStack.asNMSCopy(itemB); + } + + ItemCost itemCostA = convertItemStackToItemCost(nmsItemA); + ItemCost itemCostB = convertItemStackToItemCost(nmsItemB); + + int uses = recipe.getUses(); + int maxUses = recipe.getMaxUses(); + int exp = recipe.getVillagerExperience(); + float multiplier = recipe.getPriceMultiplier(); + + MerchantOffer merchantOffer = new MerchantOffer( + itemCostA, Optional.of(itemCostB), nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Converts an NMS item stack to an item cost. + * + * @param itemStack the item stack to convert + * @return the item cost + * @since 0.10.14 + */ + @NotNull + @Contract(value = "_ -> new", pure = true) + private ItemCost convertItemStackToItemCost(@NotNull net.minecraft.world.item.ItemStack itemStack) { + DataComponentPredicate predicate = DataComponentPredicate.allOf(itemStack.getComponents()); + + return new ItemCost(itemStack.getItemHolder(), itemStack.getCount(), predicate, itemStack); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/SmithingTableInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..145f05e97 --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_20_R4.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.20.6. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.14 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.14 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.14 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.14 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/StonecutterInventoryImpl.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/StonecutterInventoryImpl.java new file mode 100644 index 000000000..62b21ba9b --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/StonecutterInventoryImpl.java @@ -0,0 +1,221 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_20_6.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_20_R4.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.20.6 + * + * @since 0.10.14 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.14 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.14 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/CustomInventoryUtil.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/CustomInventoryUtil.java new file mode 100644 index 000000000..a0f724f18 --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.14 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.14 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/TextHolderUtil.java b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/TextHolderUtil.java new file mode 100644 index 000000000..8e945b8bb --- /dev/null +++ b/nms/1_20_6/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_20_6/util/TextHolderUtil.java @@ -0,0 +1,67 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_20_6.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.core.HolderLookup; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.stream.Stream; + +/** + * A utility class for adding {@link TextHolder} support. + * + * @since 0.10.14 + */ +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.14 + */ + @NotNull + @Contract(pure = true) + public static Component 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.14 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.14 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson(), HolderLookup.Provider.create(Stream.empty()))); + } +} diff --git a/pom.xml b/pom.xml index 6bd6e3eca..673bef248 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_20_6 nms/1_20_5 nms/1_20_3-4 nms/1_20_2 From 5a97192741af89cf1a3702296cd38ef9cb63be97 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 16 May 2024 21:46:32 +0200 Subject: [PATCH 301/382] V 0.10.14 --- IF/pom.xml | 2 +- README.md | 36 +++++++++++++++++++++++++++++++++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 26 files changed, 58 insertions(+), 28 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 1ef5bdd1a..3157c9f45 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index 71e46aa66..2ab0942b8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.13 + 0.10.14 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.13' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.14' // ... } ``` @@ -124,7 +124,7 @@ mvn install:install-file -Dfile=cache/patched_1.16.4.jar -DgroupId="io.papermc" ``` ### Installing Paper via the maven plugin -For versions 1.17-1.18, we use Paper via the [paper-nms-maven-plugin](https://github.com/Alvinn8/paper-nms-maven-plugin). To install these versions locally, we must run a few maven commands. These commands should be ran in the root directory of the project. +For versions 1.17-1.20.4, we use Paper via the [paper-nms-maven-plugin](https://github.com/Alvinn8/paper-nms-maven-plugin). To install these versions locally, we must run a few maven commands. These commands should be ran in the root directory of the project. ``` mvn paper-nms:init -pl nms/1_17_0 mvn paper-nms:init -pl nms/1_17_1 @@ -141,6 +141,36 @@ mvn paper-nms:init -pl nms/1_20_2 mvn paper-nms:init -pl nms/1_20_3-4 ``` +### Installing Spigot via BuildTools +For versions 1.20.5-1.20.6, we use BuildTools. To install these versions, we run the following commands. +``` +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 +``` + Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. ``` mvn clean package diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index a16f0ac97..e10a84953 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 87396e593..a7d5e31c8 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 361ee78f8..3dbfe55f4 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index b9f694024..a6ec7b136 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index af25bc11d..89674f5a7 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index af0736fea..1ac890f62 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index a86864d35..2253ce025 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 5f81939a0..06c7f9cb7 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index a8cf8c2d8..101b9ac9e 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index e6dddaf56..d8fe26ea8 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 5ac5240db..8d520b750 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 74eb07cf2..59f40817b 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 13027a11b..0470d5227 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index cfacaf06a..851420547 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 2ef834583..07454bf3f 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 9a6b0f564..c8647789f 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index 29b5e7af2..dccdbd32d 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 8e6f3ef74..c1a648be7 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index 57bec5a06..ca0daaa7c 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index ebb7e8435..790c6825c 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index c08b3cec2..0942a0649 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index c5dd0062e..06ae532d4 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index d973ad639..9ca30d9d0 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14-SNAPSHOT + 0.10.14 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 673bef248..d5f1fbe48 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14-SNAPSHOT + 0.10.14 pom IF From 6904540090131084c2ac1ee2fd3797167989a753 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 15 Jun 2024 21:39:21 +0200 Subject: [PATCH 302/382] Bump to 0.10.15-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 3157c9f45..0168a46b5 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index e10a84953..a1884d31f 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index a7d5e31c8..65574698d 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 3dbfe55f4..3a8424ba7 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index a6ec7b136..f63dba4bc 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 89674f5a7..901e251fd 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 1ac890f62..68b52552a 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 2253ce025..523b90b6a 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 06c7f9cb7..bb45e8337 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 101b9ac9e..68f15f130 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index d8fe26ea8..9a6b74e3c 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 8d520b750..989c5cb22 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 59f40817b..69e5abf39 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 0470d5227..47478e7b4 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 851420547..94755363d 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 07454bf3f..2947be8bb 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index c8647789f..e05ce0332 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index dccdbd32d..a11c8b7c6 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index c1a648be7..8e6d8c345 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index ca0daaa7c..ece3d57b1 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 790c6825c..496ddc118 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 0942a0649..f55886c39 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index 06ae532d4..6da81b79d 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 9ca30d9d0..fdbdb3085 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.14 + 0.10.15-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index d5f1fbe48..9814cbe53 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.14 + 0.10.15-SNAPSHOT pom IF From 927075872e5f73a7417174adaeae6cac2cc0ba97 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 17 Jun 2024 20:21:27 +0200 Subject: [PATCH 303/382] Update deploy script to use access key --- .github/deployment/deploy.sh | 4 ++-- .github/deployment/settings.xml | 2 +- .github/workflows/auto-deploy.yml | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/deployment/deploy.sh b/.github/deployment/deploy.sh index b59735a9a..ccf6f861c 100644 --- a/.github/deployment/deploy.sh +++ b/.github/deployment/deploy.sh @@ -17,11 +17,11 @@ 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.password="$2"; 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.password="$2"; 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 diff --git a/.github/deployment/settings.xml b/.github/deployment/settings.xml index b6734a58c..6f1a37206 100644 --- a/.github/deployment/settings.xml +++ b/.github/deployment/settings.xml @@ -2,7 +2,7 @@ ossrh - stefvanschie + ${deploy.username} ${deploy.password} diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 07a0ae635..47103402b 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -110,5 +110,6 @@ jobs: - name: Automatically deploy the project env: gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} + deploy_username: ${{ secrets.DEPLOY_USERNAME }} deploy_password: ${{ secrets.DEPLOY_PASSWORD }} - run: bash ./.github/deployment/deploy.sh "$gpg_passphrase" "$deploy_password" + run: bash ./.github/deployment/deploy.sh "$gpg_passphrase" "$deploy_username" "$deploy_password" From 80ea06f0089794ecb2d89dbae33e49962724dbc2 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 30 Jun 2024 20:43:21 +0200 Subject: [PATCH 304/382] Add 1.21 support --- IF/pom.xml | 6 + .../util/version/Version.java | 14 +- .../util/version/VersionMatcher.java | 16 + nms/1_21/pom.xml | 72 ++++ .../nms/v1_21/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_21/BeaconInventoryImpl.java | 200 +++++++++++ .../v1_21/CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_21/EnchantingTableInventoryImpl.java | 218 ++++++++++++ .../nms/v1_21/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_21/MerchantInventoryImpl.java | 118 ++++++ .../nms/v1_21/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_21/StonecutterInventoryImpl.java | 221 ++++++++++++ .../nms/v1_21/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_21/util/TextHolderUtil.java | 67 ++++ pom.xml | 1 + 15 files changed, 2017 insertions(+), 2 deletions(-) create mode 100644 nms/1_21/pom.xml create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/AnvilInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/CartographyTableInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/GrindstoneInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/MerchantInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/SmithingTableInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/CustomInventoryUtil.java create mode 100644 nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/TextHolderUtil.java diff --git a/IF/pom.xml b/IF/pom.xml index 0168a46b5..9334a1169 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -167,6 +167,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_21 + ${project.version} + compile + org.spigotmc spigot-api diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 64568eaed..b610147d8 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -160,14 +160,22 @@ public enum Version { * * @since 0.10.14 */ - V1_20_6; + V1_20_6, + + /** + * Version 1.21 + * + * @since 0.10.15 + */ + V1_21; /** * A collection of versions on which modern smithing tables are available. */ private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, - V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5, V1_20_6 + V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5, V1_20_6, + V1_21 ); /** @@ -268,6 +276,8 @@ public static Version getVersion() { return V1_20_5; case "1.20.6": return V1_20_6; + case "1.21": + return V1_21; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 f793eea1d..eceb0e854 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 @@ -317,6 +317,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -361,6 +363,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -405,6 +409,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -449,6 +455,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -493,6 +501,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -537,6 +547,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, @@ -553,6 +565,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -625,5 +639,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_21, + com.github.stefvanschie.inventoryframework.nms.v1_21.StonecutterInventoryImpl.class); } } diff --git a/nms/1_21/pom.xml b/nms/1_21/pom.xml new file mode 100644 index 000000000..584d50c4c --- /dev/null +++ b/nms/1_21/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.15-SNAPSHOT + ../../pom.xml + + + 1_21 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.21-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + \ No newline at end of file diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/AnvilInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/AnvilInventoryImpl.java new file mode 100644 index 000000000..82e0192df --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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 anvil inventory for 1.21 + * + * @since 0.10.15 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.15 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.15 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.15 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.15 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.15 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.15 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java new file mode 100644 index 000000000..acf6d3d4b --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java @@ -0,0 +1,200 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_21_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.21 + * + * @since 0.10.15 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.15 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.15 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * 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 ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("s"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/CartographyTableInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..37216c688 --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_21_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.21 + * + * @since 0.10.15 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.15 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.15 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..ba259c7f1 --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_21_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.21 + * + * @since 0.10.15 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.15 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.15 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * 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 ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("o"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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((Container) 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/GrindstoneInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..34f2883e5 --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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 grindstone inventory for 1.21 + * + * @since 0.10.15 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.15 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.15 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.15 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.15 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/MerchantInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/MerchantInventoryImpl.java new file mode 100644 index 000000000..b04be99eb --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/MerchantInventoryImpl.java @@ -0,0 +1,118 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.ItemCost; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_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; +import java.util.Optional; + +/** + * Internal merchant inventory for 1.21 + * + * @since 0.10.15 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); + + if (itemB != null) { + nmsItemB = CraftItemStack.asNMSCopy(itemB); + } + + ItemCost itemCostA = convertItemStackToItemCost(nmsItemA); + ItemCost itemCostB = convertItemStackToItemCost(nmsItemB); + + int uses = recipe.getUses(); + int maxUses = recipe.getMaxUses(); + int exp = recipe.getVillagerExperience(); + float multiplier = recipe.getPriceMultiplier(); + + MerchantOffer merchantOffer = new MerchantOffer( + itemCostA, Optional.of(itemCostB), nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Converts an NMS item stack to an item cost. + * + * @param itemStack the item stack to convert + * @return the item cost + * @since 0.10.15 + */ + @NotNull + @Contract(value = "_ -> new", pure = true) + private ItemCost convertItemStackToItemCost(@NotNull net.minecraft.world.item.ItemStack itemStack) { + DataComponentPredicate predicate = DataComponentPredicate.allOf(itemStack.getComponents()); + + return new ItemCost(itemStack.getItemHolder(), itemStack.getCount(), predicate, itemStack); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.15 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/SmithingTableInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..8e44a9693 --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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.21. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.15 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.15 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.15 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.15 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.15 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.15 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.15 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java new file mode 100644 index 000000000..d719bb081 --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java @@ -0,0 +1,221 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_21_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.21 + * + * @since 0.10.15 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.15 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.15 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * 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 resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/CustomInventoryUtil.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/CustomInventoryUtil.java new file mode 100644 index 000000000..0d1e73542 --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.15 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.15 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/TextHolderUtil.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/TextHolderUtil.java new file mode 100644 index 000000000..07864c3dc --- /dev/null +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/TextHolderUtil.java @@ -0,0 +1,67 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21.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.core.HolderLookup; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.stream.Stream; + +/** + * A utility class for adding {@link TextHolder} support. + * + * @since 0.10.15 + */ +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.15 + */ + @NotNull + @Contract(pure = true) + public static Component 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.15 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.15 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson(), HolderLookup.Provider.create(Stream.empty()))); + } +} diff --git a/pom.xml b/pom.xml index 9814cbe53..f16f5a31b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_21 nms/1_20_6 nms/1_20_5 nms/1_20_3-4 From 15f7c0f8421be116a847c856cc012b2be60d48a3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 30 Jun 2024 20:59:27 +0200 Subject: [PATCH 305/382] Fix GitHub actions --- .github/dependabot.yml | 4 ++++ .github/workflows/auto-deploy.yml | 1 + .github/workflows/maven.yml | 1 + 3 files changed, 6 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fc422adf2..af84739c3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -96,6 +96,10 @@ updates: directory: "/nms/1_20_6" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_21" + schedule: + interval: "daily" - package-ecosystem: "maven" directory: "/nms/abstraction" schedule: diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 47103402b..fa0a2cb83 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -104,6 +104,7 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check + java -jar BuildTools.jar --rev 1.21 --remapped --disable-java-check cd ../ - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 3ece93647..0b0c96af6 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -110,6 +110,7 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check + java -jar BuildTools.jar --rev 1.21 --remapped --disable-java-check cd ../ - name: Build with Maven run: mvn -B package --file pom.xml From 03b4ee8213abc57df5f4d2d857b7c4f8e6511145 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sun, 30 Jun 2024 21:48:57 +0200 Subject: [PATCH 306/382] V 0.10.15 --- IF/pom.xml | 2 +- README.md | 7 ++++--- adventure-support/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/1_21/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 27 files changed, 30 insertions(+), 29 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 9334a1169..49d8f4579 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index 2ab0942b8..df3b638dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IF Discord guild -*This framework works for Minecraft versions 1.14-1.20* +*This framework works for Minecraft versions 1.14-1.21* An inventory framework for managing GUIs @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.14 + 0.10.15 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.14' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.15' // ... } ``` @@ -169,6 +169,7 @@ cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.21 --remapped --disable-java-check ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index a1884d31f..223c475a0 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 4.0.0 diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 65574698d..be77609e7 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 3a8424ba7..c5aa97b54 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index f63dba4bc..a96c0c1a0 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 901e251fd..a49d580b2 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 68b52552a..1a8f592fe 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 523b90b6a..1290c08a2 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index bb45e8337..d1f4eeddd 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 68f15f130..54afac0ed 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 9a6b74e3c..920d1ca88 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 989c5cb22..52ec83c9c 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 69e5abf39..130c15940 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 47478e7b4..38445fa71 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 94755363d..fe73b9aaf 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 2947be8bb..afe6271f6 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index e05ce0332..618e00258 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index a11c8b7c6..d03cf1ad2 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 8e6d8c345..7fda37aa8 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index ece3d57b1..c7f7ebd35 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 496ddc118..4e58dd6b7 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index f55886c39..4a9cf4d5a 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index 6da81b79d..9d6367c29 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml diff --git a/nms/1_21/pom.xml b/nms/1_21/pom.xml index 584d50c4c..b2299e3bc 100644 --- a/nms/1_21/pom.xml +++ b/nms/1_21/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index fdbdb3085..e073e64a3 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15-SNAPSHOT + 0.10.15 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index f16f5a31b..f01c802ff 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15-SNAPSHOT + 0.10.15 pom IF From 85126161ddecd350666f02536bae76597e06fcca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 05:09:41 +0000 Subject: [PATCH 307/382] Bump org.apache.maven.plugins:maven-gpg-plugin in /nms/1_16_1 Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.2 to 3.2.4. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.2...maven-gpg-plugin-3.2.4) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f01c802ff..1e85310c5 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.2 + 3.2.4 sign-artifacts From 9939b51ba9307376205bf25ca381b47d064e5267 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 9 Jul 2024 20:53:34 +0200 Subject: [PATCH 308/382] Fix GitHub actions cache Previously the installation of BuildTools files was not retained, now they are. --- .github/workflows/auto-deploy.yml | 1 + .github/workflows/maven.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index fa0a2cb83..bee59c47d 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -20,6 +20,7 @@ jobs: paperclip ~/.m2/repository/io/papermc/paper ~/.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' diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0b0c96af6..8aa24c350 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,6 +26,7 @@ jobs: paperclip ~/.m2/repository/io/papermc/paper ~/.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' From ae72cd064f6fa203e79524688892fb81fc70f644 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 05:12:23 +0000 Subject: [PATCH 309/382] Bump org.apache.maven.plugins:maven-gpg-plugin from 3.2.2 to 3.2.4 Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.2 to 3.2.4. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.2...maven-gpg-plugin-3.2.4) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 49d8f4579..91a318970 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -226,7 +226,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.2 + 3.2.4 sign-artifacts From 3f2cf104d86e286e8c315786ada2c66724a146df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 May 2024 05:31:08 +0000 Subject: [PATCH 310/382] Bump net.kyori:adventure-api from 4.16.0 to 4.17.0 Bumps [net.kyori:adventure-api](https://github.com/KyoriPowered/adventure) from 4.16.0 to 4.17.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.16.0...v4.17.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1e85310c5..9e77da714 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 1.8 true UTF-8 - 4.16.0 + 4.17.0 com.github.stefvanschie.inventoryframework From 1924345402f0496b574eb6233b200a85e38eb01e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 05:10:42 +0000 Subject: [PATCH 311/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4 in /nms/1_19_1 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 38445fa71..cab43365a 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.3 + 1.4.4 process-classes From be0aef077762d4c8df8bbbd27b3855ee82d4d5ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 05:11:31 +0000 Subject: [PATCH 312/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4 in /nms/1_17_1 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_17_1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index d1f4eeddd..f8a178df7 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.3 + 1.4.4 process-classes From 2a05e78ccb81e810c60ea312cddbeabb6d74bd70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 05:13:32 +0000 Subject: [PATCH 313/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4 in /nms/1_19_4 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 618e00258..1475c46ce 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.3 + 1.4.4 process-classes From 0d10f31c20f4dce1315e1b53698edd7bb95fa468 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 05:30:06 +0000 Subject: [PATCH 314/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4 in /nms/1_18_0 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_18_0/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 54afac0ed..0da934187 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.3 + 1.4.4 process-classes From 0df16d45ea62c00aaad1485ab793c5dc14a8af72 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 05:35:34 +0000 Subject: [PATCH 315/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4 in /nms/1_19_0 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_0/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 130c15940..19c610be2 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.3 + 1.4.4 process-classes From 68955b94132b08f6dbca60b88ef955c1af92c088 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 05:40:05 +0000 Subject: [PATCH 316/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4 in /nms/1_19_2 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_19_2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index fe73b9aaf..7c5aa1a0a 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.3 + 1.4.4 process-classes From abd12680de3ff39646a04e8aca31f16860bd73c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 05:43:52 +0000 Subject: [PATCH 317/382] Bump ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4 Bumps ca.bkaw:paper-nms-maven-plugin from 1.4.3 to 1.4.4. --- updated-dependencies: - dependency-name: ca.bkaw:paper-nms-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- nms/1_17_0/pom.xml | 2 +- nms/1_18_1/pom.xml | 2 +- nms/1_18_2/pom.xml | 2 +- nms/1_19_3/pom.xml | 2 +- nms/1_20_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 1290c08a2..080cc587c 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.3 + 1.4.4 process-classes diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 920d1ca88..690dec827 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.3 + 1.4.4 process-classes diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 52ec83c9c..97fca2fb8 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.3 + 1.4.4 process-classes diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index afe6271f6..d5ed48b19 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.3 + 1.4.4 process-classes diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index d03cf1ad2..18d0f374c 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.3 + 1.4.4 process-classes diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 7fda37aa8..9491e0b84 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.3 + 1.4.4 process-classes diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index c7f7ebd35..edb22c5f1 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -36,7 +36,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.3 + 1.4.4 process-classes diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 4e58dd6b7..271015d59 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -44,7 +44,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.3 + 1.4.4 process-classes From 9d14b44b6ce0a8c1b69c7d2dcdc789d306edbe20 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 May 2024 05:03:21 +0000 Subject: [PATCH 318/382] Bump org.sonatype.plugins:nexus-staging-maven-plugin in /nms/1_16_4-5 Bumps org.sonatype.plugins:nexus-staging-maven-plugin from 1.6.13 to 1.7.0. --- updated-dependencies: - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9e77da714..9eef43f09 100644 --- a/pom.xml +++ b/pom.xml @@ -134,7 +134,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.7.0 true ossrh From d6997f9670b384b4bb7cb35b8db9953c4edbd6d6 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 26 Jul 2024 16:36:19 +0200 Subject: [PATCH 319/382] Bump to 0.10.16-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- inventory-view/abstract-class/pom.xml | 42 +++++++++++++++++++++++++++ nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/1_21/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 3 +- 27 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 inventory-view/abstract-class/pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 91a318970..d7142ee50 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 223c475a0..d916a6040 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT 4.0.0 diff --git a/inventory-view/abstract-class/pom.xml b/inventory-view/abstract-class/pom.xml new file mode 100644 index 000000000..58c79b7c4 --- /dev/null +++ b/inventory-view/abstract-class/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.15 + ../../pom.xml + + + abstract-class + + + true + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + org.spigotmc + spigot-api + 1.20.6-R0.1-SNAPSHOT + provided + + + + org.apache.commons + commons-lang3 + + + + + + \ No newline at end of file diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index be77609e7..4b2740815 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index c5aa97b54..a82df629f 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index a96c0c1a0..36f349024 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index a49d580b2..5f87e3914 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 1a8f592fe..27df4a76f 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 080cc587c..ce38f9607 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index f8a178df7..ee5e3142e 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 0da934187..d5592705b 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 690dec827..f7189cc95 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 97fca2fb8..585cbe3df 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 19c610be2..d8804a7de 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index cab43365a..9e627f272 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 7c5aa1a0a..4867472de 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index d5ed48b19..90b128dd0 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 1475c46ce..98af7130d 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index 18d0f374c..f96f4fb60 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 9491e0b84..627653186 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index edb22c5f1..05d336823 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 271015d59..b4b417fa2 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 4a9cf4d5a..83d05b420 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index 9d6367c29..107cac966 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml diff --git a/nms/1_21/pom.xml b/nms/1_21/pom.xml index b2299e3bc..5b06bf860 100644 --- a/nms/1_21/pom.xml +++ b/nms/1_21/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index e073e64a3..24c9ccf49 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 9eef43f09..32c45f693 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,7 @@ nms/1_15 nms/1_14 adventure-support + inventory-view/abstract-class @@ -42,7 +43,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT pom IF From 510704b3cc13b47629c4f7451bebf4c41070d83f Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 26 Jul 2024 20:17:34 +0200 Subject: [PATCH 320/382] Fix plugins with paper-plugin.yml not working on 1.21 --- .github/dependabot.yml | 12 +++ IF/pom.xml | 18 ++++ .../inventoryframework/gui/GuiItem.java | 4 +- .../inventoryframework/gui/GuiListener.java | 30 ++++--- .../gui/type/MerchantGui.java | 3 +- .../inventoryframework/pane/Pane.java | 5 +- .../util/InventoryViewUtil.java | 42 +++++++++ .../util/version/Version.java | 12 +++ inventory-view/iv-abstract-class/pom.xml | 47 ++++++++++ .../abstractclass/InventoryViewUtil.java | 77 ++++++++++++++++ .../pom.xml | 6 +- .../AbstractInventoryViewUtil.java | 87 +++++++++++++++++++ inventory-view/iv-interface/pom.xml | 47 ++++++++++ .../interface_/InventoryViewUtil.java | 77 ++++++++++++++++ pom.xml | 4 +- 15 files changed, 450 insertions(+), 21 deletions(-) create mode 100644 IF/src/main/java/com/github/stefvanschie/inventoryframework/util/InventoryViewUtil.java create mode 100644 inventory-view/iv-abstract-class/pom.xml create mode 100644 inventory-view/iv-abstract-class/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstractclass/InventoryViewUtil.java rename inventory-view/{abstract-class => iv-abstraction}/pom.xml (90%) create mode 100644 inventory-view/iv-abstraction/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstraction/AbstractInventoryViewUtil.java create mode 100644 inventory-view/iv-interface/pom.xml create mode 100644 inventory-view/iv-interface/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/interface_/InventoryViewUtil.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml index af84739c3..18ab4d3db 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -104,3 +104,15 @@ updates: directory: "/nms/abstraction" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/inventory-view/iv-abstract-class" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/inventory-view/iv-abstraction" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/inventory-view/iv-interface" + schedule: + interval: "daily" diff --git a/IF/pom.xml b/IF/pom.xml index d7142ee50..78d475704 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -173,6 +173,24 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + iv-abstraction + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + iv-abstract-class + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + iv-interface + ${project.version} + compile + org.spigotmc spigot-api 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..130fbf4c4 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,5 +1,6 @@ package com.github.stefvanschie.inventoryframework.gui; +import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil; import com.github.stefvanschie.inventoryframework.util.UUIDTagType; import org.bukkit.NamespacedKey; import org.bukkit.event.inventory.InventoryClickEvent; @@ -179,7 +180,8 @@ public void callAction(@NotNull InventoryClickEvent event) { action.accept(event); } catch (Throwable t) { this.logger.log(Level.SEVERE, "Exception while handling click event in inventory '" - + event.getView().getTitle() + "', slot=" + event.getSlot() + ", item=" + item.getType(), t); + + InventoryViewUtil.getInstance().getTitle(event.getView()) + "', slot=" + event.getSlot() + + ", item=" + item.getType(), t); } } diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java index 56524dd6d..ea1008114 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiListener.java @@ -2,8 +2,10 @@ import com.github.stefvanschie.inventoryframework.gui.type.*; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; +import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil; import org.bukkit.Bukkit; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -65,7 +67,7 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { } InventoryView view = event.getView(); - Inventory inventory = view.getInventory(event.getRawSlot()); + Inventory inventory = InventoryViewUtil.getInstance().getInventory(view, event.getRawSlot()); if (inventory == null) { gui.callOnOutsideClick(event); @@ -73,7 +75,7 @@ public void onInventoryClick(@NotNull InventoryClickEvent event) { } gui.callOnGlobalClick(event); - if (inventory.equals(view.getTopInventory())) { + if (inventory.equals(InventoryViewUtil.getInstance().getTopInventory(view))) { gui.callOnTopClick(event); } else { gui.callOnBottomClick(event); @@ -221,17 +223,19 @@ public void resetItemsSmithingTable(@NotNull InventoryClickEvent event) { */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onEntityPickupItem(@NotNull EntityPickupItemEvent event) { - if (!(event.getEntity() instanceof HumanEntity)) { + LivingEntity entity = event.getEntity(); + + if (!(entity instanceof HumanEntity)) { return; } - Gui gui = getGui(((HumanEntity) event.getEntity()).getOpenInventory().getTopInventory()); + Gui gui = getGui(InventoryViewUtil.getInstance().getTopInventory(((HumanEntity) entity).getOpenInventory())); if (gui == null || !gui.isPlayerInventoryUsed()) { return; } - int leftOver = gui.getHumanEntityCache().add((HumanEntity) event.getEntity(), event.getItem().getItemStack()); + int leftOver = gui.getHumanEntityCache().add((HumanEntity) entity, event.getItem().getItemStack()); if (leftOver == 0) { event.getItem().remove(); @@ -267,11 +271,11 @@ public void onInventoryDrag(@NotNull InventoryDragEvent event) { boolean top = false, bottom = false; for (int inventorySlot : inventorySlots) { - Inventory inventory = view.getInventory(inventorySlot); + Inventory inventory = InventoryViewUtil.getInstance().getInventory(view, inventorySlot); - if (view.getTopInventory().equals(inventory)) { + if (InventoryViewUtil.getInstance().getTopInventory(view).equals(inventory)) { top = true; - } else if (view.getBottomInventory().equals(inventory)) { + } else if (InventoryViewUtil.getInstance().getBottomInventory(view).equals(inventory)) { bottom = true; } @@ -291,24 +295,24 @@ public void onInventoryDrag(@NotNull InventoryDragEvent event) { } } else { int index = inventorySlots.toArray(new Integer[0])[0]; - InventoryType.SlotType slotType = view.getSlotType(index); + InventoryType.SlotType slotType = InventoryViewUtil.getInstance().getSlotType(view, index); boolean even = event.getType() == DragType.EVEN; ClickType clickType = even ? ClickType.LEFT : ClickType.RIGHT; InventoryAction inventoryAction = even ? InventoryAction.PLACE_SOME : InventoryAction.PLACE_ONE; - ItemStack previousViewCursor = view.getCursor(); + ItemStack previousViewCursor = InventoryViewUtil.getInstance().getCursor(view); // Overwrite getCursor in inventory click event to mimic real event fired by Bukkit. - view.setCursor(event.getOldCursor()); + InventoryViewUtil.getInstance().setCursor(view, event.getOldCursor()); //this is a fake click event, firing this may cause other plugins to function incorrectly, so keep it local InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(view, slotType, index, clickType, inventoryAction); onInventoryClick(inventoryClickEvent); // Restore previous cursor only if someone has not changed it manually in onInventoryClick. - if (Objects.equals(view.getCursor(), event.getOldCursor())) { - view.setCursor(previousViewCursor); + if (Objects.equals(InventoryViewUtil.getInstance().getCursor(view), event.getOldCursor())) { + InventoryViewUtil.getInstance().setCursor(view, previousViewCursor); } event.setCancelled(inventoryClickEvent.isCancelled()); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java index 5e0ee3582..480daf510 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/type/MerchantGui.java @@ -9,6 +9,7 @@ import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.type.util.NamedGui; import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil; import com.github.stefvanschie.inventoryframework.util.XMLUtil; import com.github.stefvanschie.inventoryframework.util.version.Version; import com.github.stefvanschie.inventoryframework.util.version.VersionMatcher; @@ -196,7 +197,7 @@ public void show(@NotNull HumanEntity humanEntity) { throw new IllegalStateException("Merchant could not be opened"); } - Inventory inventory = view.getTopInventory(); + Inventory inventory = InventoryViewUtil.getInstance().getTopInventory(view); addInventory(inventory, this); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java index 9a44511f5..193753b02 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java @@ -8,6 +8,7 @@ import com.github.stefvanschie.inventoryframework.exception.XMLReflectionException; import com.github.stefvanschie.inventoryframework.pane.util.Mask; import com.github.stefvanschie.inventoryframework.pane.util.Slot; +import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil; import com.github.stefvanschie.inventoryframework.util.SkullUtil; import com.github.stefvanschie.inventoryframework.util.UUIDTagType; import com.github.stefvanschie.inventoryframework.util.XMLUtil; @@ -725,8 +726,8 @@ protected void callOnClick(@NotNull InventoryClickEvent event) { } catch (Throwable t) { throw new RuntimeException( "Exception while handling click event in inventory '" - + event.getView().getTitle() + "', slot=" + event.getSlot() + ", for " - + getClass().getSimpleName() + ", x=" + getX() + ", y=" + getY() + + InventoryViewUtil.getInstance().getTitle(event.getView()) + "', slot=" + event.getSlot() + + ", for " + getClass().getSimpleName() + ", x=" + getX() + ", y=" + getY() + ", length=" + length + ", height=" + height, t ); diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/InventoryViewUtil.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/InventoryViewUtil.java new file mode 100644 index 000000000..8d6327e69 --- /dev/null +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/InventoryViewUtil.java @@ -0,0 +1,42 @@ +package com.github.stefvanschie.inventoryframework.util; + +import com.github.stefvanschie.inventoryframework.inventoryview.abstraction.AbstractInventoryViewUtil; +import com.github.stefvanschie.inventoryframework.util.version.Version; +import org.bukkit.inventory.InventoryView; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for working with {@link InventoryView}s across different definitions. + * + * @since 0.10.16 + */ +public class InventoryViewUtil { + + /** + * The underlying implementation. + */ + @Nullable + private static AbstractInventoryViewUtil IMPLEMENTATION; + + /** + * Gets the instance of this class to use for the current version. + * + * @return an instance of a utility class + * @since 0.10.16 + */ + @NotNull + @Contract(pure = true) + public static AbstractInventoryViewUtil getInstance() { + if (IMPLEMENTATION == null) { + if (Version.getVersion().isInventoryViewInterface()) { + IMPLEMENTATION = com.github.stefvanschie.inventoryframework.inventoryview.interface_.InventoryViewUtil.getInstance(); + } else { + IMPLEMENTATION = com.github.stefvanschie.inventoryframework.inventoryview.abstractclass.InventoryViewUtil.getInstance(); + } + } + + return IMPLEMENTATION; + } +} diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index b610147d8..ea53ee24a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -2,6 +2,7 @@ import com.github.stefvanschie.inventoryframework.exception.UnsupportedVersionException; import org.bukkit.Bukkit; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -191,6 +192,17 @@ public enum Version { V1_19_0, V1_19_1, V1_19_2, V1_19_3, V1_19_4 ); + /** + * Checks whether the {@link InventoryView} class is an interface on this version. + * + * @return true if the class is an interface, false otherwise + * @since 0.10.16 + */ + @Contract(pure = true) + public boolean isInventoryViewInterface() { + return this == Version.V1_21; + } + /** * Checks whether modern smithing tables exist on this version. Returns true if they do, otherwise false. * diff --git a/inventory-view/iv-abstract-class/pom.xml b/inventory-view/iv-abstract-class/pom.xml new file mode 100644 index 000000000..80a007526 --- /dev/null +++ b/inventory-view/iv-abstract-class/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.16-SNAPSHOT + ../../pom.xml + + + iv-abstract-class + + + true + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + com.github.stefvanschie.inventoryframework + iv-abstraction + ${project.version} + + + org.spigotmc + spigot-api + 1.20.6-R0.1-SNAPSHOT + provided + + + + org.apache.commons + commons-lang3 + + + + + + \ No newline at end of file diff --git a/inventory-view/iv-abstract-class/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstractclass/InventoryViewUtil.java b/inventory-view/iv-abstract-class/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstractclass/InventoryViewUtil.java new file mode 100644 index 000000000..eb8ec2084 --- /dev/null +++ b/inventory-view/iv-abstract-class/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstractclass/InventoryViewUtil.java @@ -0,0 +1,77 @@ +package com.github.stefvanschie.inventoryframework.inventoryview.abstractclass; + +import com.github.stefvanschie.inventoryframework.inventoryview.abstraction.AbstractInventoryViewUtil; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A wrapper for {@link InventoryView} methods that apply when {@link InventoryView} was an abstract class. + * + * @since 0.10.16 + */ +public class InventoryViewUtil implements AbstractInventoryViewUtil { + + /** + * Instance of this singleton class. + */ + @NotNull + private static final InventoryViewUtil INSTANCE = new InventoryViewUtil(); + + @NotNull + @Override + public Inventory getBottomInventory(@NotNull InventoryView view) { + return view.getBottomInventory(); + } + + @Nullable + @Override + public ItemStack getCursor(@NotNull InventoryView view) { + return view.getCursor(); + } + + @Override + public void setCursor(@NotNull InventoryView view, @Nullable ItemStack item) { + view.setCursor(item); + } + + @Nullable + @Override + public Inventory getInventory(@NotNull InventoryView view, int slot) { + return view.getInventory(slot); + } + + @NotNull + @Override + public InventoryType.SlotType getSlotType(@NotNull InventoryView view, int slot) { + return view.getSlotType(slot); + } + + @NotNull + @Override + public String getTitle(@NotNull InventoryView view) { + return view.getTitle(); + } + + @NotNull + @Override + public Inventory getTopInventory(@NotNull InventoryView view) { + return view.getTopInventory(); + } + + /** + * Gets the singleton instance of this class. + * + * @return the instance of this class + * @since 0.10.16 + */ + @NotNull + @Contract(pure = true) + public static InventoryViewUtil getInstance() { + return INSTANCE; + } +} diff --git a/inventory-view/abstract-class/pom.xml b/inventory-view/iv-abstraction/pom.xml similarity index 90% rename from inventory-view/abstract-class/pom.xml rename to inventory-view/iv-abstraction/pom.xml index 58c79b7c4..edfcf8498 100644 --- a/inventory-view/abstract-class/pom.xml +++ b/inventory-view/iv-abstraction/pom.xml @@ -6,11 +6,11 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.15 + 0.10.16-SNAPSHOT ../../pom.xml - abstract-class + iv-abstraction true @@ -27,7 +27,7 @@ org.spigotmc spigot-api - 1.20.6-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT provided diff --git a/inventory-view/iv-abstraction/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstraction/AbstractInventoryViewUtil.java b/inventory-view/iv-abstraction/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstraction/AbstractInventoryViewUtil.java new file mode 100644 index 000000000..8d7f0c6cc --- /dev/null +++ b/inventory-view/iv-abstraction/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/abstraction/AbstractInventoryViewUtil.java @@ -0,0 +1,87 @@ +package com.github.stefvanschie.inventoryframework.inventoryview.abstraction; + +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A wrapper for {@link InventoryView} methods that apply when {@link InventoryView} was an abstract class. + * + * @since 0.10.16 + */ +public interface AbstractInventoryViewUtil { + + /** + * Behaves according to {@link InventoryView#getBottomInventory()}. + * + * @param view the {@link InventoryView} to invoke {@link InventoryView#getBottomInventory()} on + * @return the result of invoking {@link InventoryView#getBottomInventory()} + * @since 0.10.16 + */ + @NotNull + Inventory getBottomInventory(@NotNull InventoryView view); + + /** + * Behaves according to {@link InventoryView#getCursor()}. + * + * @param view the {@link InventoryView} to invoke {@link InventoryView#getCursor()} on + * @return the result of invoking {@link InventoryView#getCursor()} + * @since 0.10.16 + */ + @Nullable + ItemStack getCursor(@NotNull InventoryView view); + + /** + * Behaves according to {@link InventoryView#setCursor(ItemStack)}. + * + * @param view the {@link InventoryView} to invoke {@link InventoryView#setCursor(ItemStack)} on + * @param item the {@link ItemStack} to apply when invoking {@link InventoryView#setCursor(ItemStack)} + * @since 0.10.16 + */ + void setCursor(@NotNull InventoryView view, @Nullable ItemStack item); + + /** + * Behaves according to {@link InventoryView#getInventory(int)}. + * + * @param view the {@link InventoryView} to invoke {@link InventoryView#getInventory(int)} on + * @param slot the slot to apply when invoking {@link InventoryView#getInventory(int)} + * @return the result of invoking {@link InventoryView#getInventory(int)} + * @since 0.10.16 + */ + @Nullable + Inventory getInventory(@NotNull InventoryView view, int slot); + + /** + * Behaves according to {@link InventoryView#getSlotType(int)}. + * + * @param view the {@link InventoryView} to invoke {@link InventoryView#getSlotType(int)} on + * @param slot the slot to apply when invoking {@link InventoryView#getSlotType(int)} + * @return the result of invoking {@link InventoryView#getSlotType(int)} + * @since 0.10.16 + */ + @NotNull + InventoryType.SlotType getSlotType(@NotNull InventoryView view, int slot); + + /** + * Behaves according to {@link InventoryView#getTitle()}. + * + * @param view the {@link InventoryView} to invoke {@link InventoryView#getTitle()} on + * @return the result of invoking {@link InventoryView#getTitle()} + * @since 0.10.16 + */ + @NotNull + String getTitle(@NotNull InventoryView view); + + /** + * Behaves according to {@link InventoryView#getTopInventory()}. + * + * @param view the {@link InventoryView} to invoke {@link InventoryView#getTopInventory()} on + * @return the result of invoking {@link InventoryView#getTopInventory()} + * @since 0.10.16 + */ + @NotNull + Inventory getTopInventory(@NotNull InventoryView view); +} diff --git a/inventory-view/iv-interface/pom.xml b/inventory-view/iv-interface/pom.xml new file mode 100644 index 000000000..2cefdda55 --- /dev/null +++ b/inventory-view/iv-interface/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.16-SNAPSHOT + ../../pom.xml + + + iv-interface + + + true + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + com.github.stefvanschie.inventoryframework + iv-abstraction + ${project.version} + + + org.spigotmc + spigot-api + 1.21-R0.1-SNAPSHOT + provided + + + + org.apache.commons + commons-lang3 + + + + + + \ No newline at end of file diff --git a/inventory-view/iv-interface/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/interface_/InventoryViewUtil.java b/inventory-view/iv-interface/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/interface_/InventoryViewUtil.java new file mode 100644 index 000000000..9d94062a0 --- /dev/null +++ b/inventory-view/iv-interface/src/main/java/com/github/stefvanschie/inventoryframework/inventoryview/interface_/InventoryViewUtil.java @@ -0,0 +1,77 @@ +package com.github.stefvanschie.inventoryframework.inventoryview.interface_; + +import com.github.stefvanschie.inventoryframework.inventoryview.abstraction.AbstractInventoryViewUtil; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A wrapper for {@link InventoryView} methods that apply when {@link InventoryView} was an abstract class. + * + * @since 0.10.16 + */ +public class InventoryViewUtil implements AbstractInventoryViewUtil { + + /** + * Instance of this singleton class. + */ + @NotNull + private static final InventoryViewUtil INSTANCE = new InventoryViewUtil(); + + @NotNull + @Override + public Inventory getBottomInventory(@NotNull InventoryView view) { + return view.getBottomInventory(); + } + + @Nullable + @Override + public ItemStack getCursor(@NotNull InventoryView view) { + return view.getCursor(); + } + + @Override + public void setCursor(@NotNull InventoryView view, @Nullable ItemStack item) { + view.setCursor(item); + } + + @Nullable + @Override + public Inventory getInventory(@NotNull InventoryView view, int slot) { + return view.getInventory(slot); + } + + @NotNull + @Override + public InventoryType.SlotType getSlotType(@NotNull InventoryView view, int slot) { + return view.getSlotType(slot); + } + + @NotNull + @Override + public String getTitle(@NotNull InventoryView view) { + return view.getTitle(); + } + + @NotNull + @Override + public Inventory getTopInventory(@NotNull InventoryView view) { + return view.getTopInventory(); + } + + /** + * Gets the singleton instance of this class. + * + * @return the instance of this class + * @since 0.10.16 + */ + @NotNull + @Contract(pure = true) + public static InventoryViewUtil getInstance() { + return INSTANCE; + } +} diff --git a/pom.xml b/pom.xml index 32c45f693..6870e2453 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,9 @@ nms/1_15 nms/1_14 adventure-support - inventory-view/abstract-class + inventory-view/iv-abstract-class + inventory-view/iv-abstraction + inventory-view/iv-interface From a07e6285083a6f497b337babbe1d84c84df06a24 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 26 Jul 2024 20:44:11 +0200 Subject: [PATCH 321/382] Fix GuiItem#copy() not working for air items --- .../stefvanschie/inventoryframework/gui/GuiItem.java | 8 +++----- 1 file changed, 3 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 130fbf4c4..3c63c1203 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 @@ -153,13 +153,11 @@ public GuiItem copy() { guiItem.properties = new ArrayList<>(properties); ItemMeta meta = guiItem.item.getItemMeta(); - if (meta == null) { - throw new IllegalArgumentException("item must be able to have ItemMeta (it mustn't be AIR)"); + if (meta != null) { + meta.getPersistentDataContainer().set(keyUUID, UUIDTagType.INSTANCE, guiItem.uuid); + guiItem.item.setItemMeta(meta); } - meta.getPersistentDataContainer().set(keyUUID, UUIDTagType.INSTANCE, guiItem.uuid); - guiItem.item.setItemMeta(meta); - return guiItem; } From e2be3936b32e985c63fb33da9cdc6e627d4b390e Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Fri, 26 Jul 2024 21:48:55 +0200 Subject: [PATCH 322/382] V 0.10.16 --- IF/pom.xml | 2 +- README.md | 4 ++-- adventure-support/pom.xml | 2 +- inventory-view/iv-abstract-class/pom.xml | 2 +- inventory-view/iv-abstraction/pom.xml | 2 +- inventory-view/iv-interface/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/1_21/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 30 files changed, 31 insertions(+), 31 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 78d475704..1fe85b3ce 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index df3b638dc..2c0241b0a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.15 + 0.10.16 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.15' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.16' // ... } ``` diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index d916a6040..4df998176 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 4.0.0 diff --git a/inventory-view/iv-abstract-class/pom.xml b/inventory-view/iv-abstract-class/pom.xml index 80a007526..5c11dacb2 100644 --- a/inventory-view/iv-abstract-class/pom.xml +++ b/inventory-view/iv-abstract-class/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/inventory-view/iv-abstraction/pom.xml b/inventory-view/iv-abstraction/pom.xml index edfcf8498..e0b77cade 100644 --- a/inventory-view/iv-abstraction/pom.xml +++ b/inventory-view/iv-abstraction/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/inventory-view/iv-interface/pom.xml b/inventory-view/iv-interface/pom.xml index 2cefdda55..dd0c0cf59 100644 --- a/inventory-view/iv-interface/pom.xml +++ b/inventory-view/iv-interface/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 4b2740815..52ff502b6 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index a82df629f..3b58d8fd0 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 36f349024..a2fa19349 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 5f87e3914..4b4305e6f 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 27df4a76f..05aafaab4 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index ce38f9607..0e57eb68e 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index ee5e3142e..cf6672894 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index d5592705b..9958fb2f4 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index f7189cc95..73453928a 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 585cbe3df..3c2939bd0 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index d8804a7de..55f797c3f 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 9e627f272..692ca6f7a 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 4867472de..7fda438db 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 90b128dd0..d52e3cafa 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 98af7130d..0add3800d 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index f96f4fb60..963bf648b 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 627653186..a9cdcf536 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index 05d336823..cf83d243f 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index b4b417fa2..7a1fdc156 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 83d05b420..994b47437 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index 107cac966..eff198034 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/1_21/pom.xml b/nms/1_21/pom.xml index 5b06bf860..f549b98fb 100644 --- a/nms/1_21/pom.xml +++ b/nms/1_21/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 24c9ccf49..bac5303fa 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16-SNAPSHOT + 0.10.16 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 6870e2453..3712fb0a2 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16-SNAPSHOT + 0.10.16 pom IF From 367c07066cecf7044039c2554268dcea10aacd5b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 14 Aug 2024 17:33:54 +0200 Subject: [PATCH 323/382] Bump to 0.10.17-SNAPSHOT --- IF/pom.xml | 2 +- adventure-support/pom.xml | 2 +- inventory-view/iv-abstract-class/pom.xml | 2 +- inventory-view/iv-abstraction/pom.xml | 2 +- inventory-view/iv-interface/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/1_21/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 29 files changed, 29 insertions(+), 29 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 1fe85b3ce..3e9ea4da3 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../pom.xml 4.0.0 diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 4df998176..04166804c 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT 4.0.0 diff --git a/inventory-view/iv-abstract-class/pom.xml b/inventory-view/iv-abstract-class/pom.xml index 5c11dacb2..d6b0a4a2c 100644 --- a/inventory-view/iv-abstract-class/pom.xml +++ b/inventory-view/iv-abstract-class/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/inventory-view/iv-abstraction/pom.xml b/inventory-view/iv-abstraction/pom.xml index e0b77cade..bfc15d83b 100644 --- a/inventory-view/iv-abstraction/pom.xml +++ b/inventory-view/iv-abstraction/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/inventory-view/iv-interface/pom.xml b/inventory-view/iv-interface/pom.xml index dd0c0cf59..987414c0e 100644 --- a/inventory-view/iv-interface/pom.xml +++ b/inventory-view/iv-interface/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 52ff502b6..f51e510d2 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 3b58d8fd0..b472ef769 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index a2fa19349..7a9b837b9 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 4b4305e6f..e1087d3b2 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 05aafaab4..91cc4a5bd 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 0e57eb68e..35e1b2b50 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index cf6672894..8a403d10e 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 9958fb2f4..f32ff8368 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 73453928a..81ea80f19 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 3c2939bd0..216a4580e 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 55f797c3f..13c6e7aba 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 692ca6f7a..52c63ee09 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 7fda438db..a14989307 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index d52e3cafa..c7c17beb6 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 0add3800d..46af970a4 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index 963bf648b..0ce31ad4f 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index a9cdcf536..7f3654dd2 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index cf83d243f..b8dbf9393 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 7a1fdc156..8d8fd89d5 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 994b47437..6f9affb09 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index eff198034..fc8388b7e 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/1_21/pom.xml b/nms/1_21/pom.xml index f549b98fb..54f7131f3 100644 --- a/nms/1_21/pom.xml +++ b/nms/1_21/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index bac5303fa..3fbc6bb8b 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.16 + 0.10.17-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 3712fb0a2..1be1ac25a 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.16 + 0.10.17-SNAPSHOT pom IF From 19d9a87f061e5228034c153b7bdf308a96df744e Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 14 Aug 2024 18:43:41 +0200 Subject: [PATCH 324/382] Bump adventure on 1.20.3-1.20.4 to 4.15.0 --- nms/1_20_3-4/pom.xml | 59 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 8d8fd89d5..2f65a1124 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -16,14 +16,6 @@ true - - - - sonatype-oss-snapshots1 - https://s01.oss.sonatype.org/content/repositories/snapshots/ - - - com.github.stefvanschie.inventoryframework @@ -39,6 +31,57 @@ + + + + + net.kyori + adventure-api + 4.15.0 + + + net.kyori + adventure-key + 4.15.0 + + + net.kyori + adventure-text-logger-slf4j + 4.15.0 + + + net.kyori + adventure-text-minimessage + 4.15.0 + + + net.kyori + adventure-text-serializer-ansi + 4.15.0 + + + net.kyori + adventure-text-serializer-gson + 4.15.0 + + + net.kyori + adventure-text-serializer-json + 4.15.0 + + + net.kyori + adventure-text-serializer-legacy + 4.15.0 + + + net.kyori + adventure-text-serializer-plain + 4.15.0 + + + + From 3b7fbb5cdad897dc0243d297233ab696ace19b26 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 14 Aug 2024 19:33:21 +0200 Subject: [PATCH 325/382] Update CI/CD for 1.21 --- .github/workflows/auto-deploy.yml | 21 +++++++++++++++++++-- .github/workflows/maven.yml | 21 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index bee59c47d..c2c739159 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -76,7 +76,7 @@ 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: 'Run BuildTools 1.20.5 & 1.20.6' + - name: 'Run BuildTools 1.20.5-1.20.6, 1.21' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -105,7 +105,24 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.21 --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 cd ../ - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8aa24c350..c82d722f0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -82,7 +82,7 @@ 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: 'Run BuildTools 1.20.5 & 1.20.6' + - name: 'Run BuildTools 1.20.5-1.20.6, 1.21' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -111,7 +111,24 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check - java -jar BuildTools.jar --rev 1.21 --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 cd ../ - name: Build with Maven run: mvn -B package --file pom.xml From ff2f992a520a1fd4f12433e5515efd81f2672fe1 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Wed, 14 Aug 2024 20:36:08 +0200 Subject: [PATCH 326/382] Update guis to latest 1.21 build Updates the beacon, enchanting table, and stonecutter guis to support the latest build of 1.21 --- .../inventoryframework/nms/v1_21/BeaconInventoryImpl.java | 8 ++++---- .../nms/v1_21/EnchantingTableInventoryImpl.java | 8 ++++---- .../nms/v1_21/StonecutterInventoryImpl.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java index acf6d3d4b..0a8f689fa 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java @@ -15,8 +15,8 @@ import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryBeacon; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftBeaconView; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -130,7 +130,7 @@ private class ContainerBeaconImpl extends BeaconMenu { * The internal bukkit entity for this container beacon */ @Nullable - private CraftInventoryView bukkitEntity; + private CraftBeaconView bukkitEntity; /** * Field for accessing the beacon field @@ -163,7 +163,7 @@ public ContainerBeaconImpl(@NotNull ServerPlayer serverPlayer, @Nullable org.buk @NotNull @Override - public CraftInventoryView getBukkitView() { + public CraftBeaconView getBukkitView() { if (bukkitEntity == null) { try { CraftInventory inventory = new CraftInventoryBeacon((Container) beaconField.get(this)) { @@ -175,7 +175,7 @@ public InventoryHolder getHolder() { } }; - bukkitEntity = new CraftInventoryView(player, inventory, this); + this.bukkitEntity = new CraftBeaconView(player, inventory, this); } catch (IllegalAccessException exception) { throw new RuntimeException(exception); } diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java index ba259c7f1..9bfd901ac 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java @@ -17,8 +17,8 @@ import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryEnchanting; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftEnchantmentView; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -144,7 +144,7 @@ private class ContainerEnchantingTableImpl extends EnchantmentMenu { * The internal bukkit entity for this container enchanting table */ @Nullable - private CraftInventoryView bukkitEntity; + private CraftEnchantmentView bukkitEntity; /** * Field for accessing the enchant slots field @@ -181,7 +181,7 @@ public ContainerEnchantingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull @Override - public CraftInventoryView getBukkitView() { + public CraftEnchantmentView getBukkitView() { if (bukkitEntity == null) { try { CraftInventory inventory = new CraftInventoryEnchanting((Container) enchantSlotsField.get(this)) { @@ -193,7 +193,7 @@ public InventoryHolder getHolder() { } }; - bukkitEntity = new CraftInventoryView(player, inventory, this); + this.bukkitEntity = new CraftEnchantmentView(player, inventory, this); } catch (IllegalAccessException exception) { exception.printStackTrace(); } diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java index d719bb081..9cadfe568 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java +++ b/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java @@ -17,8 +17,8 @@ import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryStonecutter; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftStonecutterView; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.Contract; @@ -143,7 +143,7 @@ private class ContainerStonecutterImpl extends StonecutterMenu { * The internal bukkit entity for this container enchanting table */ @Nullable - private CraftInventoryView bukkitEntity; + private CraftStonecutterView bukkitEntity; /** * Field for accessing the result inventory field @@ -173,7 +173,7 @@ public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, @NotNull @Override - public CraftInventoryView getBukkitView() { + public CraftStonecutterView getBukkitView() { if (bukkitEntity == null) { CraftInventory inventory = new CraftInventoryStonecutter(this.container, getResultInventory()) { @NotNull @@ -184,7 +184,7 @@ public InventoryHolder getHolder() { } }; - bukkitEntity = new CraftInventoryView(player, inventory, this); + this.bukkitEntity = new CraftStonecutterView(player, inventory, this); } return bukkitEntity; From f2e54bc2d8fa9fad854bffaa0c0509d017068177 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 17 Aug 2024 20:43:28 +0200 Subject: [PATCH 327/382] Add 1.21.1 support --- .github/workflows/auto-deploy.yml | 21 ++----------------- .github/workflows/maven.yml | 21 ++----------------- .../util/version/Version.java | 1 + nms/1_21/pom.xml | 10 ++++----- 4 files changed, 10 insertions(+), 43 deletions(-) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index c2c739159..721bab504 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -76,7 +76,7 @@ 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: 'Run BuildTools 1.20.5-1.20.6, 1.21' + - name: 'Run BuildTools 1.20.5-1.20.6, 1.21.1' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -105,24 +105,7 @@ jobs: 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 cd ../ - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c82d722f0..05f7da274 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -82,7 +82,7 @@ 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: 'Run BuildTools 1.20.5-1.20.6, 1.21' + - name: 'Run BuildTools 1.20.5-1.20.6, 1.21.1' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -111,24 +111,7 @@ jobs: 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 cd ../ - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index ea53ee24a..fa8fe3d60 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -289,6 +289,7 @@ public static Version getVersion() { case "1.20.6": return V1_20_6; case "1.21": + case "1.21.1": return V1_21; default: throw new UnsupportedVersionException("The server version provided is not supported"); diff --git a/nms/1_21/pom.xml b/nms/1_21/pom.xml index 54f7131f3..79393620d 100644 --- a/nms/1_21/pom.xml +++ b/nms/1_21/pom.xml @@ -26,7 +26,7 @@ org.spigotmc spigot - 1.21-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT remapped-mojang provided @@ -46,9 +46,9 @@ remap-obf - org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:txt:maps-mojang + org.spigotmc:minecraft-server:1.21.1-R0.1-SNAPSHOT:txt:maps-mojang true - org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-mojang + org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT:jar:remapped-mojang true remapped-obf @@ -61,8 +61,8 @@ remap-spigot ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-obf + org.spigotmc:minecraft-server:1.21.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT:jar:remapped-obf From 8bb33d93844c6cb3f78e21bc1af50dfbdc34bac3 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 17 Aug 2024 21:06:52 +0200 Subject: [PATCH 328/382] V 0.10.17 --- IF/pom.xml | 2 +- README.md | 6 +++--- adventure-support/pom.xml | 2 +- inventory-view/iv-abstract-class/pom.xml | 2 +- inventory-view/iv-abstraction/pom.xml | 2 +- inventory-view/iv-interface/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/1_21/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 30 files changed, 32 insertions(+), 32 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 3e9ea4da3..613743054 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index 2c0241b0a..18109e57f 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.16 + 0.10.17 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.16' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.17' // ... } ``` @@ -169,7 +169,7 @@ cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.20.6 --remapped --disable-java-check -java -jar BuildTools.jar --rev 1.21 --remapped --disable-java-check +java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 04166804c..18a875956 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 4.0.0 diff --git a/inventory-view/iv-abstract-class/pom.xml b/inventory-view/iv-abstract-class/pom.xml index d6b0a4a2c..7e93aa5e7 100644 --- a/inventory-view/iv-abstract-class/pom.xml +++ b/inventory-view/iv-abstract-class/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/inventory-view/iv-abstraction/pom.xml b/inventory-view/iv-abstraction/pom.xml index bfc15d83b..e8c41e998 100644 --- a/inventory-view/iv-abstraction/pom.xml +++ b/inventory-view/iv-abstraction/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/inventory-view/iv-interface/pom.xml b/inventory-view/iv-interface/pom.xml index 987414c0e..d79270a6a 100644 --- a/inventory-view/iv-interface/pom.xml +++ b/inventory-view/iv-interface/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index f51e510d2..4d8035bf4 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index b472ef769..78de68604 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 7a9b837b9..964021098 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index e1087d3b2..ace906da3 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index 91cc4a5bd..e6372f49d 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 35e1b2b50..7d523f9fb 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 8a403d10e..0ab843ddd 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index f32ff8368..92549d97c 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 81ea80f19..3db1fd530 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 216a4580e..9cb915bd5 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 13c6e7aba..49ee16000 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 52c63ee09..3b7b6d8e8 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index a14989307..2526e1c1e 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index c7c17beb6..da030c6bd 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 46af970a4..5c059349f 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index 0ce31ad4f..6f111cb83 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 7f3654dd2..b575179cc 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index b8dbf9393..b85178e18 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 2f65a1124..0f3c379b5 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 6f9affb09..7a7863a25 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index fc8388b7e..182ed06d1 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/1_21/pom.xml b/nms/1_21/pom.xml index 79393620d..3ad1e532c 100644 --- a/nms/1_21/pom.xml +++ b/nms/1_21/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 3fbc6bb8b..1e7aa4662 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17-SNAPSHOT + 0.10.17 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 1be1ac25a..3475a3621 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17-SNAPSHOT + 0.10.17 pom IF From 4fbf28d172f755c7b144aae123f460d74d7360aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 May 2024 05:15:55 +0000 Subject: [PATCH 329/382] Bump org.sonatype.plugins:nexus-staging-maven-plugin in /IF Bumps org.sonatype.plugins:nexus-staging-maven-plugin from 1.6.13 to 1.7.0. --- updated-dependencies: - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 613743054..427a3b414 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -292,7 +292,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.7.0 true ossrh From bc572857171e19f2135a06d05baa91c8fb69daf4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 05:02:53 +0000 Subject: [PATCH 330/382] Bump org.apache.maven.plugins:maven-javadoc-plugin in /adventure-support Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.7.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.7.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3475a3621..ab2d5f0b8 100644 --- a/pom.xml +++ b/pom.xml @@ -161,7 +161,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.3 + 3.7.0 attach-javadocs From d00531f3ba94d9843aa1568e1c04d4008556503e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 05:32:04 +0000 Subject: [PATCH 331/382] Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.2 to 3.6.0 Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.2 to 3.6.0. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.2...maven-shade-plugin-3.6.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 427a3b414..a88a8234e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -279,7 +279,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.6.0 package From 221ffdc9803f4873d7736a624b07be6084ba09a4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 05:45:51 +0000 Subject: [PATCH 332/382] Bump org.apache.maven.plugins:maven-javadoc-plugin in /IF Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.7.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.7.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index a88a8234e..d7779c626 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -316,7 +316,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.3 + 3.7.0 attach-javadocs From bee45dc29c240bcf5e017fb6145291a69a79f692 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:30:24 +0000 Subject: [PATCH 333/382] Bump org.apache.maven.plugins:maven-gpg-plugin Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.4 to 3.2.5. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.4...maven-gpg-plugin-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ab2d5f0b8..9d89a474a 100644 --- a/pom.xml +++ b/pom.xml @@ -99,7 +99,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.4 + 3.2.5 sign-artifacts From b759a4f5ef8b1a94173a66ff36128001bf4c3d9a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 05:06:58 +0000 Subject: [PATCH 334/382] Bump org.junit.jupiter:junit-jupiter-engine in /nms/abstraction Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.10.2 to 5.11.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.2...r5.11.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9d89a474a..5fe32677b 100644 --- a/pom.xml +++ b/pom.xml @@ -130,7 +130,7 @@ org.junit.jupiter junit-jupiter-engine - 5.10.2 + 5.11.0 From 4188fec29bd89ef8b3686ec5befd8d106a1fe5f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 05:11:51 +0000 Subject: [PATCH 335/382] Bump net.kyori:adventure-text-serializer-legacy from 4.15.0 to 4.17.0 Bumps [net.kyori:adventure-text-serializer-legacy](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.17.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.17.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-text-serializer-legacy dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_20_3-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 0f3c379b5..a06b69c05 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -72,7 +72,7 @@ net.kyori adventure-text-serializer-legacy - 4.15.0 + 4.17.0 net.kyori From 3bc960dd95c147820e018783b879c43f27c7041c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 05:11:56 +0000 Subject: [PATCH 336/382] Bump net.kyori:adventure-key from 4.15.0 to 4.17.0 Bumps [net.kyori:adventure-key](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.17.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.17.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-key dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_20_3-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index a06b69c05..5847ad072 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -42,7 +42,7 @@ net.kyori adventure-key - 4.15.0 + 4.17.0 net.kyori From aba82a48582fb629cb1987651fb4620164e3bd86 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 05:11:58 +0000 Subject: [PATCH 337/382] Bump net.kyori:adventure-api from 4.15.0 to 4.17.0 Bumps [net.kyori:adventure-api](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.17.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.17.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_20_3-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 5847ad072..55944f16f 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -37,7 +37,7 @@ net.kyori adventure-api - 4.15.0 + 4.17.0 net.kyori From 174979e9f06f461a516e1db31786d401e6aa402b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 05:12:01 +0000 Subject: [PATCH 338/382] Bump net.kyori:adventure-text-serializer-ansi from 4.15.0 to 4.17.0 Bumps [net.kyori:adventure-text-serializer-ansi](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.17.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.17.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-text-serializer-ansi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_20_3-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 55944f16f..5253cfb76 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -57,7 +57,7 @@ net.kyori adventure-text-serializer-ansi - 4.15.0 + 4.17.0 net.kyori From af06a26f2e1cd0e6c02495d9d249fbc5082b26c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 05:15:43 +0000 Subject: [PATCH 339/382] Bump org.apache.maven.plugins:maven-surefire-plugin Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.4.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5fe32677b..b59310f0e 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.4.0 org.apache.maven.surefire surefire-junit-platform - 3.2.5 + 3.4.0 org.junit.jupiter From 41acc9d3768f675d7dac0f221204c7464ba36cc9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:15 +0000 Subject: [PATCH 340/382] Bump org.apache.maven.plugins:maven-surefire-plugin Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 12b322209a4de47691b07bb2bf6ad66a423e45c0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:18 +0000 Subject: [PATCH 341/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_15 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From b964c1591e4ca30c30d7138a386bfeb517e2b68e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:20 +0000 Subject: [PATCH 342/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_15 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From a60749b985d63aacb88c4f89fbd7934b7b3d6fce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:21 +0000 Subject: [PATCH 343/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_18_2 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 4309b5acc3db6b6821f60d324acff6a298d845a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:24 +0000 Subject: [PATCH 344/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_18_2 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 7faf354b6730c32a6569ade6b6022fc3657e6896 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:26 +0000 Subject: [PATCH 345/382] Bump org.apache.maven.surefire:surefire-junit-platform Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 192f0a13dc2bd9e1b13fe37c061501f79f6bcd6c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:28 +0000 Subject: [PATCH 346/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_19_4 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From c9968581bd98752ffe228a177d9473a9328ccf91 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:29 +0000 Subject: [PATCH 347/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_19_4 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From a37584a6d6f6c6e64540568b527483fadc73ecfc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:31 +0000 Subject: [PATCH 348/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_20_5 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 24acd69040b99f612fcde35a0c0a3d01b9da084c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:33 +0000 Subject: [PATCH 349/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_19_3 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 97d2c4a56ce0878c3350d4091f09245f9b2b7283 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:38 +0000 Subject: [PATCH 350/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_18_0 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 539e2e6897c0e147fffeaf5cb2ff282efa2200b2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:39 +0000 Subject: [PATCH 351/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_18_0 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From e60fe096760b42b2ee9b9e1819924e00b7f647fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:41 +0000 Subject: [PATCH 352/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_20_6 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From db7f7dbcee06826e4e30d2698cd8f479eb93367c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:45 +0000 Subject: [PATCH 353/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_16_4-5 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From e3855082574dc309d61dd0cd5b0589fdd14b9c79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:48 +0000 Subject: [PATCH 354/382] Bump org.apache.maven.surefire:surefire-junit-platform Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 4b4760c5e36add198f96f47c52d1450a86764c4c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:50 +0000 Subject: [PATCH 355/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_19_2 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From e9c79aa5f398c4b253714ee5874d1dd5d0adce48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:51 +0000 Subject: [PATCH 356/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_19_2 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From a87713cbb641238893a329849a6541122125404f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:54 +0000 Subject: [PATCH 357/382] Bump org.apache.maven.plugins:maven-surefire-plugin Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 08f93db6ef7602081f09e7697b31fb31343fa3bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:43:55 +0000 Subject: [PATCH 358/382] Bump org.apache.maven.surefire:surefire-junit-platform Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 67bf4bffe43e081f236117eb0585cf8b69c2c68a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:05 +0000 Subject: [PATCH 359/382] Bump org.apache.maven.surefire:surefire-junit-platform Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From d8b097f67700e355fcaa3c0f3d60107e314df5aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:05 +0000 Subject: [PATCH 360/382] Bump org.apache.maven.plugins:maven-surefire-plugin Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 9e55d3bfedcbdc70bbc51f325eb0cf76d8555acc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:08 +0000 Subject: [PATCH 361/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_16_2-3 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 1b94b13df5d784e752f16a3986234e3116e552d0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:10 +0000 Subject: [PATCH 362/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /IF Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 4 ++-- pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index d7779c626..5b2388207 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -267,12 +267,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.2.5 + 3.5.0 diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From d1be21736ff4b8198421ebb09912ecd1592d651a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:13 +0000 Subject: [PATCH 363/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_20_0 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 1dbb7dbd1b7982515e2ab695f968e1ed98698abe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:15 +0000 Subject: [PATCH 364/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/abstraction Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b59310f0e..85f8111a4 100644 --- a/pom.xml +++ b/pom.xml @@ -120,12 +120,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 26c557171afead15f5ff08a5582120e2fa825d3d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:17 +0000 Subject: [PATCH 365/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_21 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 692b6bc6d4054a2137205ea32397f2b3494897bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:44:19 +0000 Subject: [PATCH 366/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_14 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..174a43728 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 67117a3932692c9ce687c70857ce865b9a9011f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 05:18:59 +0000 Subject: [PATCH 367/382] Bump org.junit.jupiter:junit-jupiter-engine from 5.10.2 to 5.11.0 in /IF Bumps [org.junit.jupiter:junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.10.2 to 5.11.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.2...r5.11.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index d7779c626..b1858d193 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -220,7 +220,7 @@ org.junit.jupiter junit-jupiter-engine - 5.10.2 + 5.11.0 test From 1b9a734d3af5fe9e5546e1f0abf0e169be186d15 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 05:19:10 +0000 Subject: [PATCH 368/382] Bump org.apache.maven.plugins:maven-gpg-plugin in /IF Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.4 to 3.2.5. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.4...maven-gpg-plugin-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index b1858d193..bb57e7c3e 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -244,7 +244,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.4 + 3.2.5 sign-artifacts From 4fd880827d7dcb7951b114d6dea9ccbf4e2ce199 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 05:27:10 +0000 Subject: [PATCH 369/382] Bump net.kyori:adventure-text-logger-slf4j in /nms/1_20_3-4 Bumps [net.kyori:adventure-text-logger-slf4j](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.17.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.17.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-text-logger-slf4j dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_20_3-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 5253cfb76..c679a7a3b 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -47,7 +47,7 @@ net.kyori adventure-text-logger-slf4j - 4.15.0 + 4.17.0 net.kyori From 2f7ed3c671b797f1db061ad52b69efa3c5474422 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 05:27:14 +0000 Subject: [PATCH 370/382] Bump net.kyori:adventure-text-minimessage in /nms/1_20_3-4 Bumps [net.kyori:adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.17.0. - [Release notes](https://github.com/KyoriPowered/adventure/releases) - [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.17.0) --- updated-dependencies: - dependency-name: net.kyori:adventure-text-minimessage dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- nms/1_20_3-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index c679a7a3b..232dd3953 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -52,7 +52,7 @@ net.kyori adventure-text-minimessage - 4.15.0 + 4.17.0 net.kyori From bb53e87436727f6f620e62bdc7170fa046ef0b7c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:18:28 +0000 Subject: [PATCH 371/382] Bump org.apache.maven.plugins:maven-javadoc-plugin in /nms/1_17_0 Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.10.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.10.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b59310f0e..6b7f93e28 100644 --- a/pom.xml +++ b/pom.xml @@ -161,7 +161,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.7.0 + 3.10.0 attach-javadocs From e4628cd42620a91f8d646ae6a01e7fcc610dc064 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:24:05 +0000 Subject: [PATCH 372/382] Bump org.apache.maven.plugins:maven-javadoc-plugin in /IF Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.10.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.10.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index bb57e7c3e..da7540e0d 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -316,7 +316,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.7.0 + 3.10.0 attach-javadocs From 42d17a496ffec1734e053679cf13b920ab82867a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:42:45 +0000 Subject: [PATCH 373/382] Bump org.apache.maven.surefire:surefire-junit-platform in /nms/1_17_0 Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6b7f93e28..f46b66a11 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.4.0 + 3.5.0 org.junit.jupiter From 0020e29d97348afb3ec6e659a6c56aee47ff2119 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:42:46 +0000 Subject: [PATCH 374/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_17_0 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f46b66a11..3ac4df648 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.4.0 + 3.5.0 org.apache.maven.surefire From 6c2d52101d85829523a6e9ea8cf1796b8d18e50b Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Tue, 22 Oct 2024 20:56:54 +0200 Subject: [PATCH 375/382] Fix NMS break for 1.21.1 The beacon, enchanting table, and stonecutter guis broke due to NMS changes. Bump to 0.10.18-SNAPSHOT. --- .github/dependabot.yml | 6 +- .github/workflows/auto-deploy.yml | 18 + .github/workflows/maven.yml | 18 + IF/pom.xml | 10 +- .../util/version/Version.java | 28 +- .../util/version/VersionMatcher.java | 48 ++- README.md | 23 +- adventure-support/pom.xml | 2 +- inventory-view/iv-abstract-class/pom.xml | 2 +- inventory-view/iv-abstraction/pom.xml | 2 +- inventory-view/iv-interface/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/1_21_0/pom.xml | 72 ++++ .../nms/v1_21_0}/AnvilInventoryImpl.java | 24 +- .../nms/v1_21_0/BeaconInventoryImpl.java | 202 +++++++++++ .../CartographyTableInventoryImpl.java | 18 +- .../EnchantingTableInventoryImpl.java | 22 +- .../nms/v1_21_0}/GrindstoneInventoryImpl.java | 20 +- .../nms/v1_21_0}/MerchantInventoryImpl.java | 12 +- .../v1_21_0}/SmithingTableInventoryImpl.java | 24 +- .../v1_21_0}/StonecutterInventoryImpl.java | 22 +- .../v1_21_0}/util/CustomInventoryUtil.java | 6 +- .../nms/v1_21_0}/util/TextHolderUtil.java | 10 +- nms/{1_21 => 1_21_1}/pom.xml | 4 +- .../nms/v1_21_1/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_21_1}/BeaconInventoryImpl.java | 19 +- .../CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_21_1/EnchantingTableInventoryImpl.java | 220 ++++++++++++ .../nms/v1_21_1/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_21_1/MerchantInventoryImpl.java | 118 ++++++ .../v1_21_1/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_21_1/StonecutterInventoryImpl.java | 222 ++++++++++++ .../nms/v1_21_1/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_21_1/util/TextHolderUtil.java | 67 ++++ nms/abstraction/pom.xml | 2 +- pom.xml | 5 +- 56 files changed, 2231 insertions(+), 145 deletions(-) create mode 100644 nms/1_21_0/pom.xml rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/AnvilInventoryImpl.java (95%) create mode 100644 nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/BeaconInventoryImpl.java rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/CartographyTableInventoryImpl.java (95%) rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/EnchantingTableInventoryImpl.java (93%) rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/GrindstoneInventoryImpl.java (94%) rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/MerchantInventoryImpl.java (95%) rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/SmithingTableInventoryImpl.java (96%) rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/StonecutterInventoryImpl.java (93%) rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/util/CustomInventoryUtil.java (91%) rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0}/util/TextHolderUtil.java (92%) rename nms/{1_21 => 1_21_1}/pom.xml (97%) create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/AnvilInventoryImpl.java rename nms/{1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21 => 1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1}/BeaconInventoryImpl.java (94%) create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/CartographyTableInventoryImpl.java create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/EnchantingTableInventoryImpl.java create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/GrindstoneInventoryImpl.java create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/MerchantInventoryImpl.java create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/SmithingTableInventoryImpl.java create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/StonecutterInventoryImpl.java create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/CustomInventoryUtil.java create mode 100644 nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/TextHolderUtil.java diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 18ab4d3db..fb2210cff 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -97,7 +97,11 @@ updates: schedule: interval: "daily" - package-ecosystem: "maven" - directory: "/nms/1_21" + directory: "/nms/1_21_0" + schedule: + interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_21_1" schedule: interval: "daily" - package-ecosystem: "maven" diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 721bab504..08de3d9a8 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -105,6 +105,24 @@ jobs: 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 cd ../ - name: Setup GPG keys diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 05f7da274..222b4f848 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -111,6 +111,24 @@ jobs: 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 cd ../ - name: Build with Maven diff --git a/IF/pom.xml b/IF/pom.xml index da7540e0d..946366870 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../pom.xml 4.0.0 @@ -169,7 +169,13 @@ com.github.stefvanschie.inventoryframework - 1_21 + 1_21_0 + ${project.version} + compile + + + com.github.stefvanschie.inventoryframework + 1_21_1 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index fa8fe3d60..1838a62a5 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -164,11 +164,18 @@ public enum Version { V1_20_6, /** - * Version 1.21 + * Version 1.21.0 * - * @since 0.10.15 + * @since 0.10.18 */ - V1_21; + V1_21_0, + + /** + * Version 1.21.1 + * + * @since 0.10.18 + */ + V1_21_1; /** * A collection of versions on which modern smithing tables are available. @@ -176,7 +183,7 @@ public enum Version { private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5, V1_20_6, - V1_21 + V1_21_0, V1_21_1 ); /** @@ -192,6 +199,14 @@ public enum Version { V1_19_0, V1_19_1, V1_19_2, V1_19_3, V1_19_4 ); + /** + * A collection of versions on which {@link InventoryView} is an interface. + */ + @NotNull + private static final Collection<@NotNull Version> INTERFACE_INVENTORY_VIEW = EnumSet.of( + V1_21_0, V1_21_1 + ); + /** * Checks whether the {@link InventoryView} class is an interface on this version. * @@ -200,7 +215,7 @@ public enum Version { */ @Contract(pure = true) public boolean isInventoryViewInterface() { - return this == Version.V1_21; + return INTERFACE_INVENTORY_VIEW.contains(this); } /** @@ -289,8 +304,9 @@ public static Version getVersion() { case "1.20.6": return V1_20_6; case "1.21": + return V1_21_0; case "1.21.1": - return V1_21; + return V1_21_1; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 eceb0e854..331e7c01c 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 @@ -317,8 +317,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -363,8 +365,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -409,8 +413,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -455,8 +461,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -501,8 +509,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -547,8 +557,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.MerchantInventoryImpl.class); - MERCHANT_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, @@ -565,8 +577,10 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -639,7 +653,9 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_20_5.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_20_6, com.github.stefvanschie.inventoryframework.nms.v1_20_6.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_21, - com.github.stefvanschie.inventoryframework.nms.v1_21.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_21_0, + com.github.stefvanschie.inventoryframework.nms.v1_21_0.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_21_1, + com.github.stefvanschie.inventoryframework.nms.v1_21_1.StonecutterInventoryImpl.class); } } diff --git a/README.md b/README.md index 18109e57f..4d04840dc 100644 --- a/README.md +++ b/README.md @@ -142,10 +142,10 @@ mvn paper-nms:init -pl nms/1_20_3-4 ``` ### Installing Spigot via BuildTools -For versions 1.20.5-1.20.6, we use BuildTools. To install these versions, we run the following commands. +For versions 1.20.5-1.21.1, we use BuildTools. To install these versions, we run the following commands. ``` 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 @@ -167,8 +167,25 @@ 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 ``` diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 18a875956..2e95e7461 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT 4.0.0 diff --git a/inventory-view/iv-abstract-class/pom.xml b/inventory-view/iv-abstract-class/pom.xml index 7e93aa5e7..bf33ff286 100644 --- a/inventory-view/iv-abstract-class/pom.xml +++ b/inventory-view/iv-abstract-class/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/inventory-view/iv-abstraction/pom.xml b/inventory-view/iv-abstraction/pom.xml index e8c41e998..1588aad1a 100644 --- a/inventory-view/iv-abstraction/pom.xml +++ b/inventory-view/iv-abstraction/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/inventory-view/iv-interface/pom.xml b/inventory-view/iv-interface/pom.xml index d79270a6a..8e3892852 100644 --- a/inventory-view/iv-interface/pom.xml +++ b/inventory-view/iv-interface/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 4d8035bf4..79d818929 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index 78de68604..faac5f279 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 964021098..046d24914 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index ace906da3..9fe11f679 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index e6372f49d..a86dd079e 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 7d523f9fb..3637330f0 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 0ab843ddd..79444e417 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 92549d97c..2f5b42f75 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 3db1fd530..47ff26dfb 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 9cb915bd5..4a50cdf9b 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index 49ee16000..f998d8ac5 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 3b7b6d8e8..9624357a9 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 2526e1c1e..409989889 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index da030c6bd..54fc8e0c5 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index 5c059349f..bc775d6e1 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index 6f111cb83..86cc53ffc 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index b575179cc..8ccbc5ad0 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index b85178e18..2edecfe60 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 232dd3953..81e416338 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 7a7863a25..5bc065cb9 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index 182ed06d1..4ff77993c 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml diff --git a/nms/1_21_0/pom.xml b/nms/1_21_0/pom.xml new file mode 100644 index 000000000..1de4e00a8 --- /dev/null +++ b/nms/1_21_0/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.18-SNAPSHOT + ../../pom.xml + + + 1_21_0 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.21-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + \ No newline at end of file diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/AnvilInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/AnvilInventoryImpl.java similarity index 95% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/AnvilInventoryImpl.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/AnvilInventoryImpl.java index 82e0192df..b40c02433 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/AnvilInventoryImpl.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/AnvilInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -29,9 +29,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal anvil inventory for 1.21 + * Internal anvil inventory for 1.21.0 * - * @since 0.10.15 + * @since 0.10.18 */ public class AnvilInventoryImpl extends AnvilInventory { @@ -136,7 +136,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @Deprecated @@ -152,7 +152,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @Deprecated @@ -169,7 +169,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @Contract(pure = true) @@ -183,7 +183,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @NotNull @@ -198,7 +198,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -209,7 +209,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container anvil for responding to item renaming * - * @since 0.10.15 + * @since 0.10.18 */ private class ContainerAnvilImpl extends AnvilMenu { @@ -218,7 +218,7 @@ private class ContainerAnvilImpl extends AnvilMenu { * * @param serverPlayer the player for whom this anvil container is * @param title the title of the inventory - * @since 0.10.15 + * @since 0.10.18 */ public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), diff --git a/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/BeaconInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/BeaconInventoryImpl.java new file mode 100644 index 000000000..90981e030 --- /dev/null +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/BeaconInventoryImpl.java @@ -0,0 +1,202 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftBeaconView; +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; + +/** + * Internal beacon inventory for 1.21.0 + * + * @since 0.10.18 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.18 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * The player for this beacon container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container beacon + */ + @Nullable + private CraftBeaconView bukkitEntity; + + /** + * Field for accessing the beacon field + */ + @NotNull + private final Field beaconField; + + public ContainerBeaconImpl(@NotNull ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("s"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) beaconField.get(this)).setItem(0, itemStack); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + @NotNull + @Override + public CraftBeaconView getBukkitView() { + if (bukkitEntity == null) { + try { + Container container = (Container) beaconField.get(this); + + Inventory inventory = new CraftInventoryBeacon(container) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + this.bukkitEntity = new CraftBeaconView(player, inventory, this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + return bukkitEntity; + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/CartographyTableInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/CartographyTableInventoryImpl.java similarity index 95% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/CartographyTableInventoryImpl.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/CartographyTableInventoryImpl.java index 37216c688..ee1d9a23b 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/CartographyTableInventoryImpl.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/CartographyTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -29,9 +29,9 @@ import java.lang.reflect.Field; /** - * Internal cartography table inventory for 1.21 + * Internal cartography table inventory for 1.21.0 * - * @since 0.10.15 + * @since 0.10.18 */ public class CartographyTableInventoryImpl extends CartographyTableInventory { @@ -92,7 +92,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.15 + * @since 0.10.18 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -104,7 +104,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -117,7 +117,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -128,7 +128,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container cartography table * - * @since 0.10.15 + * @since 0.10.18 */ private class ContainerCartographyTableImpl extends CartographyTableMenu { diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/EnchantingTableInventoryImpl.java similarity index 93% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/EnchantingTableInventoryImpl.java index 9bfd901ac..01de8a795 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/EnchantingTableInventoryImpl.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/EnchantingTableInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -15,11 +15,11 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryEnchanting; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftEnchantmentView; 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; @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal enchanting table inventory for 1.21 + * Internal enchanting table inventory for 1.21.0 * - * @since 0.10.15 + * @since 0.10.18 */ public class EnchantingTableInventoryImpl extends EnchantingTableInventory { @@ -94,7 +94,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.15 + * @since 0.10.18 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -106,7 +106,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -119,7 +119,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -130,7 +130,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.15 + * @since 0.10.18 */ private class ContainerEnchantingTableImpl extends EnchantmentMenu { @@ -184,7 +184,9 @@ public ContainerEnchantingTableImpl(@NotNull ServerPlayer serverPlayer, public CraftEnchantmentView getBukkitView() { if (bukkitEntity == null) { try { - CraftInventory inventory = new CraftInventoryEnchanting((Container) enchantSlotsField.get(this)) { + Container container = (Container) enchantSlotsField.get(this); + + Inventory inventory = new CraftInventoryEnchanting(container) { @NotNull @Contract(pure = true) @Override diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/GrindstoneInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/GrindstoneInventoryImpl.java similarity index 94% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/GrindstoneInventoryImpl.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/GrindstoneInventoryImpl.java index 34f2883e5..59d5f89a5 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/GrindstoneInventoryImpl.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/GrindstoneInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -27,9 +27,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal grindstone inventory for 1.21 + * Internal grindstone inventory for 1.21.0 * - * @since 0.10.15 + * @since 0.10.18 */ public class GrindstoneInventoryImpl extends GrindstoneInventory { @@ -104,7 +104,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @Contract(pure = true) @@ -118,7 +118,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @NotNull @@ -133,7 +133,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -144,7 +144,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container grindstone * - * @since 0.10.15 + * @since 0.10.18 */ private static class ContainerGrindstoneImpl extends GrindstoneMenu { @@ -153,7 +153,7 @@ private static class ContainerGrindstoneImpl extends GrindstoneMenu { * * @param serverPlayer the player for whom this container should be opened * @param title the title of the gui - * @since 0.10.15 + * @since 0.10.18 */ public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/MerchantInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/MerchantInventoryImpl.java similarity index 95% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/MerchantInventoryImpl.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/MerchantInventoryImpl.java index b04be99eb..489a02e53 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/MerchantInventoryImpl.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/MerchantInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import net.minecraft.core.component.DataComponentPredicate; @@ -19,9 +19,9 @@ import java.util.Optional; /** - * Internal merchant inventory for 1.21 + * Internal merchant inventory for 1.21.0 * - * @since 0.10.15 + * @since 0.10.18 */ public class MerchantInventoryImpl extends MerchantInventory { @@ -81,7 +81,7 @@ public void sendMerchantOffers(@NotNull Player player, * * @param itemStack the item stack to convert * @return the item cost - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(value = "_ -> new", pure = true) @@ -96,7 +96,7 @@ private ItemCost convertItemStackToItemCost(@NotNull net.minecraft.world.item.It * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -109,7 +109,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { * * @param nmsPlayer the player to get the containerId id for * @return the containerId id - * @since 0.10.15 + * @since 0.10.18 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/SmithingTableInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/SmithingTableInventoryImpl.java similarity index 96% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/SmithingTableInventoryImpl.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/SmithingTableInventoryImpl.java index 8e44a9693..b3cb11007 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/SmithingTableInventoryImpl.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/SmithingTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -29,9 +29,9 @@ import org.jetbrains.annotations.Nullable; /** - * Internal smithing table inventory for 1.21. This is only available for Minecraft 1.20 and higher. + * Internal smithing table inventory for 1.21.0. This is only available for Minecraft 1.20 and higher. * - * @since 0.10.15 + * @since 0.10.18 */ public class SmithingTableInventoryImpl extends SmithingTableInventory { @@ -139,7 +139,7 @@ public void clearCursor(@NotNull Player player) { * * @param player the player to set the cursor * @param item the item to set the cursor to - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @Deprecated @@ -155,7 +155,7 @@ private void setCursor(@NotNull Player player, @NotNull ItemStack item) { * * @param player the player to send the result item to * @param item the result item - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @Deprecated @@ -172,7 +172,7 @@ private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @Contract(pure = true) @@ -186,7 +186,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.15 + * @since 0.10.18 * @deprecated no longer used internally */ @NotNull @@ -201,7 +201,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -212,7 +212,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container smithing table * - * @since 0.10.15 + * @since 0.10.18 */ private static class ContainerSmithingTableImpl extends SmithingMenu { @@ -221,7 +221,7 @@ private static class ContainerSmithingTableImpl extends SmithingMenu { * * @param serverPlayer the player for whom this anvil container is * @param title the title of the inventory - * @since 0.10.15 + * @since 0.10.18 */ public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/StonecutterInventoryImpl.java similarity index 93% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/StonecutterInventoryImpl.java index 9cadfe568..d12e3e7f3 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/StonecutterInventoryImpl.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/StonecutterInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_0.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; @@ -15,11 +15,11 @@ import net.minecraft.world.inventory.StonecutterMenu; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryStonecutter; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftStonecutterView; 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; @@ -28,9 +28,9 @@ import java.lang.reflect.Field; /** - * Internal stonecutter inventory for 1.21 + * Internal stonecutter inventory for 1.21.0 * - * @since 0.10.15 + * @since 0.10.18 */ public class StonecutterInventoryImpl extends StonecutterInventory { @@ -93,7 +93,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.15 + * @since 0.10.18 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -105,7 +105,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -118,7 +118,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -129,7 +129,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container enchanting table * - * @since 0.10.15 + * @since 0.10.18 */ private class ContainerStonecutterImpl extends StonecutterMenu { @@ -175,7 +175,7 @@ public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, @Override public CraftStonecutterView getBukkitView() { if (bukkitEntity == null) { - CraftInventory inventory = new CraftInventoryStonecutter(this.container, getResultInventory()) { + Inventory inventory = new CraftInventoryStonecutter(this.container, getResultInventory()) { @NotNull @Contract(pure = true) @Override @@ -206,7 +206,7 @@ public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} * Gets the result inventory * * @return the result inventory - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/CustomInventoryUtil.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/util/CustomInventoryUtil.java similarity index 91% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/CustomInventoryUtil.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/util/CustomInventoryUtil.java index 0d1e73542..364fd9bca 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/CustomInventoryUtil.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/util/CustomInventoryUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21.util; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; @@ -10,7 +10,7 @@ /** * A utility class for custom inventories * - * @since 0.10.15 + * @since 0.10.18 */ public final class CustomInventoryUtil { @@ -25,7 +25,7 @@ private CustomInventoryUtil() {} * * @param items the items to convert * @return a list of converted items - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/TextHolderUtil.java b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/util/TextHolderUtil.java similarity index 92% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/TextHolderUtil.java rename to nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/util/TextHolderUtil.java index 07864c3dc..b0757a95b 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/util/TextHolderUtil.java +++ b/nms/1_21_0/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_0/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21.util; +package com.github.stefvanschie.inventoryframework.nms.v1_21_0.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; @@ -14,7 +14,7 @@ /** * A utility class for adding {@link TextHolder} support. * - * @since 0.10.15 + * @since 0.10.18 */ public final class TextHolderUtil { @@ -27,7 +27,7 @@ private TextHolderUtil() { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -44,7 +44,7 @@ public static Component toComponent(@NotNull TextHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -57,7 +57,7 @@ private static Component toComponent(@NotNull StringHolder holder) { * * @param holder the value to convert * @return the value as a vanilla component - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) diff --git a/nms/1_21/pom.xml b/nms/1_21_1/pom.xml similarity index 97% rename from nms/1_21/pom.xml rename to nms/1_21_1/pom.xml index 3ad1e532c..fdb0750d7 100644 --- a/nms/1_21/pom.xml +++ b/nms/1_21_1/pom.xml @@ -6,11 +6,11 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml - 1_21 + 1_21_1 true diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/AnvilInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/AnvilInventoryImpl.java new file mode 100644 index 000000000..807fb052c --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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 anvil inventory for 1.21.1 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.18 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.18 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/BeaconInventoryImpl.java similarity index 94% rename from nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java rename to nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/BeaconInventoryImpl.java index 0a8f689fa..676d6064c 100644 --- a/nms/1_21/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21/BeaconInventoryImpl.java +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/BeaconInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21; +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import net.minecraft.core.NonNullList; @@ -13,7 +13,6 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryBeacon; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftBeaconView; @@ -26,9 +25,9 @@ import java.lang.reflect.Field; /** - * Internal beacon inventory for 1.21 + * Internal beacon inventory for 1.21.1 * - * @since 0.10.15 + * @since 0.10.18 */ public class BeaconInventoryImpl extends BeaconInventory { @@ -80,7 +79,7 @@ public void clearCursor(@NotNull Player player) { * * @param nmsPlayer the player to get the container id for * @return the container id - * @since 0.10.15 + * @since 0.10.18 */ @Contract(pure = true) private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { @@ -92,7 +91,7 @@ private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nms * * @param serverPlayer the player to get the player connection from * @return the player connection - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -105,7 +104,7 @@ private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverP * * @param player the player to get the server player from * @return the server player - * @since 0.10.15 + * @since 0.10.18 */ @NotNull @Contract(pure = true) @@ -116,7 +115,7 @@ private ServerPlayer getServerPlayer(@NotNull Player player) { /** * A custom container beacon * - * @since 0.10.15 + * @since 0.10.18 */ private class ContainerBeaconImpl extends BeaconMenu { @@ -166,7 +165,9 @@ public ContainerBeaconImpl(@NotNull ServerPlayer serverPlayer, @Nullable org.buk public CraftBeaconView getBukkitView() { if (bukkitEntity == null) { try { - CraftInventory inventory = new CraftInventoryBeacon((Container) beaconField.get(this)) { + Container container = (Container) beaconField.get(this); + + org.bukkit.inventory.BeaconInventory inventory = new CraftInventoryBeacon(container) { @NotNull @Contract(pure = true) @Override diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/CartographyTableInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..f9a79e83e --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_21_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.21.1 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.18 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("u"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/EnchantingTableInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..0e29d26bd --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/EnchantingTableInventoryImpl.java @@ -0,0 +1,220 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftEnchantmentView; +import org.bukkit.entity.Player; +import org.bukkit.inventory.EnchantingInventory; +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.21.1 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.18 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * The player for this enchanting table container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container enchanting table + */ + @Nullable + private CraftEnchantmentView bukkitEntity; + + /** + * Field for accessing the enchant slots field + */ + @NotNull + private final Field enchantSlotsField; + + public ContainerEnchantingTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("o"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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 CraftEnchantmentView getBukkitView() { + if (bukkitEntity == null) { + try { + Container container = (Container) enchantSlotsField.get(this); + + EnchantingInventory inventory = new CraftInventoryEnchanting(container) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + this.bukkitEntity = new CraftEnchantmentView(player, inventory, this); + } catch (IllegalAccessException exception) { + exception.printStackTrace(); + } + } + + return bukkitEntity; + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/GrindstoneInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..ba8297b71 --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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 grindstone inventory for 1.21.1 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.18 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.18 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.18 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/MerchantInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/MerchantInventoryImpl.java new file mode 100644 index 000000000..97aed260a --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/MerchantInventoryImpl.java @@ -0,0 +1,118 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.ItemCost; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_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; +import java.util.Optional; + +/** + * Internal merchant inventory for 1.21.1 + * + * @since 0.10.18 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); + + if (itemB != null) { + nmsItemB = CraftItemStack.asNMSCopy(itemB); + } + + ItemCost itemCostA = convertItemStackToItemCost(nmsItemA); + ItemCost itemCostB = convertItemStackToItemCost(nmsItemB); + + int uses = recipe.getUses(); + int maxUses = recipe.getMaxUses(); + int exp = recipe.getVillagerExperience(); + float multiplier = recipe.getPriceMultiplier(); + + MerchantOffer merchantOffer = new MerchantOffer( + itemCostA, Optional.of(itemCostB), nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Converts an NMS item stack to an item cost. + * + * @param itemStack the item stack to convert + * @return the item cost + * @since 0.10.18 + */ + @NotNull + @Contract(value = "_ -> new", pure = true) + private ItemCost convertItemStackToItemCost(@NotNull net.minecraft.world.item.ItemStack itemStack) { + DataComponentPredicate predicate = DataComponentPredicate.allOf(itemStack.getComponents()); + + return new ItemCost(itemStack.getItemHolder(), itemStack.getCount(), predicate, itemStack); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/SmithingTableInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..1e1cdb77c --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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.21.1. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.18 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.18 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.18 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/StonecutterInventoryImpl.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/StonecutterInventoryImpl.java new file mode 100644 index 000000000..85f43a7e0 --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/StonecutterInventoryImpl.java @@ -0,0 +1,222 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_1.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.view.CraftStonecutterView; +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.21.1 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.18 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * The player for this enchanting table container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container enchanting table + */ + @Nullable + private CraftStonecutterView bukkitEntity; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("A"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[1])); + } + + @NotNull + @Override + public CraftStonecutterView getBukkitView() { + if (bukkitEntity == null) { + org.bukkit.inventory.StonecutterInventory inventory = new CraftInventoryStonecutter( + this.container, getResultInventory() + ) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + this.bukkitEntity = new CraftStonecutterView(player, inventory, this); + } + + return bukkitEntity; + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/CustomInventoryUtil.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/CustomInventoryUtil.java new file mode 100644 index 000000000..e1d0af6d9 --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_1.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.18 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/TextHolderUtil.java b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/TextHolderUtil.java new file mode 100644 index 000000000..16d0416fd --- /dev/null +++ b/nms/1_21_1/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_1/util/TextHolderUtil.java @@ -0,0 +1,67 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_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.core.HolderLookup; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.stream.Stream; + +/** + * A utility class for adding {@link TextHolder} support. + * + * @since 0.10.18 + */ +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.18 + */ + @NotNull + @Contract(pure = true) + public static Component 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.18 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.18 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson(), HolderLookup.Provider.create(Stream.empty()))); + } +} diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 1e7aa4662..96032f6af 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.17 + 0.10.18-SNAPSHOT ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 3ac4df648..f34a6e70b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,8 @@ IF nms/abstraction - nms/1_21 + nms/1_21_1 + nms/1_21_0 nms/1_20_6 nms/1_20_5 nms/1_20_3-4 @@ -45,7 +46,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.17 + 0.10.18-SNAPSHOT pom IF From 140822714f467dde838607ff8c47a2f27d50ca61 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 24 Oct 2024 21:40:39 +0200 Subject: [PATCH 376/382] Add 1.21.2 support --- .github/workflows/auto-deploy.yml | 19 + .github/workflows/maven.yml | 19 + IF/pom.xml | 6 + .../util/version/Version.java | 15 +- .../util/version/VersionMatcher.java | 16 + nms/1_21_2/pom.xml | 72 ++++ .../nms/v1_21_2/AnvilInventoryImpl.java | 284 +++++++++++++++ .../nms/v1_21_2/BeaconInventoryImpl.java | 201 +++++++++++ .../CartographyTableInventoryImpl.java | 218 ++++++++++++ .../v1_21_2/EnchantingTableInventoryImpl.java | 220 ++++++++++++ .../nms/v1_21_2/GrindstoneInventoryImpl.java | 208 +++++++++++ .../nms/v1_21_2/MerchantInventoryImpl.java | 118 ++++++ .../v1_21_2/SmithingTableInventoryImpl.java | 335 ++++++++++++++++++ .../nms/v1_21_2/StonecutterInventoryImpl.java | 222 ++++++++++++ .../nms/v1_21_2/util/CustomInventoryUtil.java | 41 +++ .../nms/v1_21_2/util/TextHolderUtil.java | 67 ++++ pom.xml | 1 + 17 files changed, 2059 insertions(+), 3 deletions(-) create mode 100644 nms/1_21_2/pom.xml create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/AnvilInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/BeaconInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/CartographyTableInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/EnchantingTableInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/GrindstoneInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/MerchantInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/SmithingTableInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/StonecutterInventoryImpl.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/CustomInventoryUtil.java create mode 100644 nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/TextHolderUtil.java diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 08de3d9a8..9c671e5b9 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -124,6 +124,25 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check + + cd Bukkit + git checkout 8ec77750aa334e886ed2a0cee3320c62985b28e3 + cd .. + + cd CraftBukkit + git checkout d50f50585eab860db7889b3e736a62faf430f7a4 + cd .. + + cd Spigot + git checkout a084d85da8604d468f81091f56dc81166d912931 + cd .. + + cd BuildData + git checkout 0ea6fcc9bc8ad9e7c729f5031123bcc69ce2b033 + cd .. + + java -jar BuildTools.jar --remapped --disable-java-check --dont-update + cd ../ - name: Setup GPG keys run: cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 222b4f848..1608ec054 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -130,6 +130,25 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check + + cd Bukkit + git checkout 8ec77750aa334e886ed2a0cee3320c62985b28e3 + cd .. + + cd CraftBukkit + git checkout d50f50585eab860db7889b3e736a62faf430f7a4 + cd .. + + cd Spigot + git checkout a084d85da8604d468f81091f56dc81166d912931 + cd .. + + cd BuildData + git checkout 0ea6fcc9bc8ad9e7c729f5031123bcc69ce2b033 + cd .. + + java -jar BuildTools.jar --remapped --disable-java-check --dont-update + cd ../ - name: Build with Maven run: mvn -B package --file pom.xml diff --git a/IF/pom.xml b/IF/pom.xml index 946366870..b88c70404 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -179,6 +179,12 @@ ${project.version} compile + + com.github.stefvanschie.inventoryframework + 1_21_2 + ${project.version} + compile + com.github.stefvanschie.inventoryframework iv-abstraction diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index 1838a62a5..fab2b06e1 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -175,7 +175,14 @@ public enum Version { * * @since 0.10.18 */ - V1_21_1; + V1_21_1, + + /** + * Version 1.21.2 + * + * @since 0.10.18 + */ + V1_21_2; /** * A collection of versions on which modern smithing tables are available. @@ -183,7 +190,7 @@ public enum Version { private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5, V1_20_6, - V1_21_0, V1_21_1 + V1_21_0, V1_21_1, V1_21_2 ); /** @@ -204,7 +211,7 @@ public enum Version { */ @NotNull private static final Collection<@NotNull Version> INTERFACE_INVENTORY_VIEW = EnumSet.of( - V1_21_0, V1_21_1 + V1_21_0, V1_21_1, V1_21_2 ); /** @@ -307,6 +314,8 @@ public static Version getVersion() { return V1_21_0; case "1.21.1": return V1_21_1; + case "1.21.2": + return V1_21_2; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 331e7c01c..63f7c8b72 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 @@ -321,6 +321,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -369,6 +371,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -417,6 +421,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -465,6 +471,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -513,6 +521,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -561,6 +571,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, @@ -581,6 +593,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -657,5 +671,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_21_2, + com.github.stefvanschie.inventoryframework.nms.v1_21_2.StonecutterInventoryImpl.class); } } diff --git a/nms/1_21_2/pom.xml b/nms/1_21_2/pom.xml new file mode 100644 index 000000000..943aabb8b --- /dev/null +++ b/nms/1_21_2/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + com.github.stefvanschie.inventoryframework + IF-parent + 0.10.18-SNAPSHOT + ../../pom.xml + + + 1_21_2 + + + true + + + + + com.github.stefvanschie.inventoryframework + abstraction + ${project.version} + compile + + + org.spigotmc + spigot + 1.21.2-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.21.2-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.21.2-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.21.2-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.21.2-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + \ No newline at end of file diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/AnvilInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/AnvilInventoryImpl.java new file mode 100644 index 000000000..ad7e2de91 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/AnvilInventoryImpl.java @@ -0,0 +1,284 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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; + +/** + * Internal anvil inventory for 1.21.2 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerAnvilImpl containerAnvil = new ContainerAnvilImpl(serverPlayer, 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(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.ANVIL, message)); + serverPlayer.containerMenu = containerAnvil; + serverPlayer.initMenu(containerAnvil); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container anvil for responding to item renaming + * + * @since 0.10.18 + */ + private class ContainerAnvilImpl extends AnvilMenu { + + /** + * Creates a new custom anvil container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.18 + */ + public ContainerAnvilImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + this.checkReachable = false; + this.cost.set(AnvilInventoryImpl.super.cost); + + setTitle(title); + + Slot originalSlot = this.slots.get(2); + + this.slots.set(2, new Slot(originalSlot.container, originalSlot.index, originalSlot.x, originalSlot.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + originalSlot.onTake(player, stack); + } + }); + } + + @Override + public boolean setItemName(@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 + broadcastFullState(); + return true; //no idea what this is for + } + + @Override + public void createResult() {} + + @Override + public void removed(net.minecraft.world.entity.player.@NotNull Player nmsPlayer) {} + + @Override + protected void clearContainer(net.minecraft.world.entity.player.@NotNull Player player, + @NotNull Container inventory) {} + + @Override + protected void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/BeaconInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/BeaconInventoryImpl.java new file mode 100644 index 000000000..c8ef54449 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/BeaconInventoryImpl.java @@ -0,0 +1,201 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftInventoryBeacon; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R2.inventory.view.CraftBeaconView; +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.21.2 + * + * @since 0.10.18 + */ +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) { + ServerPlayer serverPlayer = getServerPlayer(player); + ContainerBeaconImpl containerBeacon = new ContainerBeaconImpl(serverPlayer, item); + + serverPlayer.containerMenu = containerBeacon; + + int id = containerBeacon.containerId; + Component beacon = Component.literal("Beacon"); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.BEACON, beacon)); + + sendItem(player, item); + } + + @Override + public void sendItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + NonNullList items = NonNullList.of( + ItemStack.EMPTY, //the first item doesn't count for some reason, so send a dummy item + CraftItemStack.asNMSCopy(item) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, items, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container beacon + * + * @since 0.10.18 + */ + private class ContainerBeaconImpl extends BeaconMenu { + + /** + * The player for this beacon container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container beacon + */ + @Nullable + private CraftBeaconView bukkitEntity; + + /** + * Field for accessing the beacon field + */ + @NotNull + private final Field beaconField; + + public ContainerBeaconImpl(@NotNull ServerPlayer serverPlayer, @Nullable org.bukkit.inventory.ItemStack item) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + setTitle(Component.empty()); + + try { + //noinspection JavaReflectionMemberAccess + this.beaconField = BeaconMenu.class.getDeclaredField("u"); //beacon + this.beaconField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + ItemStack itemStack = CraftItemStack.asNMSCopy(item); + + ((Container) beaconField.get(this)).setItem(0, itemStack); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + @NotNull + @Override + public CraftBeaconView getBukkitView() { + if (bukkitEntity == null) { + try { + Container container = (Container) beaconField.get(this); + + org.bukkit.inventory.BeaconInventory inventory = new CraftInventoryBeacon(container) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + this.bukkitEntity = new CraftBeaconView(player, inventory, this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + return bukkitEntity; + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/CartographyTableInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/CartographyTableInventoryImpl.java new file mode 100644 index 000000000..905f3ce83 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/CartographyTableInventoryImpl.java @@ -0,0 +1,218 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftInventoryCartography; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.v1_21_R2.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.21.2 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + + ContainerCartographyTableImpl containerCartographyTable = new ContainerCartographyTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerCartographyTable; + + int id = containerCartographyTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.CARTOGRAPHY_TABLE, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container cartography table + * + * @since 0.10.18 + */ + private class ContainerCartographyTableImpl extends CartographyTableMenu { + + /** + * 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 resultContainerField; + + public ContainerCartographyTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = CartographyTableMenu.class.getDeclaredField("w"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + container.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.container, 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 stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @NotNull + @Contract(pure = true) + private Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/EnchantingTableInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/EnchantingTableInventoryImpl.java new file mode 100644 index 000000000..8b9fab943 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/EnchantingTableInventoryImpl.java @@ -0,0 +1,220 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftInventoryEnchanting; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R2.inventory.view.CraftEnchantmentView; +import org.bukkit.entity.Player; +import org.bukkit.inventory.EnchantingInventory; +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.21.2 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerEnchantingTableImpl containerEnchantmentTable = new ContainerEnchantingTableImpl( + serverPlayer, items, message + ); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(id, MenuType.ENCHANTMENT, message)); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.18 + */ + private class ContainerEnchantingTableImpl extends EnchantmentMenu { + + /** + * The player for this enchanting table container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container enchanting table + */ + @Nullable + private CraftEnchantmentView bukkitEntity; + + /** + * Field for accessing the enchant slots field + */ + @NotNull + private final Field enchantSlotsField; + + public ContainerEnchantingTableImpl(@NotNull ServerPlayer serverPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, + @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + this.player = serverPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.enchantSlotsField = EnchantmentMenu.class.getDeclaredField("q"); //enchantSlots + this.enchantSlotsField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + try { + Container input = (Container) 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 CraftEnchantmentView getBukkitView() { + if (bukkitEntity == null) { + try { + Container container = (Container) enchantSlotsField.get(this); + + EnchantingInventory inventory = new CraftInventoryEnchanting(container) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + this.bukkitEntity = new CraftEnchantmentView(player, inventory, this); + } catch (IllegalAccessException exception) { + exception.printStackTrace(); + } + } + + return bukkitEntity; + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/GrindstoneInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/GrindstoneInventoryImpl.java new file mode 100644 index 000000000..da238f427 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/GrindstoneInventoryImpl.java @@ -0,0 +1,208 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.GrindstoneMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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; + +/** + * Internal grindstone inventory for 1.21.1 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerGrindstoneImpl containerGrindstone = new ContainerGrindstoneImpl(serverPlayer, message); + + Inventory inventory = containerGrindstone.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + + int containerId = containerGrindstone.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.GRINDSTONE, message)); + serverPlayer.containerMenu = containerGrindstone; + serverPlayer.initMenu(containerGrindstone); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + if (cursor == null) { + throw new IllegalArgumentException("Cursor may not be null on version 1.19.2"); + } + + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.18 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container grindstone + * + * @since 0.10.18 + */ + private static class ContainerGrindstoneImpl extends GrindstoneMenu { + + /** + * Creates a new grindstone container + * + * @param serverPlayer the player for whom this container should be opened + * @param title the title of the gui + * @since 0.10.18 + */ + public ContainerGrindstoneImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory()); + + setTitle(title); + + 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.container, firstSlot.index, firstSlot.x, firstSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(1, new Slot(secondSlot.container, secondSlot.index, secondSlot.x, secondSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + }); + + this.slots.set(2, new Slot(thirdSlot.container, thirdSlot.index, thirdSlot.x, thirdSlot.y) { + @Override + public boolean mayPlace(ItemStack stack) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/MerchantInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/MerchantInventoryImpl.java new file mode 100644 index 000000000..4ce1393bd --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/MerchantInventoryImpl.java @@ -0,0 +1,118 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.trading.ItemCost; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_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; +import java.util.Optional; + +/** + * Internal merchant inventory for 1.21.2 + * + * @since 0.10.18 + */ +public class MerchantInventoryImpl extends MerchantInventory { + + @Override + public void sendMerchantOffers(@NotNull Player player, + @NotNull List> trades, + int level, int experience) { + MerchantOffers offers = new MerchantOffers(); + + 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.world.item.ItemStack nmsItemA = CraftItemStack.asNMSCopy(itemA); + net.minecraft.world.item.ItemStack nmsItemB = net.minecraft.world.item.ItemStack.EMPTY; + net.minecraft.world.item.ItemStack nmsItemResult = CraftItemStack.asNMSCopy(recipe.getResult()); + + if (itemB != null) { + nmsItemB = CraftItemStack.asNMSCopy(itemB); + } + + ItemCost itemCostA = convertItemStackToItemCost(nmsItemA); + ItemCost itemCostB = convertItemStackToItemCost(nmsItemB); + + int uses = recipe.getUses(); + int maxUses = recipe.getMaxUses(); + int exp = recipe.getVillagerExperience(); + float multiplier = recipe.getPriceMultiplier(); + + MerchantOffer merchantOffer = new MerchantOffer( + itemCostA, Optional.of(itemCostB), nmsItemResult, uses, maxUses, exp, multiplier + ); + merchantOffer.setSpecialPriceDiff(entry.getValue()); + + offers.add(merchantOffer); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + + serverPlayer.sendMerchantOffers(containerId, offers, level, experience, true, false); + } + + /** + * Converts an NMS item stack to an item cost. + * + * @param itemStack the item stack to convert + * @return the item cost + * @since 0.10.18 + */ + @NotNull + @Contract(value = "_ -> new", pure = true) + private ItemCost convertItemStackToItemCost(@NotNull net.minecraft.world.item.ItemStack itemStack) { + DataComponentPredicate predicate = DataComponentPredicate.allOf(itemStack.getComponents()); + + return new ItemCost(itemStack.getItemHolder(), itemStack.getCount(), predicate, itemStack); + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * Gets the containerId id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the containerId id for + * @return the containerId id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/SmithingTableInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/SmithingTableInventoryImpl.java new file mode 100644 index 000000000..ddb5aeff3 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/SmithingTableInventoryImpl.java @@ -0,0 +1,335 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R2.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_21_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; + +/** + * Internal smithing table inventory for 1.21.2. This is only available for Minecraft 1.20 and higher. + * + * @since 0.10.18 + */ +public class SmithingTableInventoryImpl extends SmithingTableInventory { + + public SmithingTableInventoryImpl(@NotNull InventoryHolder inventoryHolder) { + super(inventoryHolder); + } + + @NotNull + @Override + public Inventory openInventory(@NotNull Player player, @NotNull TextHolder title, + @Nullable org.bukkit.inventory.ItemStack[] items) { + int itemAmount = items.length; + + if (itemAmount != 4) { + throw new IllegalArgumentException( + "The amount of items for a smithing table should be 4, but is '" + itemAmount + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + + //ignore deprecation: superseding method is only available on Paper + //noinspection deprecation + CraftEventFactory.handleInventoryCloseEvent(serverPlayer); + + serverPlayer.containerMenu = serverPlayer.inventoryMenu; + + Component message = TextHolderUtil.toComponent(title); + ContainerSmithingTableImpl containerSmithingTable = new ContainerSmithingTableImpl(serverPlayer, message); + + Inventory inventory = containerSmithingTable.getBukkitView().getTopInventory(); + + inventory.setItem(0, items[0]); + inventory.setItem(1, items[1]); + inventory.setItem(2, items[2]); + inventory.setItem(3, items[3]); + + int containerId = containerSmithingTable.getContainerId(); + + serverPlayer.connection.send(new ClientboundOpenScreenPacket(containerId, MenuType.SMITHING, message)); + serverPlayer.containerMenu = containerSmithingTable; + serverPlayer.initMenu(containerSmithingTable); + + return inventory; + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items, + @Nullable org.bukkit.inventory.ItemStack cursor) { + NonNullList nmsItems = CustomInventoryUtil.convertToNMSItems(items); + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack nmsCursor = CraftItemStack.asNMSCopy(cursor); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, nmsCursor)); + } + + @Override + public void sendFirstItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 0, nmsItem)); + } + + @Override + public void sendSecondItem(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 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.EMPTY); + } + + @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) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * 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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void setCursor(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -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.10.18 + * @deprecated no longer used internally + */ + @Deprecated + private void sendResultItem(@NotNull Player player, @NotNull ItemStack item) { + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(containerId, state, 2, item)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + * @deprecated no longer used internally + */ + @Contract(pure = true) + @Deprecated + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + * @deprecated no longer used internally + */ + @NotNull + @Contract(pure = true) + @Deprecated + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container smithing table + * + * @since 0.10.18 + */ + private static class ContainerSmithingTableImpl extends SmithingMenu { + + /** + * Creates a new custom smithing table container for the specified player + * + * @param serverPlayer the player for whom this anvil container is + * @param title the title of the inventory + * @since 0.10.18 + */ + public ContainerSmithingTableImpl(@NotNull ServerPlayer serverPlayer, @NotNull Component title) { + super(serverPlayer.nextContainerCounter(), serverPlayer.getInventory(), + ContainerLevelAccess.create(serverPlayer.getCommandSenderWorld(), new BlockPos(0, 0, 0))); + + setTitle(title); + + this.checkReachable = false; + + Slot slotOne = this.slots.get(0); + Slot slotTwo = this.slots.get(1); + Slot slotThree = this.slots.get(2); + Slot slotFour = this.slots.get(3); + + this.slots.set(0, new Slot(slotOne.container, slotOne.index, slotOne.x, slotOne.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotOne.onTake(player, stack); + } + }); + + this.slots.set(1, new Slot(slotTwo.container, slotTwo.index, slotTwo.x, slotTwo.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotTwo.onTake(player, stack); + } + }); + + this.slots.set(2, new Slot(slotThree.container, slotThree.index, slotThree.x, slotThree.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotThree.onTake(player, stack); + } + }); + + this.slots.set(3, new Slot(slotFour.container, slotFour.index, slotFour.x, slotFour.y) { + @Override + public boolean mayPlace(@NotNull ItemStack stack) { + return true; + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.@NotNull Player playerEntity) { + return true; + } + + @Override + public void onTake(net.minecraft.world.entity.player.@NotNull Player player, @NotNull ItemStack stack) { + slotFour.onTake(player, stack); + } + }); + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + @Override + public void createResult() {} + + @Override + protected void onTake(net.minecraft.world.entity.player.Player player, ItemStack stack) {} + + @Override + protected boolean mayPickup(net.minecraft.world.entity.player.Player player, boolean present) { + return true; + } + + public int getContainerId() { + return this.containerId; + } + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/StonecutterInventoryImpl.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/StonecutterInventoryImpl.java new file mode 100644 index 000000000..52e648d9a --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/StonecutterInventoryImpl.java @@ -0,0 +1,222 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2; + +import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; +import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.StonecutterMenu; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftInventoryStonecutter; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R2.inventory.view.CraftStonecutterView; +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.21.2 + * + * @since 0.10.18 + */ +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 + "'" + ); + } + + ServerPlayer serverPlayer = getServerPlayer(player); + Component message = TextHolderUtil.toComponent(title); + ContainerStonecutterImpl containerEnchantmentTable = new ContainerStonecutterImpl(serverPlayer, items, message); + + serverPlayer.containerMenu = containerEnchantmentTable; + + int id = containerEnchantmentTable.containerId; + ClientboundOpenScreenPacket packet = new ClientboundOpenScreenPacket(id, MenuType.STONECUTTER, message); + + serverPlayer.connection.send(packet); + + sendItems(player, items); + } + + @Override + public void sendItems(@NotNull Player player, @Nullable org.bukkit.inventory.ItemStack[] items) { + NonNullList nmsItems = NonNullList.of( + ItemStack.EMPTY, + CraftItemStack.asNMSCopy(items[0]), + CraftItemStack.asNMSCopy(items[1]) + ); + + ServerPlayer serverPlayer = getServerPlayer(player); + int containerId = getContainerId(serverPlayer); + int state = serverPlayer.containerMenu.incrementStateId(); + ItemStack cursor = CraftItemStack.asNMSCopy(player.getItemOnCursor()); + ServerPlayerConnection playerConnection = getPlayerConnection(serverPlayer); + + playerConnection.send(new ClientboundContainerSetContentPacket(containerId, state, nmsItems, cursor)); + } + + @Override + public void clearCursor(@NotNull Player player) { + ServerPlayer serverPlayer = getServerPlayer(player); + int state = serverPlayer.containerMenu.incrementStateId(); + + getPlayerConnection(serverPlayer).send(new ClientboundContainerSetSlotPacket(-1, state, -1, ItemStack.EMPTY)); + } + + /** + * Gets the container id for the inventory view the player currently has open + * + * @param nmsPlayer the player to get the container id for + * @return the container id + * @since 0.10.18 + */ + @Contract(pure = true) + private int getContainerId(@NotNull net.minecraft.world.entity.player.Player nmsPlayer) { + return nmsPlayer.containerMenu.containerId; + } + + /** + * Gets the player connection for the specified player + * + * @param serverPlayer the player to get the player connection from + * @return the player connection + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayerConnection getPlayerConnection(@NotNull ServerPlayer serverPlayer) { + return serverPlayer.connection; + } + + /** + * Gets the server player associated to this player + * + * @param player the player to get the server player from + * @return the server player + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + private ServerPlayer getServerPlayer(@NotNull Player player) { + return ((CraftPlayer) player).getHandle(); + } + + /** + * A custom container enchanting table + * + * @since 0.10.18 + */ + private class ContainerStonecutterImpl extends StonecutterMenu { + + /** + * The player for this enchanting table container + */ + @NotNull + private final Player player; + + /** + * The internal bukkit entity for this container enchanting table + */ + @Nullable + private CraftStonecutterView bukkitEntity; + + /** + * Field for accessing the result inventory field + */ + @NotNull + private final Field resultContainerField; + + public ContainerStonecutterImpl(@NotNull ServerPlayer entityPlayer, + @Nullable org.bukkit.inventory.ItemStack[] items, @NotNull Component title) { + super(entityPlayer.nextContainerCounter(), entityPlayer.getInventory()); + + this.player = entityPlayer.getBukkitEntity(); + + setTitle(title); + + try { + //noinspection JavaReflectionMemberAccess + this.resultContainerField = StonecutterMenu.class.getDeclaredField("C"); //resultContainer + this.resultContainerField.setAccessible(true); + } catch (NoSuchFieldException exception) { + throw new RuntimeException(exception); + } + + container.setItem(0, CraftItemStack.asNMSCopy(items[0])); + getResultInventory().setItem(0, CraftItemStack.asNMSCopy(items[1])); + } + + @NotNull + @Override + public CraftStonecutterView getBukkitView() { + if (bukkitEntity == null) { + org.bukkit.inventory.StonecutterInventory inventory = new CraftInventoryStonecutter( + this.container, getResultInventory() + ) { + @NotNull + @Contract(pure = true) + @Override + public InventoryHolder getHolder() { + return inventoryHolder; + } + }; + + this.bukkitEntity = new CraftStonecutterView(player, inventory, this); + } + + return bukkitEntity; + } + + @Contract(pure = true, value = "_ -> true") + @Override + public boolean stillValid(@Nullable net.minecraft.world.entity.player.Player nmsPlayer) { + return true; + } + + @Override + public void slotsChanged(Container container) {} + + @Override + public void removed(net.minecraft.world.entity.player.Player nmsPlayer) {} + + /** + * Gets the result inventory + * + * @return the result inventory + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + public Container getResultInventory() { + try { + return (Container) resultContainerField.get(this); + } catch (IllegalAccessException exception) { + throw new RuntimeException(exception); + } + } + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/CustomInventoryUtil.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/CustomInventoryUtil.java new file mode 100644 index 000000000..145921a65 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/CustomInventoryUtil.java @@ -0,0 +1,41 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A utility class for custom inventories + * + * @since 0.10.18 + */ +public final class CustomInventoryUtil { + + /** + * A private constructor to prevent construction. + */ + private CustomInventoryUtil() {} + + /** + * Converts an array of Bukkit items into a non-null list of NMS items. The returned list is modifiable. If no items + * were specified, this returns an empty list. + * + * @param items the items to convert + * @return a list of converted items + * @since 0.10.18 + */ + @NotNull + @Contract(pure = true) + public static NonNullList convertToNMSItems(@Nullable org.bukkit.inventory.ItemStack @NotNull [] items) { + NonNullList nmsItems = NonNullList.create(); + + for (org.bukkit.inventory.ItemStack item : items) { + nmsItems.add(CraftItemStack.asNMSCopy(item)); + } + + return nmsItems; + } +} diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/TextHolderUtil.java b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/TextHolderUtil.java new file mode 100644 index 000000000..d715014b4 --- /dev/null +++ b/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/TextHolderUtil.java @@ -0,0 +1,67 @@ +package com.github.stefvanschie.inventoryframework.nms.v1_21_2.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.core.HolderLookup; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.stream.Stream; + +/** + * A utility class for adding {@link TextHolder} support. + * + * @since 0.10.18 + */ +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.18 + */ + @NotNull + @Contract(pure = true) + public static Component 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.18 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull StringHolder holder) { + return Component.literal(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.18 + */ + @NotNull + @Contract(pure = true) + private static Component toComponent(@NotNull ComponentHolder holder) { + return Objects.requireNonNull(Component.Serializer.fromJson(holder.asJson(), HolderLookup.Provider.create(Stream.empty()))); + } +} diff --git a/pom.xml b/pom.xml index f34a6e70b..b62668d49 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ IF nms/abstraction + nms/1_21_2 nms/1_21_1 nms/1_21_0 nms/1_20_6 From 60b19dc29ee4bc0fc0b812590a4675ba03270499 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 31 Oct 2024 20:24:54 +0100 Subject: [PATCH 377/382] Add 1.21.3 support --- IF/pom.xml | 2 +- .../util/version/Version.java | 11 ++++--- .../util/version/VersionMatcher.java | 32 +++++++++---------- nms/{1_21_2 => 1_21_2-3}/pom.xml | 12 +++---- .../nms/v1_21_2_3}/AnvilInventoryImpl.java | 6 ++-- .../nms/v1_21_2_3}/BeaconInventoryImpl.java | 2 +- .../CartographyTableInventoryImpl.java | 6 ++-- .../EnchantingTableInventoryImpl.java | 4 +-- .../v1_21_2_3}/GrindstoneInventoryImpl.java | 6 ++-- .../nms/v1_21_2_3}/MerchantInventoryImpl.java | 2 +- .../SmithingTableInventoryImpl.java | 6 ++-- .../v1_21_2_3}/StonecutterInventoryImpl.java | 4 +-- .../v1_21_2_3}/util/CustomInventoryUtil.java | 2 +- .../nms/v1_21_2_3}/util/TextHolderUtil.java | 2 +- pom.xml | 2 +- 15 files changed, 50 insertions(+), 49 deletions(-) rename nms/{1_21_2 => 1_21_2-3}/pom.xml (89%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/AnvilInventoryImpl.java (97%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/BeaconInventoryImpl.java (99%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/CartographyTableInventoryImpl.java (96%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/EnchantingTableInventoryImpl.java (98%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/GrindstoneInventoryImpl.java (96%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/MerchantInventoryImpl.java (98%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/SmithingTableInventoryImpl.java (98%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/StonecutterInventoryImpl.java (98%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/util/CustomInventoryUtil.java (94%) rename nms/{1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2 => 1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3}/util/TextHolderUtil.java (96%) diff --git a/IF/pom.xml b/IF/pom.xml index b88c70404..5b9d4e6ca 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -181,7 +181,7 @@ com.github.stefvanschie.inventoryframework - 1_21_2 + 1_21_2-3 ${project.version} compile diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java index fab2b06e1..93ddce445 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/util/version/Version.java @@ -178,11 +178,11 @@ public enum Version { V1_21_1, /** - * Version 1.21.2 + * Version 1.21.2 - 1.21.3 * * @since 0.10.18 */ - V1_21_2; + V1_21_2_3; /** * A collection of versions on which modern smithing tables are available. @@ -190,7 +190,7 @@ public enum Version { private static final Collection MODERN_SMITHING_TABLE_VERSIONS = EnumSet.of( V1_19_4, V1_20_0, V1_20_1, V1_20_2, V1_20_3_4, V1_20_5, V1_20_6, - V1_21_0, V1_21_1, V1_21_2 + V1_21_0, V1_21_1, V1_21_2_3 ); /** @@ -211,7 +211,7 @@ public enum Version { */ @NotNull private static final Collection<@NotNull Version> INTERFACE_INVENTORY_VIEW = EnumSet.of( - V1_21_0, V1_21_1, V1_21_2 + V1_21_0, V1_21_1, V1_21_2_3 ); /** @@ -315,7 +315,8 @@ public static Version getVersion() { case "1.21.1": return V1_21_1; case "1.21.2": - return V1_21_2; + case "1.21.3": + return V1_21_2_3; default: throw new UnsupportedVersionException("The server version provided is not supported"); } 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 63f7c8b72..5ef836807 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 @@ -321,8 +321,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.AnvilInventoryImpl.class); ANVIL_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.AnvilInventoryImpl.class); - ANVIL_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.AnvilInventoryImpl.class); + ANVIL_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.AnvilInventoryImpl.class); BEACON_INVENTORIES = new EnumMap<>(Version.class); BEACON_INVENTORIES.put(Version.V1_14, @@ -371,8 +371,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.BeaconInventoryImpl.class); BEACON_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.BeaconInventoryImpl.class); - BEACON_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.BeaconInventoryImpl.class); + BEACON_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.BeaconInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES = new EnumMap<>(Version.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_14, @@ -421,8 +421,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.CartographyTableInventoryImpl.class); CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.CartographyTableInventoryImpl.class); - CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.CartographyTableInventoryImpl.class); + CARTOGRAPHY_TABLE_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.CartographyTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES = new EnumMap<>(Version.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_14, @@ -471,8 +471,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.EnchantingTableInventoryImpl.class); ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.EnchantingTableInventoryImpl.class); - ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.EnchantingTableInventoryImpl.class); + ENCHANTING_TABLE_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.EnchantingTableInventoryImpl.class); GRINDSTONE_INVENTORIES = new EnumMap<>(Version.class); GRINDSTONE_INVENTORIES.put(Version.V1_14, @@ -521,8 +521,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.GrindstoneInventoryImpl.class); GRINDSTONE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.GrindstoneInventoryImpl.class); - GRINDSTONE_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.GrindstoneInventoryImpl.class); + GRINDSTONE_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.GrindstoneInventoryImpl.class); MERCHANT_INVENTORIES = new EnumMap<>(Version.class); MERCHANT_INVENTORIES.put(Version.V1_14, @@ -571,8 +571,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.MerchantInventoryImpl.class); MERCHANT_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.MerchantInventoryImpl.class); - MERCHANT_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.MerchantInventoryImpl.class); + MERCHANT_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.MerchantInventoryImpl.class); SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_19_4, @@ -593,8 +593,8 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.SmithingTableInventoryImpl.class); SMITHING_TABLE_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.SmithingTableInventoryImpl.class); - SMITHING_TABLE_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.SmithingTableInventoryImpl.class); + SMITHING_TABLE_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.SmithingTableInventoryImpl.class); LEGACY_SMITHING_TABLE_INVENTORIES = new EnumMap<>(Version.class); LEGACY_SMITHING_TABLE_INVENTORIES.put(Version.V1_16_1, @@ -671,7 +671,7 @@ public static StonecutterInventory newStonecutterInventory(@NotNull Version vers com.github.stefvanschie.inventoryframework.nms.v1_21_0.StonecutterInventoryImpl.class); STONECUTTER_INVENTORIES.put(Version.V1_21_1, com.github.stefvanschie.inventoryframework.nms.v1_21_1.StonecutterInventoryImpl.class); - STONECUTTER_INVENTORIES.put(Version.V1_21_2, - com.github.stefvanschie.inventoryframework.nms.v1_21_2.StonecutterInventoryImpl.class); + STONECUTTER_INVENTORIES.put(Version.V1_21_2_3, + com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.StonecutterInventoryImpl.class); } } diff --git a/nms/1_21_2/pom.xml b/nms/1_21_2-3/pom.xml similarity index 89% rename from nms/1_21_2/pom.xml rename to nms/1_21_2-3/pom.xml index 943aabb8b..f02078b13 100644 --- a/nms/1_21_2/pom.xml +++ b/nms/1_21_2-3/pom.xml @@ -10,7 +10,7 @@ ../../pom.xml - 1_21_2 + 1_21_2-3 true @@ -26,7 +26,7 @@ org.spigotmc spigot - 1.21.2-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT remapped-mojang provided @@ -46,9 +46,9 @@ remap-obf - org.spigotmc:minecraft-server:1.21.2-R0.1-SNAPSHOT:txt:maps-mojang + org.spigotmc:minecraft-server:1.21.3-R0.1-SNAPSHOT:txt:maps-mojang true - org.spigotmc:spigot:1.21.2-R0.1-SNAPSHOT:jar:remapped-mojang + org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT:jar:remapped-mojang true remapped-obf @@ -61,8 +61,8 @@ remap-spigot ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.21.2-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.21.2-R0.1-SNAPSHOT:jar:remapped-obf + org.spigotmc:minecraft-server:1.21.3-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT:jar:remapped-obf diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/AnvilInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/AnvilInventoryImpl.java similarity index 97% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/AnvilInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/AnvilInventoryImpl.java index ad7e2de91..0b3aa092f 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/AnvilInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/AnvilInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.AnvilInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/BeaconInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/BeaconInventoryImpl.java similarity index 99% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/BeaconInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/BeaconInventoryImpl.java index c8ef54449..34faf64cb 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/BeaconInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/BeaconInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.BeaconInventory; import net.minecraft.core.NonNullList; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/CartographyTableInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/CartographyTableInventoryImpl.java similarity index 96% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/CartographyTableInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/CartographyTableInventoryImpl.java index 905f3ce83..ef2b9a2bb 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/CartographyTableInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/CartographyTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.CartographyTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/EnchantingTableInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/EnchantingTableInventoryImpl.java similarity index 98% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/EnchantingTableInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/EnchantingTableInventoryImpl.java index 8b9fab943..c4cec2658 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/EnchantingTableInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/EnchantingTableInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.EnchantingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/GrindstoneInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/GrindstoneInventoryImpl.java similarity index 96% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/GrindstoneInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/GrindstoneInventoryImpl.java index da238f427..c9796f497 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/GrindstoneInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/GrindstoneInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.GrindstoneInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/MerchantInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/MerchantInventoryImpl.java similarity index 98% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/MerchantInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/MerchantInventoryImpl.java index 4ce1393bd..7f64c8787 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/MerchantInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/MerchantInventoryImpl.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.MerchantInventory; import net.minecraft.core.component.DataComponentPredicate; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/SmithingTableInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/SmithingTableInventoryImpl.java similarity index 98% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/SmithingTableInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/SmithingTableInventoryImpl.java index ddb5aeff3..03457ad75 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/SmithingTableInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/SmithingTableInventoryImpl.java @@ -1,9 +1,9 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.SmithingTableInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.CustomInventoryUtil; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.CustomInventoryUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.TextHolderUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/StonecutterInventoryImpl.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/StonecutterInventoryImpl.java similarity index 98% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/StonecutterInventoryImpl.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/StonecutterInventoryImpl.java index 52e648d9a..18d570277 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/StonecutterInventoryImpl.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/StonecutterInventoryImpl.java @@ -1,8 +1,8 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3; import com.github.stefvanschie.inventoryframework.abstraction.StonecutterInventory; import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; -import com.github.stefvanschie.inventoryframework.nms.v1_21_2.util.TextHolderUtil; +import com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util.TextHolderUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/CustomInventoryUtil.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/util/CustomInventoryUtil.java similarity index 94% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/CustomInventoryUtil.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/util/CustomInventoryUtil.java index 145921a65..eb2257b95 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/CustomInventoryUtil.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/util/CustomInventoryUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2.util; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; diff --git a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/TextHolderUtil.java b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/util/TextHolderUtil.java similarity index 96% rename from nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/TextHolderUtil.java rename to nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/util/TextHolderUtil.java index d715014b4..4f8075836 100644 --- a/nms/1_21_2/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2/util/TextHolderUtil.java +++ b/nms/1_21_2-3/src/main/java/com/github/stefvanschie/inventoryframework/nms/v1_21_2_3/util/TextHolderUtil.java @@ -1,4 +1,4 @@ -package com.github.stefvanschie.inventoryframework.nms.v1_21_2.util; +package com.github.stefvanschie.inventoryframework.nms.v1_21_2_3.util; import com.github.stefvanschie.inventoryframework.adventuresupport.ComponentHolder; import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder; diff --git a/pom.xml b/pom.xml index b62668d49..668df9c2f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ IF nms/abstraction - nms/1_21_2 + nms/1_21_2-3 nms/1_21_1 nms/1_21_0 nms/1_20_6 From 0ea0def776af87b55eea9d2b561bb773834a431c Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Thu, 31 Oct 2024 20:53:04 +0100 Subject: [PATCH 378/382] Fix CI/CD & dependabot --- .github/dependabot.yml | 4 ++++ .github/workflows/auto-deploy.yml | 3 ++- .github/workflows/maven.yml | 3 ++- README.md | 21 ++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fb2210cff..2472e19a6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -104,6 +104,10 @@ updates: directory: "/nms/1_21_1" schedule: interval: "daily" + - package-ecosystem: "maven" + directory: "/nms/1_21_2-3" + schedule: + interval: "daily" - package-ecosystem: "maven" directory: "/nms/abstraction" schedule: diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 9c671e5b9..5db9d040e 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -76,7 +76,7 @@ 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: 'Run BuildTools 1.20.5-1.20.6, 1.21.1' + - name: 'Run BuildTools 1.20.5-1.20.6, 1.21' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -142,6 +142,7 @@ jobs: cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update + java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check cd ../ - name: Setup GPG keys diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1608ec054..9113fa104 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -82,7 +82,7 @@ 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: 'Run BuildTools 1.20.5-1.20.6, 1.21.1' + - name: 'Run BuildTools 1.20.5-1.20.6, 1.21' if: steps.cache-paperclip-jars.outputs.cache-hit != 'true' run: | mkdir -p build @@ -148,6 +148,7 @@ jobs: cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update + java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check cd ../ - name: Build with Maven diff --git a/README.md b/README.md index 4d04840dc..7fc917bcd 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ mvn paper-nms:init -pl nms/1_20_3-4 ``` ### Installing Spigot via BuildTools -For versions 1.20.5-1.21.1, we use BuildTools. To install these versions, we run the following commands. +For versions 1.20.5-1.21.3, we use BuildTools. To install these versions, we run the following commands. ``` wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar @@ -187,6 +187,25 @@ cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check + +cd Bukkit +git checkout 8ec77750aa334e886ed2a0cee3320c62985b28e3 +cd .. + +cd CraftBukkit +git checkout d50f50585eab860db7889b3e736a62faf430f7a4 +cd .. + +cd Spigot +git checkout a084d85da8604d468f81091f56dc81166d912931 +cd .. + +cd BuildData +git checkout 0ea6fcc9bc8ad9e7c729f5031123bcc69ce2b033 +cd .. + +java -jar BuildTools.jar --remapped --disable-java-check --dont-update +java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check ``` Your environment is now set up correctly. To create a build, run the following inside the root folder of the project. From 07d811cf03709b89561acd1ce8d1f62b5d8e04c8 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Sat, 2 Nov 2024 21:11:58 +0100 Subject: [PATCH 379/382] Remove 1.21.2 from CI/CD --- .github/workflows/auto-deploy.yml | 18 ------------------ .github/workflows/maven.yml | 18 ------------------ README.md | 18 ------------------ 3 files changed, 54 deletions(-) diff --git a/.github/workflows/auto-deploy.yml b/.github/workflows/auto-deploy.yml index 5db9d040e..0ec441f24 100644 --- a/.github/workflows/auto-deploy.yml +++ b/.github/workflows/auto-deploy.yml @@ -124,24 +124,6 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check - - cd Bukkit - git checkout 8ec77750aa334e886ed2a0cee3320c62985b28e3 - cd .. - - cd CraftBukkit - git checkout d50f50585eab860db7889b3e736a62faf430f7a4 - cd .. - - cd Spigot - git checkout a084d85da8604d468f81091f56dc81166d912931 - cd .. - - cd BuildData - git checkout 0ea6fcc9bc8ad9e7c729f5031123bcc69ce2b033 - cd .. - - java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check cd ../ diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9113fa104..ae799f8a0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -130,24 +130,6 @@ jobs: java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check - - cd Bukkit - git checkout 8ec77750aa334e886ed2a0cee3320c62985b28e3 - cd .. - - cd CraftBukkit - git checkout d50f50585eab860db7889b3e736a62faf430f7a4 - cd .. - - cd Spigot - git checkout a084d85da8604d468f81091f56dc81166d912931 - cd .. - - cd BuildData - git checkout 0ea6fcc9bc8ad9e7c729f5031123bcc69ce2b033 - cd .. - - java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check cd ../ diff --git a/README.md b/README.md index 7fc917bcd..a73790f57 100644 --- a/README.md +++ b/README.md @@ -187,24 +187,6 @@ cd .. java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.1 --remapped --disable-java-check - -cd Bukkit -git checkout 8ec77750aa334e886ed2a0cee3320c62985b28e3 -cd .. - -cd CraftBukkit -git checkout d50f50585eab860db7889b3e736a62faf430f7a4 -cd .. - -cd Spigot -git checkout a084d85da8604d468f81091f56dc81166d912931 -cd .. - -cd BuildData -git checkout 0ea6fcc9bc8ad9e7c729f5031123bcc69ce2b033 -cd .. - -java -jar BuildTools.jar --remapped --disable-java-check --dont-update java -jar BuildTools.jar --rev 1.21.3 --remapped --disable-java-check ``` From 0a1d721e1788dd8aac85de540a34ae6c7c0b0dc4 Mon Sep 17 00:00:00 2001 From: stefvanschie Date: Mon, 4 Nov 2024 21:14:24 +0100 Subject: [PATCH 380/382] V 0.10.18 --- IF/pom.xml | 2 +- README.md | 4 ++-- adventure-support/pom.xml | 2 +- inventory-view/iv-abstract-class/pom.xml | 2 +- inventory-view/iv-abstraction/pom.xml | 2 +- inventory-view/iv-interface/pom.xml | 2 +- nms/1_14/pom.xml | 2 +- nms/1_15/pom.xml | 2 +- nms/1_16_1/pom.xml | 2 +- nms/1_16_2-3/pom.xml | 2 +- nms/1_16_4-5/pom.xml | 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_0/pom.xml | 2 +- nms/1_20_1/pom.xml | 2 +- nms/1_20_2/pom.xml | 2 +- nms/1_20_3-4/pom.xml | 2 +- nms/1_20_5/pom.xml | 2 +- nms/1_20_6/pom.xml | 2 +- nms/1_21_0/pom.xml | 2 +- nms/1_21_1/pom.xml | 2 +- nms/1_21_2-3/pom.xml | 2 +- nms/abstraction/pom.xml | 2 +- pom.xml | 2 +- 32 files changed, 33 insertions(+), 33 deletions(-) diff --git a/IF/pom.xml b/IF/pom.xml index 5b9d4e6ca..f5ebf60b4 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../pom.xml 4.0.0 diff --git a/README.md b/README.md index a73790f57..666872443 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ To add this project as a dependency to your pom.xml, add the following to your p com.github.stefvanschie.inventoryframework IF - 0.10.17 + 0.10.18 ``` The project is in the Central Repository, so specifying a repository is not needed. @@ -50,7 +50,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project. To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following: ```Groovy dependencies { - implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.17' + implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.18' // ... } ``` diff --git a/adventure-support/pom.xml b/adventure-support/pom.xml index 2e95e7461..3d4bb888f 100644 --- a/adventure-support/pom.xml +++ b/adventure-support/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 4.0.0 diff --git a/inventory-view/iv-abstract-class/pom.xml b/inventory-view/iv-abstract-class/pom.xml index bf33ff286..ea1a52a81 100644 --- a/inventory-view/iv-abstract-class/pom.xml +++ b/inventory-view/iv-abstract-class/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/inventory-view/iv-abstraction/pom.xml b/inventory-view/iv-abstraction/pom.xml index 1588aad1a..c03fa67b7 100644 --- a/inventory-view/iv-abstraction/pom.xml +++ b/inventory-view/iv-abstraction/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/inventory-view/iv-interface/pom.xml b/inventory-view/iv-interface/pom.xml index 8e3892852..cd6e8cf4c 100644 --- a/inventory-view/iv-interface/pom.xml +++ b/inventory-view/iv-interface/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_14/pom.xml b/nms/1_14/pom.xml index 79d818929..dad32016c 100644 --- a/nms/1_14/pom.xml +++ b/nms/1_14/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_15/pom.xml b/nms/1_15/pom.xml index faac5f279..c85530eb7 100644 --- a/nms/1_15/pom.xml +++ b/nms/1_15/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_16_1/pom.xml b/nms/1_16_1/pom.xml index 046d24914..6ad0fba2a 100644 --- a/nms/1_16_1/pom.xml +++ b/nms/1_16_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_16_2-3/pom.xml b/nms/1_16_2-3/pom.xml index 9fe11f679..147afb076 100644 --- a/nms/1_16_2-3/pom.xml +++ b/nms/1_16_2-3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_16_4-5/pom.xml b/nms/1_16_4-5/pom.xml index a86dd079e..8f5722fb5 100644 --- a/nms/1_16_4-5/pom.xml +++ b/nms/1_16_4-5/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_17_0/pom.xml b/nms/1_17_0/pom.xml index 3637330f0..9ed5e1571 100644 --- a/nms/1_17_0/pom.xml +++ b/nms/1_17_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_17_1/pom.xml b/nms/1_17_1/pom.xml index 79444e417..76b1958bb 100644 --- a/nms/1_17_1/pom.xml +++ b/nms/1_17_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_18_0/pom.xml b/nms/1_18_0/pom.xml index 2f5b42f75..26911cff2 100644 --- a/nms/1_18_0/pom.xml +++ b/nms/1_18_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_18_1/pom.xml b/nms/1_18_1/pom.xml index 47ff26dfb..cfa853090 100644 --- a/nms/1_18_1/pom.xml +++ b/nms/1_18_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_18_2/pom.xml b/nms/1_18_2/pom.xml index 4a50cdf9b..09e121568 100644 --- a/nms/1_18_2/pom.xml +++ b/nms/1_18_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_19_0/pom.xml b/nms/1_19_0/pom.xml index f998d8ac5..db868d974 100644 --- a/nms/1_19_0/pom.xml +++ b/nms/1_19_0/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_19_1/pom.xml b/nms/1_19_1/pom.xml index 9624357a9..2510e437f 100644 --- a/nms/1_19_1/pom.xml +++ b/nms/1_19_1/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_19_2/pom.xml b/nms/1_19_2/pom.xml index 409989889..a9d1888f9 100644 --- a/nms/1_19_2/pom.xml +++ b/nms/1_19_2/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_19_3/pom.xml b/nms/1_19_3/pom.xml index 54fc8e0c5..1f7924792 100644 --- a/nms/1_19_3/pom.xml +++ b/nms/1_19_3/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_19_4/pom.xml b/nms/1_19_4/pom.xml index bc775d6e1..9d84bb3b0 100644 --- a/nms/1_19_4/pom.xml +++ b/nms/1_19_4/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/nms/1_20_0/pom.xml b/nms/1_20_0/pom.xml index 86cc53ffc..4197a5b5f 100644 --- a/nms/1_20_0/pom.xml +++ b/nms/1_20_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_20_1/pom.xml b/nms/1_20_1/pom.xml index 8ccbc5ad0..d6231fee6 100644 --- a/nms/1_20_1/pom.xml +++ b/nms/1_20_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_20_2/pom.xml b/nms/1_20_2/pom.xml index 2edecfe60..7e531ea41 100644 --- a/nms/1_20_2/pom.xml +++ b/nms/1_20_2/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_20_3-4/pom.xml b/nms/1_20_3-4/pom.xml index 81e416338..6296cc761 100644 --- a/nms/1_20_3-4/pom.xml +++ b/nms/1_20_3-4/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_20_5/pom.xml b/nms/1_20_5/pom.xml index 5bc065cb9..ed3a0704f 100644 --- a/nms/1_20_5/pom.xml +++ b/nms/1_20_5/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_20_6/pom.xml b/nms/1_20_6/pom.xml index 4ff77993c..0a522e95d 100644 --- a/nms/1_20_6/pom.xml +++ b/nms/1_20_6/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_21_0/pom.xml b/nms/1_21_0/pom.xml index 1de4e00a8..662ae3358 100644 --- a/nms/1_21_0/pom.xml +++ b/nms/1_21_0/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_21_1/pom.xml b/nms/1_21_1/pom.xml index fdb0750d7..a70e9df9f 100644 --- a/nms/1_21_1/pom.xml +++ b/nms/1_21_1/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/1_21_2-3/pom.xml b/nms/1_21_2-3/pom.xml index f02078b13..a042895c3 100644 --- a/nms/1_21_2-3/pom.xml +++ b/nms/1_21_2-3/pom.xml @@ -6,7 +6,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml diff --git a/nms/abstraction/pom.xml b/nms/abstraction/pom.xml index 96032f6af..3d194bfef 100644 --- a/nms/abstraction/pom.xml +++ b/nms/abstraction/pom.xml @@ -5,7 +5,7 @@ IF-parent com.github.stefvanschie.inventoryframework - 0.10.18-SNAPSHOT + 0.10.18 ../../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 668df9c2f..cce22aaff 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ com.github.stefvanschie.inventoryframework IF-parent - 0.10.18-SNAPSHOT + 0.10.18 pom IF From a2b7a07b3c13a6862c695621f1a17b3a8e9146bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 20:32:08 +0000 Subject: [PATCH 381/382] Bump org.apache.maven.plugins:maven-surefire-plugin in /nms/1_14 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.5...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cce22aaff..7050fa7b4 100644 --- a/pom.xml +++ b/pom.xml @@ -122,12 +122,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.0 + 3.5.2 org.apache.maven.surefire surefire-junit-platform - 3.5.0 + 3.5.2 org.junit.jupiter From b4091d3b2497f877f53ba39eefa740822171997b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:21:30 +0000 Subject: [PATCH 382/382] Bump org.apache.maven.surefire:surefire-junit-platform in /IF Bumps org.apache.maven.surefire:surefire-junit-platform from 3.2.5 to 3.5.0. --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- IF/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IF/pom.xml b/IF/pom.xml index 853eb2cef..e14f55919 100644 --- a/IF/pom.xml +++ b/IF/pom.xml @@ -284,7 +284,7 @@ org.apache.maven.surefire surefire-junit-platform - 3.5.0 + 3.5.2