11package dev.slne.surf.essentials.command
22
33import dev.jorel.commandapi.kotlindsl.*
4+ import dev.slne.surf.essentials.command.argument.world.worldEnvironmentArgument
5+ import dev.slne.surf.essentials.command.argument.world.worldFoldersArgument
6+ import dev.slne.surf.essentials.command.argument.world.worldTypeArgument
7+ import dev.slne.surf.essentials.command.argument.world.worldsArgument
48import dev.slne.surf.essentials.service.worldService
59import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
610import dev.slne.surf.essentials.util.util.isFolia
11+ import dev.slne.surf.surfapi.core.api.font.toSmallCaps
12+ import dev.slne.surf.surfapi.core.api.messages.adventure.buildText
713import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
14+ import dev.slne.surf.surfapi.core.api.messages.pagination.Pagination
15+ import net.kyori.adventure.text.event.ClickEvent
16+ import net.kyori.adventure.text.format.TextDecoration
817import org.bukkit.Bukkit
918import org.bukkit.World
19+ import org.bukkit.WorldType
20+ import org.bukkit.entity.Player
1021
1122fun worldCommand () = commandTree(" world" ) {
1223 withPermission(EssentialsPermissionRegistry .WORLD_COMMAND )
1324
1425 literalArgument(" lock" ) {
15- worldArgument (" world" ) {
26+ worldsArgument (" world" ) {
1627 withPermission(EssentialsPermissionRegistry .WORLD_COMMAND_LOCK )
1728 anyExecutor { executor, args ->
1829 val world: World by args
@@ -45,7 +56,7 @@ fun worldCommand() = commandTree("world") {
4556 }
4657
4758 literalArgument(" unlock" ) {
48- worldArgument (" world" ) {
59+ worldsArgument (" world" ) {
4960 withPermission(EssentialsPermissionRegistry .WORLD_COMMAND_UNLOCK )
5061 anyExecutor { executor, args ->
5162 val world: World by args
@@ -78,7 +89,7 @@ fun worldCommand() = commandTree("world") {
7889 }
7990
8091 literalArgument(" join" ) {
81- worldArgument (" world" ) {
92+ worldsArgument (" world" ) {
8293 withPermission(EssentialsPermissionRegistry .WORLD_COMMAND_JOIN )
8394 playerExecutor { player, args ->
8495 val world: World by args
@@ -108,12 +119,6 @@ fun worldCommand() = commandTree("world") {
108119 anyExecutor { executor, args ->
109120 val name: String by args
110121
111- executor.sendText {
112- appendPrefix()
113- info(" Dieser Befehl ist zurzeit deaktiviert." )
114- }
115- return @anyExecutor
116-
117122 if (Bukkit .getServer().isFolia()) {
118123 executor.sendText {
119124 appendPrefix()
@@ -124,21 +129,133 @@ fun worldCommand() = commandTree("world") {
124129
125130 worldService.create(executor, name, null , null , null , null , null )
126131 }
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+ }
127250 }
128251 }
129252
130253 literalArgument(" delete" ) {
131- worldArgument (" world" ) {
254+ worldsArgument (" world" ) {
132255 withPermission(EssentialsPermissionRegistry .WORLD_COMMAND_DELETE )
133256 anyExecutor { executor, args ->
134257 val world: World by args
135258
136- executor.sendText {
137- appendPrefix()
138- info(" Dieser Befehl ist zurzeit deaktiviert." )
139- }
140- return @anyExecutor
141-
142259 if (Bukkit .getServer().isFolia()) {
143260 executor.sendText {
144261 appendPrefix()
@@ -153,7 +270,7 @@ fun worldCommand() = commandTree("world") {
153270 }
154271
155272 literalArgument(" load" ) {
156- stringArgument (" name" ) {
273+ worldFoldersArgument (" name" ) {
157274 withPermission(EssentialsPermissionRegistry .WORLD_COMMAND_LOAD )
158275 anyExecutor { executor, args ->
159276 val name: String by args
@@ -173,17 +290,11 @@ fun worldCommand() = commandTree("world") {
173290 }
174291
175292 literalArgument(" unload" ) {
176- worldArgument (" world" ) {
293+ worldsArgument (" world" ) {
177294 withPermission(EssentialsPermissionRegistry .WORLD_COMMAND_UNLOAD )
178295 anyExecutor { executor, args ->
179296 val world: World by args
180297
181- executor.sendText {
182- appendPrefix()
183- info(" Dieser Befehl ist zurzeit deaktiviert." )
184- }
185- return @anyExecutor
186-
187298 if (Bukkit .getServer().isFolia()) {
188299 executor.sendText {
189300 appendPrefix()
@@ -196,4 +307,98 @@ fun worldCommand() = commandTree("world") {
196307 }
197308 }
198309 }
199- }
310+
311+ literalArgument(" list" ) {
312+ anyExecutor { executor, _ ->
313+ val worlds = Bukkit .getWorlds()
314+
315+ if (worlds.isEmpty()) {
316+ executor.sendText {
317+ appendPrefix()
318+ error(" Es sind keine Welten geladen." )
319+ }
320+ return @anyExecutor
321+ }
322+
323+ val worldData = worlds.map {
324+ WorldData (it.name, worldService.isLocked(it))
325+ }
326+
327+ val pagination = Pagination <WorldData > {
328+ title {
329+ primary(" Geladene Welten" .toSmallCaps(), TextDecoration .BOLD )
330+ }
331+
332+ rowRenderer { row, index ->
333+ listOf (
334+ buildText {
335+ darkSpacer(" >" )
336+ appendSpace()
337+ variableValue(row.worldName)
338+ appendSpace()
339+ spacer(" (" )
340+ if (row.isLocked) {
341+ error(" Gesperrt" .toSmallCaps())
342+ } else {
343+ success(" Entsperrt" .toSmallCaps())
344+ }
345+ spacer(" )" )
346+ hoverEvent(buildText {
347+ info(" Klicke, um dich zu teleportieren." )
348+ })
349+ clickEvent(ClickEvent .callback {
350+ val world = Bukkit .getWorld(row.worldName)
351+
352+ if (world == null ) {
353+ executor.sendText {
354+ appendPrefix()
355+ error(" Die Welt ${row.worldName} ist nicht mehr geladen." )
356+ }
357+ return @callback
358+ }
359+
360+ val player = it as ? Player ? : run {
361+ executor.sendText {
362+ appendPrefix()
363+ error(" Du musst ein Spieler sein, um teleportiert zu werden." )
364+ }
365+ return @callback
366+ }
367+
368+ player.sendText {
369+ appendPrefix()
370+ info(" Du wirst in die Welt " )
371+ variableValue(world.name)
372+ info(" teleportiert..." )
373+ }
374+
375+ player.teleportAsync(world.spawnLocation).thenRun {
376+ player.sendText {
377+ appendPrefix()
378+ success(" Du wurdest in die Welt " )
379+ variableValue(world.name)
380+ success(" teleportiert." )
381+ }
382+ }
383+ })
384+ }
385+ )
386+ }
387+ }
388+
389+ executor.sendText {
390+ appendPrefix()
391+ info(" Es sind insgesamt " )
392+ variableValue(worlds.size.toString())
393+ info(" Welt(en) geladen:" )
394+ appendNewline()
395+ append(pagination.renderComponent(worldData))
396+ }
397+ }
398+ }
399+ }
400+
401+ private data class WorldData (
402+ val worldName : String ,
403+ val isLocked : Boolean
404+ )
0 commit comments