EAA_MOD/src/main/java/net/saltymc/eaa/commands/TagCommand.java

52 lines
2.4 KiB
Java

package net.saltymc.eaa.commands;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.argument.EntityArgumentType;
import net.saltymc.eaa.function.TagFunction;
import net.saltymc.eaa.util.database.DB_Tag;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal;
public class TagCommand extends EaaModCommand{
@Override
public int run(CommandContext<FabricClientCommandSource> context) {
FabricClientCommandSource source = context.getSource();
String player = StringArgumentType.getString(context,"player");
DB_Tag.Type tag = DB_Tag.Type.valueOf(StringArgumentType.getString(context,"tag"));
int grade = IntegerArgumentType.getInteger(context, "grade");
// does the magic
TagFunction.tagPlayer(player, tag, grade, source);
return 1;
}
@Override
public LiteralArgumentBuilder<FabricClientCommandSource> getCommandSpecification() {
return literal("/tag")
.then(
argument("player", StringArgumentType.word())
.suggests((ctx, builder) -> EntityArgumentType.player().listSuggestions(ctx, builder))
.then(
argument("tag", StringArgumentType.word())
.suggests(((context, builder) -> {
for (DB_Tag.Type tag : DB_Tag.Type.values())
builder.suggest(tag.name());
return builder.buildFuture();
}))
.then(
argument("grade", IntegerArgumentType.integer(0,10))
.suggests((ctx, builder) -> IntegerArgumentType.integer(0,10).listSuggestions(ctx, builder))
.executes(this)
)));
}
}