From 7080aee9dd8d57d5ad66b8fb4b95e3fe772f56dc Mon Sep 17 00:00:00 2001 From: devlrxxh Date: Sun, 7 Apr 2024 09:54:04 +0200 Subject: [PATCH] Added Placeholder support for item lores --- .../lrxh/practice/arena/selection/Selection.java | 2 ++ .../kit/menu/KitEditorSelectKitMenu.java | 2 +- .../practice/leaderboards/LeaderboardsMenu.java | 8 ++++---- .../practice/match/menu/MatchDetailsMenu.java | 4 ++-- .../practice/match/menu/ViewInventoryMenu.java | 2 +- .../java/me/lrxh/practice/menus/StatsMenu.java | 4 ++-- .../practice/party/menu/OtherPartiesMenu.java | 2 +- .../party/menu/PartyEventSelectEventMenu.java | 2 +- .../practice/queue/menu/QueueSelectKitMenu.java | 2 +- .../practice/setting/ProfileSettingsMenu.java | 4 ++-- .../me/lrxh/practice/setting/SettingsMenu.java | 2 +- .../java/me/lrxh/practice/util/ItemBuilder.java | 16 +++++++++++++++- .../util/menu/pagination/PageButton.java | 8 ++++---- .../util/menu/pagination/PageFilterButton.java | 2 +- 14 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/lrxh/practice/arena/selection/Selection.java b/src/main/java/me/lrxh/practice/arena/selection/Selection.java index 4f7a564..5c0511f 100644 --- a/src/main/java/me/lrxh/practice/arena/selection/Selection.java +++ b/src/main/java/me/lrxh/practice/arena/selection/Selection.java @@ -20,6 +20,8 @@ public class Selection { public static final ItemStack SELECTION_WAND; private static final String SELECTION_METADATA_KEY = "CLAIM_SELECTION"; + + static { SELECTION_WAND = new ItemBuilder(Material.GOLD_AXE) .name("&6Selection Wand") diff --git a/src/main/java/me/lrxh/practice/kit/menu/KitEditorSelectKitMenu.java b/src/main/java/me/lrxh/practice/kit/menu/KitEditorSelectKitMenu.java index 157bf24..eeca2ff 100644 --- a/src/main/java/me/lrxh/practice/kit/menu/KitEditorSelectKitMenu.java +++ b/src/main/java/me/lrxh/practice/kit/menu/KitEditorSelectKitMenu.java @@ -58,7 +58,7 @@ public ItemStack getButtonItem(Player player) { List lore = new ArrayList<>(Practice.getInstance().getMenusConfig().getStringList("KIT-EDITOR.LORE")); return new ItemBuilder(kit.getDisplayIcon()) .name(Practice.getInstance().getMenusConfig().getString("KIT-EDITOR.KIT-NAME").replace("", kit.getName())) - .lore(lore) + .lore(lore, player) .clearFlags() .build(); } diff --git a/src/main/java/me/lrxh/practice/leaderboards/LeaderboardsMenu.java b/src/main/java/me/lrxh/practice/leaderboards/LeaderboardsMenu.java index 49a4bd7..e1e60b1 100644 --- a/src/main/java/me/lrxh/practice/leaderboards/LeaderboardsMenu.java +++ b/src/main/java/me/lrxh/practice/leaderboards/LeaderboardsMenu.java @@ -87,7 +87,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(PlayerUtil.getPlayerHead(player.getUniqueId())) .name(Practice.getInstance().getMenusConfig().getString("LEADERBOARD.GLOBAL-STATS.GLOBAL-STATS-NAME")) - .lore(lore) + .lore(lore, player) .clearEnchantments() .clearFlags() .build(); @@ -112,7 +112,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(Material.COMPASS) .name(Practice.getInstance().getMenusConfig().getString("LEADERBOARD.TOGGLE_VIEW")) - .lore(lore) + .lore(lore, player) .clearEnchantments() .clearFlags() .build(); @@ -151,7 +151,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(queue.getKit().getDisplayIcon()) .name(Practice.getInstance().getMenusConfig().getString("LEADERBOARD.KIT-NAME") .replace("", queue.getKit().getName())) - .lore(lore) + .lore(lore, player) .clearEnchantments() .clearFlags() .build(); @@ -183,7 +183,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(queue.getKit().getDisplayIcon()) .name(Practice.getInstance().getMenusConfig().getString("LEADERBOARD.KIT-NAME") .replace("", queue.getKit().getName())) - .lore(lore) + .lore(lore, player) .clearEnchantments() .clearFlags() .build(); diff --git a/src/main/java/me/lrxh/practice/match/menu/MatchDetailsMenu.java b/src/main/java/me/lrxh/practice/match/menu/MatchDetailsMenu.java index 45dd1d6..8c6188b 100644 --- a/src/main/java/me/lrxh/practice/match/menu/MatchDetailsMenu.java +++ b/src/main/java/me/lrxh/practice/match/menu/MatchDetailsMenu.java @@ -110,7 +110,7 @@ public ItemStack getButtonItem(Player player) { lore.add("&b" + name + "&f" + duration); }); - builder.lore(lore); + builder.lore(lore, player); } return builder.build(); @@ -154,7 +154,7 @@ public ItemStack getButtonItem(Player player) { "&7• &bPotions Thrown: &f" + snapshot.getPotionsThrown(), "&7• &bPotions Missed: &f" + snapshot.getPotionsMissed(), "&7• &bPotion Accuracy: &f" + snapshot.getPotionAccuracy() - )) + ), player) .clearFlags() .build(); } diff --git a/src/main/java/me/lrxh/practice/match/menu/ViewInventoryMenu.java b/src/main/java/me/lrxh/practice/match/menu/ViewInventoryMenu.java index 4a3a890..59ac29b 100644 --- a/src/main/java/me/lrxh/practice/match/menu/ViewInventoryMenu.java +++ b/src/main/java/me/lrxh/practice/match/menu/ViewInventoryMenu.java @@ -118,7 +118,7 @@ public ItemStack getButtonItem(Player player) { lore.add(CC.PINK + name + CC.GRAY + duration); }); - builder.lore(lore); + builder.lore(lore, player); } return builder.build(); diff --git a/src/main/java/me/lrxh/practice/menus/StatsMenu.java b/src/main/java/me/lrxh/practice/menus/StatsMenu.java index 400c5b6..083dae7 100644 --- a/src/main/java/me/lrxh/practice/menus/StatsMenu.java +++ b/src/main/java/me/lrxh/practice/menus/StatsMenu.java @@ -75,7 +75,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(PlayerUtil.getPlayerHead(target.getUniqueId())) .name(Practice.getInstance().getMenusConfig().getString("STATS.GLOBAL-STATS.GLOBAL-STATS-NAME")) - .lore(lore) + .lore(lore, player) .clearEnchantments() .clearFlags() .build(); @@ -116,7 +116,7 @@ public ItemStack getButtonItem(Player player) { .name(Practice.getInstance().getMenusConfig().getString("STATS.KIT-NAME") .replace("", queue.getKit().getName()) .replace("", queue.isRanked() ? "Unranked" : "Ranked")) - .lore(lore) + .lore(lore, player) .clearEnchantments() .clearFlags() .build(); diff --git a/src/main/java/me/lrxh/practice/party/menu/OtherPartiesMenu.java b/src/main/java/me/lrxh/practice/party/menu/OtherPartiesMenu.java index 9d8d4fe..2ed06f7 100644 --- a/src/main/java/me/lrxh/practice/party/menu/OtherPartiesMenu.java +++ b/src/main/java/me/lrxh/practice/party/menu/OtherPartiesMenu.java @@ -81,7 +81,7 @@ public ItemStack getButtonItem(Player player) { .name("&6Party of &r" + party.getLeader().getName()) .amount(party.getPlayers().size(), false) .durability(3) - .lore(lore) + .lore(lore, player) .clearFlags() .build(); } diff --git a/src/main/java/me/lrxh/practice/party/menu/PartyEventSelectEventMenu.java b/src/main/java/me/lrxh/practice/party/menu/PartyEventSelectEventMenu.java index 77fe88f..1e84c67 100644 --- a/src/main/java/me/lrxh/practice/party/menu/PartyEventSelectEventMenu.java +++ b/src/main/java/me/lrxh/practice/party/menu/PartyEventSelectEventMenu.java @@ -65,7 +65,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(partyEvent == PartyEvent.FFA ? Material.DIAMOND_SWORD : Material.GOLD_AXE) .name(Practice.getInstance().getMenusConfig().getString("PARTY.EVENTS.EVENT-COLOR").replace("", partyEvent.getName())) - .lore(partyEvent == PartyEvent.FFA ? ffaLore : splitLore) + .lore(partyEvent == PartyEvent.FFA ? ffaLore : splitLore, player) .clearFlags() .build(); } diff --git a/src/main/java/me/lrxh/practice/queue/menu/QueueSelectKitMenu.java b/src/main/java/me/lrxh/practice/queue/menu/QueueSelectKitMenu.java index 7f1e79f..93115e0 100644 --- a/src/main/java/me/lrxh/practice/queue/menu/QueueSelectKitMenu.java +++ b/src/main/java/me/lrxh/practice/queue/menu/QueueSelectKitMenu.java @@ -113,7 +113,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(queue.getKit().getDisplayIcon()) .name(kitName) - .lore(lore) + .lore(lore, player) .amount(Match.getInFightsCount(queue), true) .clearFlags() .build(); diff --git a/src/main/java/me/lrxh/practice/setting/ProfileSettingsMenu.java b/src/main/java/me/lrxh/practice/setting/ProfileSettingsMenu.java index 72f72de..67483f3 100644 --- a/src/main/java/me/lrxh/practice/setting/ProfileSettingsMenu.java +++ b/src/main/java/me/lrxh/practice/setting/ProfileSettingsMenu.java @@ -58,7 +58,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(Material.REDSTONE_COMPARATOR) .name("&bSettings") - .lore(lore) + .lore(lore, player) .clearFlags() .build(); } @@ -84,7 +84,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(Material.EMERALD) .name("&bStatistics") - .lore(lore) + .lore(lore, player) .clearFlags() .build(); } diff --git a/src/main/java/me/lrxh/practice/setting/SettingsMenu.java b/src/main/java/me/lrxh/practice/setting/SettingsMenu.java index bca2904..9f2c00d 100644 --- a/src/main/java/me/lrxh/practice/setting/SettingsMenu.java +++ b/src/main/java/me/lrxh/practice/setting/SettingsMenu.java @@ -141,7 +141,7 @@ public ItemStack getButtonItem(Player player) { break; } } - return new ItemBuilder(this.settings.getMaterial()).name(Practice.getInstance().getMenusConfig().getString("SETTINGS.SETTING-NAME").replace("", settings.getName())).lore(lore).clearEnchantments().clearFlags().clearFlags().build(); + return new ItemBuilder(this.settings.getMaterial()).name(Practice.getInstance().getMenusConfig().getString("SETTINGS.SETTING-NAME").replace("", settings.getName())).lore(lore, player).clearEnchantments().clearFlags().clearFlags().build(); } @Override diff --git a/src/main/java/me/lrxh/practice/util/ItemBuilder.java b/src/main/java/me/lrxh/practice/util/ItemBuilder.java index 44c4b82..a7c95c2 100644 --- a/src/main/java/me/lrxh/practice/util/ItemBuilder.java +++ b/src/main/java/me/lrxh/practice/util/ItemBuilder.java @@ -3,6 +3,7 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -69,7 +70,7 @@ public ItemBuilder lore(String... lore) { return this; } - public ItemBuilder lore(List lore) { + public ItemBuilder lore(List lore, Player player) { List toSet = new ArrayList<>(); ItemMeta meta = is.getItemMeta(); @@ -77,6 +78,19 @@ public ItemBuilder lore(List lore) { toSet.add(ChatColor.translateAlternateColorCodes('&', string)); } + meta.setLore(PlaceholderUtil.format(toSet, player)); + is.setItemMeta(meta); + + return this; + } + + public ItemBuilder lore(List lore) { + List toSet = new ArrayList<>(); + ItemMeta meta = is.getItemMeta(); + for (String string : lore) { + toSet.add(ChatColor.translateAlternateColorCodes('&', string)); + } + meta.setLore(toSet); is.setItemMeta(meta); diff --git a/src/main/java/me/lrxh/practice/util/menu/pagination/PageButton.java b/src/main/java/me/lrxh/practice/util/menu/pagination/PageButton.java index dea3582..5cb8cb2 100644 --- a/src/main/java/me/lrxh/practice/util/menu/pagination/PageButton.java +++ b/src/main/java/me/lrxh/practice/util/menu/pagination/PageButton.java @@ -26,7 +26,7 @@ public ItemStack getButtonItem(Player player) { .lore(Arrays.asList( ChatColor.YELLOW + "Click here to jump", ChatColor.YELLOW + "to the next page." - )) + ), player) .clearFlags() .build(); } else { @@ -35,7 +35,7 @@ public ItemStack getButtonItem(Player player) { .lore(Arrays.asList( ChatColor.YELLOW + "There is no available", ChatColor.YELLOW + "next page." - )) + ), player) .clearFlags() .build(); } @@ -46,7 +46,7 @@ public ItemStack getButtonItem(Player player) { .lore(Arrays.asList( ChatColor.YELLOW + "Click here to jump", ChatColor.YELLOW + "to the previous page." - )) + ), player) .clearFlags() .build(); } else { @@ -55,7 +55,7 @@ public ItemStack getButtonItem(Player player) { .lore(Arrays.asList( ChatColor.YELLOW + "There is no available", ChatColor.YELLOW + "previous page." - )) + ), player) .clearFlags() .build(); } diff --git a/src/main/java/me/lrxh/practice/util/menu/pagination/PageFilterButton.java b/src/main/java/me/lrxh/practice/util/menu/pagination/PageFilterButton.java index ff23eb2..f864572 100644 --- a/src/main/java/me/lrxh/practice/util/menu/pagination/PageFilterButton.java +++ b/src/main/java/me/lrxh/practice/util/menu/pagination/PageFilterButton.java @@ -55,7 +55,7 @@ public ItemStack getButtonItem(Player player) { return new ItemBuilder(Material.HOPPER) .name("&7Filters") - .lore(lore) + .lore(lore, player) .build(); }