mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 02:19:05 +00:00
Merge branch 'hex-color-perms'
This commit is contained in:
commit
dd52843c68
@ -27,6 +27,9 @@ public class Me extends MineverseCommand {
|
|||||||
if(sender instanceof Player && MineverseChatAPI.getMineverseChatPlayer((Player) sender).hasFilter()) {
|
if(sender instanceof Player && MineverseChatAPI.getMineverseChatPlayer((Player) sender).hasFilter()) {
|
||||||
msg = Format.FilterChat(msg);
|
msg = Format.FilterChat(msg);
|
||||||
}
|
}
|
||||||
|
if(sender.hasPermission("venturechat.color.legacy")) {
|
||||||
|
msg = Format.FormatStringLegacyColor(msg);
|
||||||
|
}
|
||||||
if(sender.hasPermission("venturechat.color"))
|
if(sender.hasPermission("venturechat.color"))
|
||||||
msg = Format.FormatStringColor(msg);
|
msg = Format.FormatStringColor(msg);
|
||||||
if(sender.hasPermission("venturechat.format"))
|
if(sender.hasPermission("venturechat.format"))
|
||||||
|
@ -285,6 +285,9 @@ public class Party extends MineverseCommand {
|
|||||||
if(mcp.hasFilter()) {
|
if(mcp.hasFilter()) {
|
||||||
msg = Format.FilterChat(msg);
|
msg = Format.FilterChat(msg);
|
||||||
}
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
msg = Format.FormatStringLegacyColor(msg);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
msg = Format.FormatStringColor(msg);
|
msg = Format.FormatStringColor(msg);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,9 @@ public class Message extends MineverseCommand {
|
|||||||
if(mcp.hasFilter()) {
|
if(mcp.hasFilter()) {
|
||||||
msg = Format.FilterChat(msg);
|
msg = Format.FilterChat(msg);
|
||||||
}
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
msg = Format.FormatStringLegacyColor(msg);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
msg = Format.FormatStringColor(msg);
|
msg = Format.FormatStringColor(msg);
|
||||||
}
|
}
|
||||||
@ -122,6 +125,9 @@ public class Message extends MineverseCommand {
|
|||||||
if(mcp.hasFilter()) {
|
if(mcp.hasFilter()) {
|
||||||
msg = Format.FilterChat(msg);
|
msg = Format.FilterChat(msg);
|
||||||
}
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
msg = Format.FormatStringLegacyColor(msg);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
msg = Format.FormatStringColor(msg);
|
msg = Format.FormatStringColor(msg);
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,9 @@ public class Reply extends MineverseCommand {
|
|||||||
if(mcp.hasFilter()) {
|
if(mcp.hasFilter()) {
|
||||||
msg = Format.FilterChat(msg);
|
msg = Format.FilterChat(msg);
|
||||||
}
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
msg = Format.FormatStringLegacyColor(msg);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
msg = Format.FormatStringColor(msg);
|
msg = Format.FormatStringColor(msg);
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,9 @@ public class ChatListener implements Listener {
|
|||||||
if(mcp.hasFilter()) {
|
if(mcp.hasFilter()) {
|
||||||
filtered = Format.FilterChat(filtered);
|
filtered = Format.FilterChat(filtered);
|
||||||
}
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
filtered = Format.FormatStringLegacyColor(filtered);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
filtered = Format.FormatStringColor(filtered);
|
filtered = Format.FormatStringColor(filtered);
|
||||||
}
|
}
|
||||||
@ -177,6 +180,9 @@ public class ChatListener implements Listener {
|
|||||||
if(mcp.hasFilter()) {
|
if(mcp.hasFilter()) {
|
||||||
filtered = Format.FilterChat(filtered);
|
filtered = Format.FilterChat(filtered);
|
||||||
}
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
filtered = Format.FormatStringLegacyColor(filtered);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
filtered = Format.FormatStringColor(filtered);
|
filtered = Format.FormatStringColor(filtered);
|
||||||
}
|
}
|
||||||
@ -463,6 +469,9 @@ public class ChatListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
chat = Format.FormatStringLegacyColor(chat);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
chat = Format.FormatStringColor(chat);
|
chat = Format.FormatStringColor(chat);
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,15 @@ public class CommandListener implements CommandExecutor, Listener {
|
|||||||
}
|
}
|
||||||
if(send.length() > 0) send = send.substring(1);
|
if(send.length() > 0) send = send.substring(1);
|
||||||
s = Format.FormatStringAll(s);
|
s = Format.FormatStringAll(s);
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) send = Format.FormatStringColor(send);
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.format")) send = Format.FormatString(send);
|
send = Format.FormatStringLegacyColor(send);
|
||||||
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
|
send = Format.FormatStringColor(send);
|
||||||
|
}
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.format")) {
|
||||||
|
send = Format.FormatString(send);
|
||||||
|
}
|
||||||
if(s.startsWith("Command:")) {
|
if(s.startsWith("Command:")) {
|
||||||
mcp.getPlayer().chat(s.substring(9).replace("$", send));
|
mcp.getPlayer().chat(s.substring(9).replace("$", send));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -19,6 +19,9 @@ public class SignListener implements Listener {
|
|||||||
MineverseChatPlayer mcp = MineverseChatAPI.getMineverseChatPlayer(event.getPlayer());
|
MineverseChatPlayer mcp = MineverseChatAPI.getMineverseChatPlayer(event.getPlayer());
|
||||||
for(int a = 0; a < event.getLines().length; a++) {
|
for(int a = 0; a < event.getLines().length; a++) {
|
||||||
String line = event.getLine(a);
|
String line = event.getLine(a);
|
||||||
|
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
|
||||||
|
line = Format.FormatStringLegacyColor(line);
|
||||||
|
}
|
||||||
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
if(mcp.getPlayer().hasPermission("venturechat.color")) {
|
||||||
line = Format.FormatStringColor(line);
|
line = Format.FormatStringColor(line);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package mineverse.Aust1n46.chat.utilities;
|
package mineverse.Aust1n46.chat.utilities;
|
||||||
|
|
||||||
//import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
@ -22,17 +21,36 @@ import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
|||||||
import mineverse.Aust1n46.chat.json.JsonFormat;
|
import mineverse.Aust1n46.chat.json.JsonFormat;
|
||||||
import mineverse.Aust1n46.chat.versions.VersionHandler;
|
import mineverse.Aust1n46.chat.versions.VersionHandler;
|
||||||
|
|
||||||
//This class is where all formatting methods are stored.
|
/**
|
||||||
public class Format {
|
* Class containing chat formatting methods.
|
||||||
|
*/
|
||||||
|
public class Format {
|
||||||
private static MineverseChat plugin = MineverseChat.getInstance();
|
private static MineverseChat plugin = MineverseChat.getInstance();
|
||||||
|
|
||||||
public static final int LEGACY_COLOR_CODE_LENGTH = 2;
|
public static final int LEGACY_COLOR_CODE_LENGTH = 2;
|
||||||
public static final int HEX_COLOR_CODE_LENGTH = 14;
|
public static final int HEX_COLOR_CODE_LENGTH = 14;
|
||||||
public static final String DEFAULT_COLOR_CODE = String.valueOf(ChatColor.WHITE);
|
public static final String DEFAULT_COLOR_CODE = String.valueOf(ChatColor.WHITE);
|
||||||
public static final String HEX_COLOR_CODE_PREFIX = "#";
|
public static final String HEX_COLOR_CODE_PREFIX = "#";
|
||||||
public static final String BUKKIT_COLOR_CODE_PREFIX = "§";
|
public static final char BUKKIT_COLOR_CODE_PREFIX_CHAR = '\u00A7';
|
||||||
|
public static final String BUKKIT_COLOR_CODE_PREFIX = String.valueOf(BUKKIT_COLOR_CODE_PREFIX_CHAR);
|
||||||
public static final String BUKKIT_HEX_COLOR_CODE_PREFIX = "x";
|
public static final String BUKKIT_HEX_COLOR_CODE_PREFIX = "x";
|
||||||
|
|
||||||
|
private static final Pattern LEGACY_CHAT_COLOR_DIGITS_PATTERN = Pattern.compile("&([0-9])");
|
||||||
|
private static final Pattern LEGACY_CHAT_COLOR_PATTERN = Pattern.compile(
|
||||||
|
"(?<!(&x(&[a-fA-F0-9]){5}))(?<!(&x(&[a-fA-F0-9]){4}))(?<!(&x(&[a-fA-F0-9]){3}))(?<!(&x(&[a-fA-F0-9]){2}))(?<!(&x(&[a-fA-F0-9]){1}))(?<!(&x))(&)([0-9a-fA-F])");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a message to Minecraft JSON formatting while applying the
|
||||||
|
* {@link JsonFormat} from the config.
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* {@link MineverseChatPlayer} wrapper of the message sender.
|
||||||
|
* @param format
|
||||||
|
* The format section of the message.
|
||||||
|
* @param chat
|
||||||
|
* The chat section of the message.
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public static String convertToJson(MineverseChatPlayer sender, String format, String chat) {
|
public static String convertToJson(MineverseChatPlayer sender, String format, String chat) {
|
||||||
JsonFormat JSONformat = MineverseChat.jfInfo.getJsonFormat(sender.getJsonFormat());
|
JsonFormat JSONformat = MineverseChat.jfInfo.getJsonFormat(sender.getJsonFormat());
|
||||||
String f = format.replace("\\", "\\\\").replace("\"", "\\\"");
|
String f = format.replace("\\", "\\\\").replace("\"", "\\\"");
|
||||||
@ -43,31 +61,31 @@ public class Format {
|
|||||||
try {
|
try {
|
||||||
prefix = FormatStringAll(MineverseChat.chat.getPlayerPrefix(sender.getPlayer()));
|
prefix = FormatStringAll(MineverseChat.chat.getPlayerPrefix(sender.getPlayer()));
|
||||||
suffix = FormatStringAll(MineverseChat.chat.getPlayerSuffix(sender.getPlayer()));
|
suffix = FormatStringAll(MineverseChat.chat.getPlayerSuffix(sender.getPlayer()));
|
||||||
//Don't apply JSON if the prefix or suffix is just a color code
|
// Don't apply JSON if the prefix or suffix is just a color code
|
||||||
if(suffix.isEmpty() || (suffix.length() == 2 && suffix.substring(1).matches("[0-9a-fA-F]"))) {
|
if (suffix.isEmpty() || (suffix.length() == 2 && suffix.substring(1).matches("[0-9a-fA-F]"))) {
|
||||||
suffix = "venturechat_no_suffix_code";
|
suffix = "venturechat_no_suffix_code";
|
||||||
}
|
}
|
||||||
if(prefix.isEmpty() || (prefix.length() == 2 && prefix.substring(1).matches("[0-9a-fA-F]"))) {
|
if (prefix.isEmpty() || (prefix.length() == 2 && prefix.substring(1).matches("[0-9a-fA-F]"))) {
|
||||||
prefix = "venturechat_no_prefix_code";
|
prefix = "venturechat_no_prefix_code";
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
System.out.println("Exception?" + e.getLocalizedMessage());
|
System.out.println("Exception?" + e.getLocalizedMessage());
|
||||||
if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
if (plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
||||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Prefix and / or suffix don't exist, setting to nothing."));
|
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll(
|
||||||
|
"&8[&eVentureChat&8]&e - Prefix and / or suffix don't exist, setting to nothing."));
|
||||||
}
|
}
|
||||||
suffix = "venturechat_no_suffix_code";
|
suffix = "venturechat_no_suffix_code";
|
||||||
prefix = "venturechat_no_prefix_code";
|
prefix = "venturechat_no_prefix_code";
|
||||||
}
|
}
|
||||||
String nickname = "";
|
String nickname = "";
|
||||||
if(sender.getPlayer() != null) {
|
if (sender.getPlayer() != null) {
|
||||||
nickname = FormatStringAll(sender.getPlayer().getDisplayName());
|
nickname = FormatStringAll(sender.getPlayer().getDisplayName());
|
||||||
}
|
}
|
||||||
json += convertPlaceholders(f, JSONformat, prefix, nickname, suffix, sender);
|
json += convertPlaceholders(f, JSONformat, prefix, nickname, suffix, sender);
|
||||||
json += "]}";
|
json += "]}";
|
||||||
json += "," + convertLinks(c);
|
json += "," + convertLinks(c);
|
||||||
json += "]";
|
json += "]";
|
||||||
if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
if (plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
||||||
System.out.println(json);
|
System.out.println(json);
|
||||||
System.out.println("END OF JSON");
|
System.out.println("END OF JSON");
|
||||||
System.out.println("END OF JSON");
|
System.out.println("END OF JSON");
|
||||||
@ -77,18 +95,31 @@ public class Format {
|
|||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String convertPlaceholders(String s, JsonFormat format, String prefix, String nickname, String suffix, MineverseChatPlayer icp) {
|
/**
|
||||||
|
* Converts the format section of a message to JSON using PlaceholderAPI.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* @param format
|
||||||
|
* @param prefix
|
||||||
|
* @param nickname
|
||||||
|
* @param suffix
|
||||||
|
* @param icp
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
|
private static String convertPlaceholders(String s, JsonFormat format, String prefix, String nickname,
|
||||||
|
String suffix, MineverseChatPlayer icp) {
|
||||||
String remaining = s;
|
String remaining = s;
|
||||||
String temp = "";
|
String temp = "";
|
||||||
int indexStart = -1;
|
int indexStart = -1;
|
||||||
int indexEnd = -1;
|
int indexEnd = -1;
|
||||||
String placeholder = "";
|
String placeholder = "";
|
||||||
String lastCode = "§f";
|
String lastCode = DEFAULT_COLOR_CODE;
|
||||||
do {
|
do {
|
||||||
Pattern pattern = Pattern.compile("(" + escapeAllRegex(prefix) + "|" + escapeAllRegex(nickname) + "|" + escapeAllRegex(suffix) + ")");
|
Pattern pattern = Pattern.compile(
|
||||||
|
"(" + escapeAllRegex(prefix) + "|" + escapeAllRegex(nickname) + "|" + escapeAllRegex(suffix) + ")");
|
||||||
Matcher matcher = pattern.matcher(remaining);
|
Matcher matcher = pattern.matcher(remaining);
|
||||||
if(matcher.find()) {
|
if (matcher.find()) {
|
||||||
indexStart = matcher.start();
|
indexStart = matcher.start();
|
||||||
indexEnd = matcher.end();
|
indexEnd = matcher.end();
|
||||||
placeholder = remaining.substring(indexStart, indexEnd);
|
placeholder = remaining.substring(indexStart, indexEnd);
|
||||||
@ -97,89 +128,117 @@ public class Format {
|
|||||||
String action = "";
|
String action = "";
|
||||||
String text = "";
|
String text = "";
|
||||||
String hover = "";
|
String hover = "";
|
||||||
if(placeholder.contains(prefix)) {
|
if (placeholder.contains(prefix)) {
|
||||||
action = format.getClickPrefix();
|
action = format.getClickPrefix();
|
||||||
text = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickPrefixText()));
|
text = Format.FormatStringAll(
|
||||||
for(String st : format.getHoverTextPrefix()) {
|
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickPrefixText()));
|
||||||
|
for (String st : format.getHoverTextPrefix()) {
|
||||||
hover += Format.FormatStringAll(st) + "\n";
|
hover += Format.FormatStringAll(st) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(placeholder.contains(nickname)) {
|
if (placeholder.contains(nickname)) {
|
||||||
action = format.getClickName();
|
action = format.getClickName();
|
||||||
text = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickNameText()));
|
text = Format.FormatStringAll(
|
||||||
for(String st : format.getHoverTextName()) {
|
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickNameText()));
|
||||||
|
for (String st : format.getHoverTextName()) {
|
||||||
hover += Format.FormatStringAll(st) + "\n";
|
hover += Format.FormatStringAll(st) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(placeholder.contains(suffix)) {
|
if (placeholder.contains(suffix)) {
|
||||||
action = format.getClickSuffix();
|
action = format.getClickSuffix();
|
||||||
text = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickSuffixText()));
|
text = Format.FormatStringAll(
|
||||||
for(String st : format.getHoverTextSuffix()) {
|
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), format.getClickSuffixText()));
|
||||||
|
for (String st : format.getHoverTextSuffix()) {
|
||||||
hover += Format.FormatStringAll(st) + "\n";
|
hover += Format.FormatStringAll(st) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hover = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1)));
|
hover = Format.FormatStringAll(
|
||||||
temp += convertToJsonColors(lastCode + placeholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(hover) + "]}}") + ",";
|
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1)));
|
||||||
|
temp += convertToJsonColors(lastCode + placeholder,
|
||||||
|
",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text
|
||||||
|
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
|
||||||
|
+ convertToJsonColors(hover) + "]}}")
|
||||||
|
+ ",";
|
||||||
lastCode = getLastCode(lastCode + placeholder);
|
lastCode = getLastCode(lastCode + placeholder);
|
||||||
remaining = remaining.substring(indexEnd);
|
remaining = remaining.substring(indexEnd);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
temp += convertToJsonColors(lastCode + remaining);
|
temp += convertToJsonColors(lastCode + remaining);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (true);
|
||||||
while(true);
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts URL's to JSON.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
private static String convertLinks(String s) {
|
private static String convertLinks(String s) {
|
||||||
String remaining = s;
|
String remaining = s;
|
||||||
String temp = "";
|
String temp = "";
|
||||||
int indexLink = -1;
|
int indexLink = -1;
|
||||||
int indexLinkEnd = -1;
|
int indexLinkEnd = -1;
|
||||||
String link = "";
|
String link = "";
|
||||||
String lastCode = "§f";
|
String lastCode = DEFAULT_COLOR_CODE;
|
||||||
do {
|
do {
|
||||||
Pattern pattern = Pattern.compile("([a-zA-Z0-9§\\-:/]+\\.[a-zA-Z/0-9§\\-:_#]+(\\.[a-zA-Z/0-9.§\\-:#\\?\\+=_]+)?)");
|
Pattern pattern = Pattern.compile(
|
||||||
|
"([a-zA-Z0-9" + BUKKIT_COLOR_CODE_PREFIX + "\\-:/]+\\.[a-zA-Z/0-9" + BUKKIT_COLOR_CODE_PREFIX
|
||||||
|
+ "\\-:_#]+(\\.[a-zA-Z/0-9." + BUKKIT_COLOR_CODE_PREFIX + "\\-:#\\?\\+=_]+)?)");
|
||||||
Matcher matcher = pattern.matcher(remaining);
|
Matcher matcher = pattern.matcher(remaining);
|
||||||
if(matcher.find()) {
|
if (matcher.find()) {
|
||||||
indexLink = matcher.start();
|
indexLink = matcher.start();
|
||||||
indexLinkEnd = matcher.end();
|
indexLinkEnd = matcher.end();
|
||||||
link = remaining.substring(indexLink, indexLinkEnd);
|
link = remaining.substring(indexLink, indexLinkEnd);
|
||||||
temp += convertToJsonColors(lastCode + remaining.substring(0, indexLink)) + ",";
|
temp += convertToJsonColors(lastCode + remaining.substring(0, indexLink)) + ",";
|
||||||
lastCode = getLastCode(lastCode + remaining.substring(0, indexLink));
|
lastCode = getLastCode(lastCode + remaining.substring(0, indexLink));
|
||||||
String https = "";
|
String https = "";
|
||||||
if(ChatColor.stripColor(link).contains("https://"))
|
if (ChatColor.stripColor(link).contains("https://"))
|
||||||
https = "s";
|
https = "s";
|
||||||
temp += convertToJsonColors(lastCode + link, ",\"underlined\":\"" + underlineURLs() + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http" + https + "://" + ChatColor.stripColor(link.replace("http://", "").replace("https://", "")) + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(lastCode + link) + "]}}") + ",";
|
temp += convertToJsonColors(lastCode + link,
|
||||||
|
",\"underlined\":\"" + underlineURLs()
|
||||||
|
+ "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http" + https + "://"
|
||||||
|
+ ChatColor.stripColor(link.replace("http://", "").replace("https://", ""))
|
||||||
|
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
|
||||||
|
+ convertToJsonColors(lastCode + link) + "]}}")
|
||||||
|
+ ",";
|
||||||
lastCode = getLastCode(lastCode + link);
|
lastCode = getLastCode(lastCode + link);
|
||||||
remaining = remaining.substring(indexLinkEnd);
|
remaining = remaining.substring(indexLinkEnd);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
temp += convertToJsonColors(lastCode + remaining);
|
temp += convertToJsonColors(lastCode + remaining);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (true);
|
||||||
while(true);
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLastCode(String s) {
|
public static String getLastCode(String s) {
|
||||||
String ts = "";
|
String ts = "";
|
||||||
char[] ch = s.toCharArray();
|
char[] ch = s.toCharArray();
|
||||||
for(int a = 0; a < s.length() - 1; a ++) {
|
for (int a = 0; a < s.length() - 1; a++) {
|
||||||
if(String.valueOf(ch[a + 1]).matches("[lkomnLKOMN]") && ch[a] == '§') {
|
if (String.valueOf(ch[a + 1]).matches("[lkomnLKOMN]") && ch[a] == BUKKIT_COLOR_CODE_PREFIX_CHAR) {
|
||||||
ts += String.valueOf(ch[a]) + ch[a + 1];
|
ts += String.valueOf(ch[a]) + ch[a + 1];
|
||||||
a ++;
|
a++;
|
||||||
}
|
} else if (String.valueOf(ch[a + 1]).matches("[0123456789abcdefrABCDEFR]")
|
||||||
else if(String.valueOf(ch[a + 1]).matches("[0123456789abcdefrABCDEFR]") && ch[a] == '§') {
|
&& ch[a] == BUKKIT_COLOR_CODE_PREFIX_CHAR) {
|
||||||
ts = String.valueOf(ch[a]) + ch[a + 1];
|
ts = String.valueOf(ch[a]) + ch[a + 1];
|
||||||
a ++;
|
a++;
|
||||||
}
|
} else if (ch[a + 1] == 'x' && ch[a] == BUKKIT_COLOR_CODE_PREFIX_CHAR) {
|
||||||
else if(ch[a + 1] == 'x' && ch[a] == '§') {
|
if (ch.length > a + 13) {
|
||||||
if(ch.length > a + 13) {
|
if (String.valueOf(ch[a + 3]).matches("[0123456789abcdefABCDEF]")
|
||||||
if(String.valueOf(ch[a + 3]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 5]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 7]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 9]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 11]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 13]).matches("[0123456789abcdefABCDEF]") && ch[a + 2] == '§' && ch[a + 4] == '§' && ch[a + 6] == '§' && ch[a + 8] == '§' && ch[a + 10] == '§' && ch[a + 12] == '§') {
|
&& String.valueOf(ch[a + 5]).matches("[0123456789abcdefABCDEF]")
|
||||||
ts = String.valueOf(ch[a]) + ch[a + 1] + ch[a + 2] + ch[a + 3] + ch[a + 4] + ch[a + 5] + ch[a + 6] + ch[a + 7] + ch[a + 8] + ch[a + 9] + ch[a + 10] + ch[a + 11] + ch[a + 12] + ch[a + 13];
|
&& String.valueOf(ch[a + 7]).matches("[0123456789abcdefABCDEF]")
|
||||||
|
&& String.valueOf(ch[a + 9]).matches("[0123456789abcdefABCDEF]")
|
||||||
|
&& String.valueOf(ch[a + 11]).matches("[0123456789abcdefABCDEF]")
|
||||||
|
&& String.valueOf(ch[a + 13]).matches("[0123456789abcdefABCDEF]")
|
||||||
|
&& ch[a + 2] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 4] == BUKKIT_COLOR_CODE_PREFIX_CHAR
|
||||||
|
&& ch[a + 6] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 8] == BUKKIT_COLOR_CODE_PREFIX_CHAR
|
||||||
|
&& ch[a + 10] == BUKKIT_COLOR_CODE_PREFIX_CHAR
|
||||||
|
&& ch[a + 12] == BUKKIT_COLOR_CODE_PREFIX_CHAR) {
|
||||||
|
ts = String.valueOf(ch[a]) + ch[a + 1] + ch[a + 2] + ch[a + 3] + ch[a + 4] + ch[a + 5]
|
||||||
|
+ ch[a + 6] + ch[a + 7] + ch[a + 8] + ch[a + 9] + ch[a + 10] + ch[a + 11] + ch[a + 12]
|
||||||
|
+ ch[a + 13];
|
||||||
a += 13;
|
a += 13;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,11 +246,24 @@ public class Format {
|
|||||||
}
|
}
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a message to JSON colors with no additional JSON extensions.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
private static String convertToJsonColors(String s) {
|
private static String convertToJsonColors(String s) {
|
||||||
return convertToJsonColors(s, "");
|
return convertToJsonColors(s, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a message to JSON colors with additional JSON extensions.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* @param extensions
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
private static String convertToJsonColors(String s, String extensions) {
|
private static String convertToJsonColors(String s, String extensions) {
|
||||||
String remaining = s;
|
String remaining = s;
|
||||||
String temp = "";
|
String temp = "";
|
||||||
@ -207,18 +279,20 @@ public class Format {
|
|||||||
String previousColor = "";
|
String previousColor = "";
|
||||||
int colorLength = LEGACY_COLOR_CODE_LENGTH;
|
int colorLength = LEGACY_COLOR_CODE_LENGTH;
|
||||||
do {
|
do {
|
||||||
if(remaining.length() < LEGACY_COLOR_CODE_LENGTH) {
|
if (remaining.length() < LEGACY_COLOR_CODE_LENGTH) {
|
||||||
temp = "{\"text\":\"" + remaining + "\"},";
|
temp = "{\"text\":\"" + remaining + "\"},";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
modifier = "";
|
modifier = "";
|
||||||
indexColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX);
|
indexColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX);
|
||||||
previousColor = color;
|
previousColor = color;
|
||||||
|
|
||||||
color = remaining.substring(1, indexColor + LEGACY_COLOR_CODE_LENGTH);
|
color = remaining.substring(1, indexColor + LEGACY_COLOR_CODE_LENGTH);
|
||||||
if(color.equals(BUKKIT_HEX_COLOR_CODE_PREFIX)) {
|
if (color.equals(BUKKIT_HEX_COLOR_CODE_PREFIX)) {
|
||||||
if(remaining.length() >= HEX_COLOR_CODE_LENGTH) {
|
if (remaining.length() >= HEX_COLOR_CODE_LENGTH) {
|
||||||
color = HEX_COLOR_CODE_PREFIX + remaining.substring(LEGACY_COLOR_CODE_LENGTH, indexColor + HEX_COLOR_CODE_LENGTH).replace(BUKKIT_COLOR_CODE_PREFIX, "");
|
color = HEX_COLOR_CODE_PREFIX
|
||||||
|
+ remaining.substring(LEGACY_COLOR_CODE_LENGTH, indexColor + HEX_COLOR_CODE_LENGTH)
|
||||||
|
.replace(BUKKIT_COLOR_CODE_PREFIX, "");
|
||||||
colorLength = HEX_COLOR_CODE_LENGTH;
|
colorLength = HEX_COLOR_CODE_LENGTH;
|
||||||
bold = false;
|
bold = false;
|
||||||
obfuscated = false;
|
obfuscated = false;
|
||||||
@ -226,133 +300,154 @@ public class Format {
|
|||||||
strikethrough = false;
|
strikethrough = false;
|
||||||
underlined = false;
|
underlined = false;
|
||||||
}
|
}
|
||||||
}
|
} else if (!color.matches("[0123456789abcdefABCDEF]")) {
|
||||||
else if(!color.matches("[0123456789abcdefABCDEF]")) {
|
switch (color) {
|
||||||
switch(color) {
|
case "l":
|
||||||
case "l":
|
case "L": {
|
||||||
case "L": {
|
bold = true;
|
||||||
bold = true;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "k":
|
|
||||||
case "K": {
|
|
||||||
obfuscated = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "o":
|
|
||||||
case "O": {
|
|
||||||
italic = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "m":
|
|
||||||
case "M": {
|
|
||||||
strikethrough = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "n":
|
|
||||||
case "N": {
|
|
||||||
underlined = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "r":
|
|
||||||
case "R": {
|
|
||||||
bold = false;
|
|
||||||
obfuscated = false;
|
|
||||||
italic = false;
|
|
||||||
strikethrough = false;
|
|
||||||
underlined = false;
|
|
||||||
color = "f";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!color.equals("f"))
|
case "k":
|
||||||
color = previousColor;
|
case "K": {
|
||||||
if(color.length() == 0)
|
obfuscated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "o":
|
||||||
|
case "O": {
|
||||||
|
italic = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "m":
|
||||||
|
case "M": {
|
||||||
|
strikethrough = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "n":
|
||||||
|
case "N": {
|
||||||
|
underlined = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "r":
|
||||||
|
case "R": {
|
||||||
|
bold = false;
|
||||||
|
obfuscated = false;
|
||||||
|
italic = false;
|
||||||
|
strikethrough = false;
|
||||||
|
underlined = false;
|
||||||
color = "f";
|
color = "f";
|
||||||
}
|
break;
|
||||||
else {
|
}
|
||||||
|
}
|
||||||
|
if (!color.equals("f"))
|
||||||
|
color = previousColor;
|
||||||
|
if (color.length() == 0)
|
||||||
|
color = "f";
|
||||||
|
} else {
|
||||||
bold = false;
|
bold = false;
|
||||||
obfuscated = false;
|
obfuscated = false;
|
||||||
italic = false;
|
italic = false;
|
||||||
strikethrough = false;
|
strikethrough = false;
|
||||||
underlined = false;
|
underlined = false;
|
||||||
}
|
}
|
||||||
if(bold)
|
if (bold)
|
||||||
modifier += ",\"bold\":\"true\"";
|
modifier += ",\"bold\":\"true\"";
|
||||||
if(obfuscated)
|
if (obfuscated)
|
||||||
modifier += ",\"obfuscated\":\"true\"";
|
modifier += ",\"obfuscated\":\"true\"";
|
||||||
if(italic)
|
if (italic)
|
||||||
modifier += ",\"italic\":\"true\"";
|
modifier += ",\"italic\":\"true\"";
|
||||||
if(underlined)
|
if (underlined)
|
||||||
modifier += ",\"underlined\":\"true\"";
|
modifier += ",\"underlined\":\"true\"";
|
||||||
if(strikethrough)
|
if (strikethrough)
|
||||||
modifier += ",\"strikethrough\":\"true\"";
|
modifier += ",\"strikethrough\":\"true\"";
|
||||||
remaining = remaining.substring(colorLength);
|
remaining = remaining.substring(colorLength);
|
||||||
colorLength = LEGACY_COLOR_CODE_LENGTH;
|
colorLength = LEGACY_COLOR_CODE_LENGTH;
|
||||||
indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX);
|
indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX);
|
||||||
if(indexNextColor == -1) {
|
if (indexNextColor == -1) {
|
||||||
indexNextColor = remaining.length();
|
indexNextColor = remaining.length();
|
||||||
}
|
}
|
||||||
temp += "{\"text\":\"" + remaining.substring(0, indexNextColor) + "\",\"color\":\"" + hexidecimalToJsonColorRGB(color) + "\"" + modifier + extensions + "},";
|
temp += "{\"text\":\"" + remaining.substring(0, indexNextColor) + "\",\"color\":\""
|
||||||
|
+ hexidecimalToJsonColorRGB(color) + "\"" + modifier + extensions + "},";
|
||||||
remaining = remaining.substring(indexNextColor);
|
remaining = remaining.substring(indexNextColor);
|
||||||
}
|
} while (remaining.length() > 1 && indexColor != -1);
|
||||||
while(remaining.length() > 1 && indexColor != -1);
|
if (temp.length() > 1)
|
||||||
if(temp.length() > 1)
|
|
||||||
temp = temp.substring(0, temp.length() - 1);
|
temp = temp.substring(0, temp.length() - 1);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String hexidecimalToJsonColorRGB(String c) {
|
private static String hexidecimalToJsonColorRGB(String c) {
|
||||||
if(c.length() == 1) {
|
if (c.length() == 1) {
|
||||||
switch(c) {
|
switch (c) {
|
||||||
case "0": return "black";
|
case "0":
|
||||||
case "1": return "dark_blue";
|
return "black";
|
||||||
case "2": return "dark_green";
|
case "1":
|
||||||
case "3": return "dark_aqua";
|
return "dark_blue";
|
||||||
case "4": return "dark_red";
|
case "2":
|
||||||
case "5": return "dark_purple";
|
return "dark_green";
|
||||||
case "6": return "gold";
|
case "3":
|
||||||
case "7": return "gray";
|
return "dark_aqua";
|
||||||
case "8": return "dark_gray";
|
case "4":
|
||||||
case "9": return "blue";
|
return "dark_red";
|
||||||
case "a":
|
case "5":
|
||||||
case "A": return "green";
|
return "dark_purple";
|
||||||
case "b":
|
case "6":
|
||||||
case "B": return "aqua";
|
return "gold";
|
||||||
case "c":
|
case "7":
|
||||||
case "C": return "red";
|
return "gray";
|
||||||
case "d":
|
case "8":
|
||||||
case "D": return "light_purple";
|
return "dark_gray";
|
||||||
case "e":
|
case "9":
|
||||||
case "E": return "yellow";
|
return "blue";
|
||||||
case "f":
|
case "a":
|
||||||
case "F": return "white";
|
case "A":
|
||||||
default: return "white";
|
return "green";
|
||||||
|
case "b":
|
||||||
|
case "B":
|
||||||
|
return "aqua";
|
||||||
|
case "c":
|
||||||
|
case "C":
|
||||||
|
return "red";
|
||||||
|
case "d":
|
||||||
|
case "D":
|
||||||
|
return "light_purple";
|
||||||
|
case "e":
|
||||||
|
case "E":
|
||||||
|
return "yellow";
|
||||||
|
case "f":
|
||||||
|
case "F":
|
||||||
|
return "white";
|
||||||
|
default:
|
||||||
|
return "white";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isValidHexColor(c)) {
|
if (isValidHexColor(c)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
return "white";
|
return "white";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertPlainTextToJson(String s, boolean convertURL) {
|
public static String convertPlainTextToJson(String s, boolean convertURL) {
|
||||||
if(convertURL) {
|
if (convertURL) {
|
||||||
return "[" + Format.convertLinks(s) + "]";
|
return "[" + Format.convertLinks(s) + "]";
|
||||||
}
|
} else {
|
||||||
else {
|
return "[" + convertToJsonColors(DEFAULT_COLOR_CODE + s) + "]";
|
||||||
return "[" + convertToJsonColors("§f" + s) + "]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatModerationGUI(String json, Player player, String sender, String channelName, int hash) {
|
public static String formatModerationGUI(String json, Player player, String sender, String channelName, int hash) {
|
||||||
if(player.hasPermission("venturechat.gui")) {
|
if (player.hasPermission("venturechat.gui")) {
|
||||||
json = json.substring(0, json.length() - 1);
|
json = json.substring(0, json.length() - 1);
|
||||||
json += "," + Format.convertToJsonColors(Format.FormatStringAll(plugin.getConfig().getString("guiicon")), ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/vchatgui " + sender + " " + channelName + " " + hash +"\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + Format.convertToJsonColors(Format.FormatStringAll(plugin.getConfig().getString("guitext"))) + "]}}") + "]";
|
json += "," + Format.convertToJsonColors(Format.FormatStringAll(plugin.getConfig().getString("guiicon")),
|
||||||
|
",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/vchatgui " + sender + " " + channelName
|
||||||
|
+ " " + hash
|
||||||
|
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
|
||||||
|
+ Format.convertToJsonColors(
|
||||||
|
Format.FormatStringAll(plugin.getConfig().getString("guitext")))
|
||||||
|
+ "]}}")
|
||||||
|
+ "]";
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketContainer createPacketPlayOutChat(String json) {
|
public static PacketContainer createPacketPlayOutChat(String json) {
|
||||||
WrappedChatComponent component = WrappedChatComponent.fromJson(json);
|
WrappedChatComponent component = WrappedChatComponent.fromJson(json);
|
||||||
PacketContainer container = new PacketContainer(PacketType.Play.Server.CHAT);
|
PacketContainer container = new PacketContainer(PacketType.Play.Server.CHAT);
|
||||||
@ -360,133 +455,173 @@ public class Format {
|
|||||||
container.getChatComponents().write(0, component);
|
container.getChatComponents().write(0, component);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketContainer createPacketPlayOutChat(WrappedChatComponent component) {
|
public static PacketContainer createPacketPlayOutChat(WrappedChatComponent component) {
|
||||||
PacketContainer container = new PacketContainer(PacketType.Play.Server.CHAT);
|
PacketContainer container = new PacketContainer(PacketType.Play.Server.CHAT);
|
||||||
container.getModifier().writeDefaults();
|
container.getModifier().writeDefaults();
|
||||||
container.getChatComponents().write(0, component);
|
container.getChatComponents().write(0, component);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPacketPlayOutChat(Player player, PacketContainer packet) {
|
public static void sendPacketPlayOutChat(Player player, PacketContainer packet) {
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toPlainText(Object o, Class<?> c) {
|
public static String toPlainText(Object o, Class<?> c) {
|
||||||
List<Object> finalList = new ArrayList<>();
|
List<Object> finalList = new ArrayList<>();
|
||||||
StringBuilder stringbuilder = new StringBuilder();
|
StringBuilder stringbuilder = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
splitComponents(finalList, o, c);
|
splitComponents(finalList, o, c);
|
||||||
for(Object component : finalList) {
|
for (Object component : finalList) {
|
||||||
if(VersionHandler.is1_7_10()) {
|
if (VersionHandler.is1_7_10()) {
|
||||||
stringbuilder.append((String) component.getClass().getMethod("e").invoke(component));
|
stringbuilder.append((String) component.getClass().getMethod("e").invoke(component));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
stringbuilder.append((String) component.getClass().getMethod("getText").invoke(component));
|
stringbuilder.append((String) component.getClass().getMethod("getText").invoke(component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
// if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
||||||
// System.out.println("my string");
|
// System.out.println("my string");
|
||||||
// System.out.println("my string");
|
// System.out.println("my string");
|
||||||
// System.out.println("my string");
|
// System.out.println("my string");
|
||||||
// System.out.println("my string");
|
// System.out.println("my string");
|
||||||
// System.out.println("my string");
|
// System.out.println("my string");
|
||||||
// System.out.println(stringbuilder.toString());
|
// System.out.println(stringbuilder.toString());
|
||||||
// }
|
// }
|
||||||
return stringbuilder.toString();
|
return stringbuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void splitComponents(List<Object> finalList, Object o, Class<?> c) throws Exception {
|
private static void splitComponents(List<Object> finalList, Object o, Class<?> c) throws Exception {
|
||||||
// if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
// if(plugin.getConfig().getString("loglevel", "info").equals("debug")) {
|
||||||
// for(Method m : c.getMethods()) {
|
// for(Method m : c.getMethods()) {
|
||||||
// System.out.println(m.getName());
|
// System.out.println(m.getName());
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
if(VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() || VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13() || (VersionHandler.is1_14() && !VersionHandler.is1_14_4())) {
|
if (VersionHandler.is1_7() || VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10()
|
||||||
|
|| VersionHandler.is1_11() || VersionHandler.is1_12() || VersionHandler.is1_13()
|
||||||
|
|| (VersionHandler.is1_14() && !VersionHandler.is1_14_4())) {
|
||||||
ArrayList<?> list = (ArrayList<?>) c.getMethod("a").invoke(o, new Object[0]);
|
ArrayList<?> list = (ArrayList<?>) c.getMethod("a").invoke(o, new Object[0]);
|
||||||
for(Object component : list) {
|
for (Object component : list) {
|
||||||
ArrayList<?> innerList = (ArrayList<?>) c.getMethod("a").invoke(component, new Object[0]);
|
ArrayList<?> innerList = (ArrayList<?>) c.getMethod("a").invoke(component, new Object[0]);
|
||||||
if(innerList.size() > 0) {
|
if (innerList.size() > 0) {
|
||||||
splitComponents(finalList, component, c);
|
splitComponents(finalList, component, c);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
finalList.add(component);
|
finalList.add(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ArrayList<?> list = (ArrayList<?>) c.getMethod("getSiblings").invoke(o, new Object[0]);
|
ArrayList<?> list = (ArrayList<?>) c.getMethod("getSiblings").invoke(o, new Object[0]);
|
||||||
for(Object component : list) {
|
for (Object component : list) {
|
||||||
ArrayList<?> innerList = (ArrayList<?>) c.getMethod("getSiblings").invoke(component, new Object[0]);
|
ArrayList<?> innerList = (ArrayList<?>) c.getMethod("getSiblings").invoke(component, new Object[0]);
|
||||||
if(innerList.size() > 0) {
|
if (innerList.size() > 0) {
|
||||||
splitComponents(finalList, component, c);
|
splitComponents(finalList, component, c);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
finalList.add(component);
|
finalList.add(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Pattern chatColorPattern = Pattern.compile("(?i)&([0-9])");
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a string with both Spigot legacy colors codes and Spigot and
|
||||||
|
* VentureChat hex color codes.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* to format.
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public static String FormatStringColor(String string) {
|
public static String FormatStringColor(String string) {
|
||||||
String allFormated = string;
|
String allFormated = string;
|
||||||
allFormated = chatColorPattern.matcher(allFormated).replaceAll("\u00A7$1");
|
allFormated = LEGACY_CHAT_COLOR_DIGITS_PATTERN.matcher(allFormated).replaceAll("\u00A7$1");
|
||||||
|
|
||||||
allFormated = allFormated.replaceAll("&[x]", "§x");
|
allFormated = allFormated.replaceAll("&[x]", BUKKIT_COLOR_CODE_PREFIX + "x");
|
||||||
allFormated = allFormated.replaceAll("&[aA]", "§a");
|
allFormated = allFormated.replaceAll("&[aA]", BUKKIT_COLOR_CODE_PREFIX + "a");
|
||||||
allFormated = allFormated.replaceAll("&[bB]", "§b");
|
allFormated = allFormated.replaceAll("&[bB]", BUKKIT_COLOR_CODE_PREFIX + "b");
|
||||||
allFormated = allFormated.replaceAll("&[cC]", "§c");
|
allFormated = allFormated.replaceAll("&[cC]", BUKKIT_COLOR_CODE_PREFIX + "c");
|
||||||
allFormated = allFormated.replaceAll("&[dD]", "§d");
|
allFormated = allFormated.replaceAll("&[dD]", BUKKIT_COLOR_CODE_PREFIX + "d");
|
||||||
allFormated = allFormated.replaceAll("&[eE]", "§e");
|
allFormated = allFormated.replaceAll("&[eE]", BUKKIT_COLOR_CODE_PREFIX + "e");
|
||||||
allFormated = allFormated.replaceAll("&[fF]", "§f");
|
allFormated = allFormated.replaceAll("&[fF]", BUKKIT_COLOR_CODE_PREFIX + "f");
|
||||||
|
|
||||||
allFormated = allFormated.replaceAll("%", "\\%");
|
allFormated = allFormated.replaceAll("%", "\\%");
|
||||||
|
|
||||||
allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated);
|
allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated);
|
||||||
return allFormated;
|
return allFormated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String FormatString(String string) {
|
/**
|
||||||
|
* Formats a string with only legacy Spigot color codes &[0-9a-f]. Does not
|
||||||
|
* format the legacy color codes that make up a Spigot hex color code.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* to format.
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
|
public static String FormatStringLegacyColor(String string) {
|
||||||
String allFormated = string;
|
String allFormated = string;
|
||||||
allFormated = allFormated.replaceAll("&[kK]", "§k");
|
|
||||||
allFormated = allFormated.replaceAll("&[lL]", "§l");
|
allFormated = LEGACY_CHAT_COLOR_PATTERN.matcher(allFormated).replaceAll("\u00A7$13");
|
||||||
allFormated = allFormated.replaceAll("&[mM]", "§m");
|
allFormated = allFormated.replaceAll(BUKKIT_COLOR_CODE_PREFIX + "[A]", BUKKIT_COLOR_CODE_PREFIX + "a");
|
||||||
allFormated = allFormated.replaceAll("&[nN]", "§n");
|
allFormated = allFormated.replaceAll(BUKKIT_COLOR_CODE_PREFIX + "[B]", BUKKIT_COLOR_CODE_PREFIX + "b");
|
||||||
allFormated = allFormated.replaceAll("&[oO]", "§o");
|
allFormated = allFormated.replaceAll(BUKKIT_COLOR_CODE_PREFIX + "[C]", BUKKIT_COLOR_CODE_PREFIX + "c");
|
||||||
allFormated = allFormated.replaceAll("&[rR]", "§r");
|
allFormated = allFormated.replaceAll(BUKKIT_COLOR_CODE_PREFIX + "[D]", BUKKIT_COLOR_CODE_PREFIX + "d");
|
||||||
|
allFormated = allFormated.replaceAll(BUKKIT_COLOR_CODE_PREFIX + "[E]", BUKKIT_COLOR_CODE_PREFIX + "e");
|
||||||
|
allFormated = allFormated.replaceAll(BUKKIT_COLOR_CODE_PREFIX + "[F]", BUKKIT_COLOR_CODE_PREFIX + "f");
|
||||||
|
|
||||||
allFormated = allFormated.replaceAll("%", "\\%");
|
allFormated = allFormated.replaceAll("%", "\\%");
|
||||||
return allFormated;
|
return allFormated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a string with Spigot formatting codes.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* to format.
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
|
public static String FormatString(String string) {
|
||||||
|
String allFormated = string;
|
||||||
|
allFormated = allFormated.replaceAll("&[kK]", BUKKIT_COLOR_CODE_PREFIX + "k");
|
||||||
|
allFormated = allFormated.replaceAll("&[lL]", BUKKIT_COLOR_CODE_PREFIX + "l");
|
||||||
|
allFormated = allFormated.replaceAll("&[mM]", BUKKIT_COLOR_CODE_PREFIX + "m");
|
||||||
|
allFormated = allFormated.replaceAll("&[nN]", BUKKIT_COLOR_CODE_PREFIX + "n");
|
||||||
|
allFormated = allFormated.replaceAll("&[oO]", BUKKIT_COLOR_CODE_PREFIX + "o");
|
||||||
|
allFormated = allFormated.replaceAll("&[rR]", BUKKIT_COLOR_CODE_PREFIX + "r");
|
||||||
|
|
||||||
|
allFormated = allFormated.replaceAll("%", "\\%");
|
||||||
|
return allFormated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a string with Spigot legacy colors codes, Spigot and VentureChat hex
|
||||||
|
* color codes, and Spigot formatting codes.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* to format.
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public static String FormatStringAll(String string) {
|
public static String FormatStringAll(String string) {
|
||||||
String allFormated = Format.FormatString(string);
|
String allFormated = Format.FormatString(string);
|
||||||
allFormated = Format.FormatStringColor(allFormated);
|
allFormated = Format.FormatStringColor(allFormated);
|
||||||
return allFormated;
|
return allFormated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String FilterChat(String msg) {
|
public static String FilterChat(String msg) {
|
||||||
int t = 0;
|
int t = 0;
|
||||||
List<String> filters = plugin.getConfig().getStringList("filters");
|
List<String> filters = plugin.getConfig().getStringList("filters");
|
||||||
for(String s : filters) {
|
for (String s : filters) {
|
||||||
t = 0;
|
t = 0;
|
||||||
String[] pparse = new String[2];
|
String[] pparse = new String[2];
|
||||||
pparse[0] = " ";
|
pparse[0] = " ";
|
||||||
pparse[1] = " ";
|
pparse[1] = " ";
|
||||||
StringTokenizer st = new StringTokenizer(s, ",");
|
StringTokenizer st = new StringTokenizer(s, ",");
|
||||||
while(st.hasMoreTokens()) {
|
while (st.hasMoreTokens()) {
|
||||||
if(t < 2) {
|
if (t < 2) {
|
||||||
pparse[t++] = st.nextToken();
|
pparse[t++] = st.nextToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -494,49 +629,72 @@ public class Format {
|
|||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidColor(String color) {
|
public static boolean isValidColor(String color) {
|
||||||
Boolean bFound = false;
|
Boolean bFound = false;
|
||||||
for(ChatColor bkColors : ChatColor.values()) {
|
for (ChatColor bkColors : ChatColor.values()) {
|
||||||
if(color.equalsIgnoreCase(bkColors.name())) {
|
if (color.equalsIgnoreCase(bkColors.name())) {
|
||||||
bFound = true;
|
bFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bFound;
|
return bFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a hex color code.
|
||||||
|
*
|
||||||
|
* @param color
|
||||||
|
* to validate.
|
||||||
|
* @return true if color code is valid, false otherwise.
|
||||||
|
*/
|
||||||
public static boolean isValidHexColor(String color) {
|
public static boolean isValidHexColor(String color) {
|
||||||
Pattern pattern = Pattern.compile("(^#[0-9a-fA-F]{6}\\b)");
|
Pattern pattern = Pattern.compile("(^&?#[0-9a-fA-F]{6}\\b)");
|
||||||
Matcher matcher = pattern.matcher(color);
|
Matcher matcher = pattern.matcher(color);
|
||||||
return matcher.find();
|
return matcher.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a single hex color code to a single Bukkit hex color code.
|
||||||
|
*
|
||||||
|
* @param color
|
||||||
|
* to convert.
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public static String convertHexColorCodeToBukkitColorCode(String color) {
|
public static String convertHexColorCodeToBukkitColorCode(String color) {
|
||||||
|
color = color.replace("&", "");
|
||||||
StringBuilder bukkitColorCode = new StringBuilder(BUKKIT_COLOR_CODE_PREFIX + BUKKIT_HEX_COLOR_CODE_PREFIX);
|
StringBuilder bukkitColorCode = new StringBuilder(BUKKIT_COLOR_CODE_PREFIX + BUKKIT_HEX_COLOR_CODE_PREFIX);
|
||||||
for(int a = 1; a < color.length(); a++) {
|
for (int a = 1; a < color.length(); a++) {
|
||||||
bukkitColorCode.append(BUKKIT_COLOR_CODE_PREFIX + color.charAt(a));
|
bukkitColorCode.append(BUKKIT_COLOR_CODE_PREFIX + color.charAt(a));
|
||||||
}
|
}
|
||||||
return bukkitColorCode.toString().toLowerCase();
|
return bukkitColorCode.toString().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert an entire String of hex color codes to Bukkit hex color codes.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* to convert.
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public static String convertHexColorCodeStringToBukkitColorCodeString(String string) {
|
public static String convertHexColorCodeStringToBukkitColorCodeString(String string) {
|
||||||
Pattern pattern = Pattern.compile("(#[0-9a-fA-F]{6})");
|
Pattern pattern = Pattern.compile("(&?#[0-9a-fA-F]{6})");
|
||||||
Matcher matcher = pattern.matcher(string);
|
Matcher matcher = pattern.matcher(string);
|
||||||
while(matcher.find()) {
|
while (matcher.find()) {
|
||||||
int indexStart = matcher.start();
|
int indexStart = matcher.start();
|
||||||
int indexEnd = matcher.end();
|
int indexEnd = matcher.end();
|
||||||
String hexColor = string.substring(indexStart, indexEnd);
|
String hexColor = string.substring(indexStart, indexEnd);
|
||||||
String bukkitColor = convertHexColorCodeToBukkitColorCode(hexColor);
|
String bukkitColor = convertHexColorCodeToBukkitColorCode(hexColor);
|
||||||
string = string.replaceAll(hexColor, bukkitColor);
|
string = string.replaceAll(hexColor, bukkitColor);
|
||||||
matcher.reset(string);
|
matcher.reset(string);
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String escapeAllRegex(String input) {
|
public static String escapeAllRegex(String input) {
|
||||||
return input.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}").replace("(", "\\(").replace(")", "\\)").replace("|", "\\|").replace("+", "\\+").replace("*", "\\*");
|
return input.replace("[", "\\[").replace("]", "\\]").replace("{", "\\{").replace("}", "\\}").replace("(", "\\(")
|
||||||
|
.replace(")", "\\)").replace("|", "\\|").replace("+", "\\+").replace("*", "\\*");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean underlineURLs() {
|
public static boolean underlineURLs() {
|
||||||
return plugin.getConfig().getBoolean("underlineurls", true);
|
return plugin.getConfig().getBoolean("underlineurls", true);
|
||||||
}
|
}
|
||||||
@ -544,4 +702,4 @@ public class Format {
|
|||||||
public static int currentTimeMillis() {
|
public static int currentTimeMillis() {
|
||||||
return (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
|
return (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineverse.Aust1n46.chat.utilities;
|
package mineverse.Aust1n46.chat.utilities;
|
||||||
|
|
||||||
|
import static mineverse.Aust1n46.chat.utilities.Format.BUKKIT_COLOR_CODE_PREFIX;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -19,29 +20,32 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||||||
|
|
||||||
import mineverse.Aust1n46.chat.MineverseChat;
|
import mineverse.Aust1n46.chat.MineverseChat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests {@link Format}.
|
||||||
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( { MineverseChat.class })
|
@PrepareForTest({ MineverseChat.class })
|
||||||
public class FormatTest {
|
public class FormatTest {
|
||||||
|
|
||||||
private MineverseChat mockPlugin;
|
private MineverseChat mockPlugin;
|
||||||
private FileConfiguration mockConfig;
|
private FileConfiguration mockConfig;
|
||||||
|
|
||||||
private List<String> filters;
|
private List<String> filters;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
filters = new ArrayList<String>();
|
filters = new ArrayList<String>();
|
||||||
filters.add("ass,donut");
|
filters.add("ass,donut");
|
||||||
|
|
||||||
mockPlugin = Mockito.mock(MineverseChat.class);
|
mockPlugin = Mockito.mock(MineverseChat.class);
|
||||||
mockConfig = Mockito.mock(FileConfiguration.class);
|
mockConfig = Mockito.mock(FileConfiguration.class);
|
||||||
|
|
||||||
PowerMockito.mockStatic(MineverseChat.class);
|
PowerMockito.mockStatic(MineverseChat.class);
|
||||||
PowerMockito.when(MineverseChat.getInstance()).thenReturn(mockPlugin);
|
PowerMockito.when(MineverseChat.getInstance()).thenReturn(mockPlugin);
|
||||||
Mockito.when(mockPlugin.getConfig()).thenReturn(mockConfig);
|
Mockito.when(mockPlugin.getConfig()).thenReturn(mockConfig);
|
||||||
Mockito.when(mockConfig.getStringList("filters")).thenReturn(filters);
|
Mockito.when(mockConfig.getStringList("filters")).thenReturn(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
mockPlugin = null;
|
mockPlugin = null;
|
||||||
@ -51,90 +55,133 @@ public class FormatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastCodeSingleColor() {
|
public void testGetLastCodeSingleColor() {
|
||||||
String input = "§cHello";
|
String input = BUKKIT_COLOR_CODE_PREFIX + "cHello";
|
||||||
String expectedResult = "§c";
|
String expectedResult = BUKKIT_COLOR_CODE_PREFIX + "c";
|
||||||
|
|
||||||
String result = Format.getLastCode(input);
|
String result = Format.getLastCode(input);
|
||||||
|
|
||||||
assertEquals(expectedResult, result);
|
assertEquals(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastCodeColorAfterFormat() {
|
public void testGetLastCodeColorAfterFormat() {
|
||||||
String input = "§o§cHello";
|
String input = BUKKIT_COLOR_CODE_PREFIX + "o" + BUKKIT_COLOR_CODE_PREFIX + "cHello";
|
||||||
String expectedResult = "§c";
|
String expectedResult = BUKKIT_COLOR_CODE_PREFIX + "c";
|
||||||
|
|
||||||
String result = Format.getLastCode(input);
|
String result = Format.getLastCode(input);
|
||||||
|
|
||||||
assertEquals(expectedResult, result);
|
assertEquals(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastCodeColorBeforeFormat() {
|
public void testGetLastCodeColorBeforeFormat() {
|
||||||
String input = "§c§oHello";
|
String input = BUKKIT_COLOR_CODE_PREFIX + "c" + BUKKIT_COLOR_CODE_PREFIX + "oHello";
|
||||||
String expectedResult = "§c§o";
|
String expectedResult = BUKKIT_COLOR_CODE_PREFIX + "c" + BUKKIT_COLOR_CODE_PREFIX + "o";
|
||||||
|
|
||||||
String result = Format.getLastCode(input);
|
String result = Format.getLastCode(input);
|
||||||
|
|
||||||
assertEquals(expectedResult, result);
|
assertEquals(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterChat() {
|
public void testFilterChat() {
|
||||||
String test = "I am an ass";
|
String test = "I am an ass";
|
||||||
String expectedResult = "I am an donut";
|
String expectedResult = "I am an donut";
|
||||||
|
|
||||||
String result = Format.FilterChat(test);
|
String result = Format.FilterChat(test);
|
||||||
assertEquals(expectedResult, result);
|
assertEquals(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsValidColor() {
|
public void testIsValidColor() {
|
||||||
String color = "red";
|
String color = "red";
|
||||||
|
|
||||||
boolean result = Format.isValidColor(color);
|
boolean result = Format.isValidColor(color);
|
||||||
assertTrue(result);
|
assertTrue(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsInvalidColor() {
|
public void testIsInvalidColor() {
|
||||||
String color = "randomString";
|
String color = "randomString";
|
||||||
|
|
||||||
boolean result = Format.isValidColor(color);
|
boolean result = Format.isValidColor(color);
|
||||||
assertFalse(result);
|
assertFalse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsValidHexColor() {
|
public void testIsValidHexColor() {
|
||||||
String hexColor = "#ff00ff";
|
String hexColor = "#ff00ff";
|
||||||
|
|
||||||
boolean result = Format.isValidHexColor(hexColor);
|
boolean result = Format.isValidHexColor(hexColor);
|
||||||
assertTrue(result);
|
assertTrue(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsInvalidHexColor() {
|
public void testIsInvalidHexColor() {
|
||||||
String hexColor = "#random";
|
String hexColor = "#random";
|
||||||
|
|
||||||
boolean result = Format.isValidHexColor(hexColor);
|
boolean result = Format.isValidHexColor(hexColor);
|
||||||
assertFalse(result);
|
assertFalse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConvertHexColorCodeToBukkitColorCode() {
|
public void testConvertHexColorCodeToBukkitColorCode() {
|
||||||
String hexColor = "#ff00ff";
|
String hexColor = "#ff00ff";
|
||||||
String expectedResult = "§x§f§f§0§0§f§f";
|
String expectedResult = BUKKIT_COLOR_CODE_PREFIX + "x" + BUKKIT_COLOR_CODE_PREFIX + "f"
|
||||||
|
+ BUKKIT_COLOR_CODE_PREFIX + "f" + BUKKIT_COLOR_CODE_PREFIX + "0" + BUKKIT_COLOR_CODE_PREFIX + "0"
|
||||||
|
+ BUKKIT_COLOR_CODE_PREFIX + "f" + BUKKIT_COLOR_CODE_PREFIX + "f";
|
||||||
|
|
||||||
String result = Format.convertHexColorCodeToBukkitColorCode(hexColor);
|
String result = Format.convertHexColorCodeToBukkitColorCode(hexColor);
|
||||||
assertEquals(expectedResult, result);
|
assertEquals(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConvertHexColorCodeStringToBukkitColorCodeString() {
|
public void testConvertHexColorCodeStringToBukkitColorCodeString() {
|
||||||
String input = "#ff00ffHello§cThere#00ff00Austin";
|
String input = "#ff00ffHello" + BUKKIT_COLOR_CODE_PREFIX + "cThere#00ff00Austin";
|
||||||
String expectedResult = "§x§f§f§0§0§f§fHello§cThere§x§0§0§f§f§0§0Austin";
|
String expectedResult = BUKKIT_COLOR_CODE_PREFIX + "x" + BUKKIT_COLOR_CODE_PREFIX + "f"
|
||||||
|
+ BUKKIT_COLOR_CODE_PREFIX + "f" + BUKKIT_COLOR_CODE_PREFIX + "0" + BUKKIT_COLOR_CODE_PREFIX + "0"
|
||||||
|
+ BUKKIT_COLOR_CODE_PREFIX + "f" + BUKKIT_COLOR_CODE_PREFIX + "fHello" + BUKKIT_COLOR_CODE_PREFIX
|
||||||
|
+ "cThere" + BUKKIT_COLOR_CODE_PREFIX + "x" + BUKKIT_COLOR_CODE_PREFIX + "0" + BUKKIT_COLOR_CODE_PREFIX
|
||||||
|
+ "0" + BUKKIT_COLOR_CODE_PREFIX + "f" + BUKKIT_COLOR_CODE_PREFIX + "f" + BUKKIT_COLOR_CODE_PREFIX + "0"
|
||||||
|
+ BUKKIT_COLOR_CODE_PREFIX + "0Austin";
|
||||||
|
|
||||||
String result = Format.convertHexColorCodeStringToBukkitColorCodeString(input);
|
String result = Format.convertHexColorCodeStringToBukkitColorCodeString(input);
|
||||||
assertEquals(expectedResult, result);
|
assertEquals(expectedResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormatStringLegacyColor_NoColorCode() {
|
||||||
|
String input = "Hello There Austin";
|
||||||
|
String expectedResult = "Hello There Austin";
|
||||||
|
|
||||||
|
String result = Format.FormatStringLegacyColor(input);
|
||||||
|
assertEquals(expectedResult, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormatStringLegacyColor_LegacyCodeOnly() {
|
||||||
|
String input = "Hello &cThere Austin";
|
||||||
|
String expectedResult = "Hello " + BUKKIT_COLOR_CODE_PREFIX + "cThere Austin";
|
||||||
|
|
||||||
|
String result = Format.FormatStringLegacyColor(input);
|
||||||
|
assertEquals(expectedResult, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormatStringLegacyColor_SpigotHexCodeOnly() {
|
||||||
|
String input = "&x&f&f&f&f&f&fHello There Austin";
|
||||||
|
String expectedResult = "&x&f&f&f&f&f&fHello There Austin";
|
||||||
|
|
||||||
|
String result = Format.FormatStringLegacyColor(input);
|
||||||
|
assertEquals(expectedResult, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormatStringLegacyColor_BothColorCodes() {
|
||||||
|
String input = "&x&f&f&f&f&f&f&cHello There Austin";
|
||||||
|
String expectedResult = "&x&f&f&f&f&f&f" + BUKKIT_COLOR_CODE_PREFIX + "cHello There Austin";
|
||||||
|
|
||||||
|
String result = Format.FormatStringLegacyColor(input);
|
||||||
|
assertEquals(expectedResult, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user