Skip to content

Commit 8c0fa5e

Browse files
committed
2.7.1 Added Proper formatting from command actions
1 parent 3dadece commit 8c0fa5e

File tree

7 files changed

+88
-12
lines changed

7 files changed

+88
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>InteractiveChat</groupId>
44
<artifactId>InteractiveChat</artifactId>
5-
<version>2.7.0</version>
5+
<version>2.7.1</version>
66
<build>
77
<sourceDirectory>src</sourceDirectory>
88
<resources>

src/com/loohp/interactivechat/ConfigManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ public static void loadConfig() {
180180

181181
InteractiveChat.clickableCommands = getConfig().getBoolean("Commands.Enabled");
182182
String[] commandsFormat = getConfig().getString("Commands.Format").split("\\{Command\\}");
183-
InteractiveChat.clickableCommandsPrefix = commandsFormat[0];
184-
InteractiveChat.clickableCommandsSuffix = commandsFormat[commandsFormat.length - 1];
183+
InteractiveChat.clickableCommandsPrefix = ChatColorUtils.translateAlternateColorCodes('&', commandsFormat[0]);
184+
InteractiveChat.clickableCommandsSuffix = ChatColorUtils.translateAlternateColorCodes('&', commandsFormat[commandsFormat.length - 1]);
185185
InteractiveChat.clickableCommandsAction = ClickEvent.Action.valueOf(getConfig().getString("Commands.Action"));
186+
InteractiveChat.clickableCommandsFormat = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Commands.Text"));
187+
InteractiveChat.clickableCommandsHoverText = ChatColorUtils.translateAlternateColorCodes('&', String.join("\n", getConfig().getStringList("Commands.HoverMessage")));
188+
InteractiveChat.clickableCommandsEnforceColors = getConfig().getBoolean("Commands.EnforceReplaceTextColor");
186189
}
187190
}

