Skip to content

Commit

Permalink
2.7.1 Added Proper formatting from command actions
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Aug 18, 2020
1 parent 3dadece commit 8c0fa5e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>InteractiveChat</groupId>
<artifactId>InteractiveChat</artifactId>
<version>2.7.0</version>
<version>2.7.1</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
Expand Down
7 changes: 5 additions & 2 deletions src/com/loohp/interactivechat/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,11 @@ public static void loadConfig() {

InteractiveChat.clickableCommands = getConfig().getBoolean("Commands.Enabled");
String[] commandsFormat = getConfig().getString("Commands.Format").split("\\{Command\\}");
InteractiveChat.clickableCommandsPrefix = commandsFormat[0];
InteractiveChat.clickableCommandsSuffix = commandsFormat[commandsFormat.length - 1];
InteractiveChat.clickableCommandsPrefix = ChatColorUtils.translateAlternateColorCodes('&', commandsFormat[0]);
InteractiveChat.clickableCommandsSuffix = ChatColorUtils.translateAlternateColorCodes('&', commandsFormat[commandsFormat.length - 1]);
InteractiveChat.clickableCommandsAction = ClickEvent.Action.valueOf(getConfig().getString("Commands.Action"));
InteractiveChat.clickableCommandsFormat = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Commands.Text"));
InteractiveChat.clickableCommandsHoverText = ChatColorUtils.translateAlternateColorCodes('&', String.join("\n", getConfig().getStringList("Commands.HoverMessage")));
InteractiveChat.clickableCommandsEnforceColors = getConfig().getBoolean("Commands.EnforceReplaceTextColor");
}
}
3 changes: 3 additions & 0 deletions src/com/loohp/interactivechat/InteractiveChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public class InteractiveChat extends JavaPlugin {
public static String clickableCommandsPrefix = "[";
public static String clickableCommandsSuffix = "]";
public static ClickEvent.Action clickableCommandsAction = ClickEvent.Action.SUGGEST_COMMAND;
public static String clickableCommandsFormat = "";
public static String clickableCommandsHoverText = null;
public static boolean clickableCommandsEnforceColors = true;

public static String NoPermission = "&cYou do not have permission to use that command!";
public static String InvExpired = "&cThis inventory view has expired!";
Expand Down
58 changes: 55 additions & 3 deletions src/com/loohp/interactivechat/Modules/CommandsDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;

public class CommandsDisplay {

@SuppressWarnings("deprecation")
public static BaseComponent process(BaseComponent basecomponent) {
List<BaseComponent> basecomponentlist = CustomStringUtils.loadExtras(basecomponent);
List<BaseComponent> newlist = new ArrayList<BaseComponent>();
Expand All @@ -37,16 +39,44 @@ public static BaseComponent process(BaseComponent basecomponent) {
before.setText(before.getText().substring(0, end));
StringBuilder cmd = new StringBuilder();
List<BaseComponent> cmdCompList = new ArrayList<BaseComponent>();

String[] formmat = InteractiveChat.clickableCommandsFormat.split("\\{Command\\}");
String prepend = formmat[0];
String color = ChatColorUtils.getLastColors(prepend);
String append = formmat[formmat.length - 1];

for (int u = indexOfParsingStart; u < i; u++) {
BaseComponent part = basecomponentlist.get(u);
Bukkit.getConsoleSender().sendMessage(ChatColorUtils.stripColor(part.toLegacyText()));
if (InteractiveChat.clickableCommandsEnforceColors) {
if (part instanceof TextComponent) {
((TextComponent) part).setText(color + ChatColorUtils.stripColor(((TextComponent) part).getText()));
} else {
part = ChatColorUtils.applyColor(part, color);
}
}
cmdCompList.add(part);
cmd.append(ChatColorUtils.stripColor(part.toLegacyText()));
}
if (InteractiveChat.clickableCommandsEnforceColors) {
before.setText(color + ChatColorUtils.stripColor(before.getText()));
}
cmdCompList.add(before);
//Bukkit.getConsoleSender().sendMessage(((TextComponent) before).getText().replace("§", "&"));
cmd.append(ChatColorUtils.stripColor(before.toLegacyText()));

HoverEvent hover = null;
if (InteractiveChat.clickableCommandsHoverText != null) {
hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent(InteractiveChat.clickableCommandsHoverText)});
}
ClickEvent click = new ClickEvent(InteractiveChat.clickableCommandsAction, cmd.toString());
cmdCompList.add(0, new TextComponent(prepend));
cmdCompList.add(new TextComponent(append));

for (BaseComponent each : cmdCompList) {
if (hover != null) {
each.setHoverEvent(hover);
}
each.setClickEvent(click);
newlist.add(each);
}
Expand Down Expand Up @@ -81,15 +111,37 @@ public static BaseComponent process(BaseComponent basecomponent) {
if (i + 1 == basecomponentlist.size()) {
StringBuilder cmd = new StringBuilder();
List<BaseComponent> cmdCompList = new ArrayList<BaseComponent>();
for (int u = indexOfParsingStart; u < i; u++) {
String[] formmat = InteractiveChat.clickableCommandsFormat.split("\\{Command\\}");
String prepend = formmat[0];
String color = ChatColorUtils.getLastColors(prepend);
String append = formmat[formmat.length - 1];

for (int u = indexOfParsingStart; u <= i; u++) {
BaseComponent part = basecomponentlist.get(u);
Bukkit.getConsoleSender().sendMessage(ChatColorUtils.stripColor(part.toLegacyText()));
if (InteractiveChat.clickableCommandsEnforceColors) {
if (part instanceof TextComponent) {
((TextComponent) part).setText(color + ChatColorUtils.stripColor(((TextComponent) part).getText()));
} else {
part = ChatColorUtils.applyColor(part, color);
}
}
cmdCompList.add(part);
cmd.append(ChatColorUtils.stripColor(part.toLegacyText()));
}
cmdCompList.add(base);
cmd.append(ChatColorUtils.stripColor(base.toLegacyText()));

HoverEvent hover = null;
if (InteractiveChat.clickableCommandsHoverText != null) {
hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent(InteractiveChat.clickableCommandsHoverText)});
}
ClickEvent click = new ClickEvent(InteractiveChat.clickableCommandsAction, cmd.toString());
cmdCompList.add(0, new TextComponent(prepend));
cmdCompList.add(new TextComponent(append));

for (BaseComponent each : cmdCompList) {
if (hover != null) {
each.setHoverEvent(hover);
}
each.setClickEvent(click);
newlist.add(each);
}
Expand Down
10 changes: 8 additions & 2 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,21 @@ Settings:
Commands:
#Whether or not to make commands displayed in chat clickable
Enabled: true

#The formatting to trigger the command display function
Format: "[{Command}]"

#The text to replace the matched section of the message
#Use "{Command}" for the command
Text: "&b[&e{Command}&b]"
EnforceReplaceTextColor: true
#What happens when the player clicks the command
#List of actions:
#RUN_COMMAND
#SUGGEST_COMMAND
Action: SUGGEST_COMMAND

HoverMessage:
- "&eClick to use command!"

Chat:
#Convert alternate color code character
#Only one character is allowed, leave blank to disable this feature
Expand Down
10 changes: 8 additions & 2 deletions src/config_legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,21 @@ Settings:
Commands:
#Whether or not to make commands displayed in chat clickable
Enabled: true

#The formatting to trigger the command display function
Format: "[{Command}]"

#The text to replace the matched section of the message
#Use "{Command}" for the command
Text: "&b[&e{Command}&b]"
EnforceReplaceTextColor: true
#What happens when the player clicks the command
#List of actions:
#RUN_COMMAND
#SUGGEST_COMMAND
Action: SUGGEST_COMMAND

HoverMessage:
- "&eClick to use command!"

Chat:
#Enable the mention title and sound
AllowMention: true
Expand Down
10 changes: 8 additions & 2 deletions src/config_old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,21 @@ Settings:
Commands:
#Whether or not to make commands displayed in chat clickable
Enabled: true

#The formatting to trigger the command display function
Format: "[{Command}]"

#The text to replace the matched section of the message
#Use "{Command}" for the command
Text: "&b[&e{Command}&b]"
EnforceReplaceTextColor: true
#What happens when the player clicks the command
#List of actions:
#RUN_COMMAND
#SUGGEST_COMMAND
Action: SUGGEST_COMMAND

HoverMessage:
- "&eClick to use command!"

Chat:
#Enable the mention title and sound
AllowMention: true
Expand Down

0 comments on commit 8c0fa5e

Please sign in to comment.