move chat config options from config.yml -> chat.yml

This commit is contained in:
nossr50 2020-10-29 13:06:22 -07:00
parent 4bac586253
commit 8856d2b071
11 changed files with 148 additions and 75 deletions

View File

@ -1,5 +1,13 @@
Version 2.1.151
Fixed a bug where players could chat to party chat without the party chat permission
Fixed a bug where players could use the party chat command without the party chat permission
Added new config 'chat.yml'
All chat settings that used to be in 'config.yml' are now in 'chat.yml'
NOTES:
The new config file lets you disable the chat system (you can disable all of it, or just party chat, and or just admin chat) without permission nodes.
If you disable the party/admin chat, then the party/admin chat command never gets registered and attempting to use the command will result in a whole lot of nothing.
I hate adding more config files using the old .yml system, but the config update is a ways out and this works for now.
Reminder that the look/feel of party/admin chat is now determined by locale entries
Version 2.1.150
Fixed an ArrayIndexOutOfBounds exception when using /skillreset

View File

@ -4,6 +4,7 @@ import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.chat.author.ConsoleAuthor;
import com.gmail.nossr50.chat.mailer.AdminChatMailer;
import com.gmail.nossr50.chat.mailer.PartyChatMailer;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -25,12 +26,15 @@ public class ChatManager {
private final @NotNull ConsoleAuthor consoleAuthor;
private final @NotNull Audience consoleAudience;
private final boolean isChatEnabled;
public ChatManager(@NotNull mcMMO pluginRef) {
adminChatMailer = new AdminChatMailer(pluginRef);
partyChatMailer = new PartyChatMailer(pluginRef);
this.consoleAuthor = new ConsoleAuthor(LocaleLoader.getString("Chat.Identity.Console"));
this.consoleAudience = mcMMO.getAudiences().filter((cs) -> cs instanceof ConsoleCommandSender);
this.isChatEnabled = ChatConfig.getInstance().isChatEnabled();
}
/**
@ -179,5 +183,40 @@ public class ChatManager {
public void sendConsoleMessage(@NotNull Author author, @NotNull TextComponent message) {
consoleAudience.sendMessage(author, message);
}
/**
* Whether the mcMMO chat system which handles party and admin chat is enabled or disabled
* @return true if mcMMO chat processing (for party/admin chat) is enabled
*/
public boolean isChatEnabled() {
return isChatEnabled;
}
/**
* Whether or not a specific chat channel is enabled
* ChatChannels are enabled/disabled via user config
*
* If chat is disabled, this always returns false
* If NONE is passed as a {@link ChatChannel} it will return true
* @param chatChannel target chat channel
* @return true if the chat channel is enabled
*/
public boolean isChatChannelEnabled(@NotNull ChatChannel chatChannel) {
if(!isChatEnabled) {
return false;
} else {
switch(chatChannel) {
case ADMIN:
case PARTY:
case PARTY_OFFICER:
return ChatConfig.getInstance().isChatChannelEnabled(chatChannel);
case NONE:
return true;
default:
return false;
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -23,7 +24,7 @@ public class AdminAuthor implements Author {
if(overrideName != null) {
return overrideName;
} else {
if(Config.getInstance().getAdminDisplayNames()) {
if(ChatConfig.getInstance().useDisplayNames(ChatChannel.ADMIN)) {
return player.getDisplayName();
} else {
return player.getName();

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -23,7 +24,7 @@ public class PartyAuthor implements Author {
if(overrideName != null) {
return overrideName;
} else {
if(Config.getInstance().getPartyDisplayNames()) {
if(ChatConfig.getInstance().useDisplayNames(ChatChannel.PARTY)) {
return player.getDisplayName();
} else {
return player.getName();

View File

@ -5,6 +5,8 @@ import co.aikar.commands.BukkitCommandManager;
import co.aikar.commands.ConditionFailedException;
import com.gmail.nossr50.commands.chat.AdminChatCommand;
import com.gmail.nossr50.commands.chat.PartyChatCommand;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
@ -18,9 +20,9 @@ import org.jetbrains.annotations.NotNull;
* For now this class will only handle ACF converted commands, all other commands will be handled elsewhere
*/
public class CommandManager {
public static final String ADMIN_CONDITION = "adminCondition";
public static final String PARTY_CONDITION = "partyCondition";
public static final String MMO_DATA_LOADED = "mmoDataLoaded";
public static final @NotNull String ADMIN_CONDITION = "adminCondition";
public static final @NotNull String PARTY_CONDITION = "partyCondition";
public static final @NotNull String MMO_DATA_LOADED = "mmoDataLoaded";
private final @NotNull mcMMO pluginRef;
private final @NotNull BukkitCommandManager bukkitCommandManager;
@ -34,8 +36,21 @@ public class CommandManager {
}
private void registerCommands() {
bukkitCommandManager.registerCommand(new AdminChatCommand(pluginRef));
bukkitCommandManager.registerCommand(new PartyChatCommand(pluginRef));
registerChatCommands();
}
/**
* Registers chat commands if the chat system is enabled
*/
private void registerChatCommands() {
if(ChatConfig.getInstance().isChatEnabled()) {
if(ChatConfig.getInstance().isChatChannelEnabled(ChatChannel.ADMIN)) {
bukkitCommandManager.registerCommand(new AdminChatCommand(pluginRef));
}
if(ChatConfig.getInstance().isChatChannelEnabled(ChatChannel.PARTY)) {
bukkitCommandManager.registerCommand(new PartyChatCommand(pluginRef));
}
}
}
public void registerConditions() {

View File

@ -0,0 +1,51 @@
package com.gmail.nossr50.config;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.util.StringUtils;
import org.jetbrains.annotations.NotNull;
public class ChatConfig extends AutoUpdateConfigLoader {
private static ChatConfig instance;
private ChatConfig() {
super("chat.yml");
validate();
}
public static ChatConfig getInstance() {
if (instance == null) {
instance = new ChatConfig();
}
return instance;
}
@Override
protected void loadKeys() {
//Sigh this old config system...
}
@Override
protected boolean validateKeys() {
return true;
}
public boolean isChatEnabled() {
return config.getBoolean("Chat.Enable", true);
}
public boolean isChatChannelEnabled(@NotNull ChatChannel chatChannel) {
String key = "Chat.Channels." + StringUtils.getCapitalized(chatChannel.toString()) + ".Enabled";
return config.getBoolean(key, true);
}
/**
* Whether or not to use display names for players in target {@link ChatChannel}
* @param chatChannel target chat channel
* @return true if display names should be used
*/
public boolean useDisplayNames(@NotNull ChatChannel chatChannel) {
String key = "Chat.Channels." + StringUtils.getCapitalized(chatChannel.toString()) + ".Use_Display_Names";
return config.getBoolean(key, true);
}
}

View File

@ -259,13 +259,6 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); }
public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
public String getPartyChatPrefix() { return config.getString("Commands.partychat.Chat_Prefix_Format", "[[GREEN]]([[WHITE]]{0}[[GREEN]])"); }
public boolean getPartyChatColorLeaderName() { return config.getBoolean("Commands.partychat.Gold_Leader_Name", true); }
public boolean getPartyDisplayNames() { return config.getBoolean("Commands.partychat.Use_Display_Names", true); }
public String getPartyChatPrefixAlly() { return config.getString("Commands.partychat.Chat_Prefix_Format_Ally", "[[GREEN]](A)[[RESET]]"); }
public String getAdminChatPrefix() { return config.getString("Commands.adminchat.Chat_Prefix_Format", "[[AQUA]][[[WHITE]]{0}[[AQUA]]]"); }
public boolean getAdminDisplayNames() { return config.getBoolean("Commands.adminchat.Use_Display_Names", true); }
public boolean getMatchOfflinePlayers() { return config.getBoolean("Commands.Generic.Match_OfflinePlayers", false); }
public long getDatabasePlayerCooldown() { return config.getLong("Commands.Database.Player_Cooldown", 1750); }

View File

@ -1,8 +1,10 @@
package com.gmail.nossr50.datatypes.party;
import com.gmail.nossr50.chat.SamePartyPredicate;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
@ -403,7 +405,7 @@ public class Party {
List<Player> nearbyPlayerList = getNearMembers(UserManager.getPlayer(player));
boolean useDisplayNames = Config.getInstance().getPartyDisplayNames();
boolean useDisplayNames = ChatConfig.getInstance().useDisplayNames(ChatChannel.PARTY);
if(isPartyLeaderOfflineOrHidden)
{

View File

@ -1,50 +0,0 @@
package com.gmail.nossr50.runnables.party;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PartyChatTask extends BukkitRunnable {
private final Plugin plugin;
private final Party party;
private final String senderName;
private final String displayName;
private String message;
public PartyChatTask(Plugin plugin, Party party, String senderName, String displayName, String message) {
this.plugin = plugin;
this.party = party;
this.senderName = senderName;
this.displayName = displayName;
this.message = message;
}
@Override
public void run() {
if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader().getPlayerName())) {
message = message.replaceFirst(Pattern.quote(displayName), ChatColor.GOLD + Matcher.quoteReplacement(displayName) + ChatColor.RESET);
}
for (Player member : party.getOnlineMembers()) {
member.sendMessage(message);
}
if (party.getAlly() != null) {
for (Player member : party.getAlly().getOnlineMembers()) {
String allyPrefix = LocaleLoader.formatString(Config.getInstance().getPartyChatPrefixAlly());
member.sendMessage(allyPrefix + message);
}
}
plugin.getServer().getConsoleSender().sendMessage(ChatColor.stripColor("[mcMMO] [P]<" + party.getName() + ">" + message));
}
}

View File

@ -0,0 +1,20 @@
# Settings for the chat channels in mcMMO
Chat:
# Turn this off if you don't want mcMMO to process any chat (such as party chat or admin chat)
Enable: true
Channels:
Party:
# Enable or disable party chat
Enable: true
# Whether or not to use the current display name of a player
Use_Display_Names: true
Admin:
# Enable or disable party chat
Enable: true
# Whether or not to use the current display name of a player
Use_Display_Names: true
# CUSTOMIZATION INFORMATION
# If you want to customize the look and feel of chat channels, that is handled through localization which is customizeable.
# You can find information on how to handle that in the link below
# https://mcmmo.org/wiki/Locale
# When editing the locale for chat, do a search in the master text file (your local locale override file is empty at first, read the wiki article above) for "chat" and that should lead you right to the locale entries related to chat

View File

@ -575,13 +575,6 @@ Commands:
# If true, require players to have a mcmmo.commands.ptp.world.[WorldName] permission
# to teleport to, from, or within any given world.
World_Based_Permissions: false
partychat:
Chat_Prefix_Format: '[[GREEN]]([[WHITE]]{0}[[GREEN]])'
Use_Display_Names: true
Chat_Prefix_Format_Ally: '[[GREEN]](A)[[RESET]]'
adminchat:
Chat_Prefix_Format: '[[AQUA]][[[WHITE]]{0}[[AQUA]]]'
Use_Display_Names: true
#
# Settings for particles