You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
playerArgument("player") { // Defines a new PlayerArgument("player")
15
+
greedyArgument("msg") { // Defines a new GreedyStringArgument("msg)
16
+
anyExecutor { _, args ->// Command can be executed by anyone and anything (such as entities, the console, etc.)
17
+
val player:Player= args[0] asPlayer
18
+
val message:String= args[1] asString
19
+
player.sendMessage(message)
20
+
}
21
+
}
22
+
}
23
+
}
24
+
/* ANCHOR_END: dslSendMessageToCommand */
25
+
26
+
/* ANCHOR: dslSendMessageToCommand2 */
27
+
commandAPICommand("sendmessageto") {
28
+
playerArgument("player") // Defines a new PlayerArgument("player")
29
+
greedyArgument("msg") // Defines a new GreedyStringArgument("msg)
30
+
anyExecutor { _, args ->// Command can be executed by anyone and anything (such as entities, the console, etc.)
31
+
val player:Player= args[0] asPlayer
32
+
val message:String= args[1] asString
33
+
player.sendMessage(message)
34
+
}
35
+
}
36
+
/* ANCHOR_END: dslSendMessageToCommand2 */
37
+
38
+
/* ANCHOR: dslSendMessageToCommandRequirement */
39
+
commandTree("sendMessageTo") {
40
+
playerArgument("player") {
41
+
greedyArgument("msg") {
42
+
playerExecutor { _, args ->
43
+
val player:Player= args[0] asPlayer
44
+
val message:String= args[1] asString
45
+
player.sendMessage(message)
46
+
}
47
+
}
48
+
}
49
+
requirement(of("broadcast"), { sender:CommandSender-> sender.isOp }) { // Define a new LiteralArgument("broadcast") that requires the CommandSender to be a player who is a server operator
requirement(of("broadcast"), { sender:CommandSender-> sender.isOp }) // Define a new LiteralArgument("broadcast") that requires the CommandSender to be a player who is a server operator
player.sendMessage("This command can only be executed by players who are server operators.")
93
+
}
94
+
}
95
+
/* ANCHOR_END: dslCommandRequirements2 */
96
+
}
97
+
98
+
funmoreExamples() {
99
+
/* ANCHOR: optionalArgument */
100
+
commandTree("optionalArgument") {
101
+
literalArgument("give") {
102
+
itemStackArgument("item") {
103
+
playerExecutor { player, args ->// This will let you execute "/optionalArgument give minecraft:stick"
104
+
val itemStack:ItemStack= args[0] asItemStack
105
+
player.inventory.addItem(itemStack)
106
+
}
107
+
integerArgument("amount") {
108
+
playerExecutor { player, args ->// This will let you execute "/optionalArgument give minecraft:stick 5"
109
+
val itemStack:ItemStack= args[0] asItemStack
110
+
val amount:Int= args[1] asInt
111
+
itemStack.amount = amount
112
+
player.inventory.addItem(itemStack)
113
+
}
114
+
}
115
+
}
116
+
}
117
+
}
118
+
/* ANCHOR_END: optionalArgument */
119
+
120
+
/* ANCHOR: optionalArgument2 */
121
+
commandAPICommand("optionalArgument") {
122
+
literalArgument("give")
123
+
itemStackArgument("item")
124
+
playerExecutor { player, args ->// This will let you execute "/optionalArgument give minecraft:stick"
125
+
val itemStack:ItemStack= args[0] asItemStack
126
+
player.inventory.addItem(itemStack)
127
+
}
128
+
}
129
+
130
+
commandAPICommand("optionalArgument") {
131
+
literalArgument("give")
132
+
itemStackArgument("item")
133
+
integerArgument("amount")
134
+
playerExecutor { player, args ->// This will let you execute "/optionalArgument give minecraft:stick 5"
135
+
val itemStack:ItemStack= args[0] asItemStack
136
+
val amount:Int= args[1] asInt
137
+
itemStack.amount = amount
138
+
player.inventory.addItem(itemStack)
139
+
}
140
+
}
141
+
/* ANCHOR_END: optionalArgument2 */
142
+
143
+
/* ANCHOR: replaceSuggestions */
144
+
commandTree("replaceSuggestions") {
145
+
argument(StringArgument("strings").replaceSuggestions(ArgumentSuggestions.strings("one", "two", "three"))) { // Implement an argument that has suggestions
argument(StringArgument("strings").replaceSuggestions(ArgumentSuggestions.strings("one", "two", "three"))) // Implement an argument that has suggestions
0 commit comments