From eb2d32eabb904df3a89f8c8adf0d348718bd73c4 Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 11 Jan 2021 09:45:17 -0500 Subject: [PATCH] Add world aliases --- .../java/com/earth2me/essentials/ISettings.java | 2 ++ .../java/com/earth2me/essentials/Settings.java | 16 ++++++++++++++++ Essentials/src/main/resources/config.yml | 6 ++++++ .../chat/EssentialsChatPlayerListenerLowest.java | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 549dcce256f..debc89e245d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -33,6 +33,8 @@ public interface ISettings extends IConf { String getChatFormat(String group); + String getWorldAlias(String world); + int getChatRadius(); int getNearRadius(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 0267ead1579..7e651ab37de 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -129,6 +129,7 @@ public class Settings implements net.ess3.api.ISettings { private Set> nickBlacklist; private double maxProjectileSpeed; private boolean removeEffectsOnHeal; + private Map worldAliases; public Settings(final IEssentials ess) { this.ess = ess; @@ -537,6 +538,20 @@ public String getChatFormat(final String group) { return mFormat; } + @Override + public String getWorldAlias(String world) { + return worldAliases.getOrDefault(world.toLowerCase(), world); + } + + private Map _getWorldAliases() { + final Map map = new HashMap<>(); + final ConfigurationSection section = config.getConfigurationSection(""); + for (String world : section.getKeys(false)) { + map.put(world.toLowerCase(), FormatUtil.replaceFormat(section.getString(world))); + } + return map; + } + @Override public boolean getAnnounceNewPlayers() { return !config.getString("newbies.announce-format", "-").isEmpty(); @@ -651,6 +666,7 @@ public void reloadConfig() { vanishingItemPolicy = _getVanishingItemsPolicy(); bindingItemPolicy = _getBindingItemsPolicy(); currencySymbol = _getCurrencySymbol(); + worldAliases = _getWorldAliases(); } void _lateLoadItemSpawnBlacklist() { diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 8947f0890eb..a9bbb1dbeb0 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -820,6 +820,12 @@ chat: # You can use permissions to control whether players can use formatting codes in their chat messages. # See https://essentialsx.net/wiki/Color-Permissions.html for more information. + # World aliases allow you to replace the world name with something different in the chat format. + # If you are using world aliases, make sure to remove the '#' at the start to allow the setting to be read. + world-aliases: + # plots: "&dP&r" + # creative: "&eC&r" + ############################################################ # +------------------------------------------------------+ # # | EssentialsX Protect | # diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 0b280a7238d..1af1b1531be 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -54,7 +54,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { String format = ess.getSettings().getChatFormat(group); format = format.replace("{0}", group); - format = format.replace("{1}", world); + format = format.replace("{1}", ess.getSettings().getWorldAlias(world)); format = format.replace("{2}", world.substring(0, 1).toUpperCase(Locale.ENGLISH)); format = format.replace("{3}", team == null ? "" : team.getPrefix()); format = format.replace("{4}", team == null ? "" : team.getSuffix());