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
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,34 @@ import org.bukkit.command.CommandSender

class GameModeArgument(nodeName: String) :
CustomArgument<GameMode, String>(StringArgument(nodeName), { info ->
getGameMode(info.input.lowercase())
val gameMode = getGameMode(info.input.lowercase())
?: throw CustomArgumentException.fromAdventureComponent {
buildText {
appendErrorPrefix()
error("Der Spielmodus wurde nicht gefunden.")
}
}

val permission = "surf.essentials.gameMode.${gameMode.name.lowercase()}"
val sender = info.sender

if (!sender.hasPermission(permission)) {
throw CustomArgumentException.fromAdventureComponent {
Comment thread
TheBjoRedCraft marked this conversation as resolved.
buildText {
appendErrorPrefix()
error("Dazu hast du keine Berechtigung.")
}
}
}

gameMode
}) {
init {
this.replaceSuggestions(
ArgumentSuggestions.stringCollection<CommandSender> {
GameMode.entries.map {
it.name.lowercase()
}
ArgumentSuggestions.stringCollection<CommandSender> { sender ->
GameMode.entries
.filter { sender.sender.hasPermission("surf.essentials.gameMode.${it.name.lowercase()}") }
Comment thread
TheBjoRedCraft marked this conversation as resolved.
.map { it.name.lowercase() }
}
)
}
Expand Down Expand Up @@ -52,4 +66,4 @@ inline fun CommandTree.gameModeArgument(
block: Argument<*>.() -> Unit = {}
): CommandTree = then(
GameModeArgument(nodeName).setOptional(optional).apply(block)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ object EssentialsPermissionRegistry : PermissionRegistry() {
val FLY_COMMAND_OTHERS = create("$PREFIX.fly.command.others")
val GAME_MODE_SWITCHER = create("$PREFIX.gameMode.gameModeSwitcher")
val GAME_MODE_COMMAND = create("$PREFIX.gameMode.command")
val GAME_MODE_CREATIVE = create("$PREFIX.gameMode.creative")
val GAME_MODE_SURVIVAL = create("$PREFIX.gameMode.survival")
val GAME_MODE_ADVENTURE = create("$PREFIX.gameMode.adventure")
val GAME_MODE_SPECTATOR = create("$PREFIX.gameMode.spectator")
val GAME_MODE_COMMAND_OTHERS = create("$PREFIX.gameMode.command.others")
val GAME_MODE_COMMAND_OFFLINE = create("$PREFIX.gameMode.command.offline")
val GAME_MODE_COMMAND_DEFAULT = create("$PREFIX.gamemode.command.default")
Comment thread
TheBjoRedCraft marked this conversation as resolved.
Expand Down