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 tag lookup for "skript" and "paper" #7450

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -80,46 +80,55 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is

@Override
protected Tag<?> @Nullable [] get(Event event) {
String[] names = this.names.getArray(event);
List<Tag<?>> tags = new ArrayList<>();

String namespace = switch (origin) {
case ANY, BUKKIT -> "minecraft";
case PAPER -> "paper";
case SKRIPT -> "skript";
String[] namespaces = switch (origin) {
case ANY -> new String[]{"minecraft", "paper", "skript"};
case BUKKIT -> new String[]{"minecraft"};
case PAPER -> new String[]{"paper"};
case SKRIPT -> new String[]{"skript"};
};

nextName: for (String name : names) {
// get key
NamespacedKey key;
nextName: for (String name : this.names.getArray(event)) {
boolean invalidKey = false;
APickledWalrus marked this conversation as resolved.
Show resolved Hide resolved
try {
if (name.contains(":")) {
key = NamespacedKey.fromString(name);
NamespacedKey key = NamespacedKey.fromString(name);
invalidKey = key == null;
APickledWalrus marked this conversation as resolved.
Show resolved Hide resolved
if (!invalidKey) {
tags.add(findTag(key));
}
} else {
// populate namespace if not provided
key = new NamespacedKey(namespace, name);
for (String namespace : namespaces) {
Tag<?> tag = findTag(new NamespacedKey(namespace, name));
if (tag != null) {
tags.add(tag);
continue nextName;
}
}
}
} catch (IllegalArgumentException e) {
key = null;
invalidKey = true;
}
if (key == null) {
if (invalidKey) {
error("Invalid tag key: '" + name + "'. Tags may only contain a-z, 0-9, _, ., /, or - characters.");
continue;
}
}
return tags.toArray(Tag[]::new);
}

Tag<?> tag;
for (TagType<?> type : types) {
tag = TagModule.tagRegistry.getTag(origin, type, key);
if (tag != null
// ensures that only datapack/minecraft tags are sent when specifically requested
&& (origin != TagOrigin.BUKKIT || (datapackOnly ^ tag.getKey().getNamespace().equals("minecraft")))
) {
tags.add(tag);
continue nextName; // ensure 1:1
}
private Tag<?> findTag(NamespacedKey key) {
APickledWalrus marked this conversation as resolved.
Show resolved Hide resolved
for (TagType<?> type : types) {
Tag<?> tag = TagModule.tagRegistry.getTag(origin, type, key);
if (tag != null
// ensures that only datapack/minecraft tags are sent when specifically requested
&& (origin != TagOrigin.BUKKIT || (datapackOnly ^ tag.getKey().getNamespace().equals(NamespacedKey.MINECRAFT)))
) {
return tag;
}
}
return tags.toArray(new Tag[0]);
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test "7449 - tag lookup only uses minecraft namespace":
register an item tag named "my_favorite_blocks" using oak log, stone, and podzol
assert tag "my_favorite_blocks" is tag "skript:my_favorite_blocks" with "Tag lookup didn't find a skript tag ""helmets"" namespace"
assert tag "helmets" is tag "paper:helmets" with "Tag lookup didn't find a paper tag ""helmets"" namespace"
assert tag "dirt" is tag "minecraft:dirt" with "Tag lookup didn't find a minecraft tag ""dirt"" namespace"