mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-30 04:34:43 +02:00
Players & Console can now use color codes in party or admin chat (new permission node mcmmo.chat.colors)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.chat.mailer;
|
||||
|
||||
import com.gmail.nossr50.chat.author.AdminAuthor;
|
||||
import com.gmail.nossr50.chat.author.Author;
|
||||
import com.gmail.nossr50.chat.message.AdminChatMessage;
|
||||
import com.gmail.nossr50.chat.message.ChatMessage;
|
||||
@ -7,12 +8,14 @@ import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
|
||||
import com.gmail.nossr50.events.chat.McMMOChatEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -48,10 +51,15 @@ public class AdminChatMailer extends AbstractChatMailer {
|
||||
* Styles a string using a locale entry
|
||||
* @param author message author
|
||||
* @param message message contents
|
||||
* @param canColor whether to replace colors codes with colors in the raw message
|
||||
* @return the styled string, based on a locale entry
|
||||
*/
|
||||
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message) {
|
||||
return Component.text(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(), message));
|
||||
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message, boolean canColor) {
|
||||
if(canColor) {
|
||||
return Component.text(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(), LocaleLoader.addColors(message)));
|
||||
} else {
|
||||
return Component.text(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(), message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,8 +67,8 @@ public class AdminChatMailer extends AbstractChatMailer {
|
||||
chatMessage.sendMessage();
|
||||
}
|
||||
|
||||
public void processChatMessage(@NotNull Author author, @NotNull String rawString, boolean isAsync) {
|
||||
AdminChatMessage chatMessage = new AdminChatMessage(pluginRef, author, constructAudience(), rawString, addStyle(author, rawString));
|
||||
public void processChatMessage(@NotNull Author author, @NotNull String rawString, boolean isAsync, boolean canColor) {
|
||||
AdminChatMessage chatMessage = new AdminChatMessage(pluginRef, author, constructAudience(), rawString, addStyle(author, rawString, canColor));
|
||||
|
||||
McMMOChatEvent chatEvent = new McMMOAdminChatEvent(pluginRef, chatMessage, isAsync);
|
||||
Bukkit.getPluginManager().callEvent(chatEvent);
|
||||
|
@ -21,8 +21,8 @@ public class PartyChatMailer extends AbstractChatMailer {
|
||||
super(pluginRef);
|
||||
}
|
||||
|
||||
public void processChatMessage(@NotNull Author author, @NotNull String rawString, @NotNull Party party, boolean isAsync) {
|
||||
PartyChatMessage chatMessage = new PartyChatMessage(pluginRef, author, constructPartyAudience(party), rawString, addStyle(author, rawString), party);
|
||||
public void processChatMessage(@NotNull Author author, @NotNull String rawString, @NotNull Party party, boolean isAsync, boolean canColor) {
|
||||
PartyChatMessage chatMessage = new PartyChatMessage(pluginRef, author, constructPartyAudience(party), rawString, addStyle(author, rawString, canColor), party);
|
||||
|
||||
McMMOChatEvent chatEvent = new McMMOPartyChatEvent(pluginRef, chatMessage, party, isAsync);
|
||||
Bukkit.getPluginManager().callEvent(chatEvent);
|
||||
@ -36,8 +36,19 @@ public class PartyChatMailer extends AbstractChatMailer {
|
||||
return mcMMO.getAudiences().filter(party.getSamePartyPredicate());
|
||||
}
|
||||
|
||||
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message) {
|
||||
return Component.text(LocaleLoader.getString("Chat.Style.Party", author.getAuthoredName(), message));
|
||||
/**
|
||||
* Styles a string using a locale entry
|
||||
* @param author message author
|
||||
* @param message message contents
|
||||
* @param canColor whether to replace colors codes with colors in the raw message
|
||||
* @return the styled string, based on a locale entry
|
||||
*/
|
||||
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message, boolean canColor) {
|
||||
if(canColor) {
|
||||
return Component.text(LocaleLoader.getString("Chat.Style.Party", author.getAuthoredName(), LocaleLoader.addColors(message)));
|
||||
} else {
|
||||
return Component.text(LocaleLoader.getString("Chat.Style.Party", author.getAuthoredName(), message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user