package net.t2code.lib.Spigot.Lib.messages; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.md_5.bungee.api.chat.ClickEvent; import net.t2code.lib.Spigot.Lib.replace.Replace; import net.t2code.lib.Spigot.system.T2CodeMain; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class HoverModule { public static void modulePlayer(String text, String hover, String action, String actionValue, Player player) { modulePlayer((text != null ? text : "null") + "/*/" + (hover != null ? hover : "null") + "/*/" + (action != null ? action : "null") + "/*/" + (actionValue != null ? actionValue : "null"), player); } private static final MiniMessage mm = MiniMessage.miniMessage(); public static void modulePlayer(String msg, Player player) { if (msg.contains("/*/")) { t2cmodule(msg, player); return; } miniMessage(msg,player); } public static void moduleSender(String msg, CommandSender sender) { miniMessage(msg,sender); } public static void miniMessage(String msg, Player player){ Component parsed = mm.deserialize(Replace.convertColorCode(msg)); T2CodeMain.adventure.player(player).sendMessage(parsed); } public static void miniMessage(String msg, CommandSender sender){ Component parsed = mm.deserialize(Replace.convertColorCode(msg)); T2CodeMain.adventure.sender(sender).sendMessage(parsed); } private static void t2cmodule(String msg, Player player) { String[] split = msg.split("/\\*/"); int i = split.length; String text = null; String hover = null; String action = null; String actionValue = null; if (i > 0) text = split[0]; if (i > 1) hover = split[1]; if (i > 2) action = split[2]; if (i > 3) actionValue = split[3]; TextBuilder textBuilder = new TextBuilder(text); if (hover != null && !hover.equals("null")) { textBuilder.addHover(hover); } if (action != null && actionValue != null && !action.equals("null") && !actionValue.equals("null")) { textBuilder.addClickEvent(ClickEvent.Action.valueOf(action.toUpperCase()), actionValue); } player.spigot().sendMessage(textBuilder.build()); } }