Skip to content

Commit

Permalink
Add '/hud turn off/on <player>'
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 5, 2024
1 parent ab6b58d commit 11a6a2e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
42 changes: 22 additions & 20 deletions bootstrap/bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,44 @@ softdepend:
- Nexo
- Oraxen
permissions:
hud.help:
betterhud.help:
description: Access to help command.
default: op
hud.reload:
betterhud.reload:
description: Access to reload command.
default: op
hud.hud:
betterhud.hud:
description: Access to hud command.
default: op
children:
hud.hud.add: true
hud.hud.remove: true
hud.compass:
betterhud.hud.add: true
betterhud.hud.remove: true
betterhud.compass:
description: Access to compass command.
default: op
children:
hud.compass.add: true
hud.compass.remove: true
hud.turn:
betterhud.compass.add: true
betterhud.compass.remove: true
betterhud.turn:
description: Access to turn command.
default: op
children:
hud.turn.on: true
hud.turn.off: true
hud.pointer:
betterhud.turn.on: true
betterhud.turn.off: true
betterhud.turn.on.admin: true
betterhud.turn.off.admin: true
betterhud.pointer:
description: Access to pointer command.
default: op
children:
hud.pointer.set: true
hud.pointer.clear: true
hud.pointer.remove: true
hud.popup:
betterhud.pointer.set: true
betterhud.pointer.clear: true
betterhud.pointer.remove: true
betterhud.popup:
description: Access to popup command.
default: op
children:
hud.popup.add: true
hud.popup.remove: true
hud.popup.show: true
hud.popup.hide: true
betterhud.popup.add: true
betterhud.popup.remove: true
betterhud.popup.show: true
betterhud.popup.hide: true
26 changes: 18 additions & 8 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/CommandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import kr.toxicity.command.BetterCommandSource
import kr.toxicity.command.impl.ClassSerializer
import kr.toxicity.command.CommandListener
import kr.toxicity.command.impl.CommandMessage
import kr.toxicity.command.SenderType
import kr.toxicity.command.impl.annotation.Aliases
import kr.toxicity.command.impl.annotation.Command
import kr.toxicity.command.impl.annotation.Description
import kr.toxicity.command.impl.annotation.Option
import kr.toxicity.command.impl.annotation.Permission
import kr.toxicity.command.impl.annotation.Sender
import kr.toxicity.command.impl.annotation.Source
import kr.toxicity.hud.api.adapter.LocationWrapper
import kr.toxicity.hud.api.adapter.WorldWrapper
Expand Down Expand Up @@ -420,25 +418,37 @@ object CommandManager : BetterHudManager {
.permission("hud.turn")
.executes(object : CommandListener {
//Turn on
private val on_no_target = library.registerKey(CommandMessage("betterhud.turn.on.message.no_target", Component.text("No target player provided.")))
private val on_success = library.registerKey(CommandMessage("betterhud.turn.on.message.success", Component.text("Successfully turned the HUD on.")))
@Command
@Description(key = "betterhud.turn.on.description", defaultValue = "Turns on your HUD.")
@Permission("hud.turn.on")
@Sender(type = [SenderType.PLAYER])
fun on(@Source me: HudPlayer) {
me.isHudEnabled = true
fun on(@Source me: BetterCommandSource, @Option target: HudPlayerStack?) {
when {
target != null && me.hasPermission("betterhud.turn.on.admin") -> target.forEach { p ->
p.isHudEnabled = true
}
me is HudPlayer -> me.isHudEnabled = true
else -> return on_no_target.send(me)
}
on_success.send(me)
}
//Turn on

//Turn off
private val off_no_target = library.registerKey(CommandMessage("betterhud.turn.off.message.no_target", Component.text("No target player provided.")))
private val off_success = library.registerKey(CommandMessage("betterhud.turn.off.message.success", Component.text("Successfully turned the HUD off.")))
@Command
@Description(key = "betterhud.turn.off.description", defaultValue = "Turns off your HUD.")
@Permission("hud.turn.off")
@Sender(type = [SenderType.PLAYER])
fun off(@Source me: HudPlayer) {
me.isHudEnabled = false
fun off(@Source me: BetterCommandSource, @Option target: HudPlayerStack?) {
when {
target != null && me.hasPermission("betterhud.turn.off.admin") -> target.forEach { p ->
p.isHudEnabled = false
}
me is HudPlayer -> me.isHudEnabled = false
else -> return off_no_target.send(me)
}
off_success.send(me)
}
//Turn off
Expand Down

0 comments on commit 11a6a2e

Please sign in to comment.