src/com/loohp/interactivechat/InteractiveChat.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public class InteractiveChat extends JavaPlugin {
105105
public static String clickableCommandsPrefix = "[";
106106
public static String clickableCommandsSuffix = "]";
107107
public static ClickEvent.Action clickableCommandsAction = ClickEvent.Action.SUGGEST_COMMAND;
108+
public static String clickableCommandsFormat = "";
109+
public static String clickableCommandsHoverText = null;
110+
public static boolean clickableCommandsEnforceColors = true;
108111

109112
public static String NoPermission = "&cYou do not have permission to use that command!";
110113
public static String InvExpired = "&cThis inventory view has expired!";

src/com/loohp/interactivechat/Modules/CommandsDisplay.java

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
import net.md_5.bungee.api.chat.BaseComponent;
1313
import net.md_5.bungee.api.chat.ClickEvent;
14+
import net.md_5.bungee.api.chat.HoverEvent;
1415
import net.md_5.bungee.api.chat.TextComponent;
1516

1617
public class CommandsDisplay {
1718

19+
@SuppressWarnings("deprecation")
1820
public static BaseComponent process(BaseComponent basecomponent) {
1921
List<BaseComponent> basecomponentlist = CustomStringUtils.loadExtras(basecomponent);
2022
List<BaseComponent> newlist = new ArrayList<BaseComponent>();
@@ -37,16 +39,44 @@ public static BaseComponent process(BaseComponent basecomponent) {
3739
before.setText(before.getText().substring(0, end));
3840
StringBuilder cmd = new StringBuilder();
3941
List<BaseComponent> cmdCompList = new ArrayList<BaseComponent>();
42+
43+
String[] formmat = InteractiveChat.clickableCommandsFormat.split("\\{Command\\}");
44+
String prepend = formmat[0];
45+
String color = ChatColorUtils.getLastColors(prepend);
46+
String append = formmat[formmat.length - 1];
47+
4048
for (int u = indexOfParsingStart; u < i; u++) {
4149
BaseComponent part = basecomponentlist.get(u);
4250
Bukkit.getConsoleSender().sendMessage(ChatColorUtils.stripColor(part.toLegacyText()));
51+
if (InteractiveChat.clickableCommandsEnforceColors) {
52+
if (part instanceof TextComponent) {
53+
((TextComponent) part).setText(color + ChatColorUtils.stripColor(((TextComponent) part).getText()));
54+
} else {
55+
part = ChatColorUtils.applyColor(part, color);
56+
}
57+
}
4358
cmdCompList.add(part);
4459
cmd.append(ChatColorUtils.stripColor(part.toLegacyText()));
4560
}
61+
if (InteractiveChat.clickableCommandsEnforceColors) {
62+
before.setText(color + ChatColorUtils.stripColor(before.getText()));
63+
}
4664
cmdCompList.add(before);
65+
//Bukkit.getConsoleSender().sendMessage(((TextComponent) before).getText().replace("§", "&"));
4766
cmd.append(ChatColorUtils.stripColor(before.toLegacyText()));
67+
68+
HoverEvent hover = null;
69+
if (InteractiveChat.clickableCommandsHoverText != null) {
70+
hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent(InteractiveChat.clickableCommandsHoverText)});
71+
}
4872
ClickEvent click = new ClickEvent(InteractiveChat.clickableCommandsAction, cmd.toString());
73+
cmdCompList.add(0, new TextComponent(prepend));
74+
cmdCompList.add(new TextComponent(append));
75+
4976
for (BaseComponent each : cmdCompList) {
77+
if (hover != null) {
78+
each.setHoverEvent(hover);
79+
}
5080
each.setClickEvent(click);
5181
newlist.add(each);
5282
}
@@ -81,15 +111,37 @@ public static BaseComponent process(BaseComponent basecomponent) {
81111
if (i + 1 == basecomponentlist.size()) {
82112
StringBuilder cmd = new StringBuilder();
83113
List<BaseComponent> cmdCompList = new ArrayList<BaseComponent>();
84-
for (int u = indexOfParsingStart; u < i; u++) {
114+
String[] formmat = InteractiveChat.clickableCommandsFormat.split("\\{Command\\}");
115+
String prepend = formmat[0];
116+
String color = ChatColorUtils.getLastColors(prepend);
117+
String append = formmat[formmat.length - 1];
118+
119+
for (int u = indexOfParsingStart; u <= i; u++) {
85120
BaseComponent part = basecomponentlist.get(u);
121+
Bukkit.getConsoleSender().sendMessage(ChatColorUtils.stripColor(part.toLegacyText()));
122+
if (InteractiveChat.clickableCommandsEnforceColors) {
123+
if (part instanceof TextComponent) {
124+
((TextComponent) part).setText(color + ChatColorUtils.stripColor(((TextComponent) part).getText()));
125+
} else {
126+
part = ChatColorUtils.applyColor(part, color);
127+
}
128+
}
86129
cmdCompList.add(part);
87130
cmd.append(ChatColorUtils.stripColor(part.toLegacyText()));
88131
}
89-
cmdCompList.add(base);
90-
cmd.append(ChatColorUtils.stripColor(base.toLegacyText()));
132+
133+
HoverEvent hover = null;
134+
if (InteractiveChat.clickableCommandsHoverText != null) {
135+
hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent(InteractiveChat.clickableCommandsHoverText)});
136+
}
91137
ClickEvent click = new ClickEvent(InteractiveChat.clickableCommandsAction, cmd.toString());
138+
cmdCompList.add(0, new TextComponent(prepend));
139+
cmdCompList.add(new TextComponent(append));
140+
92141
for (BaseComponent each : cmdCompList) {
142+
if (hover != null) {
143+
each.setHoverEvent(hover);
144+
}
93145
each.setClickEvent(click);
94146
newlist.add(each);
95147
}

src/config.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,21 @@ Settings:
7777
Commands:
7878
#Whether or not to make commands displayed in chat clickable
7979
Enabled: true
80-
80+
#The formatting to trigger the command display function
8181
Format: "[{Command}]"
82-
82+
#The text to replace the matched section of the message
83+
#Use "{Command}" for the command
84+
Text: "&b[&e{Command}&b]"
85+
EnforceReplaceTextColor: true
8386
#What happens when the player clicks the command
8487
#List of actions:
8588
#RUN_COMMAND
8689
#SUGGEST_COMMAND
8790
Action: SUGGEST_COMMAND
8891

92+
HoverMessage:
93+
- "&eClick to use command!"
94+
8995
Chat:
9096
#Convert alternate color code character
9197
#Only one character is allowed, leave blank to disable this feature

src/config_legacy.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ Settings:
7272
Commands:
7373
#Whether or not to make commands displayed in chat clickable
7474
Enabled: true
75-
75+
#The formatting to trigger the command display function
7676
Format: "[{Command}]"
77-
77+
#The text to replace the matched section of the message
78+
#Use "{Command}" for the command
79+
Text: "&b[&e{Command}&b]"
80+
EnforceReplaceTextColor: true
7881
#What happens when the player clicks the command
7982
#List of actions:
8083
#RUN_COMMAND
8184
#SUGGEST_COMMAND
8285
Action: SUGGEST_COMMAND
8386

87+
HoverMessage:
88+
- "&eClick to use command!"
89+
8490
Chat:
8591
#Enable the mention title and sound
8692
AllowMention: true

src/config_old.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ Settings:
7272
Commands:
7373
#Whether or not to make commands displayed in chat clickable
7474
Enabled: true
75-
75+
#The formatting to trigger the command display function
7676
Format: "[{Command}]"
77-
77+
#The text to replace the matched section of the message
78+
#Use "{Command}" for the command
79+
Text: "&b[&e{Command}&b]"
80+
EnforceReplaceTextColor: true
7881
#What happens when the player clicks the command
7982
#List of actions:
8083
#RUN_COMMAND
8184
#SUGGEST_COMMAND
8285
Action: SUGGEST_COMMAND
8386

87+
HoverMessage:
88+
- "&eClick to use command!"
89+
8490
Chat:
8591
#Enable the mention title and sound
8692
AllowMention: true

0 commit comments

Comments
 (0)