Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cast exception when using invalid classes with CondIsTagged #7527

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"