I’m making an attempt to make a command that has a number of youngsters that every do a unique factor.
To visualise what I’m making an attempt to do, this is a picture:
I’ve tried to make use of literal("foo")
after which a number of .then()
nevertheless it finally ends up like /foo subfoo1 subfoo2 subfoo3
and I’ve additionally tried to duplicate the setExecution()
however it’s already outlined.
Here is my code:
import com.mer08.sidaland.sidaland.widespread.command.BaseCommand;
import com.mer08.sidaland.sidaland.core.config.configuracionsidacoins;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import internet.minecraft.command.CommandSource;
import internet.minecraft.command.Instructions;
import internet.minecraft.entity.participant.ServerPlayerEntity;
import internet.minecraft.util.Util;
import internet.minecraft.util.textual content.StringTextComponent;
public class ExampleCommand extends BaseCommand {
public ExampleCommand(String identify, int permissionLevel, boolean enabled) {
tremendous(identify, permissionLevel, enabled);
}
@Override
public LiteralArgumentBuilder<CommandSource> setExecution() {
return builder.executes(supply -> execute(supply.getSource())).then();
}
non-public int execute(CommandSource supply) {
if(supply.getEntity() instanceof ServerPlayerEntity) {
supply.getEntity().sendMessage(new StringTextComponent(""), Util.DUMMY_UUID);
}
return Command.SINGLE_SUCCESS;
}
}
And right here is the BaseCommand
class
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import internet.minecraft.command.CommandSource;
import internet.minecraft.command.Instructions;
public class BaseCommand {
protected LiteralArgumentBuilder<CommandSource> builder;
boolean enabled;
public BaseCommand(String identify, int permissionLevel, boolean enabled) {
this.builder = Instructions.literal(identify).requires(supply -> supply.hasPermissionLevel(permissionLevel));
this.enabled = enabled;
}
public LiteralArgumentBuilder<CommandSource> getBuilder() {
return builder;
}
public boolean isEnabled() {
return enabled;
}
public LiteralArgumentBuilder<CommandSource> setExecution() {
return null;
}
}
(moved from gaming.SE)