T2CodeLib/src/main/java/net/t2code/lib/Spigot/Lib/messages/HoverModule.java

40 lines
1.4 KiB
Java

package net.t2code.lib.Spigot.Lib.messages;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.entity.Player;
public class HoverModule {
public static void module(String text, String hover, String action, String actionValue, Player player) {
module((text != null ? text : "null") + "/*/" + (hover != null ? hover : "null") + "/*/" + (action != null ? action : "null")
+ "/*/" + (actionValue != null ? actionValue : "null"), player);
}
public static void module(String msg, Player player) {
if (!msg.contains("/*/")) {
player.sendMessage(msg);
return;
}
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());
}
}