會長:chenjinsheng / 此間半開一盞茶開設日:2015-05-17 23:58:58
近期編輯:chenjinsheng ...看更多 |
public class Command implements CommandExecutor{ @Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException { // 執行內容 return CommandResult.success(); // 回傳成功,empty則是失敗 } |
if (commandSource instanceof Player) { // 檢查是玩家,進一步轉型並取得玩家名稱 Player player = (Player) commandSource; player.sendMessage(Texts.of("嗨! " + player.getName() + " !!")); } else if(commandSource instanceof ConsoleSource) { // 檢查是控制台,直接回傳給控制台 commandSource.sendMessage(Texts.of("嗨!管理員!!")); } else if(commandSource instanceof CommandBlockSource) { // 回傳給指令方塊,運作方塊後再打開會顯在先前輸出內 commandSource.sendMessage(Texts.of("嗨!指令方塊!!")); } |
public static final CommandSpec spec = CommandSpec.builder() .description(Texts.of("對自己打招呼的指令")) // 建立說明 .permission("anikaba.hello.hi") // 設定權限 .executor(new Command()) // 指令類 .build(); |
// 註冊插件ID,名稱,版本號 @Plugin(id = "anikaba-HelloSponge", name = "Hello Sponge", version = "v0.1") public class HelloSponge { @Inject public static Game game; // 使用靜態寫法方便其他類取得 @Listener public void onEnable(GamePreInitializationEvent event) { game = event.getGame(); // 註冊指令”hi” game.getCommandDispatcher().register(this, Command.spec, "hi"); } } |
目前沒有資料連到「海綿寶寶日記(用指令打招呼吧~)」。