Skip to content

Commit

Permalink
Added Placeholder support for item lores
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 7, 2024
1 parent eaf7ea2 commit 7080aee
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/main/java/me/lrxh/practice/arena/selection/Selection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ItemStack getButtonItem(Player player) {
List<String> 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>", kit.getName()))
.lore(lore)
.lore(lore, player)
.clearFlags()
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -151,7 +151,7 @@ public ItemStack getButtonItem(Player player) {
return new ItemBuilder(queue.getKit().getDisplayIcon())
.name(Practice.getInstance().getMenusConfig().getString("LEADERBOARD.KIT-NAME")
.replace("<kit>", queue.getKit().getName()))
.lore(lore)
.lore(lore, player)
.clearEnchantments()
.clearFlags()
.build();
Expand Down Expand Up @@ -183,7 +183,7 @@ public ItemStack getButtonItem(Player player) {
return new ItemBuilder(queue.getKit().getDisplayIcon())
.name(Practice.getInstance().getMenusConfig().getString("LEADERBOARD.KIT-NAME")
.replace("<kit>", queue.getKit().getName()))
.lore(lore)
.lore(lore, player)
.clearEnchantments()
.clearFlags()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/lrxh/practice/menus/StatsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -116,7 +116,7 @@ public ItemStack getButtonItem(Player player) {
.name(Practice.getInstance().getMenusConfig().getString("STATS.KIT-NAME")
.replace("<kit>", queue.getKit().getName())
.replace("<type>", queue.isRanked() ? "Unranked" : "Ranked"))
.lore(lore)
.lore(lore, player)
.clearEnchantments()
.clearFlags()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<event>", partyEvent.getName()))
.lore(partyEvent == PartyEvent.FFA ? ffaLore : splitLore)
.lore(partyEvent == PartyEvent.FFA ? ffaLore : splitLore, player)
.clearFlags()
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ItemStack getButtonItem(Player player) {

return new ItemBuilder(Material.REDSTONE_COMPARATOR)
.name("&bSettings")
.lore(lore)
.lore(lore, player)
.clearFlags()
.build();
}
Expand All @@ -84,7 +84,7 @@ public ItemStack getButtonItem(Player player) {

return new ItemBuilder(Material.EMERALD)
.name("&bStatistics")
.lore(lore)
.lore(lore, player)
.clearFlags()
.build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/setting/SettingsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>", settings.getName())).lore(lore).clearEnchantments().clearFlags().clearFlags().build();
return new ItemBuilder(this.settings.getMaterial()).name(Practice.getInstance().getMenusConfig().getString("SETTINGS.SETTING-NAME").replace("<settings>", settings.getName())).lore(lore, player).clearEnchantments().clearFlags().clearFlags().build();
}

@Override
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/me/lrxh/practice/util/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,14 +70,27 @@ public ItemBuilder lore(String... lore) {
return this;
}

public ItemBuilder lore(List<String> lore) {
public ItemBuilder lore(List<String> lore, Player player) {
List<String> toSet = new ArrayList<>();
ItemMeta meta = is.getItemMeta();

for (String string : lore) {
toSet.add(ChatColor.translateAlternateColorCodes('&', string));
}

meta.setLore(PlaceholderUtil.format(toSet, player));
is.setItemMeta(meta);

return this;
}

public ItemBuilder lore(List<String> lore) {
List<String> toSet = new ArrayList<>();
ItemMeta meta = is.getItemMeta();
for (String string : lore) {
toSet.add(ChatColor.translateAlternateColorCodes('&', string));
}

meta.setLore(toSet);
is.setItemMeta(meta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
Expand All @@ -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 {
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ItemStack getButtonItem(Player player) {

return new ItemBuilder(Material.HOPPER)
.name("&7Filters")
.lore(lore)
.lore(lore, player)
.build();
}

Expand Down

0 comments on commit 7080aee

Please sign in to comment.