mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 13:10:55 +00:00
Add short gamemode commands.
This commit is contained in:
parent
69380906e6
commit
728904fa23
@ -8,8 +8,3 @@ depend:
|
||||
- Foundation
|
||||
authors:
|
||||
- kubelet
|
||||
commands:
|
||||
fbackup:
|
||||
description: Foundation Backup
|
||||
usage: /fbackup
|
||||
permission: foundation.backup
|
||||
|
@ -1,7 +1,9 @@
|
||||
package cloud.kubelet.foundation.core
|
||||
|
||||
import cloud.kubelet.foundation.core.command.BackupCommand
|
||||
import cloud.kubelet.foundation.core.command.GamemodeCommand
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
@ -38,6 +40,10 @@ class FoundationCorePlugin : JavaPlugin(), Listener {
|
||||
|
||||
// Register commands.
|
||||
registerCommandExecutor("fbackup", BackupCommand(this, backupPath))
|
||||
registerCommandExecutor(listOf("survival", "s"), GamemodeCommand(GameMode.SURVIVAL))
|
||||
registerCommandExecutor(listOf("creative", "c"), GamemodeCommand(GameMode.CREATIVE))
|
||||
registerCommandExecutor(listOf("adventure", "a"), GamemodeCommand(GameMode.ADVENTURE))
|
||||
registerCommandExecutor(listOf("spectator", "sp"), GamemodeCommand(GameMode.SPECTATOR))
|
||||
|
||||
val log = slF4JLogger
|
||||
log.info("Features:")
|
||||
@ -45,8 +51,14 @@ class FoundationCorePlugin : JavaPlugin(), Listener {
|
||||
}
|
||||
|
||||
private fun registerCommandExecutor(name: String, executor: CommandExecutor) {
|
||||
val command = getCommand(name) ?: throw Exception("Failed to get $name command")
|
||||
command.setExecutor(executor)
|
||||
registerCommandExecutor(listOf(name), executor)
|
||||
}
|
||||
|
||||
private fun registerCommandExecutor(names: List<String>, executor: CommandExecutor) {
|
||||
for (name in names) {
|
||||
val command = getCommand(name) ?: throw Exception("Failed to get $name command")
|
||||
command.setExecutor(executor)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Disabling chat reformatting until I do something with it and figure out how to make it
|
||||
|
@ -91,7 +91,7 @@ class BackupCommand(
|
||||
for (world in worlds) {
|
||||
val worldPath = world.worldFolder.toPath()
|
||||
|
||||
// Save the world.
|
||||
// Save the world, must be run on the main thread.
|
||||
server.scheduler.runTask(plugin, Runnable {
|
||||
world.save()
|
||||
})
|
||||
|
@ -0,0 +1,26 @@
|
||||
package cloud.kubelet.foundation.core.command
|
||||
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class GamemodeCommand(private val gameMode: GameMode) : CommandExecutor {
|
||||
override fun onCommand(
|
||||
sender: CommandSender,
|
||||
command: Command,
|
||||
label: String,
|
||||
args: Array<out String>
|
||||
): Boolean {
|
||||
if (sender !is Player) {
|
||||
sender.sendMessage("You are not a player.")
|
||||
return true
|
||||
}
|
||||
|
||||
sender.gameMode = gameMode
|
||||
sender.sendMessage("Switched gamemode to ${gameMode.name.lowercase()}")
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
@ -11,3 +11,27 @@ commands:
|
||||
description: Foundation Backup
|
||||
usage: /fbackup
|
||||
permission: foundation.backup
|
||||
survival:
|
||||
description: Switch to survival gamemode
|
||||
usage: /survival
|
||||
aliases:
|
||||
- s
|
||||
permission: foundation.command.survival
|
||||
creative:
|
||||
description: Switch to creative gamemode
|
||||
usage: /creative
|
||||
aliases:
|
||||
- c
|
||||
permission: foundation.command.creative
|
||||
adventure:
|
||||
description: Switch to adventure gamemode
|
||||
usage: /adventure
|
||||
aliases:
|
||||
- a
|
||||
permission: foundation.command.adventure
|
||||
spectator:
|
||||
description: Switch to spectator gamemode
|
||||
usage: /spectator
|
||||
aliases:
|
||||
- sp
|
||||
permission: foundation.command.spectator
|
||||
|
Loading…
Reference in New Issue
Block a user