From 9f2e1e61a6f082a42fb4a863293f574ba73cc8c0 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 28 Jul 2022 22:20:29 +0200 Subject: [PATCH 1/9] Added permissions for specific parts of chat formatting --- README.md | 18 ++++++++++++++++ src/main/java/me/wikmor/lpc/LPC.java | 31 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/README.md b/README.md index 8f9c4d0..9ccd6e5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # LPC A chat formatting plugin for LuckPerms. + + +#Permissions +> /lpc reload `lpc.reload` + +> ColorCodes `lpc.colorcodes` + +> RGB + Requried for other formating `lpc.rgbcodes` + +>Italics `lpc.italics` + +>Strikethrough `lpc.strikethrough` + +>Underline `lpc.underline` + +>Bold `lpc.bold` + +>Magic `lpcmagic` diff --git a/src/main/java/me/wikmor/lpc/LPC.java b/src/main/java/me/wikmor/lpc/LPC.java index 2e5765f..0cd2dec 100644 --- a/src/main/java/me/wikmor/lpc/LPC.java +++ b/src/main/java/me/wikmor/lpc/LPC.java @@ -55,6 +55,26 @@ public List onTabComplete(final CommandSender sender, final Command comm return new ArrayList<>(); } + @EventHandler(priority = EventPriority.LOW) + public void onLowChat(AsyncPlayerChatEvent event){ + Player player = event.getPlayer(); + if (!player.hasPermission("lpc.magic")) { + event.setMessage(event.getMessage().replace("&k", "")); + } + if (!player.hasPermission("lpc.bold")) { + event.setMessage(event.getMessage().replace("&l", "")); + } + if (!player.hasPermission("lpc.underline")) { + event.setMessage(event.getMessage().replace("&n", "")); + } + if (!player.hasPermission("lpc.strikethrough")) { + event.setMessage(event.getMessage().replace("&m", "")); + } + if (!player.hasPermission("lpc.italics")) { + event.setMessage(event.getMessage().replace("&o", "")); + } + } + @EventHandler(priority = EventPriority.HIGHEST) public void onChat(final AsyncPlayerChatEvent event) { final String message = event.getMessage(); @@ -64,6 +84,9 @@ public void onChat(final AsyncPlayerChatEvent event) { final CachedMetaData metaData = this.luckPerms.getPlayerAdapter(Player.class).getMetaData(player); final String group = metaData.getPrimaryGroup(); + + + String format = getConfig().getString(getConfig().getString("group-formats." + group) != null ? "group-formats." + group : "chat-format") .replace("{prefix}", metaData.getPrefix() != null ? metaData.getPrefix() : "") .replace("{suffix}", metaData.getSuffix() != null ? metaData.getSuffix() : "") @@ -77,6 +100,14 @@ public void onChat(final AsyncPlayerChatEvent event) { format = colorize(translateHexColorCodes(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, format) : format)); + + + + + + + + event.setFormat(format.replace("{message}", player.hasPermission("lpc.colorcodes") && player.hasPermission("lpc.rgbcodes") ? colorize(translateHexColorCodes(message)) : player.hasPermission("lpc.colorcodes") ? colorize(message) : player.hasPermission("lpc.rgbcodes") ? translateHexColorCodes(message) : message).replace("%", "%%")); From 8463a696467a5905ad27f4eed57ad48fe4e92487 Mon Sep 17 00:00:00 2001 From: InteliJ <97313380+PhoenixZTT@users.noreply.github.com> Date: Sun, 30 Oct 2022 19:30:55 -0400 Subject: [PATCH 2/9] fixed bug --- README.md | 2 +- src/main/java/me/wikmor/lpc/LPC.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ccd6e5..cb00b33 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,4 @@ A chat formatting plugin for LuckPerms. >Bold `lpc.bold` ->Magic `lpcmagic` +>Magic `lpc.magic` diff --git a/src/main/java/me/wikmor/lpc/LPC.java b/src/main/java/me/wikmor/lpc/LPC.java index 0cd2dec..af3d17b 100644 --- a/src/main/java/me/wikmor/lpc/LPC.java +++ b/src/main/java/me/wikmor/lpc/LPC.java @@ -60,18 +60,23 @@ public void onLowChat(AsyncPlayerChatEvent event){ Player player = event.getPlayer(); if (!player.hasPermission("lpc.magic")) { event.setMessage(event.getMessage().replace("&k", "")); + event.setMessage(event.getMessage().replace("&K", "")); } if (!player.hasPermission("lpc.bold")) { event.setMessage(event.getMessage().replace("&l", "")); + event.setMessage(event.getMessage().replace("&L", "")); } if (!player.hasPermission("lpc.underline")) { event.setMessage(event.getMessage().replace("&n", "")); + event.setMessage(event.getMessage().replace("&N", "")); } if (!player.hasPermission("lpc.strikethrough")) { event.setMessage(event.getMessage().replace("&m", "")); + event.setMessage(event.getMessage().replace("&M", "")); } if (!player.hasPermission("lpc.italics")) { event.setMessage(event.getMessage().replace("&o", "")); + event.setMessage(event.getMessage().replace("&O", "")); } } From 4bb9ad82f4dfcb0f7b201223463033e51e9e4652 Mon Sep 17 00:00:00 2001 From: InteliJ <97313380+PhoenixZTT@users.noreply.github.com> Date: Sun, 30 Oct 2022 19:32:13 -0400 Subject: [PATCH 3/9] changed jar name --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9aaac2d..65cbfee 100644 --- a/pom.xml +++ b/pom.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 me.wikmor - lpc - LPC + lpc-vanillaplus + LPC-vanillaplus A chat formatting plugin for LuckPerms. 3.6.0 jar From 9b6fc993f80fc098cad8dadcb5d2a1d2d7c5a970 Mon Sep 17 00:00:00 2001 From: Noah Ross Date: Thu, 30 May 2024 05:20:04 -0700 Subject: [PATCH 4/9] make jar name generic --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 65cbfee..ba52d49 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 me.wikmor lpc-vanillaplus - LPC-vanillaplus + LPC-color A chat formatting plugin for LuckPerms. 3.6.0 jar From 56125359b0bec1a918b56c4f8abe29eecfc7db82 Mon Sep 17 00:00:00 2001 From: Noah Ross Date: Thu, 30 May 2024 05:20:22 -0700 Subject: [PATCH 5/9] refactor ternary for simplicity --- src/main/java/me/wikmor/lpc/LPC.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/wikmor/lpc/LPC.java b/src/main/java/me/wikmor/lpc/LPC.java index af3d17b..8e13291 100644 --- a/src/main/java/me/wikmor/lpc/LPC.java +++ b/src/main/java/me/wikmor/lpc/LPC.java @@ -78,6 +78,7 @@ public void onLowChat(AsyncPlayerChatEvent event){ event.setMessage(event.getMessage().replace("&o", "")); event.setMessage(event.getMessage().replace("&O", "")); } + } @EventHandler(priority = EventPriority.HIGHEST) @@ -105,17 +106,19 @@ public void onChat(final AsyncPlayerChatEvent event) { format = colorize(translateHexColorCodes(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, format) : format)); + String formattedMessage; + if (player.hasPermission("lpc.colorcodes") && player.hasPermission("lpc.rgbcodes")) { + formattedMessage = colorize(translateHexColorCodes(message)); + } else if (player.hasPermission("lpc.colorcodes")) { + formattedMessage = colorize(message); + } else if (player.hasPermission("lpc.rgbcodes")) { + formattedMessage = translateHexColorCodes(message); + } else { + formattedMessage = message; + } - - - - - - - event.setFormat(format.replace("{message}", player.hasPermission("lpc.colorcodes") && player.hasPermission("lpc.rgbcodes") - ? colorize(translateHexColorCodes(message)) : player.hasPermission("lpc.colorcodes") ? colorize(message) : player.hasPermission("lpc.rgbcodes") - ? translateHexColorCodes(message) : message).replace("%", "%%")); + event.setFormat(format.replace("{message}", formattedMessage).replace("%", "%%")); } private String colorize(final String message) { From 72634c3df8316cab7d3890e6690a448616d7c4aa Mon Sep 17 00:00:00 2001 From: Noah Ross Date: Thu, 30 May 2024 06:46:50 -0700 Subject: [PATCH 6/9] update permissions in plugin.yml --- src/main/resources/plugin.yml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3627730..d60fb69 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -10,4 +10,33 @@ commands: lpc: description: Reload the configuration. permission: lpc.reload - usage: "Usage: /lpc reload" \ No newline at end of file + usage: "Usage: /lpc reload" + +permissions: + lpc.reload: + description: Allows the player to reload the configuration. + default: op + lpc.colorcodes: + description: Allows the player to use color codes. (e.g. &a, &b, &c, &d, &e, &f, &0, &1, &2, &3, &4, &5, &6, &7, &8, &9) + default: op + lpc.reset: + description: Allows the player to reset the chat format. (e.g. &r) + default: op + lpc.bold: + description: Allows the player to use bold text. (e.g. &l) + default: op + lpc.italic: + description: Allows the player to use italic text. (e.g. &o) + default: op + lpc.underline: + description: Allows the player to use underline text. (e.g. &n) + default: op + lpc.strikethrough: + description: Allows the player to use strikethrough text. (e.g. &m) + default: op + lpc.magic: + description: Allows the player to use magic text. (e.g. &k) + default: op + lpc.rgbcodes: + description: Allows the player to use RGB color codes. (e.g. &#ff0000) + default: op \ No newline at end of file From 5b5e08ff834f462797e20e0270d77617af392cbe Mon Sep 17 00:00:00 2001 From: Noah Ross Date: Thu, 30 May 2024 06:47:44 -0700 Subject: [PATCH 7/9] update how permissions are checked to fix possible bypass change package name, update authors, bump version --- pom.xml | 18 +-- .../java/{me/wikmor => dev/noah}/lpc/LPC.java | 123 +++++++++++------- 2 files changed, 88 insertions(+), 53 deletions(-) rename src/main/java/{me/wikmor => dev/noah}/lpc/LPC.java (52%) diff --git a/pom.xml b/pom.xml index ba52d49..5dc768a 100644 --- a/pom.xml +++ b/pom.xml @@ -2,16 +2,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - me.wikmor - lpc-vanillaplus + dev.noah + lpc-color LPC-color - A chat formatting plugin for LuckPerms. - 3.6.0 + A chat formatting plugin for LuckPerms with support for color and formatting permissions. + 4.0.0 jar - wikmor - me.wikmor.lpc.LPC + wikmor, noah + dev.noah.lpc.LPC 1.8 UTF-8 @@ -38,7 +38,7 @@ org.spigotmc spigot-api - 1.19-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT provided @@ -75,8 +75,8 @@ https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin --> 3.10.1 - ${java.version} - ${java.version} + 8 + 8 diff --git a/src/main/java/me/wikmor/lpc/LPC.java b/src/main/java/dev/noah/lpc/LPC.java similarity index 52% rename from src/main/java/me/wikmor/lpc/LPC.java rename to src/main/java/dev/noah/lpc/LPC.java index 8e13291..2271500 100644 --- a/src/main/java/me/wikmor/lpc/LPC.java +++ b/src/main/java/dev/noah/lpc/LPC.java @@ -1,4 +1,4 @@ -package me.wikmor.lpc; +package dev.noah.lpc; import me.clip.placeholderapi.PlaceholderAPI; import net.luckperms.api.LuckPerms; @@ -40,7 +40,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina if (args.length == 1 && "reload".equals(args[0])) { reloadConfig(); - sender.sendMessage(colorize("&aLPC has been reloaded.")); + sender.sendMessage(unsafeColorize("&aLPC has been reloaded.")); return true; } @@ -55,31 +55,6 @@ public List onTabComplete(final CommandSender sender, final Command comm return new ArrayList<>(); } - @EventHandler(priority = EventPriority.LOW) - public void onLowChat(AsyncPlayerChatEvent event){ - Player player = event.getPlayer(); - if (!player.hasPermission("lpc.magic")) { - event.setMessage(event.getMessage().replace("&k", "")); - event.setMessage(event.getMessage().replace("&K", "")); - } - if (!player.hasPermission("lpc.bold")) { - event.setMessage(event.getMessage().replace("&l", "")); - event.setMessage(event.getMessage().replace("&L", "")); - } - if (!player.hasPermission("lpc.underline")) { - event.setMessage(event.getMessage().replace("&n", "")); - event.setMessage(event.getMessage().replace("&N", "")); - } - if (!player.hasPermission("lpc.strikethrough")) { - event.setMessage(event.getMessage().replace("&m", "")); - event.setMessage(event.getMessage().replace("&M", "")); - } - if (!player.hasPermission("lpc.italics")) { - event.setMessage(event.getMessage().replace("&o", "")); - event.setMessage(event.getMessage().replace("&O", "")); - } - - } @EventHandler(priority = EventPriority.HIGHEST) public void onChat(final AsyncPlayerChatEvent event) { @@ -90,9 +65,6 @@ public void onChat(final AsyncPlayerChatEvent event) { final CachedMetaData metaData = this.luckPerms.getPlayerAdapter(Player.class).getMetaData(player); final String group = metaData.getPrimaryGroup(); - - - String format = getConfig().getString(getConfig().getString("group-formats." + group) != null ? "group-formats." + group : "chat-format") .replace("{prefix}", metaData.getPrefix() != null ? metaData.getPrefix() : "") .replace("{suffix}", metaData.getSuffix() != null ? metaData.getSuffix() : "") @@ -104,25 +76,88 @@ public void onChat(final AsyncPlayerChatEvent event) { .replace("{username-color}", metaData.getMetaValue("username-color") != null ? metaData.getMetaValue("username-color") : "") .replace("{message-color}", metaData.getMetaValue("message-color") != null ? metaData.getMetaValue("message-color") : ""); - format = colorize(translateHexColorCodes(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, format) : format)); + format = unsafeColorize(translateHexColorCodes(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, format) : format)); - String formattedMessage; + event.setFormat(format.replace("{message}", colorize(message,player)).replace("%", "%%")); + } - if (player.hasPermission("lpc.colorcodes") && player.hasPermission("lpc.rgbcodes")) { - formattedMessage = colorize(translateHexColorCodes(message)); - } else if (player.hasPermission("lpc.colorcodes")) { - formattedMessage = colorize(message); - } else if (player.hasPermission("lpc.rgbcodes")) { - formattedMessage = translateHexColorCodes(message); - } else { - formattedMessage = message; + // Old colorize method without any checks + private String unsafeColorize(final String message) { + return ChatColor.translateAlternateColorCodes('&', message); + } + + private String colorize(final String message, Player player) { + String output = message; + //do each step / color on its own and check for permissions for each step + if (player.hasPermission("lpc.colorcodes")) { + //translate each color individually + output = output.replace("&0", ChatColor.BLACK.toString()); + output = output.replace("&1", ChatColor.DARK_BLUE.toString()); + output = output.replace("&2", ChatColor.DARK_GREEN.toString()); + output = output.replace("&3", ChatColor.DARK_AQUA.toString()); + output = output.replace("&4", ChatColor.DARK_RED.toString()); + output = output.replace("&5", ChatColor.DARK_PURPLE.toString()); + output = output.replace("&6", ChatColor.GOLD.toString()); + output = output.replace("&7", ChatColor.GRAY.toString()); + output = output.replace("&8", ChatColor.DARK_GRAY.toString()); + output = output.replace("&9", ChatColor.BLUE.toString()); + + output = output.replace("&a", ChatColor.GREEN.toString()); + output = output.replace("&A", ChatColor.GREEN.toString()); + + output = output.replace("&b", ChatColor.AQUA.toString()); + output = output.replace("&B", ChatColor.AQUA.toString()); + + output = output.replace("&c", ChatColor.RED.toString()); + output = output.replace("&C", ChatColor.RED.toString()); + + output = output.replace("&d", ChatColor.LIGHT_PURPLE.toString()); + output = output.replace("&D", ChatColor.LIGHT_PURPLE.toString()); + + output = output.replace("&e", ChatColor.YELLOW.toString()); + output = output.replace("&E", ChatColor.YELLOW.toString()); + + output = output.replace("&f", ChatColor.WHITE.toString()); + output = output.replace("&F", ChatColor.WHITE.toString()); } - event.setFormat(format.replace("{message}", formattedMessage).replace("%", "%%")); - } + if (player.hasPermission("lpc.magic")) { + //translate magic + output = output.replace("&k", ChatColor.MAGIC.toString()); + output = output.replace("&K", ChatColor.MAGIC.toString()); + } + if(player.hasPermission("lpc.bold")) { + //translate bold + output = output.replace("&l", ChatColor.BOLD.toString()); + output = output.replace("&L", ChatColor.BOLD.toString()); + } + if(player.hasPermission("lpc.underline")) { + //translate underline + output = output.replace("&n", ChatColor.UNDERLINE.toString()); + output = output.replace("&N", ChatColor.UNDERLINE.toString()); + } + if(player.hasPermission("lpc.italics")) { + //translate italics + output = output.replace("&o", ChatColor.ITALIC.toString()); + output = output.replace("&O", ChatColor.ITALIC.toString()); + } + if(player.hasPermission("lpc.strikethrough")) { + //translate strikethrough + output = output.replace("&m", ChatColor.STRIKETHROUGH.toString()); + output = output.replace("&M", ChatColor.STRIKETHROUGH.toString()); - private String colorize(final String message) { - return ChatColor.translateAlternateColorCodes('&', message); + } + if(player.hasPermission("lpc.reset")){ + //translate reset + output = output.replace("&r", ChatColor.RESET.toString()); + output = output.replace("&R", ChatColor.RESET.toString()); + } + + if(player.hasPermission("lpc.rgbcodes")){ + output = translateHexColorCodes(output); + } + + return output; } private String translateHexColorCodes(final String message) { From 3ca90fa5a2b2316271afc8289ab13759666a0fd2 Mon Sep 17 00:00:00 2001 From: Noah Ross Date: Thu, 30 May 2024 06:52:39 -0700 Subject: [PATCH 8/9] update readme and license --- README.md | 13 ++++++++----- UNLICENSE | 24 ------------------------ 2 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 UNLICENSE diff --git a/README.md b/README.md index cb00b33..fb0c076 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# LPC -A chat formatting plugin for LuckPerms. +# LPC-Color +A chat formatting plugin for LuckPerms with support for color and formatting permissions. -#Permissions +# Permissions > /lpc reload `lpc.reload` -> ColorCodes `lpc.colorcodes` +>ColorCodes `lpc.colorcodes` -> RGB + Requried for other formating `lpc.rgbcodes` +>Reset `lpc.reset` >Italics `lpc.italics` @@ -18,3 +18,6 @@ A chat formatting plugin for LuckPerms. >Bold `lpc.bold` >Magic `lpc.magic` + +>RGB Color Codes `lpc.rgbcodes` + diff --git a/UNLICENSE b/UNLICENSE deleted file mode 100644 index 68a49da..0000000 --- a/UNLICENSE +++ /dev/null @@ -1,24 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -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 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. - -For more information, please refer to From f846c2c23e8a8df4d5c4719385458473de34f751 Mon Sep 17 00:00:00 2001 From: Noah Ross Date: Thu, 30 May 2024 06:55:16 -0700 Subject: [PATCH 9/9] license --- LICENSE | 1 + 1 file changed, 1 insertion(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2fd5a9b --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +ALL RIGHTS RESERVED. \ No newline at end of file