Skip to content

Commit 0720ca4

Browse files
committed
Add DimensionTravel command
1 parent 39b5821 commit 0720ca4

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/EssentialCommandsModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object EssentialCommandsModule: BukkitModule<BaseModuleConfiguration, EssentialC
1010

1111
init {
1212
listOf(
13-
ClientLocale, Heal, Ip, IpGroup, Ping, PlayerChunkTickets, TpChunk
13+
ClientLocale, DimensionTravel, Heal, Ip, IpGroup, Ping, PlayerChunkTickets, TpChunk
1414
).forEach { cmd -> registerFeature(cmd) }
1515
}
1616

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package io.github.rothes.esu.bukkit.module.essencialcommands
2+
3+
import io.github.rothes.esu.bukkit.user.PlayerUser
4+
import io.github.rothes.esu.bukkit.util.ComponentBukkitUtils.player
5+
import io.github.rothes.esu.bukkit.util.ServerCompatibility.tp
6+
import io.github.rothes.esu.bukkit.util.WorldUtils
7+
import io.github.rothes.esu.core.command.annotation.ShortPerm
8+
import io.github.rothes.esu.core.configuration.data.MessageData
9+
import io.github.rothes.esu.core.configuration.data.MessageData.Companion.message
10+
import io.github.rothes.esu.core.module.configuration.FeatureToggle
11+
import io.github.rothes.esu.core.user.User
12+
import io.github.rothes.esu.core.util.extension.math.floorI
13+
import org.bukkit.Bukkit
14+
import org.bukkit.Location
15+
import org.bukkit.World
16+
import org.bukkit.entity.Player
17+
import org.incendo.cloud.annotations.Command
18+
19+
object DimensionTravel : BaseCommand<FeatureToggle.DefaultTrue, DimensionTravel.Lang>() {
20+
21+
override fun onEnable() {
22+
registerCommands(object {
23+
@Command("dimensionTravel")
24+
@ShortPerm
25+
suspend fun dimensionTravel(sender: User) {
26+
val user = sender as PlayerUser
27+
dimensionTravel(sender, user.player)
28+
}
29+
30+
@Command("dimensionTravel <player>")
31+
@ShortPerm("others")
32+
suspend fun dimensionTravel(sender: User, player: Player) {
33+
val world = player.world
34+
val loc = when (world.environment) {
35+
World.Environment.NORMAL -> {
36+
val world = Bukkit.getWorld("world_nether")
37+
val x = player.location.x / 8
38+
val z = player.location.z / 8
39+
Location(world, x, 0.0, z)
40+
}
41+
World.Environment.NETHER -> {
42+
val world = Bukkit.getWorld("world")
43+
val x = player.location.x.floorI() shl 3
44+
val z = player.location.z.floorI() shl 3
45+
Location(world, x.toDouble(), 0.0, z.toDouble())
46+
}
47+
World.Environment.THE_END -> {
48+
sender.message(lang, { unsupportedTheEnd })
49+
return
50+
}
51+
else -> error("Unsupported world environment ${world.environment}")
52+
}
53+
val safeSpot = WorldUtils.findSafeSpot(loc) ?: return sender.message(module.lang, { unsafeTeleportSpot })
54+
player.tp(safeSpot)
55+
sender.message(module.lang, { teleportingPlayer }, player(player))
56+
}
57+
})
58+
}
59+
60+
data class Lang(
61+
val unsupportedTheEnd: MessageData = "<ec>Dimension travel is not possible from the end.".message,
62+
val teleporting: MessageData = "<ec>Teleporting <tdc><player></tdc>....".message,
63+
)
64+
}

0 commit comments

Comments
 (0)