As I said, it works in singleplayer, it just doesn't work on multiplayer servers, but sure:
One of the commands.
package com.versemod.command.commands;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.versemod.command.Command;
import com.versemod.configs.GeneralConfig;
import com.versemod.util.MessageBus;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
@Command.Declaration(name="Token Calculation",syntax = VerseModCommands.COMMAND_SYNTAX_PREFIX+" tc",description = "Calculates token value")
public class TokenCalculationCommand extends Command
{
private static final GeneralConfig config = new GeneralConfig();
private static final TokenCalculationCommand tokenCommand = new TokenCalculationCommand();
/*
* Used by VerseModCommands to register the TokenCalculation command.
* */
protected static ArgumentBuilder<CommandSource,?> register()
{
VerseModCommands.addCommand(tokenCommand);
return Commands.literal("tc").executes(cmd->VerseModCommands.throwSyntaxHelp(tokenCommand,"<amount>"))
.then(Commands.argument("amount", IntegerArgumentType.integer(1))
.executes(command->calculateTokenValue(IntegerArgumentType.getInteger(command,"amount")))
);
}
/*
* Calculates the token amount value based on the GeneralConfig defined token value.
* */
private static int calculateTokenValue(int amount){
int valuePerToken = config.getTokenValue();
MessageBus.sendPlayerMessage(MessageBus.DEFAULT_HIGHLIGHT_COLOR+""+amount +""+ MessageBus.DEFAULT_SUCCESS_COLOR+ " token(s) are worth "+MessageBus.DEFAULT_HIGHLIGHT_COLOR+"$" + valuePerToken * amount,true);
return -1;
}
}
Registration:
/*
* Registers all VerseMod commands.
* */
@SubscribeEvent
public void registerCommands(RegisterCommandsEvent event)
{
event.getDispatcher().register(
LiteralArgumentBuilder.<CommandSource>
literal(COMMAND_PREFIX).executes(cmd->HelpCommand.getHelp())
.then(HelpCommand.register())
.then(TokenCalculationCommand.register())
.then(TrackCommand.register())
.then(HologramCommand.register())
.then(FormattingCommand.register())
.then(WeeklyEventCommand.register())
.then(ItemBindCommand.register())
.then(PunishmentCommand.register())
.then(HostBroadcastCommand.register())
);
}