Skip to content

Commit ac663ba

Browse files
committed
Adjust README.md
1 parent 7c43f1c commit ac663ba

File tree

2 files changed

+50
-68
lines changed

2 files changed

+50
-68
lines changed

README.md

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Create a custom command by extending `BukkitCommand`:
9595
package com.example.myplugin.command;
9696

9797
import me.croabeast.command.BukkitCommand;
98-
import me.croabeast.command.BaseCommand;
9998
import me.croabeast.command.SubCommand;
10099
import me.croabeast.command.TabBuilder;
101100
import me.croabeast.command.DefaultPermissible;
@@ -105,54 +104,54 @@ import org.jetbrains.annotations.NotNull;
105104

106105
public class GreetCommand extends BukkitCommand implements DefaultPermissible {
107106

108-
/**
109-
* Constructs the GreetCommand with a reference to the owning plugin.
110-
*
111-
* @param plugin the plugin instance.
112-
*/
113-
public GreetCommand(Plugin plugin) {
114-
super(plugin, "greet");
115-
116-
// Set up the main command executable
117-
setExecutable((CommandSender sender, String[] args) -> {
118-
sender.sendMessage("Hello, " + sender.getName() + "!");
119-
return Executable.State.TRUE;
120-
});
121-
122-
// Register a sub-command "reload" with an alias "r"
123-
SubCommand reloadSub = new SubCommand(this, "reload;r");
124-
reloadSub.setPredicate((sender, args) -> {
125-
// Reload logic here
126-
sender.sendMessage("GreetCommand configuration reloaded.");
127-
return true;
128-
});
129-
registerSubCommand(reloadSub);
130-
}
131-
132-
/**
133-
* Provides custom tab completion for the command.
134-
*
135-
* @param sender the command sender.
136-
* @param alias the command alias used.
137-
* @param args the arguments passed to the command.
138-
* @return a list of suggestions.
139-
*/
140-
@NotNull
141-
@Override
142-
public java.util.List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, String[] args) {
143-
// Create a simple TabBuilder for suggestions
144-
TabBuilder builder = new TabBuilder();
145-
if (args.length == 1) {
146-
// Suggest "hello" and "hi" when no sub-command is specified
147-
builder.addArgument(1, "hello");
148-
builder.addArgument(1, "hi");
149-
} else if (args.length > 1) {
150-
// Optionally, provide additional suggestions for further arguments
151-
builder.addArgument(args.length, "option1");
152-
builder.addArgument(args.length, "option2");
153-
}
154-
return builder.build(sender, args);
107+
/**
108+
* Constructs the GreetCommand with a reference to the owning plugin.
109+
*
110+
* @param plugin the plugin instance.
111+
*/
112+
public GreetCommand(Plugin plugin) {
113+
super(plugin, "greet");
114+
115+
// Set up the main command executable
116+
setPredicate((CommandSender sender, String[] args) -> {
117+
sender.sendMessage("Hello, " + sender.getName() + "!");
118+
return Executable.State.TRUE;
119+
});
120+
121+
// Register a sub-command "reload" with an alias "r"
122+
SubCommand reloadSub = new SubCommand(this, "reload;r");
123+
reloadSub.setPredicate((sender, args) -> {
124+
// Reload logic here
125+
sender.sendMessage("GreetCommand configuration reloaded.");
126+
return true;
127+
});
128+
registerSubCommand(reloadSub);
129+
}
130+
131+
/**
132+
* Provides custom tab completion for the command.
133+
*
134+
* @param sender the command sender.
135+
* @param alias the command alias used.
136+
* @param args the arguments passed to the command.
137+
* @return a list of suggestions.
138+
*/
139+
@NotNull
140+
@Override
141+
public java.util.List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, String[] args) {
142+
// Create a simple TabBuilder for suggestions
143+
TabBuilder builder = new TabBuilder();
144+
if (args.length == 1) {
145+
// Suggest "hello" and "hi" when no sub-command is specified
146+
builder.addArgument(1, "hello");
147+
builder.addArgument(1, "hi");
148+
} else if (args.length > 1) {
149+
// Optionally, provide additional suggestions for further arguments
150+
builder.addArgument(args.length, "option1");
151+
builder.addArgument(args.length, "option2");
155152
}
153+
return builder.build(sender, args);
154+
}
156155
}
157156
```
158157

src/main/java/me/croabeast/command/BukkitCommand.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public abstract class BukkitCommand extends org.bukkit.command.Command implement
7373
/**
7474
* The executable action performed when this command is executed.
7575
*/
76-
private CommandPredicate executable = null;
76+
@Setter
77+
private CommandPredicate predicate = null;
7778

7879
/**
7980
* Predicate for handling errors during command execution.
@@ -374,25 +375,7 @@ public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String a
374375
*/
375376
@NotNull
376377
public CommandPredicate getPredicate() {
377-
return Objects.requireNonNull(executable, "Executable predicate is not set");
378-
}
379-
380-
/**
381-
* Sets the executable predicate based on a provided {@link CommandPredicate}.
382-
*
383-
* @param predicate the command predicate used to generate the executable predicate.
384-
*/
385-
public void setExecutable(CommandPredicate predicate) {
386-
this.executable = predicate;
387-
}
388-
389-
/**
390-
* Sets the executable predicate to a constant boolean value.
391-
*
392-
* @param value the boolean value representing the command outcome.
393-
*/
394-
public void setExecutable(boolean value) {
395-
this.executable = (sender, strings) -> value;
378+
return Objects.requireNonNull(predicate, "Executable predicate is not set");
396379
}
397380

398381
/**

0 commit comments

Comments
 (0)