Skip to content

Commit 35bccca

Browse files
committed
Home command literal added.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 51684eb commit 35bccca

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.mairwunnx.projectessentials.home.commands
2+
3+
import com.mairwunnx.projectessentials.core.api.v1.configuration.ConfigurationAPI.getConfigurationByName
4+
import com.mairwunnx.projectessentials.core.api.v1.extensions.getPlayer
5+
import com.mairwunnx.projectessentials.core.api.v1.extensions.isPlayerSender
6+
import com.mairwunnx.projectessentials.home.configurations.HomeConfiguration
7+
import com.mojang.brigadier.arguments.StringArgumentType
8+
import com.mojang.brigadier.builder.LiteralArgumentBuilder
9+
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
10+
import net.minecraft.command.CommandSource
11+
import net.minecraft.command.Commands
12+
import net.minecraft.command.ISuggestionProvider
13+
14+
val homeLiteral: LiteralArgumentBuilder<CommandSource> =
15+
literal<CommandSource>("home").then(
16+
Commands.argument(
17+
"home", StringArgumentType.string()
18+
).suggests { ctx, builder ->
19+
ISuggestionProvider.suggest(
20+
getConfigurationByName<HomeConfiguration>(
21+
"home"
22+
).take().let { model ->
23+
if (ctx.isPlayerSender()) {
24+
model.users.asSequence().find {
25+
it.name == ctx.getPlayer()!!.name.string || it.uuid == ctx.getPlayer()!!.uniqueID.toString()
26+
}?.homes?.asSequence()?.map { it.home }?.toList() ?: emptyList<String>()
27+
} else emptyList<String>()
28+
}, builder
29+
)
30+
}
31+
)

0 commit comments

Comments
 (0)