11package io .github .miniplaceholders .expansion .luckperms .common ;
22
33import io .github .miniplaceholders .api .Expansion ;
4- import io .github .miniplaceholders .api .utils .LegacyUtils ;
54import net .kyori .adventure .audience .Audience ;
65import net .kyori .adventure .identity .Identity ;
76import net .kyori .adventure .text .Component ;
1110import net .luckperms .api .model .group .Group ;
1211import net .luckperms .api .model .user .User ;
1312import net .luckperms .api .util .Tristate ;
13+ import org .jetbrains .annotations .NotNull ;
14+ import org .jetbrains .annotations .Nullable ;
1415
1516import java .util .UUID ;
1617
1718import static io .github .miniplaceholders .api .utils .Components .*;
19+ import static io .github .miniplaceholders .api .utils .LegacyUtils .LEGACY_HEX_SERIALIZER ;
20+ import static net .kyori .adventure .text .minimessage .MiniMessage .miniMessage ;
1821
1922public record CommonExpansion (LuckPerms luckPerms ) {
2023 private static final Component UNDEFINED_COMPONENT = Component .text ("undefined" , NamedTextColor .GRAY );
@@ -26,14 +29,14 @@ public Expansion.Builder commonBuilder() {
2629 if (user == null ) {
2730 return null ;
2831 }
29- return Tag .inserting (LegacyUtils . parsePossibleLegacy (user .getCachedData ().getMetaData ().getPrefix ()));
32+ return Tag .inserting (parsePossibleLegacy (user .getCachedData ().getMetaData ().getPrefix ()));
3033 })
3134 .audiencePlaceholder ("suffix" , (aud , queue , ctx ) -> {
3235 final User user = user (aud );
3336 if (user == null ) {
3437 return null ;
3538 }
36- return Tag .inserting (LegacyUtils . parsePossibleLegacy (user .getCachedData ().getMetaData ().getSuffix ()));
39+ return Tag .inserting (parsePossibleLegacy (user .getCachedData ().getMetaData ().getSuffix ()));
3740 })
3841 .audiencePlaceholder ("has_permission" , (aud , queue , ctx ) -> {
3942 final User user = user (aud );
@@ -67,7 +70,7 @@ public Expansion.Builder commonBuilder() {
6770 return null ;
6871 }
6972 final Component groups = user .getInheritedGroups (user .getQueryOptions ()).stream ()
70- .map (group -> LegacyUtils . parsePossibleLegacy (group .getDisplayName ()))
73+ .map (group -> parsePossibleLegacy (group .getDisplayName ()))
7174 .collect (Component .toComponent (Component .text (", " )));
7275 return Tag .selfClosingInserting (groups );
7376 })
@@ -102,4 +105,17 @@ private User user(final Audience audience) {
102105 }
103106 return luckPerms .getUserManager ().getUser (uuid );
104107 }
108+
109+ public static @ NotNull Component parsePossibleLegacy (final @ Nullable String string ) {
110+ if (string == null || string .isBlank ()) return Component .empty ();
111+ if (string .indexOf ('&' ) != 0 ) {
112+ return miniMessage ().deserialize (
113+ miniMessage ().serialize (LEGACY_HEX_SERIALIZER .deserialize (string ))
114+ .replace ("\\ <" , "<" )
115+ .replace ("\\ >" , ">" )
116+ );
117+ } else {
118+ return miniMessage ().deserialize (string );
119+ }
120+ }
105121}
0 commit comments