
[ad_1]
I’m making an attempt to make a command that has a number of kids that every do a special factor.
To visualise what I’m making an attempt to do, here is a picture:
I’ve tried to make use of literal("foo")
after which a number of .then()
but it surely finally ends up like /foo subfoo1 subfoo2 subfoo3
and I’ve additionally tried to duplicate the setExecution()
however it’s already outlined.
Here’s 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.CommandSupply;
import internet.minecraft.command.Commands;
import internet.minecraft.entity.participant.ServerPlayerEntity;
import internet.minecraft.util.Util;
import internet.minecraft.util.textual content.StringTextComponent;
public class InstanceCommand extends BaseCommand {
public InstanceCommand(String identify, int permissionLevel, boolean enabled) {
tremendous(identify, permissionLevel, enabled);
}
@Override
public LiteralArgumentBuilder<CommandSupply> setExecution() {
return builder.executes(supply -> execute(supply.getSource())).then();
}
non-public int execute(CommandSupply 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.CommandSupply;
import internet.minecraft.command.Commands;
public class BaseCommand {
protected LiteralArgumentBuilder<CommandSupply> builder;
boolean enabled;
public BaseCommand(String identify, int permissionLevel, boolean enabled) {
this.builder = Commands.literal(identify).requires(supply -> supply.hasPermissionLevel(permissionLevel));
this.enabled = enabled;
}
public LiteralArgumentBuilder<CommandSupply> getBuilder() {
return builder;
}
public boolean isEnabled() {
return enabled;
}
public LiteralArgumentBuilder<CommandSupply> setExecution() {
return null;
}
}
(moved from gaming.SE)
[ad_2]