Skip to content

Commit f21081f

Browse files
committed
Feat: Parse PAPI twice config for playerlist and playerinfo.
Why do we do this? By default it uses %vault_prefix%, which in some cases, will return placeholders AGAIN (e.g. itemsadder font prefixes) which will not be parsed.
1 parent 4574ef3 commit f21081f

File tree

2 files changed

+19
-0
lines changed
  • abstraction/src/main/java/com/loohp/multichatdiscordsrvaddon/config
  • common/src/main/java/com/loohp/multichatdiscordsrvaddon/listeners

2 files changed

+19
-0
lines changed

Diff for: abstraction/src/main/java/com/loohp/multichatdiscordsrvaddon/config/Config.java

+4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public record DiscordCommandsPlayerInfo(
178178
@Comment("Enable the /playerinfo command to show player information") boolean enabled,
179179
@Comment("If you do NOT use a shared channel for multiple servers, this should be set to true.\nIf you do, set this option on ONE of the main servers connected to the discord channel to true.") boolean isMainServer,
180180
@Comment("The description of this command on Discord") String description,
181+
@Comment("Parse PAPI placeholders twice. In some cases, such as using %vault_prefix%, it will return placeholders (e.g. ItemsAdder prefix placeholders) which will not be parsed.") boolean parsePlaceholdersTwice,
181182
@Comment("The player information to display") DiscordCommandsPlayerInfoFormatting infoFormatting
182183
) {}
183184

@@ -208,6 +209,7 @@ public record DiscordCommandsPlayerListOptions(
208209
@Comment("PlaceholderAPI placeholders in the header are parsed as the first player in the playerlist!\nLeave this variable as a single blank line to disable.") List<String> headerText,
209210
@Comment("PlaceholderAPI placeholders in the footer are parsed as the first player in the playerlist!\nLeave this variable as a single blank line to disable.") List<String> footerText,
210211
@Comment("Instead of parsing colour codes for each playername,\nparse MiniMessage tags instead.") boolean parsePlayerNamesWithMiniMessage,
212+
@Comment("Parse PAPI placeholders twice. In some cases, such as using %vault_prefix%, it will return placeholders (e.g. ItemsAdder prefix placeholders) which will not be parsed.") boolean parsePlaceholdersTwice,
211213
DiscordCommandsPlayerOrder playerOrder
212214
) {}
213215

@@ -566,6 +568,7 @@ public record Debug(
566568
true,
567569
true,
568570
"Show player information on Discord!",
571+
true,
569572
new DiscordCommandsPlayerInfoFormatting(
570573
"%player_name%'s Player Info",
571574
"%discordsrv_user_tag%",
@@ -601,6 +604,7 @@ public record Debug(
601604
List.of("&aOnline Players ({OnlinePlayers}/100}"),
602605
List.of(""),
603606
false,
607+
true,
604608
new DiscordCommandsPlayerOrder(
605609
List.of(
606610
"GROUP:owner,admin,member,default",

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/listeners/DiscordCommands.java

+15
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,21 @@ public void onSlashCommand(SlashCommandEvent event) {
647647
if (offlineICPlayer.isOnline() && !PlayerUtils.isVanished(((Player) offlineICPlayer))) {
648648
playerInfoComponents = Config.i().getDiscordCommands().playerInfo().infoFormatting().whenOnline().stream().map(each -> {
649649
each = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(offlineICPlayer, each));
650+
651+
if (Config.i().getDiscordCommands().playerInfo().parsePlaceholdersTwice()) {
652+
each = ChatColorUtils.translateAlternateColorCodes('&', each);
653+
}
654+
650655
return ToolTipComponent.text(LegacyComponentSerializer.legacySection().deserialize(each));
651656
}).collect(Collectors.toList());
652657
} else {
653658
playerInfoComponents = Config.i().getDiscordCommands().playerInfo().infoFormatting().whenOffline().stream().map(each -> {
654659
each = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(offlineICPlayer, each));
660+
661+
if (Config.i().getDiscordCommands().playerInfo().parsePlaceholdersTwice()) {
662+
each = ChatColorUtils.translateAlternateColorCodes('&', each);
663+
}
664+
655665
return ToolTipComponent.text(LegacyComponentSerializer.legacySection().deserialize(each));
656666
}).collect(Collectors.toList());
657667
}
@@ -720,6 +730,11 @@ public void onSlashCommand(SlashCommandEvent event) {
720730
OfflinePlayer bukkitOfflinePlayer = entry.getKey();
721731
playerInfo.put(bukkitOfflinePlayer.getUniqueId(), new ValuePairs<>(getPlayerGroups(bukkitOfflinePlayer), bukkitOfflinePlayer.getName()));
722732
String name = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(bukkitOfflinePlayer, Config.i().getDiscordCommands().playerList().tablistOptions().playerFormat()));
733+
734+
if (Config.i().getDiscordCommands().playerList().tablistOptions().parsePlaceholdersTwice()) {
735+
name = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderParser.parse(bukkitOfflinePlayer, name));
736+
}
737+
723738
Component nameComponent;
724739
if (Config.i().getDiscordCommands().playerList().tablistOptions().parsePlayerNamesWithMiniMessage()) {
725740
nameComponent = MiniMessage.miniMessage().deserialize(name);

0 commit comments

Comments
 (0)