Skip to content

Commit 8910eb1

Browse files
authored
Improve CondHasScoreboardTag behavior (#8248)
1 parent a5252ed commit 8910eb1

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package 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;
113
import ch.njol.skript.conditions.base.PropertyCondition;
124
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType;
135
import ch.njol.skript.doc.Description;
@@ -17,7 +9,11 @@
179
import ch.njol.skript.lang.Condition;
1810
import ch.njol.skript.lang.Expression;
1911
import ch.njol.skript.lang.SkriptParser.ParseResult;
12+
import ch.njol.skript.lang.util.SimpleExpression;
2013
import 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

Comments
 (0)