mirror of
https://github.com/games647/ColorConsole.git
synced 2024-11-30 14:23:23 +01:00
Colorize only available plugin names
Do not color brackets when there other content in it
This commit is contained in:
parent
ac63c37b46
commit
b17d0ec4bd
2
pom.xml
2
pom.xml
@ -8,7 +8,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ColorConsole</name>
|
<name>ColorConsole</name>
|
||||||
<version>1.6</version>
|
<version>1.7</version>
|
||||||
<inceptionYear>2016</inceptionYear>
|
<inceptionYear>2016</inceptionYear>
|
||||||
<url>http://dev.bukkit.org/bukkit-plugins/colorconsole/</url>
|
<url>http://dev.bukkit.org/bukkit-plugins/colorconsole/</url>
|
||||||
<description>
|
<description>
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
package com.github.games647.colorconsole.bukkit;
|
package com.github.games647.colorconsole.bukkit;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.logging.log4j.core.Appender;
|
import org.apache.logging.log4j.core.Appender;
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.apache.logging.log4j.core.appender.AbstractAppender;
|
import org.apache.logging.log4j.core.appender.AbstractAppender;
|
||||||
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
|
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
|
||||||
import org.apache.logging.log4j.message.Message;
|
import org.apache.logging.log4j.message.Message;
|
||||||
import org.apache.logging.log4j.message.SimpleMessage;
|
import org.apache.logging.log4j.message.SimpleMessage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.fusesource.jansi.Ansi;
|
import org.fusesource.jansi.Ansi;
|
||||||
import org.fusesource.jansi.Ansi.Attribute;
|
import org.fusesource.jansi.Ansi.Attribute;
|
||||||
import org.fusesource.jansi.AnsiRenderer;
|
import org.fusesource.jansi.AnsiRenderer;
|
||||||
@ -20,6 +27,8 @@ public class ColorPluginAppender extends AbstractAppender {
|
|||||||
private final String reset = Ansi.ansi().a(Attribute.RESET).toString();
|
private final String reset = Ansi.ansi().a(Attribute.RESET).toString();
|
||||||
private final String defaultPluginColor;
|
private final String defaultPluginColor;
|
||||||
|
|
||||||
|
private final Set<String> pluginNames;
|
||||||
|
|
||||||
public ColorPluginAppender(Appender oldAppender, ColorConsoleBukkit plugin) {
|
public ColorPluginAppender(Appender oldAppender, ColorConsoleBukkit plugin) {
|
||||||
super(oldAppender.getName(), null, oldAppender.getLayout());
|
super(oldAppender.getName(), null, oldAppender.getLayout());
|
||||||
|
|
||||||
@ -27,6 +36,7 @@ public class ColorPluginAppender extends AbstractAppender {
|
|||||||
|
|
||||||
this.oldAppender = oldAppender;
|
this.oldAppender = oldAppender;
|
||||||
this.defaultPluginColor = format(plugin.getConfig().getString("PLUGIN"));
|
this.defaultPluginColor = format(plugin.getConfig().getString("PLUGIN"));
|
||||||
|
this.pluginNames = loadPluginNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,8 +46,8 @@ public class ColorPluginAppender extends AbstractAppender {
|
|||||||
, event.getLevel().name()));
|
, event.getLevel().name()));
|
||||||
|
|
||||||
LogEvent newEvent = new Log4jLogEvent(event.getLoggerName(), event.getMarker(), event.getFQCN()
|
LogEvent newEvent = new Log4jLogEvent(event.getLoggerName(), event.getMarker(), event.getFQCN()
|
||||||
, event.getLevel(), newMessage, event.getThrown(), event.getContextMap()
|
, event.getLevel(), newMessage, event.getThrown(), event.getContextMap(), event.getContextStack()
|
||||||
, event.getContextStack(), event.getThreadName(), event.getSource(), event.getMillis());
|
, event.getThreadName(), event.getSource(), event.getMillis());
|
||||||
oldAppender.append(newEvent);
|
oldAppender.append(newEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,6 +70,11 @@ public class ColorPluginAppender extends AbstractAppender {
|
|||||||
int endTag = message.indexOf(']', startTag);
|
int endTag = message.indexOf(']', startTag);
|
||||||
|
|
||||||
String pluginName = message.substring(startTag, endTag);
|
String pluginName = message.substring(startTag, endTag);
|
||||||
|
if (!pluginNames.contains(pluginName)) {
|
||||||
|
//it's not a plugin tag -> cancel
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
String pluginColor = plugin.getConfig().getString("P-" + pluginName);
|
String pluginColor = plugin.getConfig().getString("P-" + pluginName);
|
||||||
if (pluginColor == null) {
|
if (pluginColor == null) {
|
||||||
pluginColor = defaultPluginColor;
|
pluginColor = defaultPluginColor;
|
||||||
@ -121,4 +136,14 @@ public class ColorPluginAppender extends AbstractAppender {
|
|||||||
|
|
||||||
return ansi.toString();
|
return ansi.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> loadPluginNames() {
|
||||||
|
Builder<String> setBuilder = ImmutableSet.builder();
|
||||||
|
for (Plugin bukkitPlugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
String loggerName = bukkitPlugin.getDescription().getName();
|
||||||
|
setBuilder.add(loggerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return setBuilder.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
package com.github.games647.colorconsole.bungee;
|
package com.github.games647.colorconsole.bungee;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
import org.fusesource.jansi.Ansi;
|
import org.fusesource.jansi.Ansi;
|
||||||
import org.fusesource.jansi.Ansi.Attribute;
|
import org.fusesource.jansi.Ansi.Attribute;
|
||||||
import org.fusesource.jansi.AnsiRenderer;
|
import org.fusesource.jansi.AnsiRenderer;
|
||||||
@ -23,18 +30,20 @@ public class ColorLogFormatter extends Formatter {
|
|||||||
private final String reset = Ansi.ansi().a(Attribute.RESET).toString();
|
private final String reset = Ansi.ansi().a(Attribute.RESET).toString();
|
||||||
private final String defaultPluginColor;
|
private final String defaultPluginColor;
|
||||||
|
|
||||||
|
private final Set<String> pluginNames;
|
||||||
|
|
||||||
public ColorLogFormatter(ColorConsoleBungee plugin, Formatter oldFormatter) {
|
public ColorLogFormatter(ColorConsoleBungee plugin, Formatter oldFormatter) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.oldFormatter = oldFormatter;
|
this.oldFormatter = oldFormatter;
|
||||||
|
|
||||||
this.defaultPluginColor = format(plugin.getConfiguration().getString("PLUGIN"));
|
this.defaultPluginColor = format(plugin.getConfiguration().getString("PLUGIN"));
|
||||||
|
this.pluginNames = loadPluginNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(LogRecord record) {
|
public String format(LogRecord record) {
|
||||||
StringBuilder formatted = new StringBuilder();
|
StringBuilder formatted = new StringBuilder();
|
||||||
|
|
||||||
String levelName = record.getLevel().getName();
|
|
||||||
String levelColor = "";
|
String levelColor = "";
|
||||||
if (plugin.getConfiguration().getBoolean("colorLoggingLevel")) {
|
if (plugin.getConfiguration().getBoolean("colorLoggingLevel")) {
|
||||||
String log4JName = translateToLog4JName(record.getLevel());
|
String log4JName = translateToLog4JName(record.getLevel());
|
||||||
@ -78,6 +87,11 @@ public class ColorLogFormatter extends Formatter {
|
|||||||
int endTag = message.indexOf(']', startTag);
|
int endTag = message.indexOf(']', startTag);
|
||||||
|
|
||||||
String pluginName = message.substring(startTag, endTag);
|
String pluginName = message.substring(startTag, endTag);
|
||||||
|
if (!pluginNames.contains(pluginName)) {
|
||||||
|
//it's not a plugin tag -> cancel
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
String pluginColor = plugin.getConfiguration().getString("P-" + pluginName);
|
String pluginColor = plugin.getConfiguration().getString("P-" + pluginName);
|
||||||
if (pluginColor == null || pluginColor.isEmpty()) {
|
if (pluginColor == null || pluginColor.isEmpty()) {
|
||||||
pluginColor = defaultPluginColor;
|
pluginColor = defaultPluginColor;
|
||||||
@ -153,4 +167,14 @@ public class ColorLogFormatter extends Formatter {
|
|||||||
return "TRACE";
|
return "TRACE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> loadPluginNames() {
|
||||||
|
Builder<String> setBuilder = ImmutableSet.builder();
|
||||||
|
for (Plugin bungeePlugin : ProxyServer.getInstance().getPluginManager().getPlugins()) {
|
||||||
|
String loggerName = bungeePlugin.getDescription().getName();
|
||||||
|
setBuilder.add(loggerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return setBuilder.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,14 @@ TRACE: blue
|
|||||||
# Plugin Colors
|
# Plugin Colors
|
||||||
PLUGIN: blue
|
PLUGIN: blue
|
||||||
P-Essentials: green
|
P-Essentials: green
|
||||||
|
P-LagMonitor: red
|
||||||
P-WorldEdit: red
|
P-WorldEdit: red
|
||||||
|
P-FastLogin: cyan
|
||||||
P-WorldGuard: cyan
|
P-WorldGuard: cyan
|
||||||
P-Vault: magenta
|
P-Vault: magenta
|
||||||
|
P-ChangeSkin: yellow
|
||||||
|
P-ScoreboardStats: white
|
||||||
|
P-mcMMOAction: blue
|
||||||
|
|
||||||
# Available foreground colors | Available background colors
|
# Available foreground colors | Available background colors
|
||||||
# Black | BG_Black
|
# Black | BG_Black
|
||||||
|
Loading…
Reference in New Issue
Block a user