Skip to content

Commit

Permalink
2.1.5 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed May 1, 2020
1 parent d47fc89 commit a808dc4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.loohp.interactivechat.ConfigManager;
import com.loohp.interactivechat.InteractiveChat;
import com.loohp.interactivechat.Utils.ChatColorUtils;
import com.loohp.interactivechat.Utils.CustomStringUtils;
import com.loohp.interactivechat.Utils.JsonUtils;

Expand Down Expand Up @@ -113,7 +114,9 @@ public static BaseComponent processCustomPlaceholder(Player parseplayer, boolean
boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText());
TextComponent message = new TextComponent(placeholder);
message = (TextComponent) ChatColorUtils.applyColor(message, color);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/com/loohp/interactivechat/Modules/EnderchestDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.loohp.interactivechat.ConfigManager;
import com.loohp.interactivechat.InteractiveChat;
import com.loohp.interactivechat.Utils.ChatColorUtils;
import com.loohp.interactivechat.Utils.CustomStringUtils;
import com.loohp.interactivechat.Utils.JsonUtils;

Expand Down Expand Up @@ -96,7 +97,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText());
TextComponent message = new TextComponent(placeholder);
message = (TextComponent) ChatColorUtils.applyColor(message, color);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/com/loohp/interactivechat/Modules/InventoryDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.loohp.interactivechat.ConfigManager;
import com.loohp.interactivechat.InteractiveChat;
import com.loohp.interactivechat.Utils.ChatColorUtils;
import com.loohp.interactivechat.Utils.CustomStringUtils;
import com.loohp.interactivechat.Utils.JsonUtils;

Expand Down Expand Up @@ -96,7 +97,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText());
TextComponent message = new TextComponent(placeholder);
message = (TextComponent) ChatColorUtils.applyColor(message, color);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/com/loohp/interactivechat/Modules/ItemDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.loohp.interactivechat.ConfigManager;
import com.loohp.interactivechat.InteractiveChat;
import com.loohp.interactivechat.Utils.ChatColorFilter;
import com.loohp.interactivechat.Utils.ChatColorUtils;
import com.loohp.interactivechat.Utils.CustomStringUtils;
import com.loohp.interactivechat.Utils.ItemNBTUtils;
import com.loohp.interactivechat.Utils.JsonUtils;
Expand Down Expand Up @@ -104,7 +105,9 @@ public static BaseComponent process(BaseComponent basecomponent, Optional<Player
boolean endwith = casesensitive ? text.endsWith(placeholder) : text.toLowerCase().endsWith(placeholder.toLowerCase());
if ((trim.size() - 1) > i || endwith) {
if (trim.get(i).endsWith("\\") && !trim.get(i).endsWith("\\\\")) {
String color = ChatColorUtils.getLastColors(newlist.get(newlist.size() - 1).toLegacyText());
TextComponent message = new TextComponent(placeholder);
message = (TextComponent) ChatColorUtils.applyColor(message, color);
((TextComponent) newlist.get(newlist.size() - 1)).setText(trim.get(i).substring(0, trim.get(i).length() - 1));
newlist.add(message);
} else {
Expand Down
31 changes: 31 additions & 0 deletions src/com/loohp/interactivechat/Utils/ChatColorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;

public class ChatColorUtils {

Expand Down Expand Up @@ -44,5 +45,35 @@ public static boolean isLegal(String color) {
}
return true;
}

public static BaseComponent applyColor(BaseComponent basecomponent, String color) {
if (color.length() >= 2 && color.charAt(1) != 'r') {
if (color.length() == 2) {
basecomponent.setColor(ChatColor.getByChar(color.charAt(1)));
} else if (color.length() == 4) {
basecomponent.setColor(ChatColor.getByChar(color.charAt(1)));
switch (ChatColor.getByChar(color.charAt(3))) {
case BOLD:
basecomponent.setBold(true);
break;
case ITALIC:
basecomponent.setItalic(true);
break;
case MAGIC:
basecomponent.setObfuscated(true);
break;
case STRIKETHROUGH:
basecomponent.setStrikethrough(true);
break;
case UNDERLINE:
basecomponent.setUnderlined(true);
break;
default:
break;
}
}
}
return basecomponent;
}

}
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.1.4
version: 2.1.5
main: com.loohp.interactivechat.InteractiveChat
api-version: 1.13
description: Make the chat interactive
Expand Down

0 comments on commit a808dc4

Please sign in to comment.