public class ExamplePlugin extends JavaPlugin {
private final static String commandName = "pumpkintrees";
private YamlFileConfig messageConfig;
private CommandManager commandManager;
@Override
public void onEnable() {
messageConfig = new YamlFileConfig(this, "messages.yml");
reloadConfig();
try {
commandManager = new CommandManager(this,
component -> messageConfig.getComponent("prefix").append(text(" ")).append(component),
"/" + commandName + " help",
new CommandConfirmationManager<>(
30L,
TimeUnit.SECONDS,
context -> context.getCommandContext().getSender().sendMessage(messageConfig.getComponent("commands.confirm.needed")),
sender -> sender.sendMessage(messageConfig.getComponent("commands.confirm.nothing"))
)
);
} catch (InstantiationException e) {
e.printStackTrace();
setEnabled(false);
return;
}
createCommands();
}
@Override
public void reloadConfig() {
saveDefaultConfig();
super.reloadConfig();
messageConfig.reload();
}
private void createCommands() {
var builder = commandManager.manager().commandBuilder(commandName);
commandManager.command(builder.literal("help", ArgumentDescription.of("The main help command"))
.permission("ah.commands.help")
.argument(StringArgument.<CommandSender>builder("query").greedy().asOptional().withSuggestionsProvider((context, string) ->
commandManager.manager().createCommandHelpHandler().queryRootIndex(context.getSender()).getEntries().stream()
.map(CommandHelpHandler.VerboseHelpEntry::getSyntaxString).collect(Collectors.toList())
).withDefaultDescription(ArgumentDescription.of("The start of the command to query")))
.handler(commandContext -> {
String query = commandContext.getOrDefault("query", "");
commandManager.queryCommands(query == null ? "" : query, commandContext.getSender());
})
);
commandManager.command(builder.literal("reload", ArgumentDescription.of("Reloads this plugin"))
.permission("ah.admin.reload")
.handler(commandContext -> {
final var sender = commandContext.getSender();
sender.sendMessage(this.getMessageConfig().getComponent("commands.reload.start"));
this.reloadConfig();
sender.sendMessage(this.getMessageConfig().getComponent("commands.reload.finish"));
})
);
commandManager.command(builder.literal("version")
.permission("ah.admin.version")
.handler(commandContext ->
commandContext.getSender().sendMessage(Component.text(getName() + " version " + getPluginMeta().getVersion()))
));
commandManager.command(builder
.senderType(Player.class)
.permission("ah.commands.open")
.handler(commandContext -> {
final Player sender = (Player) commandContext.getSender();
guiManager.openAuctionsGUI(sender);
}));
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
License
Hugo5000/PaperMC-CommandLib
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published