Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/basics-top/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| Command | Permission |
|-----------------|-------------------|
| `/top` | basics.top |
| `/top <player>` | basics.top.others |
3 changes: 3 additions & 0 deletions modules/basics-top/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("basics.module")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.github.spigotbasics.modules.basicstop

import com.github.spigotbasics.core.Spiper
import com.github.spigotbasics.core.command.parsed.CommandContextExecutor
import com.github.spigotbasics.core.command.parsed.arguments.SelectorSinglePlayerArg
import com.github.spigotbasics.core.command.parsed.context.MapContext
import com.github.spigotbasics.core.module.AbstractBasicsModule
import com.github.spigotbasics.core.module.loader.ModuleInstantiationContext
import com.github.spigotbasics.core.util.TeleportUtils
import org.bukkit.World
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause

class BasicsTopModule(context: ModuleInstantiationContext) : AbstractBasicsModule(context) {
private val permission =
permissionManager.createSimplePermission(
"basics.top",
"Allows the player to teleport to the highest block above them",
)
private val permissionOthers =
permissionManager.createSimplePermission(
"basics.top.others",
"Allows the player to teleport other players to the highest block above them",
)

private val msgTop
get() = messages.getMessage("top")

private fun msgTopOthers(player: Player) = messages.getMessage("top-others").concerns(player)

override fun onEnable() {
commandFactory.parsedCommandBuilder("top", permission).mapContext {
usage = "[player]"
description("Teleports to the highest block at your position")

path {
playerOnly()
}

path {
permissions(permissionOthers)
arguments {
named("player", SelectorSinglePlayerArg("player"))
}
}
}.executor(
object : CommandContextExecutor<MapContext> {
override fun execute(
sender: CommandSender,
context: MapContext,
) {
val target = context["player"] as Player? ?: sender as Player
val location = target.location
val block = target.world.getHighestBlockAt(location)
// The highest block in the nether is the bedrock roof
if (target.world.environment == World.Environment.NETHER || !TeleportUtils.isSafeToStandOn(block.type)) {
coreMessages.noSafeLocationFound.sendToSender(sender)
return
}

val destination = block.location.add(0.5, 1.0, 0.5).setDirection(location.direction)
Spiper.teleportAsync(target, destination, TeleportCause.COMMAND)
(if (sender == target) msgTop else msgTopOthers(target)).sendToSender(sender)
}
},
).register()
}
}
3 changes: 3 additions & 0 deletions modules/basics-top/src/main/resources/basics-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
main-class: com.github.spigotbasics.modules.basicstop.BasicsTopModule
name: basics-top
version: ${moduleVersion}
2 changes: 2 additions & 0 deletions modules/basics-top/src/main/resources/messages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
top: "<def_text>Teleported to the <lite_text>top</lite_text>!</def_text>"
top-others: "<def_text>Teleported <player-dm> to the <lite_text>top</lite_text>!</def_text>"
Loading