Skip to content

Commit

Permalink
Fix cast exception when using invalid classes with CondIsTagged (#7527)
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth authored Feb 1, 2025
1 parent 5adda36 commit 382f883
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ public boolean check(Event event) {
return elements.check(event, element -> {
boolean isAny = (element instanceof ItemType itemType && !itemType.isAll());
Keyed[] values = TagModule.getKeyed(element);
if (values == null)
if (values == null || values.length == 0)
return false;

Class<? extends Keyed> valueClass = values[0].getClass();

for (Tag<Keyed> tag : tags) {
// cursed check to ensure the tag is the same type as the values
if (!tag.getValues().iterator().next().getClass().isAssignableFrom(valueClass))
return false;
if (isTagged(tag, values, !isAny)) {
if (!and)
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/test/skript/tests/syntaxes/conditions/CondIsTagged.sk
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ test "CondIsTagged":

spawn a skeleton at spawn of world "world":
assert entity is tagged as entity tag "minecraft:skeletons" with "skeleton is not a skeleton"
assert entity is not tagged as item tag "doors" with "failed to handle checking entity for item tag"
delete entity

assert stone sword is not tagged as entity tag "skeletons" with "failed to handle checking item for entity tag"

0 comments on commit 382f883

Please sign in to comment.