1- package me . wikmor .lpc ;
1+ package dev . noah .lpc ;
22
33import me .clip .placeholderapi .PlaceholderAPI ;
44import net .luckperms .api .LuckPerms ;
@@ -40,7 +40,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
4040 if (args .length == 1 && "reload" .equals (args [0 ])) {
4141 reloadConfig ();
4242
43- sender .sendMessage (colorize ("&aLPC has been reloaded." ));
43+ sender .sendMessage (unsafeColorize ("&aLPC has been reloaded." ));
4444 return true ;
4545 }
4646
@@ -55,31 +55,6 @@ public List<String> onTabComplete(final CommandSender sender, final Command comm
5555 return new ArrayList <>();
5656 }
5757
58- @ EventHandler (priority = EventPriority .LOW )
59- public void onLowChat (AsyncPlayerChatEvent event ){
60- Player player = event .getPlayer ();
61- if (!player .hasPermission ("lpc.magic" )) {
62- event .setMessage (event .getMessage ().replace ("&k" , "" ));
63- event .setMessage (event .getMessage ().replace ("&K" , "" ));
64- }
65- if (!player .hasPermission ("lpc.bold" )) {
66- event .setMessage (event .getMessage ().replace ("&l" , "" ));
67- event .setMessage (event .getMessage ().replace ("&L" , "" ));
68- }
69- if (!player .hasPermission ("lpc.underline" )) {
70- event .setMessage (event .getMessage ().replace ("&n" , "" ));
71- event .setMessage (event .getMessage ().replace ("&N" , "" ));
72- }
73- if (!player .hasPermission ("lpc.strikethrough" )) {
74- event .setMessage (event .getMessage ().replace ("&m" , "" ));
75- event .setMessage (event .getMessage ().replace ("&M" , "" ));
76- }
77- if (!player .hasPermission ("lpc.italics" )) {
78- event .setMessage (event .getMessage ().replace ("&o" , "" ));
79- event .setMessage (event .getMessage ().replace ("&O" , "" ));
80- }
81-
82- }
8358
8459 @ EventHandler (priority = EventPriority .HIGHEST )
8560 public void onChat (final AsyncPlayerChatEvent event ) {
@@ -90,9 +65,6 @@ public void onChat(final AsyncPlayerChatEvent event) {
9065 final CachedMetaData metaData = this .luckPerms .getPlayerAdapter (Player .class ).getMetaData (player );
9166 final String group = metaData .getPrimaryGroup ();
9267
93-
94-
95-
9668 String format = getConfig ().getString (getConfig ().getString ("group-formats." + group ) != null ? "group-formats." + group : "chat-format" )
9769 .replace ("{prefix}" , metaData .getPrefix () != null ? metaData .getPrefix () : "" )
9870 .replace ("{suffix}" , metaData .getSuffix () != null ? metaData .getSuffix () : "" )
@@ -104,25 +76,88 @@ public void onChat(final AsyncPlayerChatEvent event) {
10476 .replace ("{username-color}" , metaData .getMetaValue ("username-color" ) != null ? metaData .getMetaValue ("username-color" ) : "" )
10577 .replace ("{message-color}" , metaData .getMetaValue ("message-color" ) != null ? metaData .getMetaValue ("message-color" ) : "" );
10678
107- format = colorize (translateHexColorCodes (getServer ().getPluginManager ().isPluginEnabled ("PlaceholderAPI" ) ? PlaceholderAPI .setPlaceholders (player , format ) : format ));
79+ format = unsafeColorize (translateHexColorCodes (getServer ().getPluginManager ().isPluginEnabled ("PlaceholderAPI" ) ? PlaceholderAPI .setPlaceholders (player , format ) : format ));
10880
109- String formattedMessage ;
81+ event .setFormat (format .replace ("{message}" , colorize (message ,player )).replace ("%" , "%%" ));
82+ }
11083
111- if (player .hasPermission ("lpc.colorcodes" ) && player .hasPermission ("lpc.rgbcodes" )) {
112- formattedMessage = colorize (translateHexColorCodes (message ));
113- } else if (player .hasPermission ("lpc.colorcodes" )) {
114- formattedMessage = colorize (message );
115- } else if (player .hasPermission ("lpc.rgbcodes" )) {
116- formattedMessage = translateHexColorCodes (message );
117- } else {
118- formattedMessage = message ;
84+ // Old colorize method without any checks
85+ private String unsafeColorize (final String message ) {
86+ return ChatColor .translateAlternateColorCodes ('&' , message );
87+ }
88+
89+ private String colorize (final String message , Player player ) {
90+ String output = message ;
91+ //do each step / color on its own and check for permissions for each step
92+ if (player .hasPermission ("lpc.colorcodes" )) {
93+ //translate each color individually
94+ output = output .replace ("&0" , ChatColor .BLACK .toString ());
95+ output = output .replace ("&1" , ChatColor .DARK_BLUE .toString ());
96+ output = output .replace ("&2" , ChatColor .DARK_GREEN .toString ());
97+ output = output .replace ("&3" , ChatColor .DARK_AQUA .toString ());
98+ output = output .replace ("&4" , ChatColor .DARK_RED .toString ());
99+ output = output .replace ("&5" , ChatColor .DARK_PURPLE .toString ());
100+ output = output .replace ("&6" , ChatColor .GOLD .toString ());
101+ output = output .replace ("&7" , ChatColor .GRAY .toString ());
102+ output = output .replace ("&8" , ChatColor .DARK_GRAY .toString ());
103+ output = output .replace ("&9" , ChatColor .BLUE .toString ());
104+
105+ output = output .replace ("&a" , ChatColor .GREEN .toString ());
106+ output = output .replace ("&A" , ChatColor .GREEN .toString ());
107+
108+ output = output .replace ("&b" , ChatColor .AQUA .toString ());
109+ output = output .replace ("&B" , ChatColor .AQUA .toString ());
110+
111+ output = output .replace ("&c" , ChatColor .RED .toString ());
112+ output = output .replace ("&C" , ChatColor .RED .toString ());
113+
114+ output = output .replace ("&d" , ChatColor .LIGHT_PURPLE .toString ());
115+ output = output .replace ("&D" , ChatColor .LIGHT_PURPLE .toString ());
116+
117+ output = output .replace ("&e" , ChatColor .YELLOW .toString ());
118+ output = output .replace ("&E" , ChatColor .YELLOW .toString ());
119+
120+ output = output .replace ("&f" , ChatColor .WHITE .toString ());
121+ output = output .replace ("&F" , ChatColor .WHITE .toString ());
119122 }
120123
121- event .setFormat (format .replace ("{message}" , formattedMessage ).replace ("%" , "%%" ));
122- }
124+ if (player .hasPermission ("lpc.magic" )) {
125+ //translate magic
126+ output = output .replace ("&k" , ChatColor .MAGIC .toString ());
127+ output = output .replace ("&K" , ChatColor .MAGIC .toString ());
128+ }
129+ if (player .hasPermission ("lpc.bold" )) {
130+ //translate bold
131+ output = output .replace ("&l" , ChatColor .BOLD .toString ());
132+ output = output .replace ("&L" , ChatColor .BOLD .toString ());
133+ }
134+ if (player .hasPermission ("lpc.underline" )) {
135+ //translate underline
136+ output = output .replace ("&n" , ChatColor .UNDERLINE .toString ());
137+ output = output .replace ("&N" , ChatColor .UNDERLINE .toString ());
138+ }
139+ if (player .hasPermission ("lpc.italics" )) {
140+ //translate italics
141+ output = output .replace ("&o" , ChatColor .ITALIC .toString ());
142+ output = output .replace ("&O" , ChatColor .ITALIC .toString ());
143+ }
144+ if (player .hasPermission ("lpc.strikethrough" )) {
145+ //translate strikethrough
146+ output = output .replace ("&m" , ChatColor .STRIKETHROUGH .toString ());
147+ output = output .replace ("&M" , ChatColor .STRIKETHROUGH .toString ());
123148
124- private String colorize (final String message ) {
125- return ChatColor .translateAlternateColorCodes ('&' , message );
149+ }
150+ if (player .hasPermission ("lpc.reset" )){
151+ //translate reset
152+ output = output .replace ("&r" , ChatColor .RESET .toString ());
153+ output = output .replace ("&R" , ChatColor .RESET .toString ());
154+ }
155+
156+ if (player .hasPermission ("lpc.rgbcodes" )){
157+ output = translateHexColorCodes (output );
158+ }
159+
160+ return output ;
126161 }
127162
128163 private String translateHexColorCodes (final String message ) {
0 commit comments