メインコンテンツまでスキップ

コマンドを実行する

アイテムをクリックした際に、プレイヤー自身としてコマンドを実行したり、サーバーコンソール(OP権限)としてコマンドを実行する方法を解説します。


プレイヤーコマンドの実行

クリックしたプレイヤー自身が実行者となってコマンドを実行します。

簡易記法

menu-items:
- slot: 11
material: COMPASS
name: "&aスポーンへ行く"
command: "/spawn" # 先頭スラッシュありでもなしでも動作します

型付きアクション(type: player-command

menu-items:
- slot: 11
material: COMPASS
name: "&aスポーンへ行く"
action:
type: player-command
command: "spawn"

コンソールコマンドの実行 (type: console-command)

サーバーコンソール(最高権限)としてコマンドを実行します。アイテムの付与(/give)や経済の操作(/eco give)、権限の変更など、一般プレイヤーに直接権限を与えたくないコマンドを実行する際に使用します。

menu-items:
- slot: 13
material: GOLD_INGOT
name: "&6デイリーボーナスを受け取る"
action:
type: console-command
command: "eco give {player} 500"

:::tip 実行者の明示指定 (type: command) type: command では executor キーで実行者を明示指定することもできます。

action:
type: command
executor: console # player または console
command: "give {player} diamond 1"

:::


コマンド内の変数とプレースホルダー

コマンド文字列内では、以下の変数やPlaceholderAPIのプレースホルダーが自動的に展開されます。

変数展開内容
{player}クリックしたプレイヤーのMC ID(名前)
{menu}現在のメニューID
{session}現在のセッション識別子
{input} / {input.<id>}フォームやチャットで入力された値
%<placeholder>%PlaceholderAPI の各種プレースホルダー(例: %vault_eco_balance%

記述例

actions:
- type: console-command
command: "say &e{player} &fさんがVIPショップを利用しました!"
- type: console-command
command: "lp user {player} parent add vip"