diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 98137d25..acba07e7 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -51,6 +51,9 @@ import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.Importer; import me.lucko.luckperms.common.dependencies.DependencyManager; +import me.lucko.luckperms.common.locale.LocaleManager; +import me.lucko.luckperms.common.locale.NoopLocaleManager; +import me.lucko.luckperms.common.locale.SimpleLocaleManager; import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.UserManager; @@ -66,8 +69,7 @@ import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.DebugHandler; -import me.lucko.luckperms.common.utils.LocaleManager; -import me.lucko.luckperms.common.utils.LogFactory; +import me.lucko.luckperms.common.utils.LoggerImpl; import me.lucko.luckperms.common.utils.PermissionCache; import org.bukkit.World; @@ -139,11 +141,14 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { asyncExecutor = asyncLpExecutor; syncExecutor = r -> getServer().getScheduler().runTask(this, r); - log = LogFactory.wrap(getLogger()); + localeManager = new NoopLocaleManager(); + senderFactory = new BukkitSenderFactory(this); + log = new LoggerImpl(getConsoleSender()); + LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this); + ignoringLogs = ConcurrentHashMap.newKeySet(); shutdownHooks = Collections.synchronizedSet(new HashSet<>()); debugHandler = new DebugHandler(asyncBukkitExecutor, getVersion()); - senderFactory = new BukkitSenderFactory(this); permissionCache = new PermissionCache(asyncBukkitExecutor); getLog().info("Loading configuration..."); @@ -212,7 +217,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { }; // load locale - localeManager = new LocaleManager(); + localeManager = new SimpleLocaleManager(); File locale = new File(getDataFolder(), "lang.yml"); if (locale.exists()) { getLog().info("Found locale file. Attempting to load from it."); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index c1d7aa47..d2f3c109 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -43,6 +43,9 @@ import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.Importer; import me.lucko.luckperms.common.dependencies.DependencyManager; +import me.lucko.luckperms.common.locale.LocaleManager; +import me.lucko.luckperms.common.locale.NoopLocaleManager; +import me.lucko.luckperms.common.locale.SimpleLocaleManager; import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.UserManager; @@ -58,8 +61,7 @@ import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.DebugHandler; -import me.lucko.luckperms.common.utils.LocaleManager; -import me.lucko.luckperms.common.utils.LogFactory; +import me.lucko.luckperms.common.utils.LoggerImpl; import me.lucko.luckperms.common.utils.PermissionCache; import net.md_5.bungee.api.config.ServerInfo; @@ -105,9 +107,11 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { @Override public void onEnable() { executor = r -> getProxy().getScheduler().runAsync(this, r); - log = LogFactory.wrap(getLogger()); - debugHandler = new DebugHandler(executor, getVersion()); + localeManager = new NoopLocaleManager(); senderFactory = new BungeeSenderFactory(this); + log = new LoggerImpl(getConsoleSender()); + LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this); + debugHandler = new DebugHandler(executor, getVersion()); permissionCache = new PermissionCache(executor); getLog().info("Loading configuration..."); @@ -145,7 +149,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { }; // load locale - localeManager = new LocaleManager(); + localeManager = new SimpleLocaleManager(); File locale = new File(getDataFolder(), "lang.yml"); if (locale.exists()) { getLog().info("Found locale file. Attempting to load from it."); diff --git a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java index 73d7d9d3..85fdd5b9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java @@ -30,12 +30,14 @@ import me.lucko.luckperms.common.caching.handlers.CachedStateManager; import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.commands.BaseCommand; import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.config.LPConfiguration; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.contexts.ContextManager; import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.Importer; +import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.UserManager; @@ -43,7 +45,6 @@ import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.DebugHandler; -import me.lucko.luckperms.common.utils.LocaleManager; import me.lucko.luckperms.common.utils.PermissionCache; import java.io.File; @@ -409,4 +410,13 @@ public interface LuckPermsPlugin { } + static void sendStartupBanner(Sender sender, LuckPermsPlugin plugin) { + sender.sendMessage(Util.color("&b __ &3 __ ___ __ __ ")); + sender.sendMessage(Util.color("&b | | | / ` |__/ &3|__) |__ |__) |\\/| /__` ")); + sender.sendMessage(Util.color("&b |___ \\__/ \\__, | \\ &3| |___ | \\ | | .__/ ")); + sender.sendMessage(Util.color(" ")); + sender.sendMessage(Util.color("&2 Loading version &bv" + plugin.getVersion() + "&2 on " + plugin.getType().getFriendlyName() + " - " + plugin.getServerName())); + sender.sendMessage(Util.color(" ")); + } + } diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index 6b22677d..0ca6c89f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -36,6 +36,11 @@ public enum Message { * General & Commands */ PREFIX("&7&l[&b&lL&3&lP&7&l] &c", false), + + LOG_INFO("&7&l[&bL&3P&7&l] &3{0}", false), + LOG_WARN("&7&l[&bLuck&3Perms&7&l] &c[WARN] {0}", false), + LOG_ERROR("&7&l[&bLuck&3Perms&7&l] &4[ERROR] {0}", false), + EMPTY("{0}", true), PLAYER_ONLINE("&aOnline", false), PLAYER_OFFLINE("&cOffline", false), diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java new file mode 100644 index 00000000..39594375 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/locale/LocaleManager.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 me.lucko.luckperms.common.locale; + +import me.lucko.luckperms.common.constants.Message; + +import java.io.File; + +/** + * Manages translations + */ +public interface LocaleManager { + + void loadFromFile(File file) throws Exception; + + int getSize(); + + /** + * Gets a translation for a given message key + * @param key the key + * @return the translation, or null if there isn't a translation available. + */ + String getTranslation(Message key); + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/NoopLocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/NoopLocaleManager.java new file mode 100644 index 00000000..d7a87f7c --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/locale/NoopLocaleManager.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 me.lucko.luckperms.common.locale; + +import me.lucko.luckperms.common.constants.Message; + +import java.io.File; + +public class NoopLocaleManager implements LocaleManager { + + @Override + public void loadFromFile(File file) throws Exception { + + } + + @Override + public int getSize() { + return 0; + } + + @Override + public String getTranslation(Message key) { + return null; + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/LocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/locale/SimpleLocaleManager.java similarity index 93% rename from common/src/main/java/me/lucko/luckperms/common/utils/LocaleManager.java rename to common/src/main/java/me/lucko/luckperms/common/locale/SimpleLocaleManager.java index 6e49109d..fa8ffbe4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/LocaleManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/SimpleLocaleManager.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.utils; +package me.lucko.luckperms.common.locale; import lombok.Cleanup; @@ -34,10 +34,7 @@ import java.io.File; import java.io.FileReader; import java.util.Map; -/** - * Manages translations - */ -public class LocaleManager { +public class SimpleLocaleManager implements LocaleManager { private Map translations = null; @@ -47,10 +44,12 @@ public class LocaleManager { translations = ImmutableMap.copyOf((Map) new Yaml().load(fileReader)); } + @Override public int getSize() { return translations == null ? 0 : translations.size(); } + @Override public String getTranslation(Message key) { if (translations == null) { return null; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/LogFactory.java b/common/src/main/java/me/lucko/luckperms/common/utils/LoggerImpl.java similarity index 52% rename from common/src/main/java/me/lucko/luckperms/common/utils/LogFactory.java rename to common/src/main/java/me/lucko/luckperms/common/utils/LoggerImpl.java index f583a5d2..47b856f4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/LogFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/LoggerImpl.java @@ -22,54 +22,28 @@ package me.lucko.luckperms.common.utils; -import lombok.experimental.UtilityClass; +import lombok.AllArgsConstructor; import me.lucko.luckperms.api.Logger; +import me.lucko.luckperms.common.commands.sender.Sender; +import me.lucko.luckperms.common.constants.Message; -/** - * Utility to help create wrapped log instances - */ -@UtilityClass -public class LogFactory { - public static Logger wrap(org.slf4j.Logger l) { - return new Logger() { - private final org.slf4j.Logger logger = l; +@AllArgsConstructor +public class LoggerImpl implements Logger { + private final Sender console; - @Override - public void info(String s) { - logger.info(s); - } - - @Override - public void warn(String s) { - logger.warn(s); - } - - @Override - public void severe(String s) { - logger.error(s); - } - }; + @Override + public void info(String s) { + Message.LOG_INFO.send(console, s); } - public static Logger wrap(java.util.logging.Logger l) { - return new Logger() { - private final java.util.logging.Logger logger = l; + @Override + public void warn(String s) { + Message.LOG_WARN.send(console, s); + } - @Override - public void info(String s) { - logger.info(s); - } - - @Override - public void warn(String s) { - logger.warning(s); - } - - @Override - public void severe(String s) { - logger.severe(s); - } - }; + @Override + public void severe(String s) { + Message.LOG_ERROR.send(console, s); } } diff --git a/default-lang.yml b/default-lang.yml index 5aff01fb..8a64d3b1 100644 --- a/default-lang.yml +++ b/default-lang.yml @@ -3,6 +3,9 @@ # Author: Luck prefix: "&7&l[&b&lL&3&lP&7&l] &c" +log-info: "&7&l[&bL&3P&7&l] &3{0}" +log-warn: "&7&l[&bLuck&3Perms&7&l] &c[WARN] {0}" +log-error: "&7&l[&bLuck&3Perms&7&l] &4[ERROR] {0}" empty: "{0}" player-online: "&aOnline" player-offline: "&cOffline" diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index 88174665..6d2226fd 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -44,6 +44,9 @@ import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.Importer; import me.lucko.luckperms.common.dependencies.DependencyManager; +import me.lucko.luckperms.common.locale.LocaleManager; +import me.lucko.luckperms.common.locale.NoopLocaleManager; +import me.lucko.luckperms.common.locale.SimpleLocaleManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.impl.GenericTrackManager; import me.lucko.luckperms.common.messaging.RedisMessaging; @@ -55,8 +58,7 @@ import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.DebugHandler; -import me.lucko.luckperms.common.utils.LocaleManager; -import me.lucko.luckperms.common.utils.LogFactory; +import me.lucko.luckperms.common.utils.LoggerImpl; import me.lucko.luckperms.common.utils.PermissionCache; import me.lucko.luckperms.sponge.commands.SpongeMainCommand; import me.lucko.luckperms.sponge.contexts.WorldCalculator; @@ -160,9 +162,11 @@ public class LPSpongePlugin implements LuckPermsPlugin { @Listener(order = Order.FIRST) public void onEnable(GamePreInitializationEvent event) { - log = LogFactory.wrap(logger); - debugHandler = new DebugHandler(asyncExecutor, getVersion()); + localeManager = new NoopLocaleManager(); senderFactory = new SpongeSenderFactory(this); + log = new LoggerImpl(getConsoleSender()); + LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this); + debugHandler = new DebugHandler(asyncExecutor, getVersion()); permissionCache = new PermissionCache(asyncExecutor); timings = new LPTimings(this); @@ -202,7 +206,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { }; // load locale - localeManager = new LocaleManager(); + localeManager = new SimpleLocaleManager(); File locale = new File(getMainDir(), "lang.yml"); if (locale.exists()) { getLog().info("Found locale file. Attempting to load from it.");