Skip to content

Commit f6a5462

Browse files
committed
Checking on home existing added.
Override existing argument added. Signed-off-by: Pavel Erokhin (MairwunNx) <[email protected]>
1 parent 86bd30e commit f6a5462

File tree

1 file changed

+24
-2
lines changed
  • src/main/kotlin/com/mairwunnx/projectessentials/projectessentialshome/commands

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.mairwunnx.projectessentials.projectessentialshome.EntryPoint.Companio
1010
import com.mairwunnx.projectessentials.projectessentialshome.models.HomeModel
1111
import com.mairwunnx.projectessentials.projectessentialshome.storage.StorageBase
1212
import com.mojang.brigadier.CommandDispatcher
13+
import com.mojang.brigadier.arguments.BoolArgumentType
1314
import com.mojang.brigadier.arguments.StringArgumentType
1415
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
1516
import com.mojang.brigadier.context.CommandContext
@@ -34,7 +35,15 @@ object SetHomeCommand {
3435
"home name", StringArgumentType.string()
3536
).executes {
3637
return@executes execute(it)
37-
}
38+
}.then(
39+
Commands.argument(
40+
"override", BoolArgumentType.bool()
41+
).executes {
42+
return@executes execute(
43+
it, BoolArgumentType.getBool(it, "override")
44+
)
45+
}
46+
)
3847
)
3948
)
4049
}
@@ -45,7 +54,10 @@ object SetHomeCommand {
4554
CommandsAliases.aliases["sethome"] = aliases.toMutableList()
4655
}
4756

48-
private fun execute(c: CommandContext<CommandSource>): Int {
57+
private fun execute(
58+
c: CommandContext<CommandSource>,
59+
override: Boolean = false
60+
): Int {
4961
if (c.isPlayerSender()) {
5062
val player = c.source.asPlayer()
5163
if (hasPermission(player, "ess.home.set")) {
@@ -63,6 +75,16 @@ object SetHomeCommand {
6375
val yaw = player.rotationYaw
6476
val pitch = player.rotationPitch
6577
val homeModel = StorageBase.getData(playerUUID).homes
78+
79+
if (!override) {
80+
homeModel.forEach {
81+
if (it.home == homeName) {
82+
sendMsg("home", c.source, "home.set.already_exist", homeName)
83+
return 0
84+
}
85+
}
86+
}
87+
6688
homeModel.add(
6789
HomeModel.Home(
6890
homeName, clientWorld, worldId, xPos, yPos, zPos, yaw, pitch

0 commit comments

Comments
 (0)