-
Notifications
You must be signed in to change notification settings - Fork 5
Commands
Sven Rahn edited this page Jun 28, 2019
·
10 revisions
Execute commands:
player.executeCommand("warp spawn")
Server.console.executeCommand("say What a wonderful day!")
Server.onlinePlayers.executeCommand("warp event")
Create new commands:
Official docs: https://docs.spongepowered.org/stable/en/plugin/commands/index.html
Source: CommandSpec helpers and CommandElement helpers
registerCommand("examplecommand") {
action {
commandSource.sendMessage("Executed examplecommand!".t)
}
}
registerCommand("forplayers") {
action(onlyPlayers = true) {
player.give(ItemStack.of(ItemTypes.CAKE, 1))
}
}
registerCommand("test2") {
permission("test2.perm")
action {
commandSource.sendMessage("Executed test2!")
}
}
registerCommand("giveme") {
arguments(integer("amount"), catalogedElement<ItemType>("item"))
action(onlyPlayers = true) {
val amount = argument<Int>("amount")
val itemType = argument<ItemType>("item")
if (amount > 0) {
player.give(ItemStack.of(itemType, amount))
}
}
}
registerCommand("topcmd") {
child("childcmd") {
arguments(integer("whatever"))
action {
val amount = argument<Int>("whatever")
"Some message and a number: $amount".t.broadcast()
}
}
}