├── README.md ├── .gitattributes ├── src └── main │ ├── resources │ ├── plugin.yml │ └── config.yml │ └── java │ └── me │ └── wikmor │ └── lpc │ └── LPC.java ├── .gitignore ├── UNLICENSE └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | # LPC 2 | A chat formatting plugin for LuckPerms. 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: ${project.name} 2 | description: ${project.description} 3 | version: ${project.version} 4 | main: ${main.class} 5 | author: ${author} 6 | api-version: 1.13 7 | depend: [LuckPerms] 8 | softdepend: [PlaceholderAPI] 9 | commands: 10 | lpc: 11 | description: Reload the configuration. 12 | permission: lpc.reload 13 | usage: "Usage: /lpc reload" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## IDEA 3 | ################# 4 | 5 | # User-specific stuff 6 | .idea/ 7 | .idea_modules/ 8 | *.iml 9 | 10 | # IntelliJ 11 | out/ 12 | 13 | target/ 14 | 15 | ################# 16 | ## Eclipse 17 | ################# 18 | 19 | *.pydevproject 20 | .project 21 | .metadata 22 | bin/ 23 | tmp/ 24 | *.tmp 25 | *.bak 26 | *.swp 27 | *~.nib 28 | local.properties 29 | .classpath 30 | .settings/ 31 | .loadpath 32 | .apt_generated/ 33 | .apt_generated_tests/ 34 | 35 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 36 | !/.mvn/wrapper/maven-wrapper.jar 37 | 38 | # External tool builders 39 | .externalToolBuilders/ 40 | 41 | # Locally stored "Eclipse launch configurations" 42 | *.launch 43 | 44 | # CDT-specific 45 | .cproject 46 | 47 | # PDT-specific 48 | .buildpath 49 | 50 | # Builder 51 | builder.xml 52 | build.xml 53 | 54 | ############# 55 | ## Windows detritus 56 | ############# 57 | 58 | # Windows image file caches 59 | Thumbs.db 60 | ehthumbs.db 61 | 62 | # Folder config file 63 | Desktop.ini 64 | 65 | # Recycle Bin used on file shares 66 | $RECYCLE.BIN/ 67 | 68 | # Mac crap 69 | .DS_Store 70 | REBASE.bat -------------------------------------------------------------------------------- /src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | # LPC Configuration 2 | # Please read the https://luckperms.net/wiki/Prefixes,-Suffixes-&-Meta before you set up. 3 | # 4 | # Placeholders: 5 | # {message} - the chat message 6 | # {name} - the player's name 7 | # {displayname} - the player's display name / nickname 8 | # {world} - the world name of the player's current world 9 | # {prefix} - the player's highest priority prefix 10 | # {suffix} - the player's highest priority suffix 11 | # {prefixes} - the player's prefixes sorted by the highest priority 12 | # {suffixes} - the player's suffixes sorted by the highest priority 13 | # {username-color} - the player's or the group's username color 14 | # {message-color} - the player's or the group's message color 15 | # 16 | # To reload the configuration, run '/lpc reload' command. Make sure you have the 'lpc.reload' permission assigned. 17 | # More information can be found at https://www.spigotmc.org/resources/68965. 18 | chat-format: "{prefix}{name}&r: {message}" 19 | 20 | # Set the format per group. 21 | # Note: Option for more advanced users. Remove comments to run. 22 | group-formats: 23 | # default: "[default] {name}&r: {message}" 24 | # admin: "[admin] {name}&r: {message}" -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | me.wikmor 6 | lpc 7 | LPC 8 | A chat formatting plugin for LuckPerms. 9 | 3.6.2 10 | jar 11 | 12 | 13 | wikmor 14 | me.wikmor.lpc.LPC 15 | 1.8 16 | UTF-8 17 | 18 | 19 | 20 | 21 | spigot-repo 22 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 23 | 24 | 25 | placeholderapi 26 | https://repo.extendedclip.com/content/repositories/placeholderapi/ 27 | 28 | 29 | 30 | 31 | 32 | maven-snapshots 33 | https://repository.apache.org/content/repositories/snapshots/ 34 | 35 | 36 | 37 | 38 | 39 | org.spigotmc 40 | spigot-api 41 | 1.21.5-R0.1-SNAPSHOT 42 | provided 43 | 44 | 45 | net.luckperms 46 | api 47 | 5.4 48 | provided 49 | 50 | 51 | me.clip 52 | placeholderapi 53 | 2.11.6 54 | provided 55 | 56 | 57 | 58 | 59 | 60 | ${project.name}-${project.version} 61 | 62 | 63 | org.apache.maven.plugins 64 | maven-jar-plugin 65 | 66 | 68 | 3.2.2 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-compiler-plugin 73 | 74 | 76 | 3.10.1 77 | 78 | ${java.version} 79 | ${java.version} 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-shade-plugin 85 | 86 | 88 | 3.3.1-SNAPSHOT 89 | 90 | 91 | package 92 | 93 | shade 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | src/main/resources 102 | true 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/main/java/me/wikmor/lpc/LPC.java: -------------------------------------------------------------------------------- 1 | package me.wikmor.lpc; 2 | 3 | import me.clip.placeholderapi.PlaceholderAPI; 4 | import net.luckperms.api.LuckPerms; 5 | import net.luckperms.api.cacheddata.CachedMetaData; 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.command.Command; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.EventPriority; 12 | import org.bukkit.event.Listener; 13 | import org.bukkit.event.player.AsyncPlayerChatEvent; 14 | import org.bukkit.plugin.java.JavaPlugin; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collections; 18 | import java.util.List; 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | import java.util.stream.Collectors; 22 | 23 | public final class LPC extends JavaPlugin implements Listener { 24 | 25 | private static final Pattern HEX_PATTERN = Pattern.compile("&#([A-Fa-f0-9]{6})"); 26 | 27 | private LuckPerms luckPerms; 28 | 29 | @Override 30 | public void onEnable() { 31 | // Load an instance of 'LuckPerms' using the services manager. 32 | this.luckPerms = getServer().getServicesManager().load(LuckPerms.class); 33 | 34 | saveDefaultConfig(); 35 | getServer().getPluginManager().registerEvents(this, this); 36 | } 37 | 38 | @Override 39 | public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { 40 | if (args.length == 1 && "reload".equals(args[0])) { 41 | reloadConfig(); 42 | 43 | sender.sendMessage(colorize("&aLPC has been reloaded.")); 44 | return true; 45 | } 46 | 47 | return false; 48 | } 49 | 50 | @Override 51 | public List onTabComplete(final CommandSender sender, final Command command, final String alias, final String[] args) { 52 | if (args.length == 1) 53 | return Collections.singletonList("reload"); 54 | 55 | return new ArrayList<>(); 56 | } 57 | 58 | @EventHandler(priority = EventPriority.HIGHEST) 59 | public void onChat(final AsyncPlayerChatEvent event) { 60 | final String message = event.getMessage(); 61 | final Player player = event.getPlayer(); 62 | 63 | // Get a LuckPerms cached metadata for the player. 64 | final CachedMetaData metaData = this.luckPerms.getPlayerAdapter(Player.class).getMetaData(player); 65 | final String group = metaData.getPrimaryGroup(); 66 | 67 | String format = getConfig().getString(getConfig().getString("group-formats." + group) != null ? "group-formats." + group : "chat-format") 68 | .replace("{prefix}", metaData.getPrefix() != null ? metaData.getPrefix() : "") 69 | .replace("{suffix}", metaData.getSuffix() != null ? metaData.getSuffix() : "") 70 | .replace("{prefixes}", metaData.getPrefixes().keySet().stream().map(key -> metaData.getPrefixes().get(key)).collect(Collectors.joining())) 71 | .replace("{suffixes}", metaData.getSuffixes().keySet().stream().map(key -> metaData.getSuffixes().get(key)).collect(Collectors.joining())) 72 | .replace("{world}", player.getWorld().getName()) 73 | .replace("{name}", player.getName()) 74 | .replace("{displayname}", player.getDisplayName()) 75 | .replace("{username-color}", metaData.getMetaValue("username-color") != null ? metaData.getMetaValue("username-color") : "") 76 | .replace("{message-color}", metaData.getMetaValue("message-color") != null ? metaData.getMetaValue("message-color") : ""); 77 | 78 | format = colorize(translateHexColorCodes(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI") ? PlaceholderAPI.setPlaceholders(player, format) : format)); 79 | 80 | event.setFormat(format.replace("{message}", player.hasPermission("lpc.colorcodes") && player.hasPermission("lpc.rgbcodes") 81 | ? colorize(translateHexColorCodes(message)) : player.hasPermission("lpc.colorcodes") ? colorize(message) : player.hasPermission("lpc.rgbcodes") 82 | ? translateHexColorCodes(message) : message).replace("%", "%%")); 83 | } 84 | 85 | private String colorize(final String message) { 86 | return ChatColor.translateAlternateColorCodes('&', message); 87 | } 88 | 89 | private String translateHexColorCodes(final String message) { 90 | final char colorChar = ChatColor.COLOR_CHAR; 91 | 92 | final Matcher matcher = HEX_PATTERN.matcher(message); 93 | final StringBuffer buffer = new StringBuffer(message.length() + 4 * 8); 94 | 95 | while (matcher.find()) { 96 | final String group = matcher.group(1); 97 | 98 | matcher.appendReplacement(buffer, colorChar + "x" 99 | + colorChar + group.charAt(0) + colorChar + group.charAt(1) 100 | + colorChar + group.charAt(2) + colorChar + group.charAt(3) 101 | + colorChar + group.charAt(4) + colorChar + group.charAt(5)); 102 | } 103 | 104 | return matcher.appendTail(buffer).toString(); 105 | } 106 | } --------------------------------------------------------------------------------