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

Commit

Permalink
Message: separate permissions flectonechat.formatting and flectonecha…
Browse files Browse the repository at this point in the history
…t.placeholders
  • Loading branch information
TheFaser committed Sep 24, 2023
1 parent 69b276e commit ea5af03
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/main/java/net/flectone/messages/MessageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ public String getMessage(String color) {
word = ChatColor.stripColor(word);
}

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

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

color = ChatColor.getLastColors(color) + ChatColor.getLastColors(word);
Expand Down Expand Up @@ -399,10 +403,14 @@ public BaseComponent[] buildMessage(@NotNull String lastColor, @NotNull CommandS
word = ObjectUtil.formatString(word, recipient, sender);
}

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

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

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

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

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

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

if (recipient instanceof Player playerRecipient) {
if (HookManager.enabledPlaceholderAPI && sender instanceof Player playerSender
&& (!neededPermission || sender.hasPermission("flectonechat.placeholders"))) {

string = PlaceholderAPI.setPlaceholders(playerSender, string);
string = PlaceholderAPI.setRelationalPlaceholders(playerSender, playerRecipient, string);
}
string = formatPAPI(string, recipient, sender);

FPlayer fPlayer = FPlayerManager.getPlayer(playerRecipient);
colors = fPlayer != null ? fPlayer.getColors() : null;
Expand All @@ -120,6 +111,21 @@ public static String formatString(boolean neededPermission, @NotNull String stri
.replace("&&2", colors[1]));
}

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

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

return string;
}

@NotNull
public static String formatString(@NotNull String string, @Nullable CommandSender sender) {
return formatString(string, sender, sender);
Expand Down

0 comments on commit ea5af03

Please sign in to comment.