mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 04:19:28 +00:00
fix: Menus being janky
This commit is contained in:
@@ -105,7 +105,7 @@ public class Menu {
|
||||
|
||||
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
|
||||
|
||||
List<String> slotString = null;
|
||||
List<String> slotString;
|
||||
try {
|
||||
slotString = config.node("slots").getList(String.class);
|
||||
} catch (SerializationException e) {
|
||||
@@ -126,7 +126,6 @@ public class Menu {
|
||||
ItemStack item;
|
||||
try {
|
||||
item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config.node("item"));
|
||||
//item = config.node("item").get(ItemStack.class);
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -144,8 +143,8 @@ public class Menu {
|
||||
}
|
||||
|
||||
for (int slot : slots) {
|
||||
ItemStack originalItem = updateItem(user, item, type, config, slot).clone();
|
||||
GuiItem guiItem = ItemBuilder.from(originalItem).asGuiItem();
|
||||
ItemStack modifiedItem = getMenuItem(user, type, config, item.clone(), slot).clone();
|
||||
GuiItem guiItem = ItemBuilder.from(modifiedItem).asGuiItem();
|
||||
|
||||
Type finalType = type;
|
||||
guiItem.setAction(event -> {
|
||||
@@ -153,11 +152,9 @@ public class Menu {
|
||||
final ClickType clickType = event.getClick();
|
||||
if (finalType != null) finalType.run(user, config, clickType);
|
||||
// Need to delay the update by a tick so it will actually update with new values
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
for (int guiSlot : slots) {
|
||||
gui.updateItem(guiSlot, updateItem(user, originalItem, finalType, config, guiSlot));
|
||||
}
|
||||
}, 1);
|
||||
for (int guiSlot : slots) {
|
||||
gui.updateItem(guiSlot, getMenuItem(user, finalType, config, item.clone(), guiSlot));
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("Updated slot " + slot);
|
||||
});
|
||||
|
||||
@@ -196,11 +193,9 @@ public class Menu {
|
||||
|
||||
@Contract("_, _, _, _ -> param2")
|
||||
@NotNull
|
||||
private ItemStack updateItem(CosmeticUser user, @NotNull ItemStack itemStack, Type type, ConfigurationNode config, int slot) {
|
||||
if (itemStack.hasItemMeta()) {
|
||||
itemStack = type.setItem(user, config, itemStack, slot);
|
||||
}
|
||||
return itemStack;
|
||||
private ItemStack getMenuItem(CosmeticUser user, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
if (!itemStack.hasItemMeta()) return itemStack;
|
||||
return type.setItem(user, config, itemStack, slot);
|
||||
}
|
||||
|
||||
public String getPermissionNode() {
|
||||
|
||||
@@ -56,8 +56,8 @@ public class Menus {
|
||||
return names;
|
||||
}
|
||||
|
||||
public static List<Menu> values() {
|
||||
return Menus.values();
|
||||
public static Collection<Menu> values() {
|
||||
return MENUS.values();
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
|
||||
@@ -75,7 +75,7 @@ public class TypeCosmetic extends Type {
|
||||
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
|
||||
MessagesUtil.sendDebugMessages("on-equip");
|
||||
// TODO: Redo this
|
||||
if (cosmetic.isDyable()) {
|
||||
if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) {
|
||||
DyeMenu.openMenu(user, cosmetic);
|
||||
} else {
|
||||
user.addPlayerCosmetic(cosmetic);
|
||||
@@ -99,12 +99,11 @@ public class TypeCosmetic extends Type {
|
||||
|
||||
@Override
|
||||
public ItemStack setItem(CosmeticUser user, @NotNull ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemStack.setItemMeta(processLoreLines(user, itemMeta));
|
||||
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
||||
|
||||
if (config.node("cosmetic").virtual()) {
|
||||
return itemStack;
|
||||
};
|
||||
}
|
||||
String cosmeticName = config.node("cosmetic").getString();
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
||||
if (cosmetic == null) {
|
||||
@@ -155,12 +154,10 @@ public class TypeCosmetic extends Type {
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (String loreLine : itemMeta.getLore()) {
|
||||
if (Hooks.isActiveHook("PlaceholderAPI"))
|
||||
loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine);
|
||||
if (Hooks.isActiveHook("PlaceholderAPI")) loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine);
|
||||
processedLore.add(loreLine);
|
||||
}
|
||||
}
|
||||
|
||||
itemMeta.setLore(processedLore);
|
||||
return itemMeta;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user