Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed Mar 30, 2024
1 parent b22e176 commit d101af9
Showing 1 changed file with 47 additions and 30 deletions.
77 changes: 47 additions & 30 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public class ExampleClass extends JavaPlugin {
// Initialize the framework before using
// Don't forget to shade framework in to your project
CommandFramework commandFramework = new CommandFramework(this);
// Adding custom parameters
// Adding custom parameters without @Param and @Default annotations.
// Now all String type objects will return first argument.
commandFramework.addCustomParameter(String.class, arguments -> arguments.getArgument(0));
commandFramework.addCustomParameter("String", arguments -> arguments.getArgument(0));
// Adding custom parameters to use with @Param and optionally with @Default annotations.
commandFramework.addCustomParameter("secondAsInt", arguments -> arguments.getLength() > 1 ? arguments.getArgumentAsInt(1) : null);
// Then this will register all the @Command methods as a command
// so there is no necessity to add command to your plugin.yml
commandFramework.registerCommands(this);
Expand All @@ -84,24 +86,24 @@ public class ExampleClass extends JavaPlugin {
// Before creating command the method must only have
// CommandArguments parameter and also @Command annotation
@Command(
name = "example",
aliases = {"firstAlias", "secondAlias"},
permission = "example.permission",
desc = "Sends an example message to sender",
usage = "/example",
min = 1,
max = 5,
onlyOp = false, // this option will ignore permission if it is set
// be careful if you are using non-thread safe operations
// and if you want to enable option below
async = false,
senderType = Command.SenderType.CONSOLE
name = "example",
aliases = {"firstAlias", "secondAlias"},
permission = "example.permission",
desc = "Sends an example message to sender",
usage = "/example",
min = 1,
max = 5,
onlyOp = false, // this option will ignore permission if it is set
// be careful if you are using non-thread safe operations
// and if you want to enable option below
async = false,
senderType = Command.SenderType.CONSOLE
)
@Cooldown(
cooldown = 10,
timeUnit = TimeUnit.SECONDS,
bypassPerm = "command.cooldownBypass",
overrideConsole = true // console will now be affected by cooldown
cooldown = 10,
timeUnit = TimeUnit.SECONDS,
bypassPerm = "command.cooldownBypass",
overrideConsole = true // console will now be affected by cooldown
)
public void exampleCommand(CommandArguments arguments) {
// CommandArguments class contains basic things related Bukkit commands
Expand All @@ -110,15 +112,15 @@ public class ExampleClass extends JavaPlugin {
}

@Command(
name = "nocommandargs"
name = "noParams"
)
public void noCommandArgsTest() {
public void commandWithoutParameters() {
Bukkit.getConsoleSender().sendMessage("This command is running without any parameters.");
}

@Command(
name = "customargs",
min = 1
name = "customParamWithoutAnnotations",
min = 1
)
// See CommandFramework#addCustomParameter method above.
public void customParamCommand(String firstParameter, CommandArguments arguments) {
Expand All @@ -127,23 +129,38 @@ public class ExampleClass extends JavaPlugin {
}

@Command(
name = "confirmationTest"
name = "customParams",
min = 1
)
// If command is executed with only one argument then the default value will be accepted.
// Otherwise, the given argument will be converted to specified type, in this case an int.
// If parameter is not annotated by @Default then command will throw an exception on execution.
// See the wiki page for creating custom parameters using @Param and @Default annotations.
public void customParamsCommand(CommandArguments arguments,
@Param("secondAsInt")
@Default("50")
int secondArg) {
arguments.sendMessage("Second argument as integer is " + secondArg);
}

@Command(
name = "confirmationTest"
)
@Confirmation(
message = "Are you sure, if so, please execute command again to confirm.",
expireAfter = 10,
bypassPerm = "confirmation.bypass",
timeUnit = TimeUnit.SECONDS,
overrideConsole = true
message = "Are you sure, if so, please execute command again to confirm.",
expireAfter = 10,
bypassPerm = "confirmation.bypass",
timeUnit = TimeUnit.SECONDS,
overrideConsole = true
)
public void confirmationCommand(CommandArguments arguments) {
arguments.sendMessage("Confirmation successful.");
}

// Aliases don't need to be same with the command above
@Completer(
name = "example",
aliases = {"firstAlias", "secondAlias"}
name = "example",
aliases = {"firstAlias", "secondAlias"}
)
public List<String> exampleCommandCompletion(/*CommandArguments arguments*/ /*no need to use in this case which is also supported*/) {
return Arrays.asList("first", "second", "third");
Expand Down

0 comments on commit d101af9

Please sign in to comment.