Skip to content

Commit 2856d27

Browse files
committed
Update tag permissions
1 parent b3ba0dc commit 2856d27

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

common/src/main/java/net/draycia/carbon/common/messages/TagPermissions.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import java.util.Map;
2323
import java.util.function.Predicate;
2424
import net.kyori.adventure.text.Component;
25+
import net.kyori.adventure.text.format.NamedTextColor;
2526
import net.kyori.adventure.text.format.TextDecoration;
2627
import net.kyori.adventure.text.minimessage.MiniMessage;
28+
import net.kyori.adventure.text.minimessage.tag.Tag;
2729
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
2830
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
2931
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -38,7 +40,7 @@ public final class TagPermissions {
3840
private static final Map<String, TagResolver> DEFAULT_TAGS = Map.ofEntries(
3941
Map.entry("hover", StandardTags.hoverEvent()),
4042
Map.entry("click", StandardTags.clickEvent()),
41-
Map.entry("color", StandardTags.color()),
43+
Map.entry("hex", StandardTags.color()),
4244
Map.entry("keybind", StandardTags.keybind()),
4345
Map.entry("translatable", StandardTags.translatable()),
4446
Map.entry("insertion", StandardTags.insertion()),
@@ -55,12 +57,17 @@ private TagPermissions() {
5557

5658
public static Component parseTags(final String basePermission, final String message, final Predicate<String> permission, final TagResolver.Builder resolver) {
5759
boolean hasAllDecorations = false;
60+
boolean hasAllColors = false;
61+
5862
for (final Map.Entry<String, TagResolver> entry : DEFAULT_TAGS.entrySet()) {
5963
if (permission.test(basePermission + '.' + entry.getKey())) {
6064
resolver.resolver(entry.getValue());
6165
if (entry.getKey().equals("decorations")) {
6266
hasAllDecorations = true;
6367
}
68+
if (entry.getKey().equals("hex")) {
69+
hasAllColors = true;
70+
}
6471
}
6572
}
6673

@@ -74,6 +81,16 @@ public static Component parseTags(final String basePermission, final String mess
7481
}
7582
}
7683

84+
if (!hasAllColors) {
85+
for (final NamedTextColor textColor : NamedTextColor.NAMES.values()) {
86+
if (!permission.test(basePermission + ".named." + textColor)) {
87+
continue;
88+
}
89+
90+
resolver.resolver(TagResolver.resolver(textColor.toString(), Tag.styling(msg -> msg.color(textColor))));
91+
}
92+
}
93+
7794
final MiniMessage miniMessage = MiniMessage.builder().tags(resolver.build()).build();
7895

7996
return miniMessage.deserialize(message);

0 commit comments

Comments
 (0)