11package ch .njol .skript .conditions ;
22
3- import java .util .Arrays ;
4- import java .util .List ;
5-
6- import org .bukkit .entity .Entity ;
7- import org .bukkit .event .Event ;
8- import org .jetbrains .annotations .Nullable ;
9-
10- import ch .njol .skript .Skript ;
113import ch .njol .skript .conditions .base .PropertyCondition ;
124import ch .njol .skript .conditions .base .PropertyCondition .PropertyType ;
135import ch .njol .skript .doc .Description ;
179import ch .njol .skript .lang .Condition ;
1810import ch .njol .skript .lang .Expression ;
1911import ch .njol .skript .lang .SkriptParser .ParseResult ;
12+ import ch .njol .skript .lang .util .SimpleExpression ;
2013import ch .njol .util .Kleenean ;
14+ import org .bukkit .entity .Entity ;
15+ import org .bukkit .event .Event ;
16+ import org .jetbrains .annotations .Nullable ;
2117
2218@ Name ("Has Scoreboard Tag" )
2319@ Description ("Checks whether the given entities has the given <a href='#ExprScoreboardTags'>scoreboard tags</a>." )
@@ -28,33 +24,36 @@ public class CondHasScoreboardTag extends Condition {
2824 static {
2925 PropertyCondition .register (CondHasScoreboardTag .class , PropertyType .HAVE , "[the] score[ ]board tag[s] %strings%" , "entities" );
3026 }
31-
32- @ SuppressWarnings ("null" )
27+
3328 private Expression <Entity > entities ;
34- @ SuppressWarnings ("null" )
3529 private Expression <String > tags ;
3630
37- @ SuppressWarnings ("unchecked" )
3831 @ Override
32+ @ SuppressWarnings ("unchecked" )
3933 public boolean init (Expression <?>[] exprs , int matchedPattern , Kleenean isDelayed , ParseResult parseResult ) {
4034 entities = (Expression <Entity >) exprs [0 ];
4135 tags = (Expression <String >) exprs [1 ];
4236 setNegated (matchedPattern == 1 );
4337 return true ;
4438 }
45-
39+
4640 @ Override
47- public boolean check (Event e ) {
48- List <String > tagsList = Arrays .asList (tags .getArray (e ));
49- return entities .check (e ,
50- entity -> entity .getScoreboardTags ().containsAll (tagsList ),
51- isNegated ());
41+ public boolean check (Event event ) {
42+ String [] tagsList = tags .getAll (event );
43+ return entities .check (event ,
44+ entity -> SimpleExpression .check (
45+ tagsList ,
46+ tag -> entity .getScoreboardTags ().contains (tag ),
47+ false ,
48+ tags .getAnd ()
49+ ),
50+ isNegated ());
5251 }
5352
5453 @ Override
55- public String toString (@ Nullable Event e , boolean debug ) {
56- return PropertyCondition .toString (this , PropertyType .HAVE , e , debug , entities ,
57- "the scoreboard " + (tags .isSingle () ? "tag " : "tags " ) + tags .toString (e , debug ));
54+ public String toString (@ Nullable Event event , boolean debug ) {
55+ return PropertyCondition .toString (this , PropertyType .HAVE , event , debug , entities ,
56+ "the scoreboard " + (tags .isSingle () ? "tag " : "tags " ) + tags .toString (event , debug ));
5857 }
5958
6059}
0 commit comments