Skip to content

Commit

Permalink
2.6.1 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Jul 5, 2020
1 parent 42544d3 commit d4f0c51
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/com/loohp/interactivechat/Listeners/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public void onLeave(PlayerQuitEvent event) {

@EventHandler(priority=EventPriority.HIGH)
public void onCommand(PlayerCommandPreprocessEvent event) {

translateAltColorCode(event);

String command = event.getMessage();
for (String parsecommand : InteractiveChat.commandList) {
if (command.matches(parsecommand)) {
Expand Down Expand Up @@ -193,6 +196,25 @@ private void translateAltColorCode(AsyncPlayerChatEvent event) {
event.setMessage(message);
}

private void translateAltColorCode(PlayerCommandPreprocessEvent event) {
if (event.isCancelled()) {
return;
}

if (!InteractiveChat.chatAltColorCode.isPresent()) {
return;
}

Player player = event.getPlayer();

if (!player.hasPermission("interactivechat.chatcolor.translate")) {
return;
}

String message = ChatColorUtils.translateAlternateColorCodes(InteractiveChat.chatAltColorCode.get(), event.getMessage());
event.setMessage(message);
}

@EventHandler(priority=EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent event) {
if (event.getClickedInventory() == null) {
Expand Down
16 changes: 16 additions & 0 deletions src/com/loohp/interactivechat/Utils/ChatColorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ChatColorUtils {

private static Set<Character> colors = new HashSet<Character>();
private static Pattern colorFormating = Pattern.compile("(?=(?<!\\\\)|(?<=\\\\\\\\))\\[[^\\]]*?color=#[0-9a-fA-F]{6}[^\\[]*?\\]");
private static Pattern colorEscape = Pattern.compile("\\\\\\[[^\\]]*?color=#[0-9a-fA-F]{6}[^\\[]*?\\]");

static {
colors.add('0');
Expand Down Expand Up @@ -216,6 +217,21 @@ public static String translatePluginColorFormatting(String text) {
sb.deleteCharAt(absPos - 1);
}

if (absPos > 2 && sb.charAt(absPos - 2) == '\\' && sb.charAt(absPos - 3) == '\\') {
sb.deleteCharAt(absPos - 2);
}

text = sb.toString();
} else {
break;
}
}

while (true) {
Matcher matcher = colorEscape.matcher(text);
if (matcher.find()) {
StringBuilder sb = new StringBuilder(text);
sb.deleteCharAt(matcher.start());
text = sb.toString();
} else {
break;
Expand Down
25 changes: 24 additions & 1 deletion src/com/loohp/interactivechat/Utils/ChatComponentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ChatComponentUtils {
private static MethodHandle hoverEventGetValueMethod;

private static Pattern fontFormating = Pattern.compile("(?=(?<!\\\\)|(?<=\\\\\\\\))\\[[^\\]]*?font=[0-9a-zA-Z:_]*[^\\[]*?\\]");
private static Pattern fontEscape = Pattern.compile("\\\\\\[[^\\]]*?font=[0-9a-zA-Z:_]*[^\\[]*?\\]");

public static void setupLegacy() {
try {
Expand Down Expand Up @@ -441,6 +442,11 @@ public static BaseComponent translatePluginFontFormatting(BaseComponent basecomp
if (sb.charAt(absPos) == ']' && sb.charAt(absPos - 1) == '[') {
sb.deleteCharAt(absPos - 1);
sb.deleteCharAt(absPos - 1);
}

if (absPos > 2 && sb.charAt(absPos - 2) == '\\' && sb.charAt(absPos - 3) == '\\') {
sb.deleteCharAt(absPos - 2);
absPos--;
}

absPos--;
Expand All @@ -464,7 +470,9 @@ public static BaseComponent translatePluginFontFormatting(BaseComponent basecomp
textlist.add(before);
break;
}
}

}

newlist.addAll(textlist);
} else {
if (currentFont.isPresent()) {
Expand All @@ -477,6 +485,21 @@ public static BaseComponent translatePluginFontFormatting(BaseComponent basecomp
TextComponent product = new TextComponent("");
for (int i = 0; i < newlist.size(); i++) {
BaseComponent each = newlist.get(i);
if (each instanceof TextComponent) {
TextComponent text = (TextComponent) each;
String str = text.getText();
while (true) {
Matcher matcher = fontEscape.matcher(str);
if (matcher.find()) {
StringBuilder sb = new StringBuilder(str);
sb.deleteCharAt(matcher.start());
str = sb.toString();
} else {
text.setText(str);
break;
}
}
}
product.addExtra(each);
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: InteractiveChat
author: loohp
version: 2.6.0
version: 2.6.1
main: com.loohp.interactivechat.InteractiveChat
api-version: 1.13
description: Make the chat interactive
Expand Down

0 comments on commit d4f0c51

Please sign in to comment.