Add MiniMessage support

This commit is contained in:
Roman Zhuravlev 2026-01-21 19:28:15 +05:00
parent 398a46dee0
commit c5bfb3c0d9
5 changed files with 99 additions and 46 deletions

View file

@ -218,7 +218,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View file

@ -22,7 +22,8 @@ public class SpigotHandler extends SpigotAdapter implements SpigotInterface {
public static ChatColor DARK_AQUA = ChatColor.of("#31b0e8");
public SpigotHandler() {
Color.DARK_AQUA = SpigotHandler.DARK_AQUA.toString();
//Color.DARK_AQUA = SpigotHandler.DARK_AQUA.toString();
Color.DARK_AQUA = "<#31b0e8>"; // griefus
}
@Override

View file

@ -26,24 +26,32 @@ public final class Chat {
}
public static void sendComponent(CommandSender sender, String string, String bypass) {
SpigotAdapter.ADAPTER.sendComponent(sender, string, bypass);
//SpigotAdapter.ADAPTER.sendComponent(sender, string, bypass);
sendMessage(sender, string + bypass); // griefus
}
public static void sendComponent(CommandSender sender, String string) {
sendComponent(sender, string, null);
//sendComponent(sender, string, null);
sendMessage(sender, string); // griefus
}
public static void sendMessage(CommandSender sender, String message) {
// griefus start
try {
MiniMessage miniMessage = MiniMessage.miniMessage();
sender.sendMessage(miniMessage.deserialize(message));
return;
} catch (ParsingException ignored) {
ignored.printStackTrace();
}
// griefus end
if (sender instanceof ConsoleCommandSender) {
message = message.replace(Color.DARK_AQUA, ChatColor.DARK_AQUA.toString());
}
try {
MiniMessage miniMessage = MiniMessage.miniMessage();
sender.sendMessage(miniMessage.deserialize(message));
} catch (ParsingException e) {
sender.sendMessage(message);
}
sender.sendMessage(message);
}
public static void sendConsoleMessage(String string) {

View file

@ -2,6 +2,7 @@ package net.coreprotect.utility;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.ConsoleCommandSender;
import java.text.DecimalFormat;
@ -17,7 +18,8 @@ public class ChatUtils {
}
public static String getCoordinates(String command, int worldId, int x, int y, int z, boolean displayWorld, boolean italic) {
StringBuilder message = new StringBuilder(Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND);
//StringBuilder message = new StringBuilder(Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND);
StringBuilder message = new StringBuilder("<click:run_command:\""); // griefus
StringBuilder worldDisplay = new StringBuilder();
if (displayWorld) {
@ -26,12 +28,18 @@ public class ChatUtils {
// command
DecimalFormat decimalFormat = new DecimalFormat("#.##", new DecimalFormatSymbols(Locale.ROOT));
message.append("|/" + command + " teleport wid:" + worldId + " " + decimalFormat.format(x + 0.50) + " " + y + " " + decimalFormat.format(z + 0.50) + "|");
//message.append("|/" + command + " teleport wid:" + worldId + " " + decimalFormat.format(x + 0.50) + " " + y + " " + decimalFormat.format(z + 0.50) + "|");
// griefus start
String commandLine = "/" + command + " teleport wid:" + worldId + " " + decimalFormat.format(x + 0.50) + " " + y + " " + decimalFormat.format(z + 0.50) + "|";
message.append(commandLine + "\"><hover:show_text:\"" + escape(commandLine) + "\">");
// griefus end
// chat output
message.append(Color.GREY + (italic ? Color.ITALIC : "") + "(x" + x + "/y" + y + "/z" + z + worldDisplay.toString() + ")");
return message.append(Chat.COMPONENT_TAG_CLOSE).toString();
//return message.append(Chat.COMPONENT_TAG_CLOSE).toString();
return message.append("</hover></click>").toString(); // griefus
}
public static String getPageNavigation(String command, int page, int totalPages) {
@ -41,21 +49,24 @@ public class ChatUtils {
String backArrow = "";
if (page > 1) {
backArrow = "";
backArrow = Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + (page - 1) + "|" + backArrow + Chat.COMPONENT_TAG_CLOSE;
//backArrow = Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + (page - 1) + "|" + backArrow + Chat.COMPONENT_TAG_CLOSE;
backArrow = "<click:run_command:/" + command + " l " + (page - 1) + ">" + backArrow + "</click>"; // griefus
}
// next arrow
String nextArrow = " ";
if (page < totalPages) {
nextArrow = "";
nextArrow = Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + (page + 1) + "|" + nextArrow + Chat.COMPONENT_TAG_CLOSE;
//nextArrow = Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + (page + 1) + "|" + nextArrow + Chat.COMPONENT_TAG_CLOSE;
nextArrow = "<click:run_command:/" + command + " l " + (page + 1) + ">" + nextArrow + "</click>"; // griefus
}
StringBuilder pagination = new StringBuilder();
if (totalPages > 1) {
pagination.append(Color.GREY + "(");
if (page > 3) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + 1 + "|" + "1 " + Chat.COMPONENT_TAG_CLOSE);
//pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + 1 + "|" + "1 " + Chat.COMPONENT_TAG_CLOSE);
pagination.append(Color.WHITE + "<click:run_command:/").append(command).append(" l ").append(1).append(">").append("1 </click>"); //griefus
if (page > 4 && totalPages > 7) {
pagination.append(Color.GREY + "... ");
}
@ -99,7 +110,8 @@ public class ChatUtils {
for (int displayPage = displayStart; displayPage <= displayEnd; displayPage++) {
if (page != displayPage) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + displayPage + "|" + displayPage + (displayPage < totalPages ? " " : "") + Chat.COMPONENT_TAG_CLOSE);
//pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + displayPage + "|" + displayPage + (displayPage < totalPages ? " " : "") + Chat.COMPONENT_TAG_CLOSE);
pagination.append(Color.WHITE + "<click:run_command:/" + command + " l " + displayPage + ">" + displayPage + (displayPage < totalPages ? " " : "") + "</click>"); // griefus
}
else {
pagination.append(Color.WHITE + Color.UNDERLINE + displayPage + Color.RESET + (displayPage < totalPages ? " " : ""));
@ -117,7 +129,8 @@ public class ChatUtils {
pagination.append(Color.GREY + "| ");
}
if (page != totalPages) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + totalPages + "|" + totalPages + Chat.COMPONENT_TAG_CLOSE);
//pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + totalPages + "|" + totalPages + Chat.COMPONENT_TAG_CLOSE);
pagination.append(Color.WHITE + "<click:run_command:/" + command + " l " + totalPages + ">" + totalPages + "</click>"); // griefus
}
else {
pagination.append(Color.WHITE + Color.UNDERLINE + totalPages);
@ -163,7 +176,8 @@ public class ChatUtils {
Date logDate = new Date(resultTime * 1000L);
String formattedTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(logDate);
return Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP + "|" + Color.GREY + formattedTimestamp + "|" + Color.GREY + message.toString() + Chat.COMPONENT_TAG_CLOSE;
//return Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP + "|" + Color.GREY + formattedTimestamp + "|" + Color.GREY + message.toString() + Chat.COMPONENT_TAG_CLOSE;
return "<hover:show_text:\"<gray>" + escape(formattedTimestamp) + "</gray>\"><gray>" + message + "</hover>"; // griefus
}
return message.toString();
@ -174,19 +188,27 @@ public class ChatUtils {
return phrase;
}
StringBuilder message = new StringBuilder(Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP);
//StringBuilder message = new StringBuilder(Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP);
StringBuilder message = new StringBuilder("<hover:show_text:"); // griefus
// tooltip
message.append("|" + tooltip.replace("|", Chat.COMPONENT_PIPE) + "|");
//message.append("|" + tooltip.replace("|", Chat.COMPONENT_PIPE) + "|");
message.append(escape(tooltip)); // griefus
// chat output
message.append(phrase);
return message.append(Chat.COMPONENT_TAG_CLOSE).toString();
//return message.append(Chat.COMPONENT_TAG_CLOSE).toString();
return message.append("</hover>").toString(); // griefus
}
// This theoretically initializes the component code, to prevent gson adapter errors
public static void sendConsoleComponentStartup(ConsoleCommandSender consoleSender, String string) {
Chat.sendComponent(consoleSender, Color.RESET + "[Griefus] " + string + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP + "| | " + Chat.COMPONENT_TAG_CLOSE);
//Chat.sendComponent(consoleSender, Color.RESET + "[Griefus] " + string + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP + "| | " + Chat.COMPONENT_TAG_CLOSE);
Chat.sendComponent(consoleSender, Color.RESET + "[Griefus] " + MiniMessage.miniMessage().stripTags(string)); // griefus
}
public static String escape(String string) {
return MiniMessage.miniMessage().escapeTags(string).replace("\"", "\\");
}
}

View file

@ -1,6 +1,6 @@
package net.coreprotect.utility;
import org.bukkit.ChatColor;
//import org.bukkit.ChatColor;
public final class Color {
@ -10,112 +10,134 @@ public final class Color {
/**
* Represents black.
*/
public static final String BLACK = ChatColor.BLACK.toString();
//public static final String BLACK = ChatColor.BLACK.toString();
public static final String BLACK = "<black>"; // griefus
/**
* Represents dark blue.
*/
public static final String DARK_BLUE = ChatColor.DARK_BLUE.toString();
//public static final String DARK_BLUE = ChatColor.DARK_BLUE.toString();
public static final String DARK_BLUE = "<dark_blue>"; // griefus
/**
* Represents dark green.
*/
public static final String DARK_GREEN = ChatColor.DARK_GREEN.toString();
//public static final String DARK_GREEN = ChatColor.DARK_GREEN.toString();
public static final String DARK_GREEN = "<dark_green>"; // griefus
/**
* Represents dark blue (aqua).
*/
public static String DARK_AQUA = ChatColor.DARK_AQUA.toString();
//public static String DARK_AQUA = ChatColor.DARK_AQUA.toString();
public static String DARK_AQUA = "<dark_aqua>"; // griefus
/**
* Represents dark red.
*/
public static final String DARK_RED = ChatColor.DARK_RED.toString();
//public static final String DARK_RED = ChatColor.DARK_RED.toString();
public static final String DARK_RED = "<dark_red>"; // griefus
/**
* Represents dark purple.
*/
public static final String DARK_PURPLE = ChatColor.DARK_PURPLE.toString();
//public static final String DARK_PURPLE = ChatColor.DARK_PURPLE.toString();
public static final String DARK_PURPLE = "<dark_purple>"; // griefus
/**
* Represents gold.
*/
public static final String GOLD = ChatColor.GOLD.toString();
//public static final String GOLD = ChatColor.GOLD.toString();
public static final String GOLD = "<gold>"; // griefus
/**
* Represents grey.
*/
public static final String GREY = ChatColor.GRAY.toString();
//public static final String GREY = ChatColor.GRAY.toString();
public static final String GREY = "<gray>"; // griefus
/**
* Represents dark grey.
*/
public static final String DARK_GREY = ChatColor.DARK_GRAY.toString();
//public static final String DARK_GREY = ChatColor.DARK_GRAY.toString();
public static final String DARK_GREY = "<dark_gray>"; // griefus
/**
* Represents blue.
*/
public static final String BLUE = ChatColor.BLUE.toString();
//public static final String BLUE = ChatColor.BLUE.toString();
public static final String BLUE = "<blue>"; // griefus
/**
* Represents green.
*/
public static final String GREEN = ChatColor.GREEN.toString();
//public static final String GREEN = ChatColor.GREEN.toString();
public static final String GREEN = "<green>"; // griefus
/**
* Represents aqua.
*/
public static final String AQUA = ChatColor.AQUA.toString();
//public static final String AQUA = ChatColor.AQUA.toString();
public static final String AQUA = "<aqua>"; // griefus
/**
* Represents red.
*/
public static final String RED = ChatColor.RED.toString();
//public static final String RED = ChatColor.RED.toString();
public static final String RED = "<red>"; // griefus
/**
* Represents light purple.
*/
public static final String LIGHT_PURPLE = ChatColor.LIGHT_PURPLE.toString();
//public static final String LIGHT_PURPLE = ChatColor.LIGHT_PURPLE.toString();
public static final String LIGHT_PURPLE = "<light_purple>"; // griefus
/**
* Represents yellow.
*/
public static final String YELLOW = ChatColor.YELLOW.toString();
//public static final String YELLOW = ChatColor.YELLOW.toString();
public static final String YELLOW = "<yellow>"; // griefus
/**
* Represents white.
*/
public static final String WHITE = ChatColor.WHITE.toString();
//public static final String WHITE = ChatColor.WHITE.toString();
public static final String WHITE = "<white>"; // griefus
/**
* Represents magical characters that change around randomly.
*/
public static final String MAGIC = ChatColor.COLOR_CHAR + "k";
//public static final String MAGIC = ChatColor.COLOR_CHAR + "k";
public static final String MAGIC = "<obfuscated>"; // griefus
/**
* Makes the text bold.
*/
public static final String BOLD = ChatColor.COLOR_CHAR + "l";
//public static final String BOLD = ChatColor.COLOR_CHAR + "l";
public static final String BOLD = "<bold>"; // griefus
/**
* Makes a line appear through the text.
*/
public static final String STRIKETHROUGH = ChatColor.COLOR_CHAR + "m";
//public static final String STRIKETHROUGH = ChatColor.COLOR_CHAR + "m";
public static final String STRIKETHROUGH = "<strikethrough>"; // griefus
/**
* Makes the text appear underlined.
*/
public static final String UNDERLINE = ChatColor.COLOR_CHAR + "n";
//public static final String UNDERLINE = ChatColor.COLOR_CHAR + "n";
public static final String UNDERLINE = "<underlined>"; // griefus
/**
* Makes the text italic.
*/
public static final String ITALIC = ChatColor.COLOR_CHAR + "o";
//public static final String ITALIC = ChatColor.COLOR_CHAR + "o";
public static final String ITALIC = "<italic>"; // griefus
/**
* Resets all previous chat colors or formats.
*/
public static final String RESET = ChatColor.COLOR_CHAR + "r";
//public static final String RESET = ChatColor.COLOR_CHAR + "r";
public static final String RESET = "<reset>"; // griefus
private Color() {
throw new IllegalStateException("Utility class");