Skip to content

Commit 27ac4e7

Browse files
committed
Limitations checking added.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 993b1e4 commit 27ac4e7

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/home/commands/SetHomeCommand.kt

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import com.mairwunnx.projectessentials.core.api.v1.extensions.currentDimensionId
77
import com.mairwunnx.projectessentials.core.api.v1.extensions.getPlayer
88
import com.mairwunnx.projectessentials.core.api.v1.messaging.MessagingAPI
99
import com.mairwunnx.projectessentials.core.api.v1.messaging.ServerMessagingAPI
10+
import com.mairwunnx.projectessentials.core.api.v1.permissions.hasPermission
1011
import com.mairwunnx.projectessentials.home.configurations.HomeConfigurationModel
1112
import com.mairwunnx.projectessentials.home.helpers.validateAndExecute
1213
import com.mairwunnx.projectessentials.home.homeConfiguration
14+
import com.mairwunnx.projectessentials.home.homeSettingsConfiguration
1315
import com.mojang.brigadier.context.CommandContext
1416
import net.minecraft.command.CommandSource
17+
import net.minecraft.entity.player.ServerPlayerEntity
1518

1619
object SetHomeCommand : CommandBase(setHomeLiteral, false) {
1720
override val name = "set-home"
@@ -36,15 +39,17 @@ object SetHomeCommand : CommandBase(setHomeLiteral, false) {
3639
player.rotationYaw, player.rotationPitch
3740
).also { out("success", name).also { super.process(context) } }
3841

39-
user?.homes?.add(fromUser()) ?: run {
40-
homeConfiguration.users.add(
41-
HomeConfigurationModel.User(
42-
player.name.string,
43-
player.uniqueID.toString(),
44-
mutableListOf(fromUser())
42+
if (!hasLimitations(player, user)) {
43+
user?.homes?.add(fromUser()) ?: run {
44+
homeConfiguration.users.add(
45+
HomeConfigurationModel.User(
46+
player.name.string,
47+
player.uniqueID.toString(),
48+
mutableListOf(fromUser())
49+
)
4550
)
46-
)
47-
}
51+
}
52+
} else out("limit")
4853
}
4954

5055
homeConfiguration.users.asSequence().find {
@@ -57,4 +62,20 @@ object SetHomeCommand : CommandBase(setHomeLiteral, false) {
5762
}
5863
}
5964
}
65+
66+
private fun hasLimitations(
67+
player: ServerPlayerEntity,
68+
user: HomeConfigurationModel.User?
69+
): Boolean {
70+
if (hasPermission(player, "ess.home.limit.except", 4)) return false
71+
var allowed = 1
72+
homeSettingsConfiguration.homeLimitations.also { map ->
73+
homeSettingsConfiguration.homeLimitations.keys.asSequence().forEach {
74+
if (hasPermission(player, "ess.home.limit.$it", 0)) {
75+
if (allowed < map.getValue(it)) allowed = map.getValue(it)
76+
}
77+
}
78+
}
79+
return if (user == null) false else user.homes.count() >= allowed
80+
}
6081
}

0 commit comments

Comments
 (0)