Skip to content

Commit

Permalink
Merge pull request #5 from stevimeister/patch-2
Browse files Browse the repository at this point in the history
Update MessageUtil.java
  • Loading branch information
arthurr0 authored Nov 6, 2021
2 parents 300dc20 + ec7ac7d commit 0f72e18
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/pl/minecodes/mineeconomy/util/MessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Collections;

public class MessageUtil {

private static final Pattern hexPattern = Pattern.compile("#[a-fA-F0-9]{6}");
private static final Pattern HEX_REGEX = Pattern.compile("#[a-fA-F0-9]{6}");

private MessageUtil() {
}
Expand All @@ -29,10 +30,10 @@ public static void sendMessage(Player player, String message) {
}

public static String implementColors(String message) {
if (message == null) {
return null;
if (message == null || message.isEmpty()) {
return "";
}
for (Matcher matcher = hexPattern.matcher(message); matcher.find(); matcher = hexPattern.matcher(message)) {
for (Matcher matcher = HEX_REGEX.matcher(message); matcher.find(); matcher = HEX_REGEX.matcher(message)) {
String color = message.substring(matcher.start(), matcher.end());
message = message.replace(color, ChatColor.of(color) + "");
}
Expand All @@ -41,9 +42,11 @@ public static String implementColors(String message) {
}

public static List<String> implementColors(List<String> message) {
if (message == null) {
return null;
if (message == null || message.isEmpty()) {
return Collections.emptyList();
}

//TODO 06/11/2021: Naprawić syf kod
List<String> messages = new ArrayList<>();
message.forEach(s -> messages.add(implementColors(s)));
return messages;
Expand Down

0 comments on commit 0f72e18

Please sign in to comment.