Skip to content

Commit a78155d

Browse files
feat: add world environment and type arguments to world command
1 parent a6e6cc5 commit a78155d

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed

src/main/kotlin/dev/slne/surf/essentials/command/WorldCommand.kt

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package dev.slne.surf.essentials.command
22

33
import dev.jorel.commandapi.kotlindsl.*
4+
import dev.slne.surf.essentials.command.argument.world.worldEnvironmentArgument
45
import dev.slne.surf.essentials.command.argument.world.worldFoldersArgument
6+
import dev.slne.surf.essentials.command.argument.world.worldTypeArgument
57
import dev.slne.surf.essentials.command.argument.world.worldsArgument
68
import dev.slne.surf.essentials.service.worldService
79
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
@@ -14,6 +16,7 @@ import net.kyori.adventure.text.event.ClickEvent
1416
import net.kyori.adventure.text.format.TextDecoration
1517
import org.bukkit.Bukkit
1618
import org.bukkit.World
19+
import org.bukkit.WorldType
1720
import org.bukkit.entity.Player
1821

1922
fun worldCommand() = commandTree("world") {
@@ -126,6 +129,124 @@ fun worldCommand() = commandTree("world") {
126129

127130
worldService.create(executor, name, null, null, null, null, null)
128131
}
132+
133+
worldEnvironmentArgument("environment") {
134+
anyExecutor { executor, args ->
135+
val name: String by args
136+
val environment: World.Environment by args
137+
138+
if (Bukkit.getServer().isFolia()) {
139+
executor.sendText {
140+
appendPrefix()
141+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
142+
}
143+
return@anyExecutor
144+
}
145+
146+
worldService.create(executor, name, environment, null, null, null, null)
147+
}
148+
149+
worldTypeArgument("type") {
150+
anyExecutor { executor, args ->
151+
val name: String by args
152+
val environment: World.Environment by args
153+
val type: WorldType by args
154+
155+
if (Bukkit.getServer().isFolia()) {
156+
executor.sendText {
157+
appendPrefix()
158+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
159+
}
160+
return@anyExecutor
161+
}
162+
163+
worldService.create(executor, name, environment, type, null, null, null)
164+
}
165+
166+
booleanArgument("generateStructures") {
167+
anyExecutor { executor, args ->
168+
val name: String by args
169+
val environment: World.Environment by args
170+
val type: WorldType by args
171+
val generateStructures: Boolean by args
172+
173+
if (Bukkit.getServer().isFolia()) {
174+
executor.sendText {
175+
appendPrefix()
176+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
177+
}
178+
return@anyExecutor
179+
}
180+
181+
worldService.create(
182+
executor,
183+
name,
184+
environment,
185+
type,
186+
generateStructures,
187+
null,
188+
null
189+
)
190+
}
191+
booleanArgument("hardcore") {
192+
anyExecutor { executor, args ->
193+
val name: String by args
194+
val environment: World.Environment by args
195+
val type: WorldType by args
196+
val generateStructures: Boolean by args
197+
val hardcore: Boolean by args
198+
199+
if (Bukkit.getServer().isFolia()) {
200+
executor.sendText {
201+
appendPrefix()
202+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
203+
}
204+
return@anyExecutor
205+
}
206+
207+
worldService.create(
208+
executor,
209+
name,
210+
environment,
211+
type,
212+
generateStructures,
213+
hardcore,
214+
null
215+
)
216+
}
217+
218+
longArgument("seed") {
219+
anyExecutor { executor, args ->
220+
val name: String by args
221+
val environment: World.Environment by args
222+
val type: WorldType by args
223+
val generateStructures: Boolean by args
224+
val hardcore: Boolean by args
225+
val seed: Long by args
226+
227+
if (Bukkit.getServer().isFolia()) {
228+
executor.sendText {
229+
appendPrefix()
230+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
231+
}
232+
return@anyExecutor
233+
}
234+
235+
worldService.create(
236+
executor,
237+
name,
238+
environment,
239+
type,
240+
generateStructures,
241+
hardcore,
242+
seed
243+
)
244+
}
245+
}
246+
}
247+
}
248+
}
249+
}
129250
}
130251
}
131252

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.slne.surf.essentials.command.argument.world
2+
3+
import dev.jorel.commandapi.CommandTree
4+
import dev.jorel.commandapi.arguments.Argument
5+
import dev.jorel.commandapi.arguments.ArgumentSuggestions
6+
import dev.jorel.commandapi.arguments.CustomArgument
7+
import dev.jorel.commandapi.arguments.StringArgument
8+
import dev.slne.surf.surfapi.core.api.messages.adventure.buildText
9+
import org.bukkit.World
10+
import org.bukkit.command.CommandSender
11+
12+
class WorldEnvironmentArgument(nodeName: String) :
13+
CustomArgument<World.Environment, String>(StringArgument(nodeName), { info ->
14+
World.Environment.entries.firstOrNull { it.name == info.input.uppercase() }
15+
?: throw CustomArgumentException.fromAdventureComponent {
16+
buildText {
17+
appendPrefix()
18+
error("Das Welt-Umfeld wurde nicht gefunden.")
19+
}
20+
}
21+
}) {
22+
init {
23+
this.replaceSuggestions(
24+
ArgumentSuggestions.stringCollection<CommandSender> {
25+
World.Environment.entries.map { it.name.lowercase() }
26+
}
27+
)
28+
}
29+
}
30+
31+
inline fun Argument<*>.worldEnvironmentArgument(
32+
nodeName: String,
33+
optional: Boolean = false,
34+
block: Argument<*>.() -> Unit = {}
35+
): Argument<*> = then(
36+
WorldEnvironmentArgument(nodeName).setOptional(optional).apply(block)
37+
)
38+
39+
inline fun CommandTree.worldEnvironmentArgument(
40+
nodeName: String,
41+
optional: Boolean = false,
42+
block: Argument<*>.() -> Unit = {}
43+
): CommandTree = then(
44+
WorldEnvironmentArgument(nodeName).setOptional(optional).apply(block)
45+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package dev.slne.surf.essentials.command.argument.world
2+
3+
import dev.jorel.commandapi.CommandTree
4+
import dev.jorel.commandapi.arguments.Argument
5+
import dev.jorel.commandapi.arguments.ArgumentSuggestions
6+
import dev.jorel.commandapi.arguments.CustomArgument
7+
import dev.jorel.commandapi.arguments.StringArgument
8+
import dev.slne.surf.surfapi.core.api.messages.adventure.buildText
9+
import org.bukkit.WorldType
10+
import org.bukkit.command.CommandSender
11+
12+
class WorldTypeArgument(nodeName: String) :
13+
CustomArgument<WorldType, String>(StringArgument(nodeName), { info ->
14+
WorldType.entries.firstOrNull { it.name == info.input.uppercase() }
15+
?: throw CustomArgumentException.fromAdventureComponent {
16+
buildText {
17+
appendPrefix()
18+
error("Der Welttyp wurde nicht gefunden.")
19+
}
20+
}
21+
}) {
22+
init {
23+
this.replaceSuggestions(
24+
ArgumentSuggestions.stringCollection<CommandSender> {
25+
WorldType.entries.map {
26+
it.name.lowercase()
27+
}
28+
}
29+
)
30+
}
31+
}
32+
33+
inline fun Argument<*>.worldTypeArgument(
34+
nodeName: String,
35+
optional: Boolean = false,
36+
block: Argument<*>.() -> Unit = {}
37+
): Argument<*> = then(
38+
WorldTypeArgument(nodeName).setOptional(optional).apply(block)
39+
)
40+
41+
inline fun CommandTree.worldTypeArgument(
42+
nodeName: String,
43+
optional: Boolean = false,
44+
block: Argument<*>.() -> Unit = {}
45+
): CommandTree = then(
46+
WorldTypeArgument(nodeName).setOptional(optional).apply(block)
47+
)

0 commit comments

Comments
 (0)