mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-29 03:49:19 +00:00
General Improvements + Items now update in menu
This commit is contained in:
@@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.PlayerMenuOpenEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.PlayerWardrobeLeaveEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Types;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
@@ -15,6 +16,7 @@ import dev.triumphteam.gui.guis.GuiItem;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -123,31 +125,28 @@ public class Menu {
|
||||
MessagesUtil.sendDebugMessages("something went wrong! " + item);
|
||||
continue;
|
||||
}
|
||||
ItemStack originalItem = item.clone();
|
||||
item = updateLore(player, item);
|
||||
|
||||
if (item.hasItemMeta()) {
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
Type type = null;
|
||||
|
||||
if (item.getItemMeta().hasLore()) {
|
||||
for (String loreLine : item.getItemMeta().getLore()) {
|
||||
processedLore.add(PlaceholderAPI.setPlaceholders(player, loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
itemMeta.setLore(processedLore);
|
||||
item.setItemMeta(itemMeta);
|
||||
if (!config.node("type").virtual()) {
|
||||
String typeId = config.node("type").getString();
|
||||
if (Types.isType(typeId)) type = Types.getType(typeId);
|
||||
}
|
||||
|
||||
GuiItem guiItem = ItemBuilder.from(item).asGuiItem();
|
||||
|
||||
Type finalType = type;
|
||||
guiItem.setAction(event -> {
|
||||
if (config.node("type").virtual()) return;
|
||||
String type = config.node("type").getString();
|
||||
if (Types.isType(type)) Types.getType(type).run(user, config);
|
||||
if (finalType != null) finalType.run(user, config);
|
||||
|
||||
for (int i : slots) {
|
||||
gui.updateItem(i, guiItem);
|
||||
gui.updateItem(i, updateLore(player, originalItem.clone()));
|
||||
MessagesUtil.sendDebugMessages("Updated slot " + i);
|
||||
}
|
||||
});
|
||||
|
||||
MessagesUtil.sendDebugMessages("Added " + slots + " as " + guiItem + " in the menu");
|
||||
gui.setItem(slots, guiItem);
|
||||
}
|
||||
@@ -177,4 +176,21 @@ public class Menu {
|
||||
for (int i = small; i <= max; i++) slots.add(i);
|
||||
return slots;
|
||||
}
|
||||
|
||||
private ItemStack updateLore(Player player, ItemStack itemStack) {
|
||||
if (itemStack.hasItemMeta()) {
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
|
||||
if (itemStack.getItemMeta().hasLore()) {
|
||||
for (String loreLine : itemStack.getItemMeta().getLore()) {
|
||||
processedLore.add(PlaceholderAPI.setPlaceholders(player, loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.setLore(processedLore);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.type;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Type {
|
||||
|
||||
private String id;
|
||||
@@ -19,4 +27,9 @@ public class Type {
|
||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
||||
// Override
|
||||
}
|
||||
|
||||
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
|
||||
//TODO: Finish this
|
||||
return null; // Override
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PAPIHook extends PlaceholderExpansion {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
|
||||
if (user == null) return null;
|
||||
|
||||
List<String> placeholderArgs = Arrays.asList(params.split("_"));
|
||||
List<String> placeholderArgs = Arrays.asList(params.split("_", 3));
|
||||
|
||||
switch (placeholderArgs.get(0).toLowerCase()) {
|
||||
case "using":
|
||||
@@ -94,7 +94,14 @@ public class PAPIHook extends PlaceholderExpansion {
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||
if (cosmetic == null) return "INVALID_COSMETIC";
|
||||
if (cosmetic == null) {
|
||||
Cosmetic secondAttemptCosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1) + "_" + placeholderArgs.get(2));
|
||||
if (secondAttemptCosmetic == null) {
|
||||
return "INVALID_COSMETIC";
|
||||
} else {
|
||||
cosmetic = secondAttemptCosmetic;
|
||||
}
|
||||
}
|
||||
return TranslationUtil.getTranslation("unlockedCosmetic", String.valueOf(user.canEquipCosmetic(cosmetic)));
|
||||
}
|
||||
case "equipped":
|
||||
@@ -103,7 +110,14 @@ public class PAPIHook extends PlaceholderExpansion {
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||
if (cosmetic == null) return "INVALID_COSMETIC";
|
||||
if (cosmetic == null) {
|
||||
Cosmetic secondAttemptCosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1) + "_" + placeholderArgs.get(2));
|
||||
if (secondAttemptCosmetic == null) {
|
||||
return "INVALID_COSMETIC";
|
||||
} else {
|
||||
cosmetic = secondAttemptCosmetic;
|
||||
}
|
||||
}
|
||||
if (user.getCosmetic(cosmetic.getSlot()) == null) return "false";
|
||||
if (cosmetic.getId() == user.getCosmetic(cosmetic.getSlot()).getId()) {
|
||||
return "true";
|
||||
|
||||
Reference in New Issue
Block a user