mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 17:15:47 +00:00
hex support 1.8 - 1.18 + command event after fix
This commit is contained in:
parent
300f97b522
commit
92b244e9d1
@ -49,9 +49,10 @@ public class Commands {
|
||||
RTP_CommandEvent event = new RTP_CommandEvent(sendi, cmd);
|
||||
//Command Event
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled())
|
||||
if (!event.isCancelled()) {
|
||||
cmd.execute(sendi, label, args);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CommandEvent_After(sendi, cmd));
|
||||
}
|
||||
} else
|
||||
pl.getText().getNoPermission(sendi);
|
||||
return;
|
||||
|
@ -5,6 +5,8 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Messages {
|
||||
private final String preM = "Messages.", preH = "Help.", preU = "Usage.";
|
||||
@ -129,7 +131,28 @@ public class Messages {
|
||||
}
|
||||
|
||||
public String color(String str) {
|
||||
return ChatColor.translateAlternateColorCodes('&', str);
|
||||
return translateHexColorCodes(str);
|
||||
}
|
||||
|
||||
//Thank you to zwrumpy on Spigot! (https://www.spigotmc.org/threads/hex-color-code-translate.449748/#post-4270781)
|
||||
//Supports 1.8 to 1.18
|
||||
private static String translateHexColorCodes(String message) {
|
||||
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
while (matcher.find()) {
|
||||
String hexCode = message.substring(matcher.start(), matcher.end());
|
||||
String replaceSharp = hexCode.replace('#', 'x');
|
||||
|
||||
char[] ch = replaceSharp.toCharArray();
|
||||
StringBuilder builder = new StringBuilder("");
|
||||
for (char c : ch) {
|
||||
builder.append("&").append(c);
|
||||
}
|
||||
|
||||
message = message.replace(hexCode, builder.toString());
|
||||
matcher = pattern.matcher(message);
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
public String colorPre(String str) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user