Last active
September 10, 2021 08:03
-
-
Save ivon852/044f8d8c4b2feb937b3b5878952bac99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example; | |
| import cn.nukkit.plugin.PluginBase; | |
| import cn.nukkit.utils.TextFormat; | |
| import cn.nukkit.command.Command; | |
| import cn.nukkit.command.CommandSender; | |
| import cn.nukkit.event.EventHandler; | |
| import cn.nukkit.event.Listener; | |
| import cn.nukkit.event.player.PlayerJoinEvent; | |
| import cn.nukkit.event.player.PlayerQuitEvent; | |
| public class main extends PluginBase implements Listener { | |
| // 遊戲載入時觸發 | |
| @Override | |
| public void onLoad() { | |
| this.getLogger().info(TextFormat.GREEN + "插件已載入"); | |
| } | |
| @Override | |
| public void onEnable() { | |
| this.getLogger().info(TextFormat.GREEN + "插件已啟用"); | |
| this.getServer().getPluginManager().registerEvents(this, this); | |
| } | |
| @Override | |
| public void onDisable() { | |
| this.getLogger().info(TextFormat.RED + "插件已停用"); | |
| } | |
| // 偵測指令 | |
| @Override | |
| public boolean onCommand(CommandSender sender, Command command, String label, String[] Args) { | |
| if (command.getName().toLowerCase().equals("sayhi")) { | |
| sender.sendMessage("你好," + TextFormat.GREEN + sender.getName()); | |
| return true; | |
| } | |
| return true; | |
| } | |
| @EventHandler | |
| public void onPlayerJoin(PlayerJoinEvent event) { | |
| event.setJoinMessage("你好,歡迎" + event.getPlayer().getName() + "加入伺服器!"); | |
| } | |
| @EventHandler | |
| public void onPlayerQuit(PlayerQuitEvent event) { | |
| event.setQuitMessage("再見," + event.getPlayer().getName()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment