Skip to content

Commit

Permalink
Adds turn on/off command.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Mar 19, 2024
1 parent ac207d7 commit 34b8c50
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/src/main/java/kr/toxicity/hud/api/player/HudPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface HudPlayer {
@NotNull WidthComponent getHudComponent();
void setAdditionalComponent(@Nullable WidthComponent component);
@Nullable WidthComponent getAdditionalComponent();
boolean isHudEnabled();
void setHudEnabled(boolean toEnable);
long getTick();
void cancel();
void update();
Expand Down
30 changes: 30 additions & 0 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/CommandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package kr.toxicity.hud.manager
import kr.toxicity.hud.api.plugin.ReloadState
import kr.toxicity.hud.api.update.UpdateEvent
import kr.toxicity.hud.command.CommandModule
import kr.toxicity.hud.command.SenderType
import kr.toxicity.hud.resource.GlobalResource
import kr.toxicity.hud.util.*
import org.bukkit.Bukkit
import org.bukkit.entity.Player

object CommandManager: BetterHudManager {

Expand Down Expand Up @@ -216,6 +218,34 @@ object CommandManager: BetterHudManager {
}
}
}
.addCommandModule("turn", {
aliases = listOf("t")
permission = listOf("$NAME_SPACE.turn")
allowedSender = listOf(SenderType.PLAYER)
}) {
addCommand("on") {
description = "Turns on your hud.".toComponent()
usage = "off".toComponent()
permission = listOf("$NAME_SPACE.turn.on")
executer = { sender, _ ->
PlayerManager.getHudPlayer((sender as Player).uniqueId)?.let {
it.isHudEnabled = true
sender.info("Successfully turns on.")
} ?: sender.warn("You are not available player!")
}
}
addCommand("off") {
description = "Turns off your hud.".toComponent()
usage = "off".toComponent()
permission = listOf("$NAME_SPACE.turn.off")
executer = { sender, _ ->
PlayerManager.getHudPlayer((sender as Player).uniqueId)?.let {
it.isHudEnabled = false
sender.info("Successfully turns off.")
} ?: sender.warn("You are not available player!")
}
}
}

override fun start() {
PLUGIN.getCommand(NAME_SPACE)?.setExecutor(command.createTabExecutor())
Expand Down
7 changes: 6 additions & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/player/HudPlayerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class HudPlayerImpl(
private val popupGroup = ConcurrentHashMap<String, PopupIteratorGroup>()
private var task: HudTask? = null
private var color: BarColor? = null
private var enabled = true
private val autoSave = asyncTaskTimer(6000, 6000) {
save()
}
Expand Down Expand Up @@ -76,6 +77,10 @@ class HudPlayerImpl(
override fun getBukkitPlayer(): Player = player
override fun getVariableMap(): MutableMap<String, String> = variable
override fun getHead(): HudPlayerHead = h
override fun isHudEnabled(): Boolean = enabled
override fun setHudEnabled(toEnable: Boolean) {
enabled = toEnable
}
override fun save() {
DatabaseManagerImpl.currentDatabase.save(this)
}
Expand All @@ -85,7 +90,7 @@ class HudPlayerImpl(
tick++
val compList = ArrayList<WidthComponent>()

if (!PLUGIN.isOnReload) {
if (enabled && !PLUGIN.isOnReload) {
popups.removeIf {
runCatching {
it.show(UpdateEvent.EMPTY, this)
Expand Down
6 changes: 6 additions & 0 deletions dist/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ permissions:
children:
hud.hud.add: true
hud.hud.remove: true
hud.turn:
description: Access to turn command.
default: op
children:
hud.turn.on: true
hud.turn.off: true
hud.popup:
description: Access to popup command.
default: op
Expand Down

0 comments on commit 34b8c50

Please sign in to comment.