Skip to content

Commit deb21b5

Browse files
Fix tag lookup for "skript" and "paper" (#7450)
--------- Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
1 parent c278805 commit deb21b5

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

src/main/java/org/skriptlang/skript/bukkit/tags/elements/ExprTag.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,55 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
8080

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

86-
String namespace = switch (origin) {
87-
case ANY, BUKKIT -> "minecraft";
88-
case PAPER -> "paper";
89-
case SKRIPT -> "skript";
85+
String[] namespaces = switch (origin) {
86+
case ANY -> new String[]{"minecraft", "paper", "skript"};
87+
case BUKKIT -> new String[]{"minecraft"};
88+
case PAPER -> new String[]{"paper"};
89+
case SKRIPT -> new String[]{"skript"};
9090
};
9191

92-
nextName: for (String name : names) {
93-
// get key
94-
NamespacedKey key;
92+
nextName: for (String name : this.names.getArray(event)) {
93+
boolean invalidKey = false;
9594
try {
9695
if (name.contains(":")) {
97-
key = NamespacedKey.fromString(name);
96+
NamespacedKey key = NamespacedKey.fromString(name);
97+
invalidKey = key == null;
98+
if (!invalidKey) {
99+
tags.add(findTag(key));
100+
}
98101
} else {
99-
// populate namespace if not provided
100-
key = new NamespacedKey(namespace, name);
102+
for (String namespace : namespaces) {
103+
Tag<?> tag = findTag(new NamespacedKey(namespace, name));
104+
if (tag != null) {
105+
tags.add(tag);
106+
continue nextName;
107+
}
108+
}
101109
}
102110
} catch (IllegalArgumentException e) {
103-
key = null;
111+
invalidKey = true;
104112
}
105-
if (key == null) {
113+
if (invalidKey) {
106114
error("Invalid tag key: '" + name + "'. Tags may only contain a-z, 0-9, _, ., /, or - characters.");
107115
continue;
108116
}
117+
}
118+
return tags.toArray(Tag[]::new);
119+
}
109120

110-
Tag<?> tag;
111-
for (TagType<?> type : types) {
112-
tag = TagModule.tagRegistry.getTag(origin, type, key);
113-
if (tag != null
114-
// ensures that only datapack/minecraft tags are sent when specifically requested
115-
&& (origin != TagOrigin.BUKKIT || (datapackOnly ^ tag.getKey().getNamespace().equals("minecraft")))
116-
) {
117-
tags.add(tag);
118-
continue nextName; // ensure 1:1
119-
}
121+
private @Nullable Tag<?> findTag(NamespacedKey key) {
122+
for (TagType<?> type : types) {
123+
Tag<?> tag = TagModule.tagRegistry.getTag(origin, type, key);
124+
if (tag != null
125+
// ensures that only datapack/minecraft tags are sent when specifically requested
126+
&& (origin != TagOrigin.BUKKIT || (datapackOnly ^ tag.getKey().getNamespace().equals(NamespacedKey.MINECRAFT)))
127+
) {
128+
return tag;
120129
}
121130
}
122-
return tags.toArray(new Tag[0]);
131+
return null;
123132
}
124133

125134
@Override
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test "7449 - tag lookup only uses minecraft namespace":
2+
register an item tag named "my_favorite_blocks" using oak log, stone, and podzol
3+
assert tag "my_favorite_blocks" is tag "skript:my_favorite_blocks" with "Tag lookup didn't find a skript tag ""helmets"" namespace"
4+
assert tag "helmets" is tag "paper:helmets" with "Tag lookup didn't find a paper tag ""helmets"" namespace"
5+
assert tag "dirt" is tag "minecraft:dirt" with "Tag lookup didn't find a minecraft tag ""dirt"" namespace"

0 commit comments

Comments
 (0)