mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2026-01-04 15:41:45 +00:00
Finished tokens
This commit is contained in:
@@ -27,6 +27,7 @@ public class CosmeticItem {
|
||||
|
||||
public CosmeticItem(
|
||||
final ItemStack itemStack,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack locked,
|
||||
final ItemStack applied,
|
||||
@@ -34,7 +35,7 @@ public class CosmeticItem {
|
||||
final ArmorItem.Type type,
|
||||
final boolean dyeable,
|
||||
final int rgb) {
|
||||
this.armorItem = new ArmorItem(itemStack, id, locked, applied, permission, type, dyeable, rgb);
|
||||
this.armorItem = new ArmorItem(itemStack, name, id, locked, applied, permission, type, dyeable, rgb);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,6 +48,7 @@ public class CosmeticItem {
|
||||
|
||||
public CosmeticItem(
|
||||
final Material material,
|
||||
final String name,
|
||||
final String id,
|
||||
final Material locked,
|
||||
final Material applied,
|
||||
@@ -55,7 +57,7 @@ public class CosmeticItem {
|
||||
final boolean dyeable,
|
||||
final int rgb
|
||||
) {
|
||||
this.armorItem = new ArmorItem(material, id, new ItemStack(locked), new ItemStack(applied), permission, type, dyeable, rgb);
|
||||
this.armorItem = new ArmorItem(material, name, id, new ItemStack(locked), new ItemStack(applied), permission, type, dyeable, rgb);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,8 +66,8 @@ public class CosmeticItem {
|
||||
* @param type the cosmetic item type
|
||||
*/
|
||||
|
||||
public CosmeticItem(final ItemStack itemStack, final String id, final ItemStack locked, final ItemStack applied, final ArmorItem.Type type) {
|
||||
this(itemStack, id, locked, applied, "", type, false, -1);
|
||||
public CosmeticItem(final ItemStack itemStack, final String name, final String id, final ItemStack locked, final ItemStack applied, final ArmorItem.Type type) {
|
||||
this(itemStack, name, id, locked, applied, "", type, false, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,8 +76,8 @@ public class CosmeticItem {
|
||||
* @param type the cosmetic item type
|
||||
*/
|
||||
|
||||
public CosmeticItem(final Material material, final Material locked, final Material applied, final String id, final ArmorItem.Type type) {
|
||||
this(material, id, locked, applied, "", type, false, -1);
|
||||
public CosmeticItem(final Material material, final Material locked, final Material applied, final String name, final String id, final ArmorItem.Type type) {
|
||||
this(material, name, id, locked, applied, "", type, false, -1);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(final ArmorItem.Status status) {
|
||||
|
||||
@@ -379,7 +379,10 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
@SubCommand("token")
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.GIVE_TOKEN)
|
||||
public void token(final CommandSender sender, @Completion("#tokens") final String tokenId, @me.mattstudios.mf.annotations.Optional Player giveTo) {
|
||||
public void token(
|
||||
final CommandSender sender,
|
||||
@Completion("#tokens") final String tokenId,
|
||||
@Completion("#players") @me.mattstudios.mf.annotations.Optional Player giveTo) {
|
||||
if (!(sender instanceof Player) && giveTo == null) {
|
||||
this.messageHandler.sendMessage(
|
||||
sender,
|
||||
@@ -399,7 +402,7 @@ public class CosmeticsCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
giveTo.getInventory().addItem(token.getItemStack().clone());
|
||||
final String tokenName = token.getArmorItem().getItemName();
|
||||
final String tokenName = token.getArmorItem().getName();
|
||||
this.messageHandler.sendMessage(
|
||||
sender,
|
||||
Messages.GAVE_TOKEN,
|
||||
|
||||
@@ -30,8 +30,9 @@ public class ArmorItemSerializer implements TypeSerializer<WrappedGuiItem> {
|
||||
private ArmorItemSerializer() {
|
||||
}
|
||||
|
||||
private static final String ITEM = "item";
|
||||
private static final String NAME = "name";
|
||||
private static final String LOCKED_LORE = "locked-lore";
|
||||
private static final String APPLIED_LORE = "applied-lore";
|
||||
private static final String LOCKED_ITEM = "locked-item";
|
||||
private static final String APPLIED_ITEM = "applied-item";
|
||||
private static final String PERMISSION = "permission";
|
||||
@@ -54,7 +55,9 @@ public class ArmorItemSerializer implements TypeSerializer<WrappedGuiItem> {
|
||||
@Override
|
||||
public WrappedGuiItem deserialize(final Type type, final ConfigurationNode source)
|
||||
throws SerializationException {
|
||||
final ConfigurationNode nameNode = source.node(NAME);
|
||||
final ConfigurationNode lockedLoreNode = source.node(LOCKED_LORE);
|
||||
final ConfigurationNode appliedLoreNode = source.node(APPLIED_LORE);
|
||||
final ConfigurationNode lockedItemNode = source.node(LOCKED_ITEM);
|
||||
final ConfigurationNode appliedItemNode = source.node(APPLIED_ITEM);
|
||||
final ConfigurationNode permissionNode = source.node(PERMISSION);
|
||||
@@ -76,7 +79,12 @@ public class ArmorItemSerializer implements TypeSerializer<WrappedGuiItem> {
|
||||
lockedItem = ItemBuilder.from(itemStack.clone()).lore(lockedLore).build();
|
||||
}
|
||||
ItemStack appliedItem = ItemSerializer.INSTANCE.deserialize(ItemStack.class, appliedItemNode);
|
||||
if (appliedItem == null) appliedItem = itemStack.clone();
|
||||
if (appliedItem == null) {
|
||||
final List<String> appliedLore = Utils.replaceIfNull(appliedLoreNode.getList(String.class),
|
||||
new ArrayList<String>()).
|
||||
stream().map(StringUtils::parseStringToString).collect(Collectors.toList());
|
||||
appliedItem = ItemBuilder.from(itemStack.clone()).lore(appliedLore).build();
|
||||
}
|
||||
|
||||
final boolean dyeable = dyeableNode.getBoolean();
|
||||
|
||||
@@ -95,6 +103,7 @@ public class ArmorItemSerializer implements TypeSerializer<WrappedGuiItem> {
|
||||
return new BalloonItem(
|
||||
itemStack,
|
||||
actions,
|
||||
Utils.replaceIfNull(nameNode.getString(), ""),
|
||||
Utils.replaceIfNull(idNode.getString(), ""),
|
||||
lockedItem,
|
||||
appliedItem,
|
||||
@@ -109,6 +118,7 @@ public class ArmorItemSerializer implements TypeSerializer<WrappedGuiItem> {
|
||||
return new ArmorItem(
|
||||
itemStack,
|
||||
actions,
|
||||
Utils.replaceIfNull(nameNode.getString(), ""),
|
||||
Utils.replaceIfNull(idNode.getString(), ""),
|
||||
lockedItem,
|
||||
appliedItem,
|
||||
|
||||
@@ -2,13 +2,10 @@ package io.github.fisher2911.hmccosmetics.gui;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import dev.triumphteam.gui.components.GuiAction;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.config.CosmeticGuiAction;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ColorBuilder;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Color;
|
||||
@@ -16,12 +13,12 @@ import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ArmorItem extends WrappedGuiItem {
|
||||
|
||||
private final String name;
|
||||
private final String id;
|
||||
private final ItemStack lockedItem;
|
||||
private final ItemStack appliedItem;
|
||||
@@ -34,6 +31,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
public ArmorItem(
|
||||
@NotNull final ItemStack itemStack,
|
||||
final List<CosmeticGuiAction> actions,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -41,7 +39,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final Type type,
|
||||
final int dye) {
|
||||
super(itemStack, null);
|
||||
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
@@ -53,6 +51,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
|
||||
public ArmorItem(
|
||||
@NotNull final ItemStack itemStack,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -61,6 +60,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final int dye) {
|
||||
super(itemStack);
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
this.actions = new ArrayList<>();
|
||||
@@ -71,6 +71,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
|
||||
public ArmorItem(
|
||||
@NotNull final Material material,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -79,6 +80,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final int dye) {
|
||||
super(material);
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
this.actions = new ArrayList<>();
|
||||
@@ -90,6 +92,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
public ArmorItem(
|
||||
@NotNull final Material material,
|
||||
final List<CosmeticGuiAction> actions,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -97,10 +100,11 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final Type type,
|
||||
final int dye) {
|
||||
super(material, null);
|
||||
this.actions = actions;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
this.actions = new ArrayList<>();
|
||||
this.permission = permission;
|
||||
this.type = type;
|
||||
this.dye = dye;
|
||||
@@ -109,6 +113,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
public ArmorItem(
|
||||
@NotNull final ItemStack itemStack,
|
||||
final List<CosmeticGuiAction> actions,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -117,6 +122,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final boolean dyeable,
|
||||
final int dye) {
|
||||
super(itemStack, null);
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
@@ -129,6 +135,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
|
||||
public ArmorItem(
|
||||
@NotNull final ItemStack itemStack,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -137,6 +144,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final boolean dyeable,
|
||||
final int dye) {
|
||||
super(itemStack);
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
@@ -149,6 +157,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
|
||||
public ArmorItem(
|
||||
@NotNull final Material material,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -158,6 +167,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final int dye) {
|
||||
super(material);
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
this.actions = new ArrayList<>();
|
||||
@@ -170,6 +180,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
public ArmorItem(
|
||||
@NotNull final Material material,
|
||||
@Nullable final GuiAction<InventoryClickEvent> action,
|
||||
final String name,
|
||||
final String id,
|
||||
final ItemStack lockedItem,
|
||||
final ItemStack appliedItem,
|
||||
@@ -178,6 +189,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
final boolean dyeable,
|
||||
final int dye) {
|
||||
super(material, action);
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.lockedItem = lockedItem;
|
||||
this.appliedItem = appliedItem;
|
||||
@@ -190,6 +202,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
|
||||
protected ArmorItem(final ArmorItem armorItem) {
|
||||
super(armorItem.getItemStack().clone(), null);
|
||||
this.name = armorItem.getName();
|
||||
this.id = armorItem.getId();
|
||||
this.lockedItem = armorItem.getLockedItem().clone();
|
||||
this.appliedItem = armorItem.getAppliedItem().clone();
|
||||
@@ -209,6 +222,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
return new BalloonItem(
|
||||
new ItemStack(Material.AIR),
|
||||
id,
|
||||
id,
|
||||
new ItemStack(Material.AIR),
|
||||
new ItemStack(Material.AIR),
|
||||
"",
|
||||
@@ -220,6 +234,7 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
return new ArmorItem(
|
||||
new ItemStack(Material.AIR),
|
||||
id,
|
||||
id,
|
||||
new ItemStack(Material.AIR),
|
||||
new ItemStack(Material.AIR),
|
||||
"",
|
||||
@@ -298,10 +313,8 @@ public class ArmorItem extends WrappedGuiItem {
|
||||
return new ArmorItem(this);
|
||||
}
|
||||
|
||||
public String getItemName() {
|
||||
final ItemMeta itemMeta = this.getItemStack(Status.ALLOWED).getItemMeta();
|
||||
if (itemMeta == null) return this.id;
|
||||
return itemMeta.getDisplayName();
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
|
||||
@@ -19,6 +19,7 @@ public class BalloonItem extends ArmorItem {
|
||||
this(
|
||||
item.getItemStack(),
|
||||
item.getActions(),
|
||||
item.getName(),
|
||||
item.getId(),
|
||||
item.getLockedItem(),
|
||||
item.getAppliedItem(),
|
||||
@@ -29,43 +30,43 @@ public class BalloonItem extends ArmorItem {
|
||||
);
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final List<CosmeticGuiAction> actions, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(itemStack, actions, id, lockedItem, appliedItem, permission, type, dye);
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final List<CosmeticGuiAction> actions, final String name, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(itemStack, actions, name, id, lockedItem, appliedItem, permission, type, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(itemStack, id, lockedItem, appliedItem, permission, type, dye);
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final String name, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(itemStack, name, id, lockedItem, appliedItem, permission, type, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull Material material, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(material, id, lockedItem, appliedItem, permission, type, dye);
|
||||
public BalloonItem(final @NotNull Material material, final String name, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(material, name, id, lockedItem, appliedItem, permission, type, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull Material material, final List<CosmeticGuiAction> actions, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(material, actions, id, lockedItem, appliedItem, permission, type, dye);
|
||||
public BalloonItem(final @NotNull Material material, final List<CosmeticGuiAction> actions, final String name, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final int dye, final String modelId) {
|
||||
super(material, actions, name, id, lockedItem, appliedItem, permission, type, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final List<CosmeticGuiAction> actions, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(itemStack, actions, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final List<CosmeticGuiAction> actions, final String name, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(itemStack, actions, name, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(itemStack, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
public BalloonItem(final @NotNull ItemStack itemStack, final String name, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(itemStack, name, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull Material material, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(material, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
public BalloonItem(final @NotNull Material material, final String name, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(material, name, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public BalloonItem(final @NotNull Material material, final @Nullable GuiAction<InventoryClickEvent> action, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(material, action, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
public BalloonItem(final @NotNull Material material, final String name, final @Nullable GuiAction<InventoryClickEvent> action, final String id, final ItemStack lockedItem, final ItemStack appliedItem, final String permission, final Type type, final boolean dyeable, final int dye, final String modelId) {
|
||||
super(material, action, name, id, lockedItem, appliedItem, permission, type, dyeable, dye);
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package io.github.fisher2911.hmccosmetics.gui;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
|
||||
import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -33,28 +35,38 @@ public class TokenGui extends CosmeticGui {
|
||||
|
||||
@Override
|
||||
public void open(final User user, final Player player) {
|
||||
player.sendMessage("Opened GUI");
|
||||
super.open(user, player);
|
||||
this.gui.setDragAction(event -> event.setCancelled(true));
|
||||
this.gui.setDefaultClickAction(event -> {
|
||||
player.sendMessage("Test");
|
||||
final int slot = event.getSlot();
|
||||
final Inventory inventory = event.getClickedInventory();
|
||||
if (inventory == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getClickedInventory().equals(event.getView().getBottomInventory())) {
|
||||
player.sendMessage("Same inventory");
|
||||
return;
|
||||
}
|
||||
player.sendMessage("Not same");
|
||||
if (slot != tokenSlot && slot != this.cosmeticSlot) {
|
||||
final ClickType clickType = event.getClick();
|
||||
if (clickType == ClickType.SHIFT_RIGHT || clickType == ClickType.SHIFT_LEFT) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getClickedInventory().equals(event.getView().getBottomInventory())) return;
|
||||
ItemStack tokenItem = event.getInventory().getItem(this.tokenSlot);
|
||||
if (slot != tokenSlot && slot != this.cosmeticSlot) {
|
||||
event.setCancelled(true);
|
||||
if (tokenItem == null) {
|
||||
inventory.setItem(this.cosmeticSlot, new ItemStack(Material.AIR));
|
||||
}
|
||||
return;
|
||||
}
|
||||
final ItemStack inHand = event.getCursor();
|
||||
Token token;
|
||||
if (slot == this.tokenSlot) {
|
||||
final Token token = this.cosmeticManager.getToken(inHand);
|
||||
if (inHand == null || inHand.getType() == Material.AIR) {
|
||||
if (tokenItem != null && tokenItem.getAmount() > 1 && clickType == ClickType.RIGHT) return;
|
||||
inventory.setItem(this.cosmeticSlot, new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
token = this.cosmeticManager.getToken(inHand);
|
||||
if (token == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -63,18 +75,16 @@ public class TokenGui extends CosmeticGui {
|
||||
inventory.setItem(this.cosmeticSlot, item.getItemStack(ArmorItem.Status.ALLOWED));
|
||||
return;
|
||||
}
|
||||
final ItemStack tokenItem = event.getInventory().getItem(this.tokenSlot);
|
||||
if (tokenItem == null) {
|
||||
if (inHand != null && inHand.getType() != Material.AIR) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Token token = this.cosmeticManager.getToken(tokenItem);
|
||||
tokenItem = inventory.getItem(this.tokenSlot);
|
||||
token = this.cosmeticManager.getToken(tokenItem);
|
||||
if (token == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
tokenItem.setAmount(tokenItem.getAmount() - 1);
|
||||
inventory.setItem(this.tokenSlot, tokenItem);
|
||||
final ItemStack clicked = event.getCurrentItem();
|
||||
final ArmorItem armorItem = token.getArmorItem();
|
||||
if (clicked == null) return;
|
||||
@@ -82,22 +92,26 @@ public class TokenGui extends CosmeticGui {
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.ALREADY_UNLOCKED,
|
||||
Map.of(Placeholder.ID, armorItem.getItemName())
|
||||
Map.of(Placeholder.ID, armorItem.getName())
|
||||
);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
tokenItem.setAmount(tokenItem.getAmount() - 1);
|
||||
inventory.setItem(this.tokenSlot, tokenItem);
|
||||
clicked.setAmount(0);
|
||||
player.addAttachment(this.plugin, armorItem.getPermission(), true);
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
Messages.TRADED_TOKEN,
|
||||
Map.of(Placeholder.ID, armorItem.getItemName())
|
||||
Map.of(Placeholder.ID, armorItem.getName())
|
||||
);
|
||||
});
|
||||
|
||||
this.gui.setCloseGuiAction(event -> {
|
||||
final Inventory inventory = event.getInventory();
|
||||
final ItemStack tokens = inventory.getItem(this.tokenSlot);
|
||||
if (tokens == null) return;
|
||||
event.getPlayer().getInventory().addItem(tokens);
|
||||
user.setOpenGui(null);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.api.CosmeticItem;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.message.Translation;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
@@ -12,9 +10,6 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PAPIExpansion extends PlaceholderExpansion {
|
||||
@@ -76,7 +71,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||
for (final ArmorItem item : user.getPlayerArmor().getArmorItems()) {
|
||||
if (item.getType().equals(type)) {
|
||||
if (formatted) {
|
||||
final String name = item.getItemName();
|
||||
final String name = item.getName();
|
||||
if (name.isBlank()) return item.getId().replace("_", "");
|
||||
return name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user