diff --git a/bukkit/acf-bukkit.iml b/bukkit/acf-bukkit.iml index 1d608a14..cd9c9205 100644 --- a/bukkit/acf-bukkit.iml +++ b/bukkit/acf-bukkit.iml @@ -19,8 +19,9 @@ + - + diff --git a/bungee/acf-bungee.iml b/bungee/acf-bungee.iml index 51d9b321..8bcf1ab8 100644 --- a/bungee/acf-bungee.iml +++ b/bungee/acf-bungee.iml @@ -19,6 +19,7 @@ + diff --git a/core/acf-core.iml b/core/acf-core.iml index 143048f3..2c3840b4 100644 --- a/core/acf-core.iml +++ b/core/acf-core.iml @@ -18,5 +18,6 @@ + \ No newline at end of file diff --git a/core/pom.xml b/core/pom.xml index 0c241d05..f34f4908 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -51,6 +51,39 @@ annotations 15.0 + + co.aikar + locales + 1.0-SNAPSHOT + compile + - + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + + package + + shade + + + + + ${project.build.directory}/dependency-reduced-pom.xml + + true + + + co.aikar.locales + co.aikar.commands.locales + + + + + + diff --git a/core/src/main/java/co/aikar/commands/CommandManager.java b/core/src/main/java/co/aikar/commands/CommandManager.java index daa93acb..bd5ed2dd 100644 --- a/core/src/main/java/co/aikar/commands/CommandManager.java +++ b/core/src/main/java/co/aikar/commands/CommandManager.java @@ -23,6 +23,8 @@ package co.aikar.commands; +import co.aikar.locales.MessageKey; + import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.EnumMap; @@ -41,7 +43,7 @@ abstract class CommandManager { protected ExceptionHandler defaultExceptionHandler = null; protected Map formatters = new IdentityHashMap<>(); { - MessageFormatter plain = new MessageFormatter() { + MessageFormatter plain = new MessageFormatter() { @Override String format(Object color, String message) { return message; @@ -151,8 +153,7 @@ abstract class CommandManager { protected void sendMessage(Object issuerArg, MessageType type, MessageKey key, String... replacements) { CommandIssuer issuer = issuerArg instanceof CommandIssuer ? (CommandIssuer) issuerArg : getCommandIssuer(issuerArg); - Locale locale = getIssuerLocale(issuer); - String message = getLocales().getMessage(locale, key); + String message = getLocales().getMessage(issuer, key); if (replacements.length > 0) { message = ACFUtil.replaceStrings(message, replacements); } diff --git a/core/src/main/java/co/aikar/commands/LanguageTable.java b/core/src/main/java/co/aikar/commands/LanguageTable.java deleted file mode 100644 index 6166f4b6..00000000 --- a/core/src/main/java/co/aikar/commands/LanguageTable.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -import com.google.common.collect.Maps; -import org.jetbrains.annotations.NotNull; - -import java.util.Locale; -import java.util.Map; - -class LanguageTable { - - private final Locale locale; - private final Map messages = Maps.newHashMap(); - - LanguageTable(Locale locale) { - this.locale = locale; - } - - public String addMessage(MessageKey key, String message) { - return messages.put(key, message); - } - - public String getMessage(MessageKey key) { - return messages.get(key); - } - - public void addMessages(@NotNull Map messages) { - this.messages.putAll(messages); - } -} diff --git a/core/src/main/java/co/aikar/commands/Locales.java b/core/src/main/java/co/aikar/commands/Locales.java index 0923cd58..57c40a1d 100644 --- a/core/src/main/java/co/aikar/commands/Locales.java +++ b/core/src/main/java/co/aikar/commands/Locales.java @@ -23,12 +23,12 @@ package co.aikar.commands; -import com.google.common.collect.Maps; +import co.aikar.locales.LocaleManager; +import co.aikar.locales.MessageKey; import org.jetbrains.annotations.NotNull; import java.util.Locale; import java.util.Map; -import java.util.Objects; /** * This isn't public yet, still WIP - API will break @@ -38,17 +38,16 @@ import java.util.Objects; @Deprecated public class Locales { - private Locale defaultLocale = Locale.ENGLISH; private final CommandManager manager; - private final Map tables = Maps.newHashMap(); + private final LocaleManager localeManager; Locales(CommandManager manager) { this.manager = manager; + this.localeManager = LocaleManager.create(manager::getIssuerLocale); this.initializeSystemMessages(); } private void initializeSystemMessages() { - LanguageTable table = getTable(Locale.ENGLISH); //table.addMessage(MessageKey.FOO, "bar"); } @@ -58,31 +57,23 @@ public class Locales { * @return Previous default locale */ public Locale setDefaultLocale(Locale locale) { - Locale prev = this.defaultLocale; - this.defaultLocale = locale; - return prev; + return localeManager.setDefaultLocale(locale); } public Locale getDefaultLocale() { - return defaultLocale; + return localeManager.getDefaultLocale(); } public void addMessages(Locale locale, @NotNull Map messages) { - getTable(locale).addMessages(messages); + localeManager.addMessages(locale, messages); } public String addMessage(Locale locale, MessageKey key, String message) { - return getTable(locale).addMessage(key, message); + return localeManager.addMessage(locale, key, message); } - public String getMessage(Locale locale, MessageKey key) { - String message = getTable(locale).getMessage(key); - if (message == null && !Objects.equals(locale, defaultLocale)) { - message = getTable(defaultLocale).getMessage(key); - } - if (message == null && !Objects.equals(Locale.ENGLISH, defaultLocale) && !Objects.equals(Locale.ENGLISH, locale)) { - message = getTable(Locale.ENGLISH).getMessage(key); - } + public String getMessage(CommandIssuer issuer, MessageKey key) { + String message = localeManager.getMessage(issuer, key); if (message == null) { manager.log(LogLevel.ERROR, "Missing Language Key: " + key); message = ""; @@ -90,8 +81,5 @@ public class Locales { return message; } - public LanguageTable getTable(Locale locale) { - return tables.computeIfAbsent(locale, LanguageTable::new); - } } diff --git a/core/src/main/java/co/aikar/commands/MessageKey.java b/core/src/main/java/co/aikar/commands/MessageKey.java deleted file mode 100644 index 500a7065..00000000 --- a/core/src/main/java/co/aikar/commands/MessageKey.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -@Deprecated -public class MessageKey { - private static final AtomicInteger counter = new AtomicInteger(); - private static final Map keyMap = new ConcurrentHashMap<>(); - private final int id = counter.getAndIncrement(); - private final String key; - - private MessageKey(String key) { - this.key = key; - } - - public static MessageKey of(String key) { - return keyMap.computeIfAbsent(key.toLowerCase(), MessageKey::new); - } - - public int hashCode() { - return id; - } - - @Override - public boolean equals(Object o) { - return (this == o); - } - - public String getKey() { - return key; - } -} diff --git a/example/acf-example.iml b/example/acf-example.iml index 6dc644cd..a6b5d1a6 100644 --- a/example/acf-example.iml +++ b/example/acf-example.iml @@ -36,6 +36,7 @@ + diff --git a/paper/acf-paper.iml b/paper/acf-paper.iml index cb34f812..70d01850 100644 --- a/paper/acf-paper.iml +++ b/paper/acf-paper.iml @@ -2,11 +2,7 @@ - - - BUKKIT - - + @@ -20,15 +16,9 @@ + - - - - - - - - + \ No newline at end of file diff --git a/sponge/acf-sponge.iml b/sponge/acf-sponge.iml index 8b98d79d..a15a7211 100644 --- a/sponge/acf-sponge.iml +++ b/sponge/acf-sponge.iml @@ -19,6 +19,7 @@ +