Skip to content

Commit c9901ca

Browse files
Fixed HEX colors on newer versions within PlayerBalancerAddon
Cleaned up some code
1 parent 543e000 commit c9901ca

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerAddon.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ public void updateCheck() {
7575
return;
7676
}
7777
}
78-
79-
@Override
80-
public void onDisable() {
81-
// Nothing to do...
82-
}
83-
8478
public PluginMessageManager getManager() {
8579
return manager;
8680
}

addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerPlaceholderExpansion.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ public String onRequest(OfflinePlayer player, String identifier) {
2424

2525
// For the first call this placeholder will return 0
2626
// For the next one, the result of the previous one
27-
plugin.getManager().getSectionPlayerCount(section, (count) -> {
28-
sectionPlayerCounts.put(section, count);
29-
});
27+
plugin.getManager().getSectionPlayerCount(section, (count) -> sectionPlayerCounts.put(section, count));
3028

3129
return String.valueOf(sectionPlayerCounts.getOrDefault(section, 0));
3230
}
Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.jaimemartz.playerbalanceraddon.util;
22

3-
import org.bukkit.Bukkit;
43
import org.bukkit.ChatColor;
54

65
import java.util.List;
@@ -10,30 +9,22 @@
109

1110
public class Color {
1211

13-
public static String translate(String message) {
14-
if (isOnePointSixteenPlus()) {
15-
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
16-
Matcher matcher = pattern.matcher(message);
12+
private static final Pattern HEX_PATTERN = Pattern.compile("(&#[0-9a-fA-F]{6})");
1713

18-
while (matcher.find()) {
19-
String color = message.substring(matcher.start(), matcher.end());
20-
message = message.replace(color, net.md_5.bungee.api.ChatColor.of(color) + "");
21-
matcher = pattern.matcher(message);
22-
}
14+
public static String translate(String message) {
15+
Matcher matcher = HEX_PATTERN.matcher(message);
16+
StringBuffer sb = new StringBuffer();
17+
while (matcher.find()) {
18+
String hex = matcher.group(1).substring(1);
19+
matcher.appendReplacement(sb, net.md_5.bungee.api.ChatColor.of(hex) + "");
2320
}
21+
matcher.appendTail(sb);
2422

25-
return ChatColor.translateAlternateColorCodes('&', message);
26-
}
23+
String hexColored = sb.toString();
2724

25+
return ChatColor.translateAlternateColorCodes('&', hexColored);
26+
}
2827
public static List<String> translate(List<String> source) {
2928
return source.stream().map(Color::translate).collect(Collectors.toList());
3029
}
31-
32-
public static boolean isOnePointSixteenPlus() {
33-
if (Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17") || Bukkit.getVersion().contains("1.18")) {
34-
return true;
35-
}
36-
return false;
37-
}
38-
3930
}

0 commit comments

Comments
 (0)