Skip to content

Commit 7c43f1c

Browse files
committed
Removed Executable
1 parent 893b4ce commit 7c43f1c

File tree

7 files changed

+40
-402
lines changed

7 files changed

+40
-402
lines changed

README.md

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Paper forks of Bukkit/Spigot often break traditional command registration method
8787

8888
## Usage Examples
8989

90-
### Example 1: Custom Command by Extending BukkitCommand
90+
### Example: Custom Command by Extending BukkitCommand
9191

9292
Create a custom command by extending `BukkitCommand`:
9393

@@ -96,16 +96,13 @@ package com.example.myplugin.command;
9696

9797
import me.croabeast.command.BukkitCommand;
9898
import me.croabeast.command.BaseCommand;
99-
import me.croabeast.command.Executable;
10099
import me.croabeast.command.SubCommand;
101100
import me.croabeast.command.TabBuilder;
102101
import me.croabeast.command.DefaultPermissible;
103102
import org.bukkit.command.CommandSender;
104103
import org.bukkit.plugin.Plugin;
105104
import org.jetbrains.annotations.NotNull;
106105

107-
import java.util.Arrays;
108-
109106
public class GreetCommand extends BukkitCommand implements DefaultPermissible {
110107

111108
/**
@@ -115,7 +112,7 @@ public class GreetCommand extends BukkitCommand implements DefaultPermissible {
115112
*/
116113
public GreetCommand(Plugin plugin) {
117114
super(plugin, "greet");
118-
115+
119116
// Set up the main command executable
120117
setExecutable((CommandSender sender, String[] args) -> {
121118
sender.sendMessage("Hello, " + sender.getName() + "!");
@@ -124,10 +121,10 @@ public class GreetCommand extends BukkitCommand implements DefaultPermissible {
124121

125122
// Register a sub-command "reload" with an alias "r"
126123
SubCommand reloadSub = new SubCommand(this, "reload;r");
127-
reloadSub.setExecutable((sender, args) -> {
124+
reloadSub.setPredicate((sender, args) -> {
128125
// Reload logic here
129126
sender.sendMessage("GreetCommand configuration reloaded.");
130-
return Executable.State.TRUE;
127+
return true;
131128
});
132129
registerSubCommand(reloadSub);
133130
}
@@ -183,43 +180,6 @@ public class MyPlugin extends JavaPlugin {
183180
}
184181
```
185182

186-
### Example 2: Creating a Command with CommandBuilder
187-
188-
Alternatively, use the fluent API provided by `CommandBuilder`:
189-
190-
```java
191-
package com.example.myplugin;
192-
193-
import com.example.myplugin.command.CommandBuilder;
194-
import com.example.myplugin.command.Executable;
195-
import com.example.myplugin.command.TabBuilder;
196-
import org.bukkit.plugin.java.JavaPlugin;
197-
198-
import java.util.Arrays;
199-
200-
public class MyPlugin extends JavaPlugin {
201-
202-
@Override
203-
public void onEnable() {
204-
// Create a command "example" using CommandBuilder
205-
CommandBuilder builder = CommandBuilder.from(this, "example")
206-
.setOverriding(true)
207-
.setCompletions((sender, args) -> Arrays.asList("optionA", "optionB", "optionC"))
208-
.setCompletionBuilder(new TabBuilder().addArgument(1, "optionA"))
209-
.apply(cmd -> cmd.setExecutable((sender, args) -> {
210-
sender.sendMessage("Example command executed with arguments: " + String.join(" ", args));
211-
return Executable.State.TRUE;
212-
}));
213-
214-
// Register the command at runtime (works seamlessly on Paper)
215-
builder.register();
216-
217-
// To unregister later:
218-
// builder.unregister();
219-
}
220-
}
221-
```
222-
223183
---
224184

225185
## Maven / Gradle Installation

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* <ul>
1212
* <li>The command name, as returned by {@link #getName()}.</li>
1313
* <li>A list of alternative names (aliases) via {@link #getAliases()}.</li>
14-
* <li>An executable action defined by {@link Executable}, which is run when the command is invoked.</li>
14+
* <li>An executable predicate defined by {@link CommandPredicate}, which is run when the command is invoked.</li>
1515
* </ul>
1616
* </p>
1717
* <p>
@@ -34,10 +34,10 @@
3434
* }
3535
*
3636
* {@literal @}Override
37-
* public Executable getExecutable() {
37+
* public CommandPredicate getPredicate() {
3838
* return (sender, args) -&gt; {
3939
* // command execution logic
40-
* return Executable.State.TRUE;
40+
* return true;
4141
* };
4242
* }
4343
*
@@ -48,7 +48,7 @@
4848
* }</code></pre></p>
4949
*
5050
* @see Permissible
51-
* @see Executable
51+
* @see CommandPredicate
5252
*/
5353
public interface BaseCommand extends Permissible {
5454

@@ -72,13 +72,13 @@ public interface BaseCommand extends Permissible {
7272
List<String> getAliases();
7373

7474
/**
75-
* Gets the executable action associated with this command.
75+
* Gets the executable predicate associated with this command.
7676
* <p>
77-
* The returned {@link Executable} defines the logic that is run when the command is invoked.
77+
* The returned {@link CommandPredicate} defines the logic that is run when the command is invoked.
7878
* </p>
7979
*
80-
* @return the {@link Executable} instance representing the command's behavior.
80+
* @return the {@link CommandPredicate} instance representing the command's behavior.
8181
*/
8282
@NotNull
83-
Executable getExecutable();
83+
CommandPredicate getPredicate();
8484
}

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

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

7878
/**
7979
* Predicate for handling errors during command execution.
@@ -323,15 +323,15 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
323323
if (args.length > 1)
324324
System.arraycopy(args, 1, newArgs, 0, last);
325325
try {
326-
success = sub.getExecutable().executeAction(sender, newArgs).asBoolean();
326+
success = sub.getPredicate().test(sender, newArgs);
327327
} catch (Throwable e) {
328328
success = executingError.test(sender, e);
329329
}
330330
return success;
331331
}
332332
}
333333
try {
334-
success = getExecutable().executeAction(sender, args).asBoolean();
334+
success = getPredicate().test(sender, args);
335335
} catch (Throwable e) {
336336
success = executingError.test(sender, e);
337337
}
@@ -367,41 +367,32 @@ public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String a
367367
}
368368

369369
/**
370-
* Retrieves the executable action associated with this command.
370+
* Retrieves the executable predicate associated with this command.
371371
*
372-
* @return the {@link Executable} representing the command's action.
373-
* @throws NullPointerException if the executable action is not set.
372+
* @return the {@link CommandPredicate} representing the command's action.
373+
* @throws NullPointerException if the executable predicate is not set.
374374
*/
375375
@NotNull
376-
public Executable getExecutable() {
377-
return Objects.requireNonNull(executable, "Executable action is not set");
376+
public CommandPredicate getPredicate() {
377+
return Objects.requireNonNull(executable, "Executable predicate is not set");
378378
}
379379

380380
/**
381-
* Sets the executable action for this command.
381+
* Sets the executable predicate based on a provided {@link CommandPredicate}.
382382
*
383-
* @param executable the executable action to assign.
384-
*/
385-
public void setExecutable(Executable executable) {
386-
this.executable = executable;
387-
}
388-
389-
/**
390-
* Sets the executable action based on a provided {@link CommandPredicate}.
391-
*
392-
* @param predicate the command predicate used to generate the executable action.
383+
* @param predicate the command predicate used to generate the executable predicate.
393384
*/
394385
public void setExecutable(CommandPredicate predicate) {
395-
this.executable = Executable.from(predicate);
386+
this.executable = predicate;
396387
}
397388

398389
/**
399-
* Sets the executable action to a constant boolean value.
390+
* Sets the executable predicate to a constant boolean value.
400391
*
401392
* @param value the boolean value representing the command outcome.
402393
*/
403394
public void setExecutable(boolean value) {
404-
this.executable = Executable.from(value);
395+
this.executable = (sender, strings) -> value;
405396
}
406397

407398
/**
@@ -539,7 +530,7 @@ public static void syncCommands() {
539530
* @return {@code true} if the command was successfully registered; {@code false} otherwise.
540531
*/
541532
public boolean register(boolean sync) {
542-
if (registered || !isEnabled()) return false;
533+
if (registered) return false;
543534

544535
org.bukkit.command.Command c = knownCommands().get(getName());
545536
if (isOverriding() && c != null)
@@ -574,7 +565,7 @@ public boolean register() {
574565
*/
575566
@SuppressWarnings("all")
576567
public boolean unregister(boolean sync) {
577-
if (!registered || isEnabled()) return false;
568+
if (!registered) return false;
578569

579570
org.bukkit.command.Command c = knownCommands().get(getName());
580571
if (!Objects.equals(c, this)) return false;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* <p>
1616
* A {@code Command} extends multiple interfaces to provide a comprehensive structure for commands:
1717
* <ul>
18-
* <li>{@link BaseCommand} for basic command properties (name, aliases, and executable action).</li>
18+
* <li>{@link BaseCommand} for basic command properties (name, aliases, and executable predicate).</li>
1919
* <li>{@link Completable} for generating tab-completion suggestions.</li>
2020
* <li>{@link PluginIdentifiableCommand} and {@link Keyed} for associating the command with a plugin.</li>
2121
* <li>{@link Registrable} for handling command registration.</li>
@@ -42,10 +42,10 @@
4242
* }
4343
*
4444
* {@literal @}Override
45-
* public Executable getExecutable() {
45+
* public CommandPredicate getPredicate() {
4646
* return (sender, args) -&gt; {
4747
* // command logic
48-
* return Executable.State.TRUE;
48+
* return true;
4949
* };
5050
* }
5151
*

0 commit comments

Comments
 (0)