Skip to content

Commit b95a73c

Browse files
committed
validateAndExecute added to Helpers.kt.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 258e3db commit b95a73c

File tree

1 file changed

+23
-0
lines changed
  • src/main/kotlin/com/mairwunnx/projectessentials/spawn/helpers

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.mairwunnx.projectessentials.spawn.helpers
2+
3+
import com.mairwunnx.projectessentials.core.api.v1.MESSAGE_MODULE_PREFIX
4+
import com.mairwunnx.projectessentials.core.api.v1.extensions.getPlayer
5+
import com.mairwunnx.projectessentials.core.api.v1.messaging.MessagingAPI
6+
import com.mairwunnx.projectessentials.core.api.v1.permissions.hasPermission
7+
import com.mojang.brigadier.context.CommandContext
8+
import net.minecraft.command.CommandSource
9+
10+
inline fun validateAndExecute(
11+
context: CommandContext<CommandSource>,
12+
node: String,
13+
opLevel: Int,
14+
crossinline action: (isServer: Boolean) -> Unit
15+
) = context.getPlayer()?.let {
16+
if (hasPermission(it, node, opLevel)) {
17+
action(false)
18+
} else {
19+
MessagingAPI.sendMessage(
20+
context.getPlayer()!!, "${MESSAGE_MODULE_PREFIX}spawn.restricted"
21+
)
22+
}
23+
} ?: run { action(true) }

0 commit comments

Comments
 (0)