mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-27 10:59:14 +00:00
Fixed issue with dye items not running actions
This commit is contained in:
@@ -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<DyeSelectorGui> {
|
||||
|
||||
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<DyeSelectorGui> {
|
||||
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<Integer, ArmorItem.Type> cosmeticSlots = HashBiMap.create();
|
||||
|
||||
@@ -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<GuiItem> {
|
||||
public class ItemSerializer implements TypeSerializer<WrappedGuiItem> {
|
||||
|
||||
public static final ItemSerializer INSTANCE = new ItemSerializer();
|
||||
private static final HMCCosmetics plugin;
|
||||
@@ -79,7 +81,7 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
}
|
||||
|
||||
@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<GuiItem> {
|
||||
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
final GuiItem guiItem = dev.triumphteam.gui.builder.item.ItemBuilder.from(itemStack).asGuiItem();
|
||||
guiItem.setAction(event -> {
|
||||
final GuiAction<InventoryClickEvent> 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 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> lockedLore;
|
||||
|
||||
@@ -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<InventoryClickEvent> action,
|
||||
final Color color) {
|
||||
public ColorItem(final GuiItem item, final GuiAction<InventoryClickEvent> 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<InventoryClickEvent> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}))
|
||||
|
||||
@@ -139,6 +139,7 @@ public class DyeSelectorGui extends CosmeticGui {
|
||||
} else {
|
||||
this.plugin.getUserManager().setItem(user, armorItem);
|
||||
}
|
||||
colorItem.getAction().execute(event);
|
||||
this.updateSelected(user, player);
|
||||
});
|
||||
|
||||
|
||||
@@ -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<InventoryClickEvent> action;
|
||||
|
||||
public WrappedGuiItem(final GuiItem item, final GuiAction<InventoryClickEvent> 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<InventoryClickEvent> getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAction(final GuiAction<InventoryClickEvent> action) {
|
||||
super.setAction(action);
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user