From 66ff1fc2b5e993a0ee4cd8ad21641866e8caa2a1 Mon Sep 17 00:00:00 2001 From: speedxx <43330808+speedxx@users.noreply.github.com> Date: Sat, 11 Jul 2020 23:34:30 -0400 Subject: [PATCH] support for hex color codes --- .../tfguilds/command/DisbandGuildCommand.java | 2 +- .../tfguilds/command/GuildTagCommand.java | 4 ++-- .../tfguilds/command/LeaveGuildCommand.java | 2 +- .../me/totalfreedom/tfguilds/util/GUtil.java | 17 +++++++++++++++++ src/main/resources/plugin.yml | 4 ++-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandGuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandGuildCommand.java index 3502b71..0e626e6 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/DisbandGuildCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/DisbandGuildCommand.java @@ -39,7 +39,7 @@ public class DisbandGuildCommand implements CommandExecutor if (args.length == 0) { - player.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type 'CONFIRM' to continue."); + player.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type '/disbandguild CONFIRM' or '/deleteguild CONFIRM' to continue."); return true; } diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java index 8581d6e..c673dca 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java @@ -50,8 +50,8 @@ public class GuildTagCommand extends GBase implements CommandExecutor tag = tag.replace("%tag%", guild); - GUtil.setTag(GUtil.color(tag) + " ", guild); - player.sendMessage(ChatColor.GREEN + "Guild tag set to \"" + GUtil.color(tag) + ChatColor.GREEN + "\""); + GUtil.setTag(GUtil.translateHexColorCodes(tag) + " ", guild); + player.sendMessage(ChatColor.GREEN + "Guild tag set to \"" + GUtil.translateHexColorCodes(tag) + ChatColor.GREEN + "\""); return true; } } diff --git a/src/main/java/me/totalfreedom/tfguilds/command/LeaveGuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/LeaveGuildCommand.java index bf256f4..b8e4dd1 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/LeaveGuildCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/LeaveGuildCommand.java @@ -41,7 +41,7 @@ public class LeaveGuildCommand extends GBase implements CommandExecutor if (args.length == 0) { - player.sendMessage(ChatColor.RED + "Are you sure you want to leave your guild? Type 'CONFIRM' to continue."); + player.sendMessage(ChatColor.RED + "Are you sure you want to leave your guild? Type '/leaveguild CONFIRM' or '/guildleave CONFIRM' to continue."); return true; } diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java index 46f7636..01f85a0 100644 --- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java +++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java @@ -15,6 +15,8 @@ import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class GUtil { @@ -229,4 +231,19 @@ public class GUtil { return ChatColor.translateAlternateColorCodes('&', s); } + + public static String translateHexColorCodes(String message) + { + Pattern pattern = Pattern.compile("&#[a-f0-9A-F]{6}"); + Matcher matcher = pattern.matcher(message); + + while (matcher.find()) + { + String color = matcher.group().replace("&", ""); + message = message.replace("&" + color, net.md_5.bungee.api.ChatColor.of(color) + ""); + } + + message = ChatColor.translateAlternateColorCodes('&', message); + return message; + } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6895ac0..531f195 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -24,7 +24,7 @@ commands: aliases: [gchat] disbandguild: description: Deletes your guild - usage: / + usage: / aliases: [deleteguild] guildteleport: description: Teleport to other guild members @@ -36,7 +36,7 @@ commands: aliases: [guildinvite] leaveguild: description: Leave your guild - usage: / + usage: / aliases: [guildleave] guildkick: description: Kicks a player from the guild