Skip to content

Commit

Permalink
add party placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Sep 30, 2023
1 parent 71bee97 commit cd14215
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.inject.Inject;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.Party;
import net.draycia.carbon.api.users.UserManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -64,17 +65,35 @@ public boolean persist() {

@Override
public @Nullable String onRequest(final OfflinePlayer player, final String params) {
final CarbonPlayer carbonPlayer = this.userManager.user(player.getUniqueId()).join();

final Component nickname = carbonPlayer.displayName();

if (params.endsWith("nickname")) {
return MiniMessage.miniMessage().serialize(nickname);
if (params.endsWith("party")) {
return mm(this.partyName(player));
} else if (params.endsWith("party_l")) {
return legacy(this.partyName(player));
} else if (params.endsWith("nickname")) {
return mm(this.displayName(player));
} else if (params.endsWith("nickname_l")) {
return LegacyComponentSerializer.legacySection().serialize(nickname);
return legacy(this.displayName(player));
}

return null;
}

private static String mm(final Component in) {
return MiniMessage.miniMessage().serialize(in);
}

private static String legacy(final Component in) {
return LegacyComponentSerializer.legacySection().serialize(in);
}

private Component partyName(final OfflinePlayer player) {
final @Nullable Party party = this.userManager.user(player.getUniqueId()).thenCompose(CarbonPlayer::party).join();
return party == null ? Component.empty() : party.name();
}

private Component displayName(final OfflinePlayer player) {
final CarbonPlayer carbonPlayer = this.userManager.user(player.getUniqueId()).join();
return carbonPlayer.displayName();
}

}

0 comments on commit cd14215

Please sign in to comment.