Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions api/src/main/java/ru/mrbrikster/chatty/util/TextUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
@UtilityClass
public class TextUtil {

private final Pattern HEX_COLORS_PATTERN = Pattern.compile("\\{#([a-fA-F0-9]{6})}");
private final Pattern HEX_COLORS_PATTERN_1 = Pattern.compile("\\{#([a-fA-F0-9]{6})}");
private final Pattern HEX_COLORS_PATTERN_2 = Pattern.compile("&#([a-fA-F0-9]{6})");
private final Pattern HEX_COLORS_PATTERN_3 = Pattern.compile("#([a-fA-F0-9]{6})");
private final Pattern HEX_GRADIENT_PATTERN = Pattern.compile("\\{#([a-fA-F0-9]{6})(:#([a-fA-F0-9]{6}))+( )([^{}])*(})");
private final Pattern HEX_SPIGOT_PATTERN = Pattern.compile("§[xX](§[a-fA-F0-9]){6}");

Expand Down Expand Up @@ -143,9 +145,11 @@ public String stylish(String text) {
}

matcher.appendTail(stringBuffer);
// 1 hex color pattern
// {#12ABCD} text
text = stringBuffer.toString();

matcher = HEX_COLORS_PATTERN.matcher(text);
matcher = HEX_COLORS_PATTERN_1.matcher(text);
stringBuffer = new StringBuffer();

while (matcher.find()) {
Expand All @@ -154,6 +158,33 @@ public String stylish(String text) {
}

matcher.appendTail(stringBuffer);
// 2 hex color pattern
// &#12ABCD text
text = stringBuffer.toString();

matcher = HEX_COLORS_PATTERN_2.matcher(text);
stringBuffer = new StringBuffer();

while (matcher.find()) {
String hexColorString = matcher.group();
matcher.appendReplacement(stringBuffer, ChatColor.of(hexColorString.substring(1)).toString());
}

matcher.appendTail(stringBuffer);
// 3 hex color pattern
// #12ABCD text
text = stringBuffer.toString();

matcher = HEX_COLORS_PATTERN_3.matcher(text);
stringBuffer = new StringBuffer();

while (matcher.find()) {
String hexColorString = matcher.group();
matcher.appendReplacement(stringBuffer, ChatColor.of(hexColorString).toString());
}

matcher.appendTail(stringBuffer);


return ChatColor.translateAlternateColorCodes('&', stringBuffer.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void handle(CommandSender sender, String label, String[] args) {
return;
}

if (recipient.equals(sender)) {
if (recipient.equals(sender) && !configuration.getNode("pm.allow-yourself").getAsBoolean(false)) {
sender.sendMessage(Chatty.instance().messages().get("msg-command.cannot-message-yourself"));
return;
}
Expand Down
4 changes: 4 additions & 0 deletions spigot/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ pm:
# Default: false
allow-console: false

# Allows you to send messages to yourself
# Default: true
allow-yourself: true

# Allows to PM players, that in vanish
# Supports EssentialsX, SuperVanish, PremiumVanish, VanishNoPacket etc.
# Default: true
Expand Down