Skip to content

Commit

Permalink
fix(papi): use offline player for placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Mar 3, 2022
1 parent a636bdf commit 0eaefcc
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.silthus.schat.message.MessageSource;
import net.silthus.schat.ui.placeholder.Replacements;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.OfflinePlayer;

public class PlaceholderApiIntegration {

Expand All @@ -41,15 +42,14 @@ public PlaceholderApiIntegration(Replacements replacements) {

public void init() {
replacements.addMessageReplacement(message -> {
final Player player = Bukkit.getPlayer(message.source().uniqueId());
if (player != null)
return replacePlaceholderAPIPlaceholders(player);
else
if (message.source().equals(MessageSource.nil()))
return null;
else
return replacePlaceholderAPIPlaceholders(Bukkit.getOfflinePlayer(message.source().uniqueId()));
});
}

private TextReplacementConfig replacePlaceholderAPIPlaceholders(Player player) {
private TextReplacementConfig replacePlaceholderAPIPlaceholders(OfflinePlayer player) {
return TextReplacementConfig.builder()
.match(Pattern.compile("(%[a-zA-Z0-9_-]+%)"))
.replacement((matchResult, builder) -> Component.text(PlaceholderAPI.setPlaceholders(player, matchResult.group())))
Expand Down

0 comments on commit 0eaefcc

Please sign in to comment.