// Function to set hover text and click command in Minecraft chat // [Example 1] sendHoverText (player, "click here", null, "/ say good morning"); // [Example 2] sendHoverText (player, "Hover over", "Help message", null); // [Example 3] sendHoverText (player, "place the cursor and click", "help message", "/ say good morning"); public static void sendHoverText(Player p,String text,String hoverText,String command){ ////////////////////////////////////////// // Create hover text and events HoverEvent hoverEvent = null; if(hoverText != null){ BaseComponent[] hover = new ComponentBuilder(hoverText).create(); hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover); }
//////////////////////////////////////////
// Create a click event ClickEvent clickEvent = null; if(command != null){ clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND,command); }
BaseComponent[] message = new ComponentBuilder(text).event(hoverEvent).event(clickEvent). create();
p.spigot().sendMessage(message);
}
Recommended Posts