2019-07-08 17:55:14 +00:00
|
|
|
/*
|
2019-07-11 21:30:35 +00:00
|
|
|
* Copyright (c) 2019 GeyserMC. http://geysermc.org
|
2019-07-08 17:55:14 +00:00
|
|
|
*
|
2019-07-11 21:30:35 +00:00
|
|
|
* 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:
|
2019-07-08 17:55:14 +00:00
|
|
|
*
|
2019-07-11 21:30:35 +00:00
|
|
|
* 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.
|
2019-07-08 17:55:14 +00:00
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.api;
|
|
|
|
|
|
|
|
public class ChatColor {
|
|
|
|
|
|
|
|
public static final char ESCAPE = '§';
|
|
|
|
public static final String BLACK = ESCAPE + "0";
|
|
|
|
public static final String DARK_BLUE = ESCAPE + "1";
|
|
|
|
public static final String DARK_GREEN = ESCAPE + "2";
|
|
|
|
public static final String DARK_AQUA = ESCAPE + "3";
|
|
|
|
public static final String DARK_RED = ESCAPE + "4";
|
|
|
|
public static final String DARK_PURPLE = ESCAPE + "5";
|
|
|
|
public static final String GOLD = ESCAPE + "6";
|
|
|
|
public static final String GRAY = ESCAPE + "7";
|
|
|
|
public static final String DARK_GRAY = ESCAPE + "8";
|
|
|
|
public static final String BLUE = ESCAPE + "9";
|
|
|
|
public static final String GREEN = ESCAPE + "a";
|
|
|
|
public static final String AQUA = ESCAPE + "b";
|
|
|
|
public static final String RED = ESCAPE + "c";
|
|
|
|
public static final String LIGHT_PURPLE = ESCAPE + "d";
|
|
|
|
public static final String YELLOW = ESCAPE + "e";
|
|
|
|
public static final String WHITE = ESCAPE + "f";
|
|
|
|
public static final String OBFUSCATED = ESCAPE + "k";
|
|
|
|
public static final String BOLD = ESCAPE + "l";
|
|
|
|
public static final String STRIKETHROUGH = ESCAPE + "m";
|
|
|
|
public static final String UNDERLINE = ESCAPE + "n";
|
|
|
|
public static final String ITALIC = ESCAPE + "o";
|
|
|
|
public static final String RESET = ESCAPE + "r";
|
|
|
|
|
|
|
|
public static String toANSI(String string) {
|
2019-07-13 19:00:51 +00:00
|
|
|
string = string.replace(BOLD, (char) 0x1b + "[1m");
|
|
|
|
string = string.replace(OBFUSCATED, (char) 0x1b + "[5m");
|
2019-07-08 17:55:14 +00:00
|
|
|
string = string.replace(ITALIC, (char) 0x1b + "[3m");
|
|
|
|
string = string.replace(UNDERLINE, (char) 0x1b + "[4m");
|
|
|
|
string = string.replace(STRIKETHROUGH, (char) 0x1b + "[9m");
|
|
|
|
string = string.replace(RESET, (char) 0x1b + "[0m");
|
|
|
|
string = string.replace(BLACK, (char) 0x1b + "[0;30m");
|
|
|
|
string = string.replace(DARK_BLUE, (char) 0x1b + "[0;34m");
|
|
|
|
string = string.replace(DARK_GREEN, (char) 0x1b + "[0;32m");
|
|
|
|
string = string.replace(DARK_AQUA, (char) 0x1b + "[0;36m");
|
|
|
|
string = string.replace(DARK_RED, (char) 0x1b + "[0;31m");
|
|
|
|
string = string.replace(DARK_PURPLE, (char) 0x1b + "[0;35m");
|
|
|
|
string = string.replace(GOLD, (char) 0x1b + "[0;33m");
|
|
|
|
string = string.replace(GRAY, (char) 0x1b + "[0;37m");
|
|
|
|
string = string.replace(DARK_GRAY, (char) 0x1b + "[30;1m");
|
|
|
|
string = string.replace(BLUE, (char) 0x1b + "[34;1m");
|
|
|
|
string = string.replace(GREEN, (char) 0x1b + "[32;1m");
|
|
|
|
string = string.replace(AQUA, (char) 0x1b + "[36;1m");
|
|
|
|
string = string.replace(RED, (char) 0x1b + "[31;1m");
|
|
|
|
string = string.replace(LIGHT_PURPLE, (char) 0x1b + "[35;1m");
|
|
|
|
string = string.replace(YELLOW, (char) 0x1b + "[33;1m");
|
|
|
|
string = string.replace(WHITE, (char) 0x1b + "[37;1m");
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String translateAlternateColorCodes(char color, String message) {
|
|
|
|
return message.replace(color, ESCAPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String stripColors(String message) {
|
|
|
|
return message = message.replaceAll("(&([a-fk-or0-9]))","").replaceAll("(§([a-fk-or0-9]))","").replaceAll("s/\\x1b\\[[0-9;]*[a-zA-Z]//g","");
|
|
|
|
}
|
|
|
|
}
|