Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Message: fix PAPI formatting for all players
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Sep 28, 2023
1 parent 85f48d1 commit e75708f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/main/java/net/flectone/messages/MessageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ public String getMessage(String color) {
}

if (sender.hasPermission("flectonechat.placeholders")) {
word = ObjectUtil.formatPAPI(word, sender, sender);
word = ObjectUtil.formatPAPI(word, sender, sender, true);
}

if (sender.hasPermission("flectonechat.formatting")) {
word = ObjectUtil.formatString(word, sender, sender);
word = ObjectUtil.formatString(word, sender, sender, true);
}

color = ChatColor.getLastColors(color) + ChatColor.getLastColors(word);
Expand Down Expand Up @@ -404,13 +404,13 @@ public BaseComponent[] buildMessage(@NotNull String lastColor, @NotNull CommandS
}

if (sender.hasPermission("flectonechat.placeholders")) {
word = ObjectUtil.formatPAPI(word, sender, sender);
word = ObjectUtil.formatPAPI(word, sender, sender, true);
}

if (sender.hasPermission("flectonechat.formatting") && !wordParams.isEdited()) {
wordParams.setFormatted(true);

String newWord = ObjectUtil.formatString(lastColor + wordParams.getText(), recipient, sender);
String newWord = ObjectUtil.formatString(lastColor + wordParams.getText(), recipient, sender, true);
lastColor = ChatColor.getLastColors(newWord);

word = lastColor + wordParams.getFormatting() + ChatColor.stripColor(newWord);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/net/flectone/utils/ObjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ public static String translateHexToColor(@NotNull String string) {

@NotNull
public static String formatString(@NotNull String string, @Nullable CommandSender recipient, @Nullable CommandSender sender) {
return formatString(string, recipient, sender, false);
}

@NotNull
public static String formatString(@NotNull String string, @Nullable CommandSender recipient, @Nullable CommandSender sender, boolean needPermission) {
String[] colors = null;

if (recipient instanceof Player playerRecipient) {

string = formatPAPI(string, recipient, sender);
string = formatPAPI(string, recipient, sender, needPermission);

FPlayer fPlayer = FPlayerManager.getPlayer(playerRecipient);
colors = fPlayer != null ? fPlayer.getColors() : null;
Expand All @@ -112,11 +117,11 @@ public static String formatString(@NotNull String string, @Nullable CommandSende
}

@NotNull
public static String formatPAPI(@NotNull String string, @Nullable CommandSender recipient, @Nullable CommandSender sender) {
public static String formatPAPI(@NotNull String string, @Nullable CommandSender recipient, @Nullable CommandSender sender, boolean needPermission) {
if (recipient instanceof Player playerRecipient) {
if (HookManager.enabledPlaceholderAPI
&& sender instanceof Player playerSender
&& sender.hasPermission("flectonechat.placeholders")) {
&& (sender.hasPermission("flectonechat.placeholders") || !needPermission)) {

string = PlaceholderAPI.setPlaceholders(playerSender, string);
string = PlaceholderAPI.setRelationalPlaceholders(playerSender, playerRecipient, string);
Expand Down

0 comments on commit e75708f

Please sign in to comment.