Skip to content

Commit 55b0d42

Browse files
made .require statements take a custom Require function
1 parent c0c0ca0 commit 55b0d42

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/com/datasiqn/commandcore/command/builder/CommandLink.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919
*/
2020
public abstract class CommandLink<T> {
2121
protected final Set<CommandNode<?>> children = new HashSet<>();
22-
protected final List<Function<CommandContext, Result<None, String>>> requires = new ArrayList<>();
22+
protected final List<Require> requires = new ArrayList<>();
2323

2424
protected Consumer<CommandContext> executor;
2525

2626
/**
2727
* Requires the context in which the command is executed in to pass the {@code requires} check
28-
* @param requires A function that determines if a {@code CommandContext} can run the command
28+
* @param require A function that determines if a {@code CommandContext} can run the command
2929
* @return Itself, for chaining
3030
*/
31-
public T requires(@NotNull Function<CommandContext, Result<None, String>> requires) {
32-
this.requires.add(requires);
31+
public T requires(@NotNull Require require) {
32+
this.requires.add(require);
3333
return getThis();
3434
}
3535

3636
/**
3737
* Requires the sender to be a {@code Player}
38-
* @see #requires(Function)
38+
* @see #requires(Require)
3939
* @return Itself, for chaining
4040
*/
4141
public T requiresPlayer() {
@@ -44,7 +44,7 @@ public T requiresPlayer() {
4444

4545
/**
4646
* Requires the sender to be an {@code Entity}
47-
* @see #requires(Function)
47+
* @see #requires(Require)
4848
* @return Itself, for chaining
4949
*/
5050
public T requiresEntity() {
@@ -80,4 +80,10 @@ public Consumer<CommandContext> getExecutor() {
8080
}
8181

8282
protected abstract @NotNull T getThis();
83+
84+
/**
85+
* A function that defines a command requirement.
86+
* This interface is basically a shorthand for {@code Function<CommandContext, Result<None, String>>}
87+
*/
88+
public interface Require extends Function<CommandContext, Result<None, String>> { }
8389
}

0 commit comments

Comments
 (0)