I’ve been going over the basics of sponge and wrote a basic command plugin. Would someone be able to check over it quickly, particularly my command arguments?
Main:
package me.thunder.lunadp;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.state.InitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.spec.CommandSpec;
import static org.spongepowered.api.util.command.args.GenericArguments.*;
@Plugin(id="me.thunder.lunadp", name="LunaDP", version="0.0.1")
public class lunadp {
@Subscribe
public void onInitialization(InitializationEvent e) {
CommandSpec startdp = CommandSpec.builder()
.description(Texts.of("Starts DP based upon input of item id and displays custom message."))
.permission("lunadp.startdp")
.executor(new quickdp())
.arguments(optional(player(Texts.of("target"), e.getGame())))
.arguments(GenericArguments.integer("itemid"), GenericArguments.string("message"))
.build();
e.getGame().getCommandDispatcher().register(this, startdp, "startdp");
}
}
Command:
package me.thunder.dpcommand;
import org.spongepowered.api.data.DataTransactionResult;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.CommandException;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import org.spongepowered.api.util.command.args.CommandContext;
import org.spongepowered.api.util.command.spec.CommandExecutor;
public class dpcommand implements CommandExecutor {
public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
CommandResult r = Sponge.getCommandManager().proccess(Sponge.getServer().getConsole(), "give @a " + itemid);
game.getServer().getBroadcastChannel().send(message);
return CommandResult.success();
}
}
Particularly the arguments, I am worried about, in the main class are meant to then be used in the outputs in the command class, but I am not particularly sure if I have structured that correctly.
Thanks!