diff --git a/.idea/modules/HMCCosmetics.main.iml b/.idea/modules/HMCCosmetics.main.iml
new file mode 100644
index 00000000..85578b10
--- /dev/null
+++ b/.idea/modules/HMCCosmetics.main.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+ MCP
+ ADVENTURE
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/HMCCosmetics.test.iml b/.idea/modules/HMCCosmetics.test.iml
new file mode 100644
index 00000000..c4622759
--- /dev/null
+++ b/.idea/modules/HMCCosmetics.test.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+ ADVENTURE
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java b/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java
index 60b8e1e7..d1bf72c4 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java
@@ -76,11 +76,9 @@ public class CosmeticsCommand extends CommandBase {
case BACKPACK -> user.getPlayerArmor().getBackpack();
};
- new DyeSelectorGui("test", 3, Map.of(
- 10, Color.fromRGB(1, 2, 3),
- 11, Color.fromRGB(0, 0, 255)
- ), armorItem
- ).getGui(user).open(player);
+ player.sendMessage("Opening dye menu");
+
+ this.cosmeticsMenu.openDyeSelectorGui(user, armorItem);
}
}
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java b/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java
new file mode 100644
index 00000000..83ddb704
--- /dev/null
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java
@@ -0,0 +1,94 @@
+package io.github.fisher2911.hmccosmetics.config;
+
+import dev.triumphteam.gui.guis.GuiItem;
+import io.github.fisher2911.hmccosmetics.HMCCosmetics;
+import io.github.fisher2911.hmccosmetics.gui.ColorItem;
+import io.github.fisher2911.hmccosmetics.gui.DyeSelectorGui;
+import org.bukkit.Color;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.spongepowered.configurate.ConfigurationNode;
+import org.spongepowered.configurate.serialize.SerializationException;
+import org.spongepowered.configurate.serialize.TypeSerializer;
+
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class DyeGuiSerializer implements TypeSerializer {
+
+ private static final HMCCosmetics plugin;
+
+ static {
+ plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
+ }
+
+ public static final DyeGuiSerializer INSTANCE = new DyeGuiSerializer();
+
+ private DyeGuiSerializer() {}
+
+ private static final String TITLE = "title";
+ private static final String ROWS = "rows";
+ private static final String ITEMS = "items";
+ private static final String SET_COLOR = "set-color";
+ private static final String RED = "red";
+ private static final String GREEN = "green";
+ private static final String BLUE = "blue";
+
+ private ConfigurationNode nonVirtualNode(final ConfigurationNode source, final Object... path) throws SerializationException {
+ if (!source.hasChild(path)) {
+ throw new SerializationException("Required field " + Arrays.toString(path) + " was not present in node");
+ }
+ return source.node(path);
+ }
+
+ @Override
+ public DyeSelectorGui deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
+ final ConfigurationNode titleNode = this.nonVirtualNode(source, TITLE);
+ final ConfigurationNode rowsNode = this.nonVirtualNode(source, ROWS);
+ final ConfigurationNode itemsNode = source.node(ITEMS);
+
+
+ final Map guiItemMap = new HashMap<>();
+
+ final var map = itemsNode.childrenMap();
+
+ for (final var entry : map.entrySet()) {
+ if (!(entry.getKey() instanceof final Integer slot)) {
+ continue;
+ }
+
+ final var node = entry.getValue();
+
+ final GuiItem guiItem = ItemSerializer.INSTANCE.deserialize(
+ GuiItem.class,
+ node
+ );
+
+ final ConfigurationNode colorNode = node.node(SET_COLOR);
+
+ if (colorNode.virtual()) {
+ guiItemMap.put(slot, guiItem);
+ continue;
+ }
+
+ final int red = colorNode.node(RED).getInt();
+ final int green = colorNode.node(GREEN).getInt();
+ final int blue = colorNode.node(BLUE).getInt();
+
+ guiItemMap.put(slot, new ColorItem(guiItem.getItemStack(), Color.fromRGB(red, green, blue)));
+ }
+
+ return new DyeSelectorGui(
+ plugin,
+ titleNode.getString(),
+ rowsNode.getInt(),
+ guiItemMap);
+ }
+
+ @Override
+ public void serialize(final Type type, @Nullable final DyeSelectorGui obj, final ConfigurationNode node) throws SerializationException {
+
+ }
+}
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java b/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java
index 2a30f395..a6464728 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java
@@ -3,11 +3,13 @@ package io.github.fisher2911.hmccosmetics.config;
import dev.triumphteam.gui.guis.GuiItem;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
+import io.github.fisher2911.hmccosmetics.message.Adventure;
import io.github.fisher2911.hmccosmetics.util.StringUtils;
import io.github.fisher2911.hmccosmetics.util.Utils;
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
-import io.github.fisher2911.hmccosmetics.util.builder.LeatherArmorBuilder;
+import io.github.fisher2911.hmccosmetics.util.builder.ColorBuilder;
import io.github.fisher2911.hmccosmetics.util.builder.SkullBuilder;
+import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
@@ -41,6 +43,7 @@ public class ItemSerializer implements TypeSerializer {
private static final String UNBREAKABLE = "unbreakable";
private static final String GLOWING = "glowing";
private static final String LORE = "lore";
+ private static final String LOCKED_LORE = "locked-lore";
private static final String MODEL_DATA = "model-data";
private static final String ENCHANTS = "enchants";
private static final String ITEM_FLAGS = "item-flags";
@@ -54,6 +57,7 @@ public class ItemSerializer implements TypeSerializer {
private static final String TYPE = "type";
private static final String OPEN_MENU = "open-menu";
private static final String ID = "id";
+ private static final String DYEABLE = "dyeable";
private ItemSerializer() {
}
@@ -74,6 +78,7 @@ public class ItemSerializer implements TypeSerializer {
final ConfigurationNode unbreakableNode = source.node(UNBREAKABLE);
final ConfigurationNode glowingNode = source.node(GLOWING);
final ConfigurationNode loreNode = source.node(LORE);
+ final ConfigurationNode lockedLoreNode = source.node(LOCKED_LORE);
final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
final ConfigurationNode enchantsNode = source.node(ENCHANTS);
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS);
@@ -87,17 +92,22 @@ public class ItemSerializer implements TypeSerializer {
final ConfigurationNode typeNode = source.node(TYPE);
final ConfigurationNode openMenuNode = source.node(OPEN_MENU);
final ConfigurationNode idNode = source.node(ID);
+ final ConfigurationNode dyeableNode = source.node(DYEABLE);
final Material material = Utils.stringToEnum(Utils.replaceIfNull(materialNode.getString(), ""),
Material.class, Material.AIR);
final int amount = amountNode.getInt();
- final String name = StringUtils.parseStringToString(Utils.replaceIfNull(nameNode.getString(), ""));
+ final Component name = Adventure.MINI_MESSAGE.parse(
+ Utils.replaceIfNull(nameNode.getString(), "")
+ );
final boolean unbreakable = unbreakableNode.getBoolean();
final boolean glowing = glowingNode.getBoolean();
final List lore = Utils.replaceIfNull(loreNode.getList(String.class), new ArrayList()).
stream().map(StringUtils::parseStringToString).collect(Collectors.toList());
+ final List lockedLore = Utils.replaceIfNull(lockedLoreNode.getList(String.class), new ArrayList()).
+ stream().map(StringUtils::parseStringToString).collect(Collectors.toList());
final int modelData = modelDataNode.getInt();
final Set itemFlags = Utils.replaceIfNull(itemFlagsNode.getList(String.class), new ArrayList()).
stream().map(flag -> {
@@ -109,7 +119,17 @@ public class ItemSerializer implements TypeSerializer {
}).collect(Collectors.toSet());
final String texture = textureNode.getString();
final String owner = ownerNode.getString();
- final Color color = Color.fromBGR(redNode.getInt(), greenNode.getInt(), blueNode.getInt());
+
+
+ final boolean dyeable = dyeableNode.getBoolean();
+
+ final Color color;
+
+ if (colorNode.virtual()) {
+ color = null;
+ } else {
+ color = Color.fromBGR(redNode.getInt(), greenNode.getInt(), blueNode.getInt());
+ }
final Map enchantments =
Utils.replaceIfNull(enchantsNode.getList(String.class),
@@ -150,10 +170,10 @@ public class ItemSerializer implements TypeSerializer {
final OfflinePlayer player = Bukkit.getOfflinePlayer(owner);
((SkullBuilder) itemBuilder).owner(player);
}
- } else if (LeatherArmorBuilder.isLeatherArmor(material)) {
- itemBuilder = LeatherArmorBuilder.from(material);
+ } else if (ColorBuilder.canBeColored(material)) {
+ itemBuilder = ColorBuilder.from(material);
if (color != null) {
- ((LeatherArmorBuilder) itemBuilder).color(color);
+ ((ColorBuilder) itemBuilder).color(color);
}
} else {
itemBuilder = ItemBuilder.from(material);
@@ -182,8 +202,10 @@ public class ItemSerializer implements TypeSerializer {
return new ArmorItem(
itemStack,
Utils.replaceIfNull(idNode.getString(), ""),
+ lockedLore,
permission,
- cosmeticType);
+ cosmeticType,
+ dyeable);
} catch (final IllegalArgumentException exception) {
final String openMenu = openMenuNode.getString(
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java b/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java
index 71f868a3..6f5078a3 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java
@@ -2,15 +2,19 @@ package io.github.fisher2911.hmccosmetics.gui;
import dev.triumphteam.gui.components.GuiAction;
import dev.triumphteam.gui.guis.GuiItem;
+import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
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;
+import java.util.List;
+
public class ArmorItem extends GuiItem {
private final String id;
+ private final List lockedLore;
private final GuiAction action;
private final String permission;
private final Type type;
@@ -20,10 +24,12 @@ public class ArmorItem extends GuiItem {
@NotNull final ItemStack itemStack,
final GuiAction action,
final String id,
+ final List lockedLore,
final String permission,
final Type type) {
super(itemStack, action);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = action;
this.permission = permission;
this.type = type;
@@ -32,10 +38,12 @@ public class ArmorItem extends GuiItem {
public ArmorItem(
@NotNull final ItemStack itemStack,
final String id,
+ final List lockedLore,
final String permission,
final Type type) {
super(itemStack);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = null;
this.permission = permission;
this.type = type;
@@ -44,10 +52,12 @@ public class ArmorItem extends GuiItem {
public ArmorItem(
@NotNull final Material material,
final String id,
+ final List lockedLore,
final String permission,
final Type type) {
super(material);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = null;
this.permission = permission;
this.type = type;
@@ -57,10 +67,12 @@ public class ArmorItem extends GuiItem {
@NotNull final Material material,
@Nullable final GuiAction action,
final String id,
+ final List lockedLore,
final String permission,
final Type type) {
super(material, action);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = action;
this.permission = permission;
this.type = type;
@@ -69,11 +81,14 @@ public class ArmorItem extends GuiItem {
public ArmorItem(
@NotNull final ItemStack itemStack,
final GuiAction action,
- final String id, final String permission,
+ final String id,
+ final List lockedLore,
+ final String permission,
final Type type,
final boolean dyeable) {
super(itemStack, action);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = action;
this.permission = permission;
this.type = type;
@@ -83,11 +98,13 @@ public class ArmorItem extends GuiItem {
public ArmorItem(
@NotNull final ItemStack itemStack,
final String id,
+ final List lockedLore,
final String permission,
final Type type,
final boolean dyeable) {
super(itemStack);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = null;
this.permission = permission;
this.type = type;
@@ -97,11 +114,13 @@ public class ArmorItem extends GuiItem {
public ArmorItem(
@NotNull final Material material,
final String id,
+ final List lockedLore,
final String permission,
final Type type,
final boolean dyeable) {
super(material);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = null;
this.permission = permission;
this.type = type;
@@ -112,11 +131,13 @@ public class ArmorItem extends GuiItem {
@NotNull final Material material,
@Nullable final GuiAction action,
final String id,
+ final List lockedLore,
final String permission,
final Type type,
final boolean dyeable) {
super(material, action);
this.id = id;
+ this.lockedLore = lockedLore;
this.action = action;
this.permission = permission;
this.type = type;
@@ -127,6 +148,10 @@ public class ArmorItem extends GuiItem {
return id;
}
+ public List getLockedLore() {
+ return lockedLore;
+ }
+
public GuiAction getAction() {
return this.action;
}
@@ -143,6 +168,16 @@ public class ArmorItem extends GuiItem {
return dyeable;
}
+ public ItemStack getItemStack(final boolean allowed) {
+ if (allowed) {
+ return this.getItemStack();
+ }
+
+ return ItemBuilder.from(this.getItemStack()).
+ lore(lockedLore).
+ build();
+ }
+
public enum Type {
HAT,
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/gui/ColorItem.java b/src/main/java/io/github/fisher2911/hmccosmetics/gui/ColorItem.java
new file mode 100644
index 00000000..6b8a60ef
--- /dev/null
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/gui/ColorItem.java
@@ -0,0 +1,39 @@
+package io.github.fisher2911.hmccosmetics.gui;
+
+import dev.triumphteam.gui.components.GuiAction;
+import dev.triumphteam.gui.guis.GuiItem;
+import org.bukkit.Color;
+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 ColorItem extends GuiItem {
+
+ private final Color color;
+
+ public ColorItem(final @NotNull ItemStack itemStack, final GuiAction action, final Color color) {
+ super(itemStack, action);
+ this.color = color;
+ }
+
+ public ColorItem(final @NotNull ItemStack itemStack, final Color color) {
+ super(itemStack);
+ this.color = color;
+ }
+
+ public ColorItem(final @NotNull Material material, final Color color) {
+ super(material);
+ this.color = color;
+ }
+
+ public ColorItem(final @NotNull Material material, final @Nullable GuiAction action, final Color color) {
+ super(material, action);
+ this.color = color;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+}
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java b/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java
index 053ffe26..04be601b 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java
@@ -9,7 +9,6 @@ import io.github.fisher2911.hmccosmetics.message.MessageHandler;
import io.github.fisher2911.hmccosmetics.message.Messages;
import io.github.fisher2911.hmccosmetics.message.Placeholder;
import io.github.fisher2911.hmccosmetics.user.User;
-import io.github.fisher2911.hmccosmetics.user.UserManager;
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
@@ -22,12 +21,12 @@ import java.util.Optional;
public class CosmeticGui {
- private final HMCCosmetics plugin;
- private final MessageHandler messageHandler;
- private final String title;
- private final int rows;
- private final Map guiItemMap;
- private Gui gui;
+ protected final HMCCosmetics plugin;
+ protected final MessageHandler messageHandler;
+ protected final String title;
+ protected final int rows;
+ protected final Map guiItemMap;
+ protected Gui gui;
public CosmeticGui(
final HMCCosmetics plugin,
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java b/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java
index 6d71ca6b..7f29a1ac 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticsMenu.java
@@ -2,9 +2,12 @@ package io.github.fisher2911.hmccosmetics.gui;
import dev.triumphteam.gui.guis.GuiItem;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
+import io.github.fisher2911.hmccosmetics.config.DyeGuiSerializer;
import io.github.fisher2911.hmccosmetics.config.GuiSerializer;
import io.github.fisher2911.hmccosmetics.config.ItemSerializer;
+import io.github.fisher2911.hmccosmetics.user.User;
import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
@@ -17,6 +20,7 @@ import java.util.Map;
public class CosmeticsMenu {
public static final String MAIN_MENU = "main";
+ public static final String DYE_MENU = "dye-menu";
private final HMCCosmetics plugin;
@@ -42,6 +46,27 @@ public class CosmeticsMenu {
this.load();
}
+ public void openDyeSelectorGui(
+ final User user,
+ final ArmorItem armorItem) {
+
+ final Player player = user.getPlayer();
+
+ if (player == null) {
+ return;
+ }
+
+ final CosmeticGui gui = this.guiMap.get(DYE_MENU);
+
+ if (gui instanceof final DyeSelectorGui dyeSelectorGui) {
+ player.sendMessage("Is Dye selector");
+ dyeSelectorGui.getGui(user, armorItem).open(player);
+ } else {
+ player.sendMessage("Not dye selector");
+ player.sendMessage(gui.getClass().toString());
+ }
+ }
+
public void load() {
this.guiMap.clear();
final File file = Path.of(this.plugin.getDataFolder().getPath(),
@@ -49,9 +74,18 @@ public class CosmeticsMenu {
if (!Path.of(this.plugin.getDataFolder().getPath(),
"menus",
- "main").toFile().exists()) {
+ MAIN_MENU).toFile().exists()) {
this.plugin.saveResource(
- new File("menus", "main.yml").getPath(),
+ new File("menus", MAIN_MENU).getPath(),
+ false
+ );
+ }
+
+ if (!Path.of(this.plugin.getDataFolder().getPath(),
+ "menus",
+ DYE_MENU).toFile().exists()) {
+ this.plugin.saveResource(
+ new File("menus", DYE_MENU).getPath(),
false
);
}
@@ -79,12 +113,20 @@ public class CosmeticsMenu {
opts.serializers(build -> {
build.register(GuiItem.class, ItemSerializer.INSTANCE);
build.register(CosmeticGui.class, GuiSerializer.INSTANCE);
+ build.register(DyeSelectorGui.class, DyeGuiSerializer.INSTANCE);
}))
.build();
try {
final ConfigurationNode source = loader.load();
+ if (id.equals(DYE_MENU)) {
+ this.guiMap.put(id, DyeGuiSerializer.INSTANCE.deserialize(DyeSelectorGui.class,
+ source));
+ this.plugin.getLogger().severe("Loaded dye gui: " + id);
+ continue;
+ }
+
this.guiMap.put(id, source.get(CosmeticGui.class));
this.plugin.getLogger().severe("Loaded gui: " + id);
} catch (final ConfigurateException exception) {
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java b/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java
index 85b22267..c075a55a 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.java
@@ -2,54 +2,43 @@ package io.github.fisher2911.hmccosmetics.gui;
import dev.triumphteam.gui.builder.item.ItemBuilder;
import dev.triumphteam.gui.guis.Gui;
-import io.github.fisher2911.hmccosmetics.config.ItemSerializer;
+import dev.triumphteam.gui.guis.GuiItem;
+import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
import io.github.fisher2911.hmccosmetics.user.User;
-import io.github.fisher2911.hmccosmetics.util.builder.LeatherArmorBuilder;
+import io.github.fisher2911.hmccosmetics.util.builder.ColorBuilder;
import net.kyori.adventure.text.Component;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
-import org.checkerframework.checker.units.qual.A;
-import java.util.HashMap;
import java.util.Map;
-public class DyeSelectorGui {
-
- private final String title;
- private final int rows;
- private final Map itemColors;
- private final ArmorItem armorItem;
+public class DyeSelectorGui extends CosmeticGui{
public DyeSelectorGui(
+ final HMCCosmetics plugin,
final String title,
final int rows,
- final Map itemColors,
- final ArmorItem armorItem) {
- this.title = title;
- this.rows = rows;
- this.itemColors = itemColors;
- this.armorItem = armorItem;
+ final Map guiItemMap) {
+ super(plugin, title, rows, guiItemMap);
}
- public Gui getGui(final User user) {
+ public Gui getGui(final User user, final ArmorItem armorItem) {
final Gui gui = Gui.gui().
title(Component.text(this.title)).
rows(rows).
create();
- for (final var entry : itemColors.entrySet()) {
- gui.setItem(entry.getKey(), ItemBuilder.from(Material.BLACK_DYE).
- name(Component.text(
- String.valueOf(entry.getValue().asRGB()))).asGuiItem());
+ for (final var entry : this.guiItemMap.entrySet()) {
+ gui.setItem(entry.getKey(), entry.getValue());
}
gui.setDefaultClickAction(event -> {
event.setCancelled(true);
- final ArmorItem.Type type = this.armorItem.getType();
+ final ArmorItem.Type type = armorItem.getType();
final PlayerArmor playerArmor = user.getPlayerArmor();
@@ -77,55 +66,45 @@ public class DyeSelectorGui {
};
if (itemStack == null) {
+ event.getWhoClicked().sendMessage("ItemStack null");
return;
}
- if (!(itemStack.getItemMeta() instanceof final LeatherArmorMeta itemMeta)) {
+ if (!armorItem.isDyeable()) {
+ event.getWhoClicked().sendMessage("Not dyeable");
return;
}
- final LeatherArmorBuilder leatherArmorBuilder =
- LeatherArmorBuilder.from(itemStack);
+ final ColorBuilder colorBuilder =
+ ColorBuilder.from(itemStack);
- final Color color = this.itemColors.get(event.getSlot());
+ final GuiItem guiItem = this.guiItemMap.get(event.getSlot());
- if (color == null) {
+ if (!(guiItem instanceof final ColorItem colorItem)) {
+ event.getWhoClicked().sendMessage("Not color item");
return;
}
- leatherArmorBuilder.color(color);
+ final Color color = colorItem.getColor();
- final ArmorItem armorItem = new ArmorItem(
- leatherArmorBuilder.build(),
- this.armorItem.getAction(),
- this.armorItem.getId(),
- this.armorItem.getPermission(),
- this.armorItem.getType(),
- this.armorItem.isDyeable()
+ colorBuilder.color(color);
+
+ final ArmorItem newArmorItem = new ArmorItem(
+ colorBuilder.build(),
+ armorItem.getAction(),
+ armorItem.getId(),
+ armorItem.getLockedLore(),
+ armorItem.getPermission(),
+ armorItem.getType(),
+ armorItem.isDyeable()
);
switch (type) {
- case HAT -> user.setHat(armorItem);
- case BACKPACK -> user.setBackpack(armorItem);
+ case HAT -> user.setHat(newArmorItem);
+ case BACKPACK -> user.setBackpack(newArmorItem);
}
});
return gui;
}
-
- public String getTitle() {
- return title;
- }
-
- public int getRows() {
- return rows;
- }
-
- public Map getItemColors() {
- return itemColors;
- }
-
- public ArmorItem getArmorItem() {
- return armorItem;
- }
}
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/inventory/PlayerArmor.java b/src/main/java/io/github/fisher2911/hmccosmetics/inventory/PlayerArmor.java
index 0f85a06a..e99324c3 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/inventory/PlayerArmor.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/inventory/PlayerArmor.java
@@ -4,6 +4,8 @@ import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
+import java.util.ArrayList;
+
public class PlayerArmor {
private ArmorItem hat;
@@ -19,12 +21,14 @@ public class PlayerArmor {
new ArmorItem(
new ItemStack(Material.AIR),
"",
+ new ArrayList<>(),
"",
ArmorItem.Type.HAT
),
new ArmorItem(
new ItemStack(Material.AIR),
"",
+ new ArrayList<>(),
"",
ArmorItem.Type.BACKPACK
));
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java b/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java
index f07aca8b..f147cf1a 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java
@@ -12,6 +12,7 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
+import java.util.ArrayList;
import java.util.UUID;
public class User {
@@ -53,6 +54,7 @@ public class User {
this.setBackpack(new ArmorItem(
new ItemStack(Material.AIR),
"",
+ new ArrayList<>(),
"",
ArmorItem.Type.BACKPACK
));
@@ -90,6 +92,7 @@ public class User {
this.setHat(new ArmorItem(
new ItemStack(Material.AIR),
"",
+ new ArrayList<>(),
"",
ArmorItem.Type.HAT
));
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/ColorBuilder.java b/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/ColorBuilder.java
new file mode 100644
index 00000000..2d0a54c0
--- /dev/null
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/ColorBuilder.java
@@ -0,0 +1,88 @@
+package io.github.fisher2911.hmccosmetics.util.builder;
+
+import org.bukkit.Color;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.LeatherArmorMeta;
+import org.bukkit.inventory.meta.PotionMeta;
+
+import java.util.EnumSet;
+import java.util.Set;
+
+public class ColorBuilder extends ItemBuilder{
+
+ /**
+ *
+ * @param material ItemStack material
+ */
+
+ ColorBuilder(final Material material) {
+ super(material);
+ }
+
+ /**
+ *
+ * @param itemStack ItemStack
+ */
+
+ ColorBuilder(final ItemStack itemStack) {
+ super(itemStack);
+ }
+
+ /**
+ *
+ * @param material ItemStack material
+ * @return this
+ * @throws IllegalArgumentException thrown if itemStack's type can not change color
+ */
+
+ public static ColorBuilder from(final Material material) throws IllegalArgumentException {
+ if (!canBeColored(material)) {
+ throw new IllegalArgumentException(material.name() + " is not leather armor!");
+ }
+ return new ColorBuilder(material);
+ }
+
+ /**
+ *
+ * @param itemStack ItemStack
+ * @return this
+ * @throws IllegalArgumentException thrown if itemStack's type can not change color
+ */
+
+ public static ColorBuilder from(final ItemStack itemStack) throws IllegalArgumentException {
+ final Material material = itemStack.getType();
+ if (!canBeColored(itemStack)) {
+ throw new IllegalArgumentException(material.name() + " is not leather armor!");
+ }
+ return new ColorBuilder(itemStack);
+ }
+
+ /**
+ *
+ * @param color armor color
+ * @return this
+ */
+
+ public ColorBuilder color(final Color color) {
+ if (this.itemMeta instanceof final PotionMeta meta) {
+ meta.setColor(color);
+ }
+ if (this.itemMeta instanceof final LeatherArmorMeta meta) {
+ meta.setColor(color);
+ }
+ return this;
+ }
+
+ public static boolean canBeColored(final Material material) {
+ return canBeColored(new ItemStack(material));
+ }
+
+ public static boolean canBeColored(final ItemStack itemStack) {
+ final ItemMeta itemMeta = itemStack.getItemMeta();
+
+ return (itemMeta instanceof LeatherArmorMeta ||
+ itemMeta instanceof PotionMeta);
+ }
+}
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/ItemBuilder.java b/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/ItemBuilder.java
index c0a27427..19987528 100644
--- a/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/ItemBuilder.java
+++ b/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/ItemBuilder.java
@@ -2,6 +2,7 @@ package io.github.fisher2911.hmccosmetics.util.builder;
import io.github.fisher2911.hmccosmetics.message.Adventure;
import io.github.fisher2911.hmccosmetics.util.StringUtils;
+import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@@ -76,6 +77,11 @@ public class ItemBuilder {
return this;
}
+ public ItemBuilder name(final Component name) {
+ this.itemMeta.displayName(name);
+ return this;
+ }
+
/**
* Sets placeholders to the item's name
*
diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/LeatherArmorBuilder.java b/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/LeatherArmorBuilder.java
deleted file mode 100644
index 62021832..00000000
--- a/src/main/java/io/github/fisher2911/hmccosmetics/util/builder/LeatherArmorBuilder.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package io.github.fisher2911.hmccosmetics.util.builder;
-
-import org.bukkit.Color;
-import org.bukkit.Material;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.LeatherArmorMeta;
-
-import java.util.EnumSet;
-import java.util.Set;
-
-public class LeatherArmorBuilder extends ItemBuilder{
-
- private static final Set VALID_ARMOR = EnumSet.of(Material.LEATHER_BOOTS,
- Material.LEATHER_LEGGINGS, Material.LEATHER_CHESTPLATE, Material.LEATHER_HELMET);
-
- /**
- *
- * @param material ItemStack material
- */
-
- LeatherArmorBuilder(final Material material) {
- super(material);
- }
-
- /**
- *
- * @param itemStack ItemStack
- */
-
- LeatherArmorBuilder(final ItemStack itemStack) {
- super(itemStack);
- }
-
- /**
- *
- * @param material ItemStack material
- * @return this
- * @throws IllegalArgumentException thrown if material is not leather armor
- */
-
- public static LeatherArmorBuilder from(final Material material) throws IllegalArgumentException {
- if (!VALID_ARMOR.contains(material)) {
- throw new IllegalArgumentException(material.name() + " is not leather armor!");
- }
- return new LeatherArmorBuilder(material);
- }
-
- /**
- *
- * @param itemStack ItemStack
- * @return this
- * @throws IllegalArgumentException thrown if itemStack's type is not leather armor
- */
-
- public static LeatherArmorBuilder from(final ItemStack itemStack) throws IllegalArgumentException {
- final Material material = itemStack.getType();
- if (!VALID_ARMOR.contains(material)) {
- throw new IllegalArgumentException(material.name() + " is not leather armor!");
- }
- return new LeatherArmorBuilder(itemStack);
- }
-
- /**
- *
- * @param color armor color
- * @return this
- */
-
- public LeatherArmorBuilder color(final Color color) {
- if (itemMeta instanceof final LeatherArmorMeta meta) {
- meta.setColor(color);
- this.itemMeta = meta;
- }
- return this;
- }
-
- /**
- *
- * @param material checked material
- * @return true if is leather armor, else false
- */
-
- public static boolean isLeatherArmor(final Material material) {
- return VALID_ARMOR.contains(material);
- }
-}
diff --git a/src/main/resources/menus/dye-menu.yml b/src/main/resources/menus/dye-menu.yml
new file mode 100644
index 00000000..a3dcf49c
--- /dev/null
+++ b/src/main/resources/menus/dye-menu.yml
@@ -0,0 +1,17 @@
+title: Set Color
+rows: 3
+items:
+ 10:
+ material: BLUE_STAINED_GLASS
+ name: Set to blue
+ set-color:
+ red: 55
+ green: 49
+ blue: 181
+ 11:
+ material: RED_STAINED_GLASS
+ name: Set to red
+ set-color:
+ red: 190
+ green: 20
+ blue: 20
\ No newline at end of file
diff --git a/src/main/resources/menus/main.yml b/src/main/resources/menus/main.yml
index 93dd31d2..a9c7ba35 100644
--- a/src/main/resources/menus/main.yml
+++ b/src/main/resources/menus/main.yml
@@ -8,6 +8,8 @@ items:
- ""
- "Enabled: %enabled%"
- "Allowed: %allowed%"
+ locked-lore:
+ - "Not allowed"
amount: 1
type: BACKPACK
permission: ""
@@ -19,6 +21,8 @@ items:
- ""
- "Enabled: %enabled%"
- "Allowed: %allowed%"
+ locked-lore:
+ - "Not allowed"
amount: 1
type: HAT
permission: ""
@@ -30,6 +34,8 @@ items:
- ""
- "Enabled: %enabled%"
- "Allowed: %allowed%"
+ locked-lore:
+ - "Not allowed"
amount: 1
type: BACKPACK
permission: ""
@@ -41,6 +47,8 @@ items:
- ""
- "Enabled: %enabled%"
- "Allowed: %allowed%"
+ locked-lore:
+ - "Not allowed"
amount: 1
type: HAT
permission: ""
@@ -52,10 +60,13 @@ items:
- ""
- "Enabled: %enabled%"
- "Allowed: %allowed%"
+ locked-lore:
+ - "Not allowed"
amount: 1
type: BACKPACK
permission: ""
id: leather_backpack
+ dyeable: true
15:
material: LEATHER_HELMET
name: "Hat "
@@ -63,6 +74,8 @@ items:
- ""
- "Enabled: %enabled%"
- "Allowed: %allowed%"
+ locked-lore:
+ - "Not allowed"
amount: 1
type: HAT
color:
@@ -71,3 +84,4 @@ items:
green: 230
permission: ""
id: leather_hat
+ dyeable: true