mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 18:24:43 +02:00
move chat config options from config.yml -> chat.yml
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
51
src/main/java/com/gmail/nossr50/config/ChatConfig.java
Normal file
51
src/main/java/com/gmail/nossr50/config/ChatConfig.java
Normal 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);
|
||||
}
|
||||
}
|
@ -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); }
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user