mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-22 18:09:06 +00:00
Merge pull request #19 from Aust1n46/issues/18
ISSUE #18 Add input validation for click_actions
This commit is contained in:
commit
b950d21580
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>mineverse.Aust1n46.chat</groupId>
|
<groupId>mineverse.Aust1n46.chat</groupId>
|
||||||
<artifactId>VentureChat</artifactId>
|
<artifactId>VentureChat</artifactId>
|
||||||
<version>3.4.3</version>
|
<version>3.4.4</version>
|
||||||
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
|
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
|
||||||
<scm>
|
<scm>
|
||||||
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
|
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
|
||||||
|
16
src/main/java/mineverse/Aust1n46/chat/ClickAction.java
Normal file
16
src/main/java/mineverse/Aust1n46/chat/ClickAction.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package mineverse.Aust1n46.chat;
|
||||||
|
|
||||||
|
public enum ClickAction {
|
||||||
|
SUGGEST_COMMAND, RUN_COMMAND, OPEN_URL, NONE;
|
||||||
|
|
||||||
|
private final String jsonValue;
|
||||||
|
|
||||||
|
ClickAction() {
|
||||||
|
jsonValue = name().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return jsonValue;
|
||||||
|
}
|
||||||
|
}
|
@ -203,7 +203,7 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getConfig().getString("loglevel", "info").equals("debug")) {
|
if (getConfig().getString("loglevel", "info").equals("trace")) {
|
||||||
Bukkit.getConsoleSender()
|
Bukkit.getConsoleSender()
|
||||||
.sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Updating Player Mutes"));
|
.sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Updating Player Mutes"));
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,15 @@ package mineverse.Aust1n46.chat.json;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import mineverse.Aust1n46.chat.ClickAction;
|
||||||
|
|
||||||
public class JsonAttribute {
|
public class JsonAttribute {
|
||||||
private String name;
|
private String name;
|
||||||
private List<String> hoverText;
|
private List<String> hoverText;
|
||||||
private String clickAction;
|
private ClickAction clickAction;
|
||||||
private String clickText;
|
private String clickText;
|
||||||
|
|
||||||
public JsonAttribute(String name, List<String> hoverText, String clickAction, String clickText) {
|
public JsonAttribute(String name, List<String> hoverText, ClickAction clickAction, String clickText) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.hoverText = hoverText;
|
this.hoverText = hoverText;
|
||||||
this.clickAction = clickAction;
|
this.clickAction = clickAction;
|
||||||
@ -23,7 +25,7 @@ public class JsonAttribute {
|
|||||||
return hoverText;
|
return hoverText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClickAction() {
|
public ClickAction getClickAction() {
|
||||||
return clickAction;
|
return clickAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import mineverse.Aust1n46.chat.ClickAction;
|
||||||
import mineverse.Aust1n46.chat.MineverseChat;
|
import mineverse.Aust1n46.chat.MineverseChat;
|
||||||
|
import mineverse.Aust1n46.chat.utilities.Format;
|
||||||
|
|
||||||
public class JsonFormat {
|
public class JsonFormat {
|
||||||
private static MineverseChat plugin = MineverseChat.getInstance();
|
private static MineverseChat plugin = MineverseChat.getInstance();
|
||||||
@ -33,9 +35,15 @@ public class JsonFormat {
|
|||||||
if (jsonAttributeSection != null) {
|
if (jsonAttributeSection != null) {
|
||||||
for (String attribute : jsonAttributeSection.getKeys(false)) {
|
for (String attribute : jsonAttributeSection.getKeys(false)) {
|
||||||
List<String> hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text");
|
List<String> hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text");
|
||||||
String clickAction = 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", "");
|
String clickText = jsonAttributeSection.getString(attribute + ".click_text", "");
|
||||||
jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText));
|
jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText));
|
||||||
|
} catch (IllegalArgumentException | NullPointerException exception) {
|
||||||
|
plugin.getServer().getConsoleSender()
|
||||||
|
.sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&c - Illegal click_action: " + clickActionText + " in jsonFormat: " + jsonFormat));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes));
|
jsonFormats.put(jsonFormat.toLowerCase(), new JsonFormat(jsonFormat, priority, jsonAttributes));
|
||||||
|
@ -10,6 +10,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -22,6 +23,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
|||||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import mineverse.Aust1n46.chat.ClickAction;
|
||||||
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
|
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
|
||||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||||
import mineverse.Aust1n46.chat.json.JsonAttribute;
|
import mineverse.Aust1n46.chat.json.JsonAttribute;
|
||||||
@ -112,28 +114,45 @@ public class Format {
|
|||||||
formattedPlaceholder = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder));
|
formattedPlaceholder = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder));
|
||||||
temp += convertToJsonColors(lastCode + remaining.substring(0, indexStart)) + ",";
|
temp += convertToJsonColors(lastCode + remaining.substring(0, indexStart)) + ",";
|
||||||
lastCode = getLastCode(lastCode + remaining.substring(0, indexStart));
|
lastCode = getLastCode(lastCode + remaining.substring(0, indexStart));
|
||||||
String action = "";
|
boolean placeholderHasJsonAttribute = false;
|
||||||
String text = "";
|
|
||||||
String hover = "";
|
|
||||||
for (JsonAttribute jsonAttribute : format.getJsonAttributes()) {
|
for (JsonAttribute jsonAttribute : format.getJsonAttributes()) {
|
||||||
if (placeholder.contains(jsonAttribute.getName().replace("{", "").replace("}", ""))) {
|
if (placeholder.contains(jsonAttribute.getName().replace("{", "").replace("}", ""))) {
|
||||||
action = jsonAttribute.getClickAction();
|
final StringBuilder hover = new StringBuilder();
|
||||||
text = Format.FormatStringAll(
|
|
||||||
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText()));
|
|
||||||
for (String st : jsonAttribute.getHoverText()) {
|
for (String st : jsonAttribute.getHoverText()) {
|
||||||
hover += Format.FormatStringAll(st) + "\n";
|
hover.append(Format.FormatStringAll(st) + "\n");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
final String hoverText;
|
||||||
if(!hover.isEmpty()) {
|
if(!hover.isEmpty()) {
|
||||||
hover = Format.FormatStringAll(
|
hoverText = Format.FormatStringAll(
|
||||||
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1)));
|
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1)));
|
||||||
|
} else {
|
||||||
|
hoverText = StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!placeholderHasJsonAttribute) {
|
||||||
|
temp += convertToJsonColors(lastCode + formattedPlaceholder) + ",";
|
||||||
}
|
}
|
||||||
temp += convertToJsonColors(lastCode + formattedPlaceholder,
|
|
||||||
",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text
|
|
||||||
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
|
|
||||||
+ convertToJsonColors(hover) + "]}}")
|
|
||||||
+ ",";
|
|
||||||
lastCode = getLastCode(lastCode + formattedPlaceholder);
|
lastCode = getLastCode(lastCode + formattedPlaceholder);
|
||||||
remaining = remaining.substring(indexEnd);
|
remaining = remaining.substring(indexEnd);
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,7 +136,7 @@ messageremovertext: '&c&o<message removed>'
|
|||||||
# The name of the group is the permissions node for the format
|
# The name of the group is the permissions node for the format
|
||||||
# Example: venturechat.json.Owner is the node for the group Owner
|
# 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
|
# A lower priority overrides a higher priority if a player has more than 1 group
|
||||||
# Possible options for click_name and click_prefix are suggest_command, run_command, and open_url
|
# Possible options for click_action are suggest_command, run_command, open_url, and none
|
||||||
jsonformatting:
|
jsonformatting:
|
||||||
Default: # This default format is required! Do not delete or rename it!
|
Default: # This default format is required! Do not delete or rename it!
|
||||||
priority: 2147483647 # Integer.MAX_VALUE
|
priority: 2147483647 # Integer.MAX_VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user