Skip to content

Commit

Permalink
feat: add fly/walkspeed/speed/flyspeed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Dec 11, 2023
1 parent 0472eb3 commit a351ad8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ExtraCommandExecutor : IdofrontCommandExecutor(), TabCompleter {
suicideCommand()
itemRenameCommand()
afkCommand()
movementCommands()

mineInAbyssCommands()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ class ExtraCommands : JavaPlugin() {
override fun onEnable() {
createExtraCommandsContext()
ExtraCommandExecutor()

ExtraPlaceholders().register()
}

fun createExtraCommandsContext() {
DI.remove<ExtraCommandContext>()
DI.add<ExtraCommandContext>(object : ExtraCommandContext {
override val plugin = this@ExtraCommands
override val config = ExtraConfig()
})
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mineinabyss.extracommands

import com.mineinabyss.extracommands.commands.AfkPlayer
import com.mineinabyss.geary.papermc.tracking.entities.toGeary
import me.clip.placeholderapi.expansion.PlaceholderExpansion
import org.bukkit.entity.Player
import kotlin.time.toKotlinDuration

class Placeholders : PlaceholderExpansion() {
class ExtraPlaceholders : PlaceholderExpansion() {

override fun getIdentifier() = "extracommands"

Expand All @@ -14,7 +16,7 @@ class Placeholders : PlaceholderExpansion() {

override fun onPlaceholderRequest(player: Player, identifier: String) =
when (identifier) {
"afk" -> extraCommands.config.afk.takeIf { afk -> player.idleDuration.toKotlinDuration() >= afk.idleTime }?.text ?: ""
"afk" -> extraCommands.config.afk.takeIf { afk -> player.idleDuration.toKotlinDuration() >= afk.idleTime || player.toGeary().has<AfkPlayer>() }?.text ?: ""
else -> null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.mineinabyss.extracommands.commands

import com.mineinabyss.idofront.commands.arguments.genericArg
import com.mineinabyss.idofront.commands.entrypoint.CommandDSLEntrypoint
import com.mineinabyss.idofront.commands.extensions.actions.playerAction
import com.mineinabyss.idofront.messaging.error
import com.mineinabyss.idofront.messaging.success

fun CommandDSLEntrypoint.movementCommands() {
command("flyspeed") {
val speed: Double by genericArg(parseFunction = { it.takeIf { it != "reset" && (it.toDouble() in 0.0..1.0) }?.toDoubleOrNull() ?: 0.1 })
playerAction {
player.flySpeed = speed.toFloat()
}
}
command("fly") {
playerAction {
when (player.allowFlight) {
true -> {
player.allowFlight = false
player.fallDistance = 0f
player.flySpeed = 0.1f
player.error(if (sender == player) "Flight is now disabled!" else "Flight disabled for ${player.name}")
}
false -> {
val defaultSpeed = 1.0f
player.allowFlight = true
player.flySpeed = defaultSpeed
player.success(if (player == sender) "Flight is now enabled!" else "Flight enabled for ${player.name}")
}
}
player.allowFlight = !player.allowFlight
player.flySpeed = 0.1f
}
}
command("walkspeed") {
val speed: Double by genericArg(parseFunction = { it.takeIf { it != "reset" && (it.toDouble() in 0.0..1.0) }?.toDoubleOrNull() ?: 0.2 })
playerAction {
player.walkSpeed = speed.toFloat()
}
}
command("speed") {
val speed: Double? by genericArg(parseFunction = { it.takeIf { it != "reset" && (it.toDouble() in 0.0..1.0) }?.toDoubleOrNull() })
playerAction {
when (player.isFlying) {
true -> player.flySpeed = speed?.toFloat() ?: 0.1f
false -> player.walkSpeed = speed?.toFloat() ?: 0.2f
}
player.success("${if (player.isFlying) "Flyspeed" else "Walkspeed"} set to $speed${if (player == sender) "" else " for ${player.name}"}")
}
}
}

0 comments on commit a351ad8

Please sign in to comment.