22
22
import java .util .Map ;
23
23
import java .util .function .Predicate ;
24
24
import net .kyori .adventure .text .Component ;
25
+ import net .kyori .adventure .text .format .NamedTextColor ;
25
26
import net .kyori .adventure .text .format .TextDecoration ;
26
27
import net .kyori .adventure .text .minimessage .MiniMessage ;
28
+ import net .kyori .adventure .text .minimessage .tag .Tag ;
27
29
import net .kyori .adventure .text .minimessage .tag .resolver .TagResolver ;
28
30
import net .kyori .adventure .text .minimessage .tag .standard .StandardTags ;
29
31
import org .checkerframework .checker .nullness .qual .NonNull ;
@@ -38,7 +40,7 @@ public final class TagPermissions {
38
40
private static final Map <String , TagResolver > DEFAULT_TAGS = Map .ofEntries (
39
41
Map .entry ("hover" , StandardTags .hoverEvent ()),
40
42
Map .entry ("click" , StandardTags .clickEvent ()),
41
- Map .entry ("color " , StandardTags .color ()),
43
+ Map .entry ("hex " , StandardTags .color ()),
42
44
Map .entry ("keybind" , StandardTags .keybind ()),
43
45
Map .entry ("translatable" , StandardTags .translatable ()),
44
46
Map .entry ("insertion" , StandardTags .insertion ()),
@@ -55,12 +57,17 @@ private TagPermissions() {
55
57
56
58
public static Component parseTags (final String basePermission , final String message , final Predicate <String > permission , final TagResolver .Builder resolver ) {
57
59
boolean hasAllDecorations = false ;
60
+ boolean hasAllColors = false ;
61
+
58
62
for (final Map .Entry <String , TagResolver > entry : DEFAULT_TAGS .entrySet ()) {
59
63
if (permission .test (basePermission + '.' + entry .getKey ())) {
60
64
resolver .resolver (entry .getValue ());
61
65
if (entry .getKey ().equals ("decorations" )) {
62
66
hasAllDecorations = true ;
63
67
}
68
+ if (entry .getKey ().equals ("hex" )) {
69
+ hasAllColors = true ;
70
+ }
64
71
}
65
72
}
66
73
@@ -74,6 +81,16 @@ public static Component parseTags(final String basePermission, final String mess
74
81
}
75
82
}
76
83
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
+
77
94
final MiniMessage miniMessage = MiniMessage .builder ().tags (resolver .build ()).build ();
78
95
79
96
return miniMessage .deserialize (message );
0 commit comments