mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Players & Console can now use color codes in party or admin chat (new permission node mcmmo.chat.colors)
This commit is contained in:
parent
1d55c4c2bc
commit
d183d1217c
@ -1,6 +1,8 @@
|
|||||||
Version 2.1.150
|
Version 2.1.150
|
||||||
mcMMO should now be compatible with 1.16.4's new social features
|
mcMMO should now be compatible with 1.16.4's new social features
|
||||||
mcMMO Party & Admin Chat have had a rewrite, work was put in to make sure their API would be mostly compatible with the old one
|
mcMMO Party & Admin Chat have had a rewrite, work was put in to make sure their API would be mostly compatible with the old one
|
||||||
|
Players & Console can now use color codes (including stuff like &a or [[GREEN]]) in party or admin chat
|
||||||
|
Added new permission node 'mcmmo.chat.colors' which allows players to use color codes, negate to disallow this
|
||||||
The style and look of admin/party chat is now determined by locale file instead of options in config.yml
|
The style and look of admin/party chat is now determined by locale file instead of options in config.yml
|
||||||
Improved messages players recieve when they toggle on or off admin or party chat
|
Improved messages players recieve when they toggle on or off admin or party chat
|
||||||
All locale files have had [[]] color codes replaced by & color codes, you can still use [[GOLD]] and stuff if you want
|
All locale files have had [[]] color codes replaced by & color codes, you can still use [[GOLD]] and stuff if you want
|
||||||
|
@ -60,10 +60,10 @@ public class ChatManager {
|
|||||||
private void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull ChatChannel chatChannel, @NotNull String rawMessage, boolean isAsync) {
|
private void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull ChatChannel chatChannel, @NotNull String rawMessage, boolean isAsync) {
|
||||||
switch (chatChannel) {
|
switch (chatChannel) {
|
||||||
case ADMIN:
|
case ADMIN:
|
||||||
adminChatMailer.processChatMessage(mmoPlayer.getAdminAuthor(), rawMessage, isAsync);
|
adminChatMailer.processChatMessage(mmoPlayer.getAdminAuthor(), rawMessage, isAsync, Permissions.colorChat(mmoPlayer.getPlayer()));
|
||||||
break;
|
break;
|
||||||
case PARTY:
|
case PARTY:
|
||||||
partyChatMailer.processChatMessage(mmoPlayer.getPartyAuthor(), rawMessage, mmoPlayer.getParty(), isAsync);
|
partyChatMailer.processChatMessage(mmoPlayer.getPartyAuthor(), rawMessage, mmoPlayer.getParty(), isAsync, Permissions.colorChat(mmoPlayer.getPlayer()));
|
||||||
break;
|
break;
|
||||||
case PARTY_OFFICER:
|
case PARTY_OFFICER:
|
||||||
case NONE:
|
case NONE:
|
||||||
@ -76,7 +76,7 @@ public class ChatManager {
|
|||||||
* @param rawMessage raw message from the console
|
* @param rawMessage raw message from the console
|
||||||
*/
|
*/
|
||||||
public void processConsoleMessage(@NotNull String rawMessage) {
|
public void processConsoleMessage(@NotNull String rawMessage) {
|
||||||
adminChatMailer.processChatMessage(getConsoleAuthor(), rawMessage, false);
|
adminChatMailer.processChatMessage(getConsoleAuthor(), rawMessage, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +93,7 @@ public class ChatManager {
|
|||||||
* @param party target party
|
* @param party target party
|
||||||
*/
|
*/
|
||||||
public void processConsoleMessage(@NotNull String rawMessage, @NotNull Party party) {
|
public void processConsoleMessage(@NotNull String rawMessage, @NotNull Party party) {
|
||||||
partyChatMailer.processChatMessage(getConsoleAuthor(), rawMessage, party, false);
|
partyChatMailer.processChatMessage(getConsoleAuthor(), rawMessage, party, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,14 @@ public class AdminAuthor implements Author {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getOverrideName() {
|
||||||
|
return overrideName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setName(@NotNull String newName) {
|
public void setName(@NotNull String newName) {
|
||||||
overrideName = newName;
|
overrideName = newName;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.chat.mailer;
|
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.author.Author;
|
||||||
import com.gmail.nossr50.chat.message.AdminChatMessage;
|
import com.gmail.nossr50.chat.message.AdminChatMessage;
|
||||||
import com.gmail.nossr50.chat.message.ChatMessage;
|
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.events.chat.McMMOChatEvent;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -48,10 +51,15 @@ public class AdminChatMailer extends AbstractChatMailer {
|
|||||||
* Styles a string using a locale entry
|
* Styles a string using a locale entry
|
||||||
* @param author message author
|
* @param author message author
|
||||||
* @param message message contents
|
* @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
|
* @return the styled string, based on a locale entry
|
||||||
*/
|
*/
|
||||||
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message) {
|
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message, boolean canColor) {
|
||||||
return Component.text(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(), message));
|
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
|
@Override
|
||||||
@ -59,8 +67,8 @@ public class AdminChatMailer extends AbstractChatMailer {
|
|||||||
chatMessage.sendMessage();
|
chatMessage.sendMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processChatMessage(@NotNull Author author, @NotNull String rawString, boolean isAsync) {
|
public void processChatMessage(@NotNull Author author, @NotNull String rawString, boolean isAsync, boolean canColor) {
|
||||||
AdminChatMessage chatMessage = new AdminChatMessage(pluginRef, author, constructAudience(), rawString, addStyle(author, rawString));
|
AdminChatMessage chatMessage = new AdminChatMessage(pluginRef, author, constructAudience(), rawString, addStyle(author, rawString, canColor));
|
||||||
|
|
||||||
McMMOChatEvent chatEvent = new McMMOAdminChatEvent(pluginRef, chatMessage, isAsync);
|
McMMOChatEvent chatEvent = new McMMOAdminChatEvent(pluginRef, chatMessage, isAsync);
|
||||||
Bukkit.getPluginManager().callEvent(chatEvent);
|
Bukkit.getPluginManager().callEvent(chatEvent);
|
||||||
|
@ -21,8 +21,8 @@ public class PartyChatMailer extends AbstractChatMailer {
|
|||||||
super(pluginRef);
|
super(pluginRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processChatMessage(@NotNull Author author, @NotNull String rawString, @NotNull Party party, boolean isAsync) {
|
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), party);
|
PartyChatMessage chatMessage = new PartyChatMessage(pluginRef, author, constructPartyAudience(party), rawString, addStyle(author, rawString, canColor), party);
|
||||||
|
|
||||||
McMMOChatEvent chatEvent = new McMMOPartyChatEvent(pluginRef, chatMessage, party, isAsync);
|
McMMOChatEvent chatEvent = new McMMOPartyChatEvent(pluginRef, chatMessage, party, isAsync);
|
||||||
Bukkit.getPluginManager().callEvent(chatEvent);
|
Bukkit.getPluginManager().callEvent(chatEvent);
|
||||||
@ -36,8 +36,19 @@ public class PartyChatMailer extends AbstractChatMailer {
|
|||||||
return mcMMO.getAudiences().filter(party.getSamePartyPredicate());
|
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
|
@Override
|
||||||
|
@ -128,7 +128,7 @@ public final class LocaleLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String addColors(String input) {
|
public static String addColors(String input) {
|
||||||
input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString());
|
input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString());
|
||||||
input = input.replaceAll("\\Q[[DARK_BLUE]]\\E", ChatColor.DARK_BLUE.toString());
|
input = input.replaceAll("\\Q[[DARK_BLUE]]\\E", ChatColor.DARK_BLUE.toString());
|
||||||
input = input.replaceAll("\\Q[[DARK_GREEN]]\\E", ChatColor.DARK_GREEN.toString());
|
input = input.replaceAll("\\Q[[DARK_GREEN]]\\E", ChatColor.DARK_GREEN.toString());
|
||||||
|
@ -39,6 +39,7 @@ public final class Permissions {
|
|||||||
/* CHAT */
|
/* CHAT */
|
||||||
public static boolean partyChat(Permissible permissible) { return permissible.hasPermission("mcmmo.chat.partychat"); }
|
public static boolean partyChat(Permissible permissible) { return permissible.hasPermission("mcmmo.chat.partychat"); }
|
||||||
public static boolean adminChat(Permissible permissible) { return permissible.hasPermission("mcmmo.chat.adminchat"); }
|
public static boolean adminChat(Permissible permissible) { return permissible.hasPermission("mcmmo.chat.adminchat"); }
|
||||||
|
public static boolean colorChat(Permissible permissible) { return permissible.hasPermission("mcmmo.chat.colors"); }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* COMMANDS
|
* COMMANDS
|
||||||
|
@ -746,12 +746,15 @@ permissions:
|
|||||||
mcmmo.chat.all:
|
mcmmo.chat.all:
|
||||||
description: Implies all mcmmo.chat permissions. (Warning, contains adminchat)
|
description: Implies all mcmmo.chat permissions. (Warning, contains adminchat)
|
||||||
children:
|
children:
|
||||||
mcmmo.chat.adminchat: true
|
mcmmo.chat.adminchat: true
|
||||||
mcmmo.chat.partychat: true
|
mcmmo.chat.partychat: true
|
||||||
|
mcmmo.chat.colors: true
|
||||||
mcmmo.chat.adminchat:
|
mcmmo.chat.adminchat:
|
||||||
description: Allows participation in admin chat
|
description: Allows participation in admin chat
|
||||||
mcmmo.chat.partychat:
|
mcmmo.chat.partychat:
|
||||||
description: Allows participation in party chat
|
description: Allows participation in party chat
|
||||||
|
mcmmo.chat.colors:
|
||||||
|
description: players can use color codes like &a or [[GREEN]] in mcMMO chat channels
|
||||||
mcmmo.motd:
|
mcmmo.motd:
|
||||||
description: Allows access to the motd
|
description: Allows access to the motd
|
||||||
mcmmo.commands.*:
|
mcmmo.commands.*:
|
||||||
@ -1297,6 +1300,7 @@ permissions:
|
|||||||
mcmmo.commands.defaults: true
|
mcmmo.commands.defaults: true
|
||||||
mcmmo.motd: true
|
mcmmo.motd: true
|
||||||
mcmmo.skills.all: true
|
mcmmo.skills.all: true
|
||||||
|
mcmmo.chat.colors: true
|
||||||
mcmmo.defaultsop:
|
mcmmo.defaultsop:
|
||||||
default: op
|
default: op
|
||||||
description: mcmmo permissions that default to op
|
description: mcmmo permissions that default to op
|
||||||
|
Loading…
Reference in New Issue
Block a user