Skip to content

Commit

Permalink
ISSUE #18 Only show hover when it is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Aust1n46 committed Jul 3, 2022
1 parent 8527cb5 commit 0f3b306
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/mineverse/Aust1n46/chat/ClickAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mineverse.Aust1n46.chat;

public enum ClickAction {
SUGGEST_COMMAND, RUN_COMMAND, OPEN_URL;
SUGGEST_COMMAND, RUN_COMMAND, OPEN_URL, NONE;

private final String jsonValue;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mineverse/Aust1n46/chat/MineverseChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void run() {
}
}
}
if (getConfig().getString("loglevel", "info").equals("debug")) {
if (getConfig().getString("loglevel", "info").equals("trace")) {
Bukkit.getConsoleSender()
.sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Updating Player Mutes"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mineverse/Aust1n46/chat/json/JsonFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void initialize() {
if (jsonAttributeSection != null) {
for (String attribute : jsonAttributeSection.getKeys(false)) {
List<String> hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text");
String clickActionText = jsonAttributeSection.getString(attribute + ".click_action", "");
String clickActionText = jsonAttributeSection.getString(attribute + ".click_action", "none");
try {
ClickAction clickAction = ClickAction.valueOf(clickActionText.toUpperCase());
String clickText = jsonAttributeSection.getString(attribute + ".click_text", "");
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/mineverse/Aust1n46/chat/utilities/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.comphenix.protocol.wrappers.WrappedChatComponent;

import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.ClickAction;
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.json.JsonAttribute;
Expand Down Expand Up @@ -116,9 +117,6 @@ private static String convertPlaceholders(String s, JsonFormat format, Mineverse
boolean placeholderHasJsonAttribute = false;
for (JsonAttribute jsonAttribute : format.getJsonAttributes()) {
if (placeholder.contains(jsonAttribute.getName().replace("{", "").replace("}", ""))) {
final String action = jsonAttribute.getClickAction().toString();
final String text = Format.FormatStringAll(
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText()));
final StringBuilder hover = new StringBuilder();
for (String st : jsonAttribute.getHoverText()) {
hover.append(Format.FormatStringAll(st) + "\n");
Expand All @@ -130,11 +128,24 @@ private static String convertPlaceholders(String s, JsonFormat format, Mineverse
} else {
hoverText = StringUtils.EMPTY;
}
temp += convertToJsonColors(lastCode + formattedPlaceholder,
",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
+ convertToJsonColors(hoverText) + "]}}")
+ ",";
final ClickAction clickAction = jsonAttribute.getClickAction();
final String actionJson;
if (clickAction == ClickAction.NONE) {
actionJson = StringUtils.EMPTY;
} else {
final String clickText = Format.FormatStringAll(
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText()));
actionJson = ",\"clickEvent\":{\"action\":\"" + jsonAttribute.getClickAction().toString() + "\",\"value\":\"" + clickText
+ "\"}";
}
final String hoverJson;
if (hoverText.isEmpty()) {
hoverJson = StringUtils.EMPTY;
} else {
hoverJson = ",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
+ convertToJsonColors(hoverText) + "]}}";
}
temp += convertToJsonColors(lastCode + formattedPlaceholder, actionJson + hoverJson) + ",";
placeholderHasJsonAttribute = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ messageremovertext: '&c&o<message removed>'
# The name of the group is the permissions node for the format
# Example: venturechat.json.Owner is the node for the group Owner
# A lower priority overrides a higher priority if a player has more than 1 group
# Possible options for click_action are suggest_command, run_command, and open_url
# Possible options for click_action are suggest_command, run_command, open_url, and none
jsonformatting:
Default: # This default format is required! Do not delete or rename it!
priority: 2147483647 # Integer.MAX_VALUE
Expand Down

0 comments on commit 0f3b306

Please sign in to comment.