This repository has been archived by the owner on Oct 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Adding a subcommand
NotMyFault edited this page Jul 7, 2019
·
4 revisions
This guide is for PlotSquared versions <= 1.12.2
Registering a sub command will have it show up when a user types in
/plot help <category> - where category is the category of your command
The following is an example
@CommandDeclaration(
// The name of the command
command = "test",
// The permission
permission = "plots.music",
// The command description
description = "Player music in a plot",
// The usage message
usage = "/plot music",
// The command category
category = CommandCategory.ACTIONS,
// The required command caller (NONE allows console, which would pass ConsolePlayer for the PlotPlayer)
requiredType = RequiredType.NONE
)
public class TestCommand extends SubCommand {
public TestCommand() {
// You can register the command here, or somewhere else
MainCommand.getInstance().addCommand(this);
// Then just call:
// new TestCommand();
// And in game use: /plot test
}
// What happens when the command is executed:
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
Location loc = player.getLocation();
Plot plot = Plot plot1 = MainUtil.getPlot(loc);
if (plot1 == null) {
sendMessage(player, C.NOT_IN_PLOT);
return false;
}
Plot plot = MainUtil.getCurrentPlot(plr);
MainUtil.sendMessage(player, "You are in plot " + plot.getId());
return true;
}
}
Command<PlotPlayer> cmd = new Command<PlotPlayer>(String command, String usage, String description, String permission, String[] aliases, RequiredType requiredType) {
@Override
public boolean onCommand(PlotPlayer plr, String[] arguments) {
Location loc = player.getLocation();
Plot plot = Plot plot1 = MainUtil.getPlot(loc);
if (plot1 == null) {
sendMessage(player, C.NOT_IN_PLOT);
return false;
}
Plot plot = MainUtil.getCurrentPlot(plr);
MainUtil.sendMessage(player, "You are in plot " + plot.getId());
return true;
}
};
MainCommand.getInstance().addCommand(cmd);