Colorize console info messages

This commit is contained in:
Luck 2017-01-19 19:51:41 +00:00
parent 8aa7d272fa
commit 241507228f
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
10 changed files with 158 additions and 63 deletions

View File

@ -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.");

View File

@ -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.");

View File

@ -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(" "));
}
}

View File

@ -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),

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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);
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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;
}
}

View File

@ -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<String, String> translations = null;
@ -47,10 +44,12 @@ public class LocaleManager {
translations = ImmutableMap.copyOf((Map<String, String>) 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;

View File

@ -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);
Message.LOG_INFO.send(console, s);
}
@Override
public void warn(String s) {
logger.warn(s);
Message.LOG_WARN.send(console, s);
}
@Override
public void severe(String s) {
logger.error(s);
}
};
}
public static Logger wrap(java.util.logging.Logger l) {
return new Logger() {
private final java.util.logging.Logger logger = l;
@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);
}
};
Message.LOG_ERROR.send(console, s);
}
}

View File

@ -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"

View File

@ -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.");