Skip to content

Commit 17569bc

Browse files
feat: add Folia server support checks in world commands and portal events
1 parent 52a89f3 commit 17569bc

File tree

2 files changed

+88
-15
lines changed

2 files changed

+88
-15
lines changed

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

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package dev.slne.surf.essentials.command
33
import dev.jorel.commandapi.kotlindsl.*
44
import dev.slne.surf.essentials.service.worldService
55
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
6+
import dev.slne.surf.essentials.util.util.isFolia
67
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
8+
import org.bukkit.Bukkit
79
import org.bukkit.World
810

911
fun worldCommand() = commandTree("world") {
@@ -15,6 +17,14 @@ fun worldCommand() = commandTree("world") {
1517
anyExecutor { executor, args ->
1618
val world: World by args
1719

20+
if (Bukkit.getServer().isFolia()) {
21+
executor.sendText {
22+
appendPrefix()
23+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
24+
}
25+
return@anyExecutor
26+
}
27+
1828
if (worldService.isLocked(world)) {
1929
executor.sendText {
2030
appendPrefix()
@@ -40,6 +50,14 @@ fun worldCommand() = commandTree("world") {
4050
anyExecutor { executor, args ->
4151
val world: World by args
4252

53+
if (Bukkit.getServer().isFolia()) {
54+
executor.sendText {
55+
appendPrefix()
56+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
57+
}
58+
return@anyExecutor
59+
}
60+
4361
if (!worldService.isLocked(world)) {
4462
executor.sendText {
4563
appendPrefix()
@@ -65,12 +83,20 @@ fun worldCommand() = commandTree("world") {
6583
playerExecutor { player, args ->
6684
val world: World by args
6785

68-
player.teleport(world.spawnLocation)
6986
player.sendText {
7087
appendPrefix()
71-
success("Du wurdest in die Welt ")
88+
info("Du wirst in die Welt ")
7289
variableValue(world.name)
73-
success(" teleportiert.")
90+
info(" teleportiert...")
91+
}
92+
93+
player.teleportAsync(world.spawnLocation).thenRun {
94+
player.sendText {
95+
appendPrefix()
96+
success("Du wurdest in die Welt ")
97+
variableValue(world.name)
98+
success(" teleportiert.")
99+
}
74100
}
75101
}
76102
}
@@ -81,6 +107,15 @@ fun worldCommand() = commandTree("world") {
81107
withPermission(EssentialsPermissionRegistry.WORLD_COMMAND_CREATE)
82108
anyExecutor { executor, args ->
83109
val name: String by args
110+
111+
if (Bukkit.getServer().isFolia()) {
112+
executor.sendText {
113+
appendPrefix()
114+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
115+
}
116+
return@anyExecutor
117+
}
118+
84119
worldService.create(executor, name, null, null, null, null, null)
85120
}
86121
}
@@ -91,6 +126,15 @@ fun worldCommand() = commandTree("world") {
91126
withPermission(EssentialsPermissionRegistry.WORLD_COMMAND_DELETE)
92127
anyExecutor { executor, args ->
93128
val world: World by args
129+
130+
if (Bukkit.getServer().isFolia()) {
131+
executor.sendText {
132+
appendPrefix()
133+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
134+
}
135+
return@anyExecutor
136+
}
137+
94138
worldService.delete(executor, world)
95139
}
96140
}
@@ -101,6 +145,16 @@ fun worldCommand() = commandTree("world") {
101145
withPermission(EssentialsPermissionRegistry.WORLD_COMMAND_LOAD)
102146
anyExecutor { executor, args ->
103147
val name: String by args
148+
149+
if (Bukkit.getServer().isFolia()) {
150+
executor.sendText {
151+
appendPrefix()
152+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
153+
}
154+
return@anyExecutor
155+
}
156+
157+
104158
worldService.load(executor, name)
105159
}
106160
}
@@ -111,6 +165,15 @@ fun worldCommand() = commandTree("world") {
111165
withPermission(EssentialsPermissionRegistry.WORLD_COMMAND_UNLOAD)
112166
anyExecutor { executor, args ->
113167
val world: World by args
168+
169+
if (Bukkit.getServer().isFolia()) {
170+
executor.sendText {
171+
appendPrefix()
172+
error("Dieser Befehl wird auf Folia-Servern nicht unterstützt.")
173+
}
174+
return@anyExecutor
175+
}
176+
114177
worldService.unload(executor, world)
115178
}
116179
}
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
package dev.slne.surf.essentials.listener
22

3+
import dev.slne.surf.essentials.service.worldService
34
import dev.slne.surf.essentials.util.permission.EssentialsPermissionRegistry
5+
import dev.slne.surf.surfapi.bukkit.api.event.cancel
46
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
5-
import org.bukkit.entity.Player
7+
import org.bukkit.World
68
import org.bukkit.event.EventHandler
79
import org.bukkit.event.Listener
8-
import org.bukkit.event.entity.EntityPortalEnterEvent
10+
import org.bukkit.event.player.PlayerPortalEvent
911

1012
object WorldListener : Listener {
1113
@EventHandler
12-
fun onEntityPortalEnter(event: EntityPortalEnterEvent) {
13-
val entity = event.entity
14-
val portal = event.portalType
14+
fun onPortal(event: PlayerPortalEvent) {
15+
val player = event.player
16+
val world = event.to.world
1517

16-
(entity as? Player)?.let {
17-
if (it.hasPermission(EssentialsPermissionRegistry.WORLD_BYPASS)) {
18-
it.sendText {
18+
if (worldService.isLocked(world)) {
19+
if (!player.hasPermission(EssentialsPermissionRegistry.WORLD_BYPASS)) {
20+
event.cancel()
21+
player.sendText {
1922
appendPrefix()
20-
success("")
23+
24+
when (world.environment) {
25+
World.Environment.NETHER -> error("Der Nether ist zurzeit deaktiviert.")
26+
World.Environment.THE_END -> error("Das End ist zurzeit deaktiviert.")
27+
else -> error("Du kannst dieses Portal nicht benutzen!")
28+
}
29+
}
30+
} else {
31+
player.sendText {
32+
appendPrefix()
33+
success("Du hast die Portal-Sperre umgangen.")
2134
}
22-
return
2335
}
2436
}
25-
26-
portal
2737
}
2838
}

0 commit comments

Comments
 (0)