From 48217cca0d4d94d1076511d63d7e53e48fbed6e5 Mon Sep 17 00:00:00 2001 From: Fortern Date: Wed, 12 Feb 2025 17:54:44 +0800 Subject: [PATCH] init 8 --- .../kotlin/xyz/fortern/minehunt/Console.kt | 9 ++++++-- .../kotlin/xyz/fortern/minehunt/Minehunt.kt | 5 +++-- .../fortern/minehunt/command/GodCommand.kt | 14 ------------ .../fortern/minehunt/command/TestCommand.kt | 22 +++++++++++++++++-- .../minehunt/listener/PlayerListener.kt | 13 ----------- src/main/resources/plugin.yml | 4 ++-- 6 files changed, 32 insertions(+), 35 deletions(-) delete mode 100644 src/main/kotlin/xyz/fortern/minehunt/command/GodCommand.kt diff --git a/src/main/kotlin/xyz/fortern/minehunt/Console.kt b/src/main/kotlin/xyz/fortern/minehunt/Console.kt index 2fccc70..19ef905 100644 --- a/src/main/kotlin/xyz/fortern/minehunt/Console.kt +++ b/src/main/kotlin/xyz/fortern/minehunt/Console.kt @@ -3,7 +3,12 @@ package xyz.fortern.minehunt import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.title.Title -import org.bukkit.* +import org.bukkit.Bukkit +import org.bukkit.Difficulty +import org.bukkit.GameMode +import org.bukkit.GameRule +import org.bukkit.Location +import org.bukkit.Material import org.bukkit.enchantments.Enchantment import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack @@ -21,7 +26,7 @@ class Console { var stage: GameStage = GameStage.PREPARING - var overworld = Bukkit.getWorld("world")!! + private var overworld = Bukkit.getWorld("world")!! /** * 速通者队伍 diff --git a/src/main/kotlin/xyz/fortern/minehunt/Minehunt.kt b/src/main/kotlin/xyz/fortern/minehunt/Minehunt.kt index bff8895..7a7b254 100644 --- a/src/main/kotlin/xyz/fortern/minehunt/Minehunt.kt +++ b/src/main/kotlin/xyz/fortern/minehunt/Minehunt.kt @@ -2,7 +2,6 @@ package xyz.fortern.minehunt import org.bukkit.Bukkit import org.bukkit.plugin.java.JavaPlugin -import xyz.fortern.minehunt.command.GodCommand import xyz.fortern.minehunt.command.TestCommand import xyz.fortern.minehunt.listener.PlayerListener @@ -22,9 +21,11 @@ class Minehunt : JavaPlugin() { // 初始化 instance = this val console = Console() + + // 注册命令 Bukkit.getPluginManager().registerEvents(PlayerListener(console), this) - Bukkit.getPluginCommand("god")!!.setExecutor(GodCommand()) + // 注册事件 Bukkit.getPluginCommand("test")!!.setExecutor(TestCommand()) } diff --git a/src/main/kotlin/xyz/fortern/minehunt/command/GodCommand.kt b/src/main/kotlin/xyz/fortern/minehunt/command/GodCommand.kt deleted file mode 100644 index 3592ca8..0000000 --- a/src/main/kotlin/xyz/fortern/minehunt/command/GodCommand.kt +++ /dev/null @@ -1,14 +0,0 @@ -package xyz.fortern.minehunt.command - -import org.bukkit.command.Command -import org.bukkit.command.CommandExecutor -import org.bukkit.command.CommandSender -import org.bukkit.entity.Player - -class GodCommand : CommandExecutor { - override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array?): Boolean { - if (sender is Player) - sender.isInvulnerable = !sender.isInvulnerable - return true - } -} \ No newline at end of file diff --git a/src/main/kotlin/xyz/fortern/minehunt/command/TestCommand.kt b/src/main/kotlin/xyz/fortern/minehunt/command/TestCommand.kt index 02aedd4..8fe95ce 100644 --- a/src/main/kotlin/xyz/fortern/minehunt/command/TestCommand.kt +++ b/src/main/kotlin/xyz/fortern/minehunt/command/TestCommand.kt @@ -1,5 +1,6 @@ package xyz.fortern.minehunt.command +import net.kyori.adventure.text.Component import org.bukkit.Bukkit import org.bukkit.command.Command import org.bukkit.command.CommandExecutor @@ -11,15 +12,32 @@ import org.bukkit.command.CommandSender class TestCommand : CommandExecutor { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { when (args[0]) { + // 发送消息 "sendTo" -> { + if (args.size < 2) { + sender.sendMessage(Component.text("需要参数")) + return true + } // 给某个玩家发消息 val name = args[1] val player = Bukkit.getPlayer(name) - if (player != null) { + if (player != null) player.sendMessage("离线发送消息") - } else { + else sender.sendMessage("玩家 $name 不存在") + } + // 无敌 + "invulnerable" -> { + if (args.size < 2) { + sender.sendMessage(Component.text("需要参数")) + return true } + val name = args[1] + val player = Bukkit.getPlayer(name) + if (player != null) + player.isInvulnerable = !player.isInvulnerable + else + sender.sendMessage("玩家 $name 不存在") } } return true diff --git a/src/main/kotlin/xyz/fortern/minehunt/listener/PlayerListener.kt b/src/main/kotlin/xyz/fortern/minehunt/listener/PlayerListener.kt index 37a70e4..c55cf29 100644 --- a/src/main/kotlin/xyz/fortern/minehunt/listener/PlayerListener.kt +++ b/src/main/kotlin/xyz/fortern/minehunt/listener/PlayerListener.kt @@ -7,7 +7,6 @@ import org.bukkit.event.entity.PlayerDeathEvent import org.bukkit.event.player.PlayerDropItemEvent import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerMoveEvent -import org.bukkit.event.player.PlayerQuitEvent import xyz.fortern.minehunt.Console import xyz.fortern.minehunt.Console.GameStage @@ -41,18 +40,6 @@ class PlayerListener( } } - /** - * 玩家退出服务器时的操作 - */ - @EventHandler - fun onPlayerQuit(event: PlayerQuitEvent) { - val player = event.player - // 速通者退出时,从speedrunnerList中移除,避免指南针遍历 -// if (console.stage == GameStage.PROCESSING && console.speedrunnerSet.contains(player)) -// console.speedrunnerList.remove(player) - - } - /** * 玩家丢弃物品时,阻止玩家丢弃猎人指南针,并将追踪目标切换到下一个 */ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7700c24..75ae72f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,8 +4,8 @@ main: xyz.fortern.minehunt.Minehunt api-version: '1.21' authors: [ Fortern ] +# TODO 插件加载时机 + commands: - god: - description: "使自己无敌" test: description: "测试"