Improve comments/strip ChatColors
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 Ronald Jack Jenkins Jr.
|
||||
Copyright (C) 2016-2017 Ronald Jack Jenkins Jr., SLF4Bukkit contributors.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Ronald Jack Jenkins Jr.
|
||||
* Copyright (C) 2016-2017 Ronald Jack Jenkins Jr., SLF4Bukkit contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,28 +25,20 @@ import org.fusesource.jansi.Ansi.Attribute;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Maps {@link ChatColor} values to their Jansi equivalents.
|
||||
*
|
||||
* <p>This class might not always be instantiable as Jansi might not be present at runtime.</p>
|
||||
* Maps {@link ChatColor} values to their JAnsi equivalents.
|
||||
*
|
||||
* @author Ronald Jack Jenkins Jr.
|
||||
*/
|
||||
final class AnsiColorMapper implements ColorMapper {
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* No-op constructor. Callers must catch {@code Throwable} and handle the
|
||||
* scenario in which JAnsi is not available by substituting another
|
||||
* {@link ColorMapper} implementation.
|
||||
*
|
||||
* <p>This class relies on Jansi. If this dependency is not present at runtime, it cannot be initialized as the JVM
|
||||
* raises a {@code Throwable} due to missing dependencies.</p>
|
||||
*
|
||||
* <p>In this case callers of this constructor should fall back to an alternative {@code ColorMapper}
|
||||
* implementation.</p>
|
||||
*
|
||||
* @throws Throwable if Jansi is not present at runtime
|
||||
* @throws Throwable if JAnsi is not present at runtime.
|
||||
*/
|
||||
AnsiColorMapper() throws Throwable {
|
||||
//see javadoc
|
||||
}
|
||||
AnsiColorMapper() throws Throwable {}
|
||||
|
||||
// @formatter:off
|
||||
private final Map<ChatColor, String> MAP = ImmutableMap.<ChatColor, String>builder()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Ronald Jack Jenkins Jr.
|
||||
* Copyright (C) 2016-2017 Ronald Jack Jenkins Jr., SLF4Bukkit contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,13 +19,15 @@ package info.ronjenkins.slf4bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Utility class that maps {@link ChatColor} values to their equivalents,
|
||||
* so that messages logged to the console are formatted correctly.
|
||||
* Implementations of this interface map {@link ChatColor} values to their
|
||||
* equivalents, based on what the current Bukkit implementation supports.
|
||||
*
|
||||
* @author Ronald Jack Jenkins Jr.
|
||||
*/
|
||||
public interface ColorMapper {
|
||||
|
||||
/**
|
||||
* Translates {@link ChatColor} directives to their equivalents.
|
||||
* Translates {@link ChatColor} directives to their string equivalents.
|
||||
*
|
||||
* @param input
|
||||
* null is coerced to the empty string.
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2017 TheE, Ronald Jack Jenkins Jr, SLF4Bukkit contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package info.ronjenkins.slf4bukkit;
|
||||
|
||||
/**
|
||||
* Creates {@code ColorMapper} instances.
|
||||
* Creates the {@link ColorMapper} instance that best suits the capabilities of
|
||||
* the current Bukkit environment.
|
||||
*
|
||||
* @see ColorMapper
|
||||
* @author TheE
|
||||
*/
|
||||
public final class ColorMapperFactory {
|
||||
|
||||
/**
|
||||
* Creates an new {@code ColorMapper} instance.
|
||||
*
|
||||
* @return a new instance
|
||||
* @return never null.
|
||||
*/
|
||||
public static ColorMapper create() {
|
||||
try {
|
||||
|
||||
@@ -1,12 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2017 TheE, Ronald Jack Jenkins Jr, SLF4Bukkit contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package info.ronjenkins.slf4bukkit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Does not do any mapping but simply returns the given string or, if {@code null} is given, an empty string.
|
||||
* Strips all {@link ChatColor}s from the input string.
|
||||
*
|
||||
* @author TheE
|
||||
*/
|
||||
final class NotSupportedColorMapper implements ColorMapper {
|
||||
|
||||
@Override
|
||||
public String map(final String input) {
|
||||
return input == null ? "" : input;
|
||||
if (input == null) {
|
||||
return "";
|
||||
}
|
||||
String output = input;
|
||||
for (final ChatColor chatColor : ChatColor.values()) {
|
||||
output = output.replace(chatColor.toString(), "");
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
/*
|
||||
* Portions of this file are
|
||||
* Copyright (C) 2016 Ronald Jack Jenkins Jr.
|
||||
* Copyright (C) 2016-2017 Ronald Jack Jenkins Jr., SLF4Bukkit contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -181,6 +181,14 @@ import com.google.common.collect.ImmutableMap;
|
||||
* of markers does not affect whether or not a given logging level is enabled.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When executed on a Bukkit implementation that does not contain the JAnsi
|
||||
* library (e.g. PaperSpigot), all color-related functionality is silently
|
||||
* ignored. Any messages logged in such an environment by SLF4Bukkit will have
|
||||
* any {@link ChatColor} values stripped. SLF4Bukkit does not emit any warnings
|
||||
* when executed in an environment where JAnsi is not available.
|
||||
* </p>
|
||||
*
|
||||
* @author Ceki Gülcü
|
||||
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
|
||||
* @author Rod Waldhoff
|
||||
|
||||
Reference in New Issue
Block a user