LoginSignup
6
2

More than 5 years have passed since last update.

マインクラフトプラグインでホバーテキストや、クリックでコマンド実行できるテキストを表示する方法

Last updated at Posted at 2018-05-04
//  マインクラフトチャットに、ホバーテキストや、クリックコマンドを設定する関数
// [例1] sendHoverText(player,"ここをクリック",null,"/say おはまん");
// [例2] sendHoverText(player,"カーソルをあわせて","ヘルプメッセージとか",null);
// [例3] sendHoverText(player,"カーソルをあわせてクリック","ヘルプメッセージとか","/say おはまん");
public static void sendHoverText(Player p,String text,String hoverText,String command){
    //////////////////////////////////////////
    //      ホバーテキストとイベントを作成する
    HoverEvent hoverEvent = null;
    if(hoverText != null){
        BaseComponent[] hover = new ComponentBuilder(hoverText).create();
        hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover);
    }

    //////////////////////////////////////////
    //   クリックイベントを作成する
    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);
}
6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2