diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 11d8c057..d4f07fc9 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -41,7 +41,7 @@ dependencies { implementation("net.kyori:adventure-api:4.9.3") implementation ("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT") implementation("net.kyori:adventure-platform-bukkit:4.0.1") - implementation("dev.triumphteam:triumph-gui:3.1.1") + implementation("dev.triumphteam:triumph-gui:3.1.2") implementation("me.mattstudios.utils:matt-framework:1.4.6") implementation("org.spongepowered:configurate-yaml:4.1.2") implementation("org.bstats:bstats-bukkit:2.2.1") diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class index 604f872d..46efa1ec 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.class index b700bc7e..6973a6f4 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/GuiSerializer.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/GuiSerializer.class index 83d6615e..11d4bc8c 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/GuiSerializer.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/GuiSerializer.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ItemSerializer.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ItemSerializer.class index c1a766b4..6192bc9a 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ItemSerializer.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ItemSerializer.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ArmorItem.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ArmorItem.class index 7c0a04cb..cf3a77ed 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ArmorItem.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ArmorItem.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ColorItem.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ColorItem.class index 75568b89..6768a630 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ColorItem.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/ColorItem.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.class index f249630c..7925f0d3 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class index 8c371dda..d2abeeec 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class differ diff --git a/common/build/libs/HMCCosmetics.jar b/common/build/libs/HMCCosmetics.jar index cb0656d3..bc6f83b6 100644 Binary files a/common/build/libs/HMCCosmetics.jar and b/common/build/libs/HMCCosmetics.jar differ diff --git a/common/build/tmp/compileJava/previous-compilation-data.bin b/common/build/tmp/compileJava/previous-compilation-data.bin index 06cad71c..a3efe597 100644 Binary files a/common/build/tmp/compileJava/previous-compilation-data.bin and b/common/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java index 78a2c28f..8b8d6ebf 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java @@ -7,6 +7,7 @@ import io.github.fisher2911.hmccosmetics.HMCCosmetics; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.ColorItem; import io.github.fisher2911.hmccosmetics.gui.DyeSelectorGui; +import io.github.fisher2911.hmccosmetics.gui.WrappedGuiItem; import io.github.fisher2911.hmccosmetics.message.Adventure; import java.lang.reflect.Type; import java.util.Arrays; @@ -67,7 +68,7 @@ public class DyeGuiSerializer implements TypeSerializer { final var node = entry.getValue(); - final GuiItem guiItem = ItemSerializer.INSTANCE.deserialize( + final WrappedGuiItem guiItem = ItemSerializer.INSTANCE.deserialize( GuiItem.class, node ); @@ -84,7 +85,8 @@ public class DyeGuiSerializer implements TypeSerializer { final int blue = colorNode.node(BLUE).getInt(); guiItemMap.put(slot, - new ColorItem(guiItem.getItemStack(), Color.fromRGB(red, green, blue))); + new ColorItem(guiItem.getItemStack(), guiItem.getAction(), Color.fromRGB(red, green, blue)) + ); } final BiMap cosmeticSlots = HashBiMap.create(); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java index c9f7bfe4..a83701ca 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java @@ -5,6 +5,7 @@ import dev.triumphteam.gui.guis.GuiItem; import io.github.fisher2911.hmccosmetics.HMCCosmetics; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.BalloonItem; +import io.github.fisher2911.hmccosmetics.gui.WrappedGuiItem; import io.github.fisher2911.hmccosmetics.hook.HookManager; import io.github.fisher2911.hmccosmetics.util.Keys; import io.github.fisher2911.hmccosmetics.util.StringUtils; @@ -27,6 +28,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.checkerframework.checker.nullness.qual.Nullable; @@ -34,7 +36,7 @@ import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; import org.spongepowered.configurate.serialize.TypeSerializer; -public class ItemSerializer implements TypeSerializer { +public class ItemSerializer implements TypeSerializer { public static final ItemSerializer INSTANCE = new ItemSerializer(); private static final HMCCosmetics plugin; @@ -79,7 +81,7 @@ public class ItemSerializer implements TypeSerializer { } @Override - public GuiItem deserialize(final Type type, final ConfigurationNode source) + public WrappedGuiItem deserialize(final Type type, final ConfigurationNode source) throws SerializationException { final ConfigurationNode materialNode = this.nonVirtualNode(source, MATERIAL); final ConfigurationNode amountNode = source.node(AMOUNT); @@ -259,17 +261,18 @@ public class ItemSerializer implements TypeSerializer { } catch (final IllegalArgumentException exception) { final GuiItem guiItem = dev.triumphteam.gui.builder.item.ItemBuilder.from(itemStack).asGuiItem(); - guiItem.setAction(event -> { + final GuiAction guiAction = event -> { for (final CosmeticGuiAction action : actions) { action.execute(event, CosmeticGuiAction.When.ALL); } - }); - return guiItem; + }; + guiItem.setAction(guiAction); + return new WrappedGuiItem(guiItem, guiAction); } } @Override - public void serialize(final Type type, @Nullable final GuiItem obj, final ConfigurationNode node) throws SerializationException { + public void serialize(final Type type, @Nullable final WrappedGuiItem obj, final ConfigurationNode node) throws SerializationException { } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java index 5e2c5b1d..3a427cb8 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java @@ -20,7 +20,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ArmorItem extends GuiItem { +public class ArmorItem extends WrappedGuiItem { private final String id; private final List lockedLore; diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ColorItem.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ColorItem.java index 744e5f29..e3209386 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ColorItem.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/ColorItem.java @@ -9,13 +9,16 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ColorItem extends GuiItem { +public class ColorItem extends WrappedGuiItem { private final Color color; - public ColorItem(final @NotNull ItemStack itemStack, - final GuiAction action, - final Color color) { + public ColorItem(final GuiItem item, final GuiAction action, final Color color) { + super(item, action); + this.color = color; + } + + public ColorItem(final @NotNull ItemStack itemStack, final @Nullable GuiAction<@NotNull InventoryClickEvent> action, final Color color) { super(itemStack, action); this.color = color; } @@ -30,8 +33,7 @@ public class ColorItem extends GuiItem { this.color = color; } - public ColorItem(final @NotNull Material material, - final @Nullable GuiAction action, final Color color) { + public ColorItem(final @NotNull Material material, final @Nullable GuiAction<@NotNull InventoryClickEvent> action, final Color color) { super(material, action); this.color = color; } @@ -39,5 +41,4 @@ public class ColorItem extends GuiItem { public Color getColor() { return color; } - } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java index 7df3aa89..daad4107 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java @@ -152,7 +152,7 @@ public class CosmeticsMenu { path(Path.of(guiFile.getPath())). defaultOptions(opts -> opts.serializers(build -> { - build.register(GuiItem.class, ItemSerializer.INSTANCE); + build.register(WrappedGuiItem.class, ItemSerializer.INSTANCE); build.register(CosmeticGui.class, GuiSerializer.INSTANCE); build.register(DyeSelectorGui.class, DyeGuiSerializer.INSTANCE); })) diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java index 7c548016..daccf738 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java @@ -139,6 +139,7 @@ public class DyeSelectorGui extends CosmeticGui { } else { this.plugin.getUserManager().setItem(user, armorItem); } + colorItem.getAction().execute(event); this.updateSelected(user, player); }); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/WrappedGuiItem.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/WrappedGuiItem.java new file mode 100644 index 00000000..fe71dd32 --- /dev/null +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/WrappedGuiItem.java @@ -0,0 +1,50 @@ +package io.github.fisher2911.hmccosmetics.gui; + +import dev.triumphteam.gui.components.GuiAction; +import dev.triumphteam.gui.guis.GuiItem; +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class WrappedGuiItem extends GuiItem { + + private GuiAction action; + + public WrappedGuiItem(final GuiItem item, final GuiAction action) { + super(item.getItemStack(), action); + this.action = action; + } + + public WrappedGuiItem(final @NotNull ItemStack itemStack, @Nullable final GuiAction<@NotNull InventoryClickEvent> action) { + super(itemStack, action); + this.action = action; + } + + public WrappedGuiItem(final @NotNull ItemStack itemStack) { + super(itemStack); + this.action = null; + } + + public WrappedGuiItem(final @NotNull Material material) { + super(material); + this.action = null; + } + + public WrappedGuiItem(final @NotNull Material material, @Nullable final GuiAction<@NotNull InventoryClickEvent> action) { + super(material, action); + this.action = action; + } + + @Nullable + public GuiAction getAction() { + return action; + } + + @Override + public void setAction(final GuiAction action) { + super.setAction(action); + this.action = action; + } +}