Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add permission checks for hex colors and magic color code #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/mineverse/Aust1n46/chat/command/chat/Me.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public boolean execute(CommandSender sender, String command, String[] args) {
msg = Format.FormatStringLegacyColor(msg);
}
if (sender.hasPermission("venturechat.color"))
msg = Format.FormatStringColor(msg);
msg = Format.FormatStringColor(msg, sender.hasPermission("venturechat.color.hex"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already exists a legacy only permission, so this is unnecessary.

if (sender.hasPermission("venturechat.format"))
msg = Format.FormatString(msg);
msg = Format.FormatString(msg, sender.hasPermission("venturechat.format.magic"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg = Format.FormatString(msg, sender.hasPermission("venturechat.format.magic"));
msg = Format.FormatString(msg, sender.hasPermission("venturechat.format.obfuscated"));

Is the technical name for &k

if (sender instanceof Player) {
Player p = (Player) sender;
Format.broadcastToServer("* " + p.getDisplayName() + msg);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mineverse/Aust1n46/chat/command/chat/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ public boolean execute(CommandSender sender, String command, String[] args) {
msg = Format.FormatStringLegacyColor(msg);
}
if (mcp.getPlayer().hasPermission("venturechat.color")) {
msg = Format.FormatStringColor(msg);
msg = Format.FormatStringColor(msg, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if (mcp.getPlayer().hasPermission("venturechat.format")) {
msg = Format.FormatString(msg);
msg = Format.FormatString(msg, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}
if (plugin.getConfig().getString("partyformat").equalsIgnoreCase("Default")) {
partyformat = ChatColor.GREEN + "[" + MineverseChatAPI.getMineverseChatPlayer(mcp.getParty()).getName() + "'s Party] " + mcp.getName() + ":" + msg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public boolean execute(CommandSender sender, String command, String[] args) {
msg = Format.FormatStringLegacyColor(msg);
}
if (mcp.getPlayer().hasPermission("venturechat.color")) {
msg = Format.FormatStringColor(msg);
msg = Format.FormatStringColor(msg, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if (mcp.getPlayer().hasPermission("venturechat.format")) {
msg = Format.FormatString(msg);
msg = Format.FormatString(msg, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}

send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", "")));
Expand Down Expand Up @@ -176,10 +176,10 @@ private void sendBungeeCordMessage(MineverseChatPlayer mcp, String command, Stri
msg = Format.FormatStringLegacyColor(msg);
}
if (mcp.getPlayer().hasPermission("venturechat.color")) {
msg = Format.FormatStringColor(msg);
msg = Format.FormatStringColor(msg, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if (mcp.getPlayer().hasPermission("venturechat.format")) {
msg = Format.FormatString(msg);
msg = Format.FormatString(msg, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}

String send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", "")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public boolean execute(CommandSender sender, String command, String[] args) {
msg = Format.FormatStringLegacyColor(msg);
}
if (mcp.getPlayer().hasPermission("venturechat.color")) {
msg = Format.FormatStringColor(msg);
msg = Format.FormatStringColor(msg, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if (mcp.getPlayer().hasPermission("venturechat.format")) {
msg = Format.FormatString(msg);
msg = Format.FormatString(msg, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}

send = Format
Expand Down Expand Up @@ -122,10 +122,10 @@ private void sendBungeeCordReply(MineverseChatPlayer mcp, String[] args) {
msg = Format.FormatStringLegacyColor(msg);
}
if (mcp.getPlayer().hasPermission("venturechat.color")) {
msg = Format.FormatStringColor(msg);
msg = Format.FormatStringColor(msg, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if (mcp.getPlayer().hasPermission("venturechat.format")) {
msg = Format.FormatString(msg);
msg = Format.FormatString(msg, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}

String send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatfrom").replaceAll("sender_", "")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public void handleTrueAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
filtered = Format.FormatStringLegacyColor(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
filtered = Format.FormatStringColor(filtered);
filtered = Format.FormatStringColor(filtered, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
filtered = Format.FormatString(filtered);
filtered = Format.FormatString(filtered, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}
filtered = " " + filtered;

Expand Down Expand Up @@ -168,10 +168,10 @@ public void handleTrueAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
filtered = Format.FormatStringLegacyColor(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
filtered = Format.FormatStringColor(filtered);
filtered = Format.FormatStringColor(filtered, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
filtered = Format.FormatString(filtered);
filtered = Format.FormatString(filtered, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}
filtered = " " + filtered;
if(plugin.getConfig().getString("partyformat").equalsIgnoreCase("Default")) {
Expand Down Expand Up @@ -468,10 +468,10 @@ else if(!(mplayer.getFactionName().equals(mplayerp.getFactionName()))) {
chat = Format.FormatStringLegacyColor(chat);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
chat = Format.FormatStringColor(chat);
chat = Format.FormatStringColor(chat, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
chat = Format.FormatString(chat);
chat = Format.FormatString(chat, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}
if(!mcp.isQuickChat()) {
chat = " " + chat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws
send = Format.FormatStringLegacyColor(send);
}
if (mcp.getPlayer().hasPermission("venturechat.color")) {
send = Format.FormatStringColor(send);
send = Format.FormatStringColor(send, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if (mcp.getPlayer().hasPermission("venturechat.format")) {
send = Format.FormatString(send);
send = Format.FormatString(send, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}
if (s.startsWith("Command:")) {
mcp.getPlayer().chat(s.substring(9).replace("$", send));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public void onSignChange(SignChangeEvent event) {
line = Format.FormatStringLegacyColor(line);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
line = Format.FormatStringColor(line);
line = Format.FormatStringColor(line, mcp.getPlayer().hasPermission("venturechat.color.hex"));
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
line = Format.FormatString(line);
line = Format.FormatString(line, mcp.getPlayer().hasPermission("venturechat.format.magic"));
}
event.setLine(a, line);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/mineverse/Aust1n46/chat/utilities/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ private static void splitComponents(List<Object> finalList, Object o, Class<?> c
* @param string to format.
* @return {@link String}
*/
public static String FormatStringColor(String string) {
public static String FormatStringColor(String string, boolean hex) {
String allFormated = string;
allFormated = LEGACY_CHAT_COLOR_DIGITS_PATTERN.matcher(allFormated).replaceAll("\u00A7$1");

Expand All @@ -644,7 +644,7 @@ public static String FormatStringColor(String string) {

allFormated = allFormated.replaceAll("%", "\\%");

allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated);
if(hex) allFormated = convertHexColorCodeStringToBukkitColorCodeString(allFormated);
return allFormated;
}

Expand Down Expand Up @@ -676,9 +676,9 @@ public static String FormatStringLegacyColor(String string) {
* @param string to format.
* @return {@link String}
*/
public static String FormatString(String string) {
public static String FormatString(String string, boolean magic) {
String allFormated = string;
allFormated = allFormated.replaceAll("&[kK]", BUKKIT_COLOR_CODE_PREFIX + "k");
if(magic) 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");
Expand All @@ -697,8 +697,8 @@ public static String FormatString(String string) {
* @return {@link String}
*/
public static String FormatStringAll(String string) {
String allFormated = Format.FormatString(string);
allFormated = Format.FormatStringColor(allFormated);
String allFormated = Format.FormatString(string, true);
allFormated = Format.FormatStringColor(allFormated, true);
return allFormated;
}

Expand Down