Skip to content

Commit

Permalink
1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ImDaMilan committed Feb 11, 2023
1 parent bf409c5 commit bae361e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.imdamilan</groupId>
<artifactId>SpigotAdditions</artifactId>
<version>1.2</version>
<version>1.2.2</version>
<packaging>jar</packaging>

<name>SpigotAdditions</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import com.imdamilan.spigotadditions.SpigotAdditions;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;

import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BukkitUtils {

Expand Down Expand Up @@ -235,7 +238,30 @@ public static String getColorCoded(String string) {
* @return The string with color codes.
*/
public static String getColorCoded(String string, char colorCode) {
return string.replace(colorCode, '§');
return ChatColor.translateAlternateColorCodes(colorCode, string);
}

/**
* Returns the string with the hex color codes replaced with the desired color.
* The hex color codes must be in the format of &#RRGGBB.
* @param message The string to replace.
* @return The string with hex color codes replaced.
*/
public static String applyHex(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').replace("&", "");
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);
}

/**
Expand Down

0 comments on commit bae361e

Please sign in to comment.