19
19
package com .plotsquared .core .commands ;
20
20
21
21
import cloud .commandframework .context .CommandContext ;
22
+ import cloud .commandframework .keys .CloudKey ;
22
23
import com .plotsquared .core .configuration .caption .TranslatableCaption ;
23
24
import com .plotsquared .core .permissions .Permission ;
24
25
import com .plotsquared .core .player .PlotPlayer ;
26
+ import io .leangen .geantyref .TypeToken ;
25
27
import net .kyori .adventure .text .minimessage .tag .Tag ;
26
28
import net .kyori .adventure .text .minimessage .tag .resolver .TagResolver ;
27
29
import org .checkerframework .checker .nullness .qual .NonNull ;
30
+ import org .incendo .cloud .requirement .Requirement ;
31
+ import org .incendo .cloud .requirement .Requirements ;
28
32
29
33
import java .util .List ;
30
34
31
35
/**
32
36
* Something that is required for a command to be executed.
33
37
*/
34
- public interface CommandRequirement {
38
+ public interface CommandRequirement extends Requirement < PlotPlayer <?>, CommandRequirement > {
35
39
36
40
/**
37
- * Returns the caption sent when the requirement is not met.
38
- *
39
- * @return the caption
41
+ * The key used to store the requirements in the {@link cloud.commandframework.meta.CommandMeta}.
40
42
*/
41
- @ NonNull TranslatableCaption failureCaption ();
43
+ CloudKey <Requirements <PlotPlayer <?>, CommandRequirement >> REQUIREMENTS_KEY = CloudKey .of (
44
+ "requirements" ,
45
+ new TypeToken <Requirements <PlotPlayer <?>, CommandRequirement >>() {
46
+ }
47
+ );
42
48
43
49
/**
44
- * Evaluates whether the requirement is met.
50
+ * Returns the caption sent when the requirement is not met.
45
51
*
46
- * @param context command context to evaluate
47
- * @return {@code true} if the requirement is met, else {@code false}
52
+ * @return the caption
48
53
*/
49
- boolean evaluate ( final @ NonNull CommandContext < PlotPlayer <?>> context );
54
+ @ NonNull TranslatableCaption failureCaption ( );
50
55
51
56
/**
52
57
* Returns the placeholder values.
@@ -57,15 +62,6 @@ public interface CommandRequirement {
57
62
return new TagResolver [0 ];
58
63
}
59
64
60
- /**
61
- * Returns the list of parent requirements that should be evaluated before this requirement.
62
- *
63
- * @return the requirements
64
- */
65
- default @ NonNull List <@ NonNull CommandRequirement > parents () {
66
- return List .of ();
67
- }
68
-
69
65
/**
70
66
* Returns a requirement that evaluates to {@code true} if the sender has the given {@code permission} or if
71
67
* this requirement evaluates to {@code true}.
@@ -94,8 +90,8 @@ public interface CommandRequirement {
94
90
}
95
91
96
92
@ Override
97
- public boolean evaluate (final @ NonNull CommandContext <PlotPlayer <?>> context ) {
98
- return context .sender ().hasPermission (permission ) || thisRequirement .evaluate (context );
93
+ public boolean evaluateRequirement (final @ NonNull CommandContext <PlotPlayer <?>> context ) {
94
+ return context .sender ().hasPermission (permission ) || thisRequirement .evaluateRequirement (context );
99
95
}
100
96
};
101
97
}
0 commit comments