Skip to content

Commit e975973

Browse files
committed
SetSpawnCommand.kt cleanup.
Signed-off-by: Pavel Erokhin (MairwunNx) <[email protected]>
1 parent adb8817 commit e975973

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/spawn/commands/SetSpawnCommand.kt

+14-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.mairwunnx.projectessentials.spawn.commands
22

3+
import com.mairwunnx.projectessentials.cooldown.essentials.CommandsAliases
4+
import com.mairwunnx.projectessentials.core.extensions.isPlayerSender
5+
import com.mairwunnx.projectessentials.core.extensions.sendMsg
6+
import com.mairwunnx.projectessentials.core.helpers.ONLY_PLAYER_CAN
7+
import com.mairwunnx.projectessentials.core.helpers.PERMISSION_LEVEL
8+
import com.mairwunnx.projectessentials.spawn.EntryPoint
9+
import com.mairwunnx.projectessentials.spawn.EntryPoint.Companion.hasPermission
310
import com.mairwunnx.projectessentials.spawn.models.SpawnModelBase
4-
import com.mairwunnx.projectessentialscooldown.essentials.CommandsAliases
5-
import com.mairwunnx.projectessentialscore.extensions.isPlayerSender
6-
import com.mairwunnx.projectessentialscore.extensions.sendMsg
7-
import com.mairwunnx.projectessentialscore.helpers.ONLY_PLAYER_CAN
8-
import com.mairwunnx.projectessentialscore.helpers.PERMISSION_LEVEL
9-
import com.mairwunnx.projectessentialspermissions.permissions.PermissionsAPI
1011
import com.mojang.brigadier.CommandDispatcher
1112
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
1213
import com.mojang.brigadier.context.CommandContext
@@ -21,33 +22,25 @@ object SetSpawnCommand {
2122
private val logger = LogManager.getLogger()
2223

2324
fun register(dispatcher: CommandDispatcher<CommandSource>) {
24-
logger.info(" - register \"/setspawn\" command ...")
25+
logger.info("Register \"/setspawn\" command")
26+
applyCommandAliases()
27+
2528
aliases.forEach { command ->
2629
dispatcher.register(
27-
literal<CommandSource>(command).executes {
28-
return@executes execute(it)
29-
}
30+
literal<CommandSource>(command).executes(::execute)
3031
)
3132
}
32-
applyCommandAliases()
3333
}
3434

3535
private fun applyCommandAliases() {
36-
try {
37-
Class.forName(
38-
"com.mairwunnx.projectessentialscooldown.essentials.CommandsAliases"
39-
)
40-
CommandsAliases.aliases["setspawn"] = aliases.toMutableList()
41-
logger.info(" - applying aliases: $aliases")
42-
} catch (_: ClassNotFoundException) {
43-
// ignored
44-
}
36+
if (!EntryPoint.cooldownsInstalled) return
37+
CommandsAliases.aliases["setspawn"] = aliases.toMutableList()
4538
}
4639

4740
private fun execute(c: CommandContext<CommandSource>): Int {
4841
if (c.isPlayerSender()) {
4942
val player = c.source.asPlayer()
50-
if (PermissionsAPI.hasPermission(player.name.string, "ess.spawn.set")) {
43+
if (hasPermission(player, "ess.spawn.set")) {
5144
SpawnModelBase.spawnModel.xPos = player.posX
5245
SpawnModelBase.spawnModel.yPos = player.posY
5346
SpawnModelBase.spawnModel.zPos = player.posZ

0 commit comments

Comments
 (0)