1515public class PlayerPlaceholders {
1616 public static void register () {
1717 Placeholders .register (new Identifier ("player" , "name" ), (ctx , arg ) -> {
18- if (ctx .player () != null ) {
18+ if (ctx .hasPlayer () ) {
1919 return PlaceholderResult .value (ctx .player ().getName ());
20+ } else if (ctx .hasGameProfile ()) {
21+ return PlaceholderResult .value (Text .of (ctx .gameProfile ().getName ()));
2022 } else {
2123 return PlaceholderResult .invalid ("No player!" );
2224 }
2325 });
2426
2527 Placeholders .register (new Identifier ("player" , "name_visual" ), (ctx , arg ) -> {
26- if (ctx .player () != null ) {
28+ if (ctx .hasPlayer () ) {
2729 return PlaceholderResult .value (GeneralUtils .removeHoverAndClick (ctx .player ().getName ()));
30+ } else if (ctx .hasGameProfile ()) {
31+ return PlaceholderResult .value (Text .of (ctx .gameProfile ().getName ()));
2832 } else {
2933 return PlaceholderResult .invalid ("No player!" );
3034 }
3135 });
3236
3337 Placeholders .register (new Identifier ("player" , "name_unformatted" ), (ctx , arg ) -> {
34- if (ctx .player () != null ) {
38+ if (ctx .hasPlayer () ) {
3539 return PlaceholderResult .value (ctx .player ().getName ().getString ());
40+ } else if (ctx .hasGameProfile ()) {
41+ return PlaceholderResult .value (Text .of (ctx .gameProfile ().getName ()));
3642 } else {
3743 return PlaceholderResult .invalid ("No player!" );
3844 }
3945 });
4046
4147 Placeholders .register (new Identifier ("player" , "ping" ), (ctx , arg ) -> {
42- if (ctx .player () != null ) {
48+ if (ctx .hasPlayer () ) {
4349 return PlaceholderResult .value (String .valueOf (ctx .player ().pingMilliseconds ));
4450 } else {
4551 return PlaceholderResult .invalid ("No player!" );
4652 }
4753 });
4854
4955 Placeholders .register (new Identifier ("player" , "ping_colored" ), (ctx , arg ) -> {
50- if (ctx .player () != null ) {
56+ if (ctx .hasPlayer () ) {
5157 int x = ctx .player ().pingMilliseconds ;
5258 return PlaceholderResult .value (Text .literal (String .valueOf (x )).formatted (x < 100 ? Formatting .GREEN : x < 200 ? Formatting .GOLD : Formatting .RED ));
5359 } else {
@@ -56,31 +62,37 @@ public static void register() {
5662 });
5763
5864 Placeholders .register (new Identifier ("player" , "displayname" ), (ctx , arg ) -> {
59- if (ctx .player () != null ) {
65+ if (ctx .hasPlayer () ) {
6066 return PlaceholderResult .value (ctx .player ().getDisplayName ());
67+ } else if (ctx .hasGameProfile ()) {
68+ return PlaceholderResult .value (Text .of (ctx .gameProfile ().getName ()));
6169 } else {
6270 return PlaceholderResult .invalid ("No player!" );
6371 }
6472 });
6573
6674 Placeholders .register (new Identifier ("player" , "displayname_visual" ), (ctx , arg ) -> {
67- if (ctx .player () != null ) {
75+ if (ctx .hasPlayer () ) {
6876 return PlaceholderResult .value (GeneralUtils .removeHoverAndClick (ctx .player ().getDisplayName ()));
77+ } else if (ctx .hasGameProfile ()) {
78+ return PlaceholderResult .value (Text .of (ctx .gameProfile ().getName ()));
6979 } else {
7080 return PlaceholderResult .invalid ("No player!" );
7181 }
7282 });
7383
7484 Placeholders .register (new Identifier ("player" , "displayname_unformatted" ), (ctx , arg ) -> {
75- if (ctx .player () != null ) {
76- return PlaceholderResult .value (ctx .player ().getDisplayName ().getString ());
85+ if (ctx .hasPlayer ()) {
86+ return PlaceholderResult .value (Text .literal (ctx .player ().getDisplayName ().getString ()));
87+ } else if (ctx .hasGameProfile ()) {
88+ return PlaceholderResult .value (Text .of (ctx .gameProfile ().getName ()));
7789 } else {
7890 return PlaceholderResult .invalid ("No player!" );
7991 }
8092 });
8193
8294 Placeholders .register (new Identifier ("player" , "inventory_slot" ), (ctx , arg ) -> {
83- if (ctx .player () != null && arg != null ) {
95+ if (ctx .hasPlayer () && arg != null ) {
8496 try {
8597 int slot = Integer .parseInt (arg );
8698
@@ -102,7 +114,7 @@ public static void register() {
102114 });
103115
104116 Placeholders .register (new Identifier ("player" , "equipment_slot" ), (ctx , arg ) -> {
105- if (ctx .player () != null && arg != null ) {
117+ if (ctx .hasPlayer () && arg != null ) {
106118 try {
107119 var slot = EquipmentSlot .byName (arg );
108120
@@ -118,7 +130,7 @@ public static void register() {
118130 });
119131
120132 Placeholders .register (new Identifier ("player" , "playtime" ), (ctx , arg ) -> {
121- if (ctx .player () != null ) {
133+ if (ctx .hasPlayer () ) {
122134 int x = ctx .player ().getStatHandler ().getStat (Stats .CUSTOM .getOrCreateStat (Stats .PLAY_TIME ));
123135 return PlaceholderResult .value (arg != null
124136 ? DurationFormatUtils .formatDuration ((long ) x * 50 , arg , true )
@@ -130,7 +142,7 @@ public static void register() {
130142 });
131143
132144 Placeholders .register (new Identifier ("player" , "statistic" ), (ctx , arg ) -> {
133- if (ctx .player () != null && arg != null ) {
145+ if (ctx .hasPlayer () && arg != null ) {
134146 try {
135147 Identifier identifier = Identifier .tryParse (arg );
136148 if (identifier != null ) {
@@ -147,7 +159,7 @@ public static void register() {
147159 });
148160
149161 Placeholders .register (new Identifier ("player" , "pos_x" ), (ctx , arg ) -> {
150- if (ctx .player () != null ) {
162+ if (ctx .hasPlayer () ) {
151163 double value = ctx .player ().getX ();
152164 String format = "%.2f" ;
153165
@@ -167,7 +179,7 @@ public static void register() {
167179 });
168180
169181 Placeholders .register (new Identifier ("player" , "pos_y" ), (ctx , arg ) -> {
170- if (ctx .player () != null ) {
182+ if (ctx .hasPlayer () ) {
171183 double value = ctx .player ().getY ();
172184 String format = "%.2f" ;
173185
@@ -187,7 +199,7 @@ public static void register() {
187199 });
188200
189201 Placeholders .register (new Identifier ("player" , "pos_z" ), (ctx , arg ) -> {
190- if (ctx .player () != null ) {
202+ if (ctx .hasPlayer () ) {
191203 double value = ctx .player ().getZ ();
192204 String format = "%.2f" ;
193205
@@ -207,39 +219,41 @@ public static void register() {
207219 });
208220
209221 Placeholders .register (new Identifier ("player" , "uuid" ), (ctx , arg ) -> {
210- if (ctx .player () != null ) {
222+ if (ctx .hasPlayer () ) {
211223 return PlaceholderResult .value (ctx .player ().getUuidAsString ());
224+ } else if (ctx .hasGameProfile ()) {
225+ return PlaceholderResult .value (Text .of ("" + ctx .gameProfile ().getId ()));
212226 } else {
213227 return PlaceholderResult .invalid ("No player!" );
214228 }
215229 });
216230
217231 Placeholders .register (new Identifier ("player" , "health" ), (ctx , arg ) -> {
218- if (ctx .player () != null ) {
232+ if (ctx .hasPlayer () ) {
219233 return PlaceholderResult .value (String .format ("%.0f" , ctx .player ().getHealth ()));
220234 } else {
221235 return PlaceholderResult .invalid ("No player!" );
222236 }
223237 });
224238
225239 Placeholders .register (new Identifier ("player" , "max_health" ), (ctx , arg ) -> {
226- if (ctx .player () != null ) {
240+ if (ctx .hasPlayer () ) {
227241 return PlaceholderResult .value (String .format ("%.0f" , ctx .player ().getMaxHealth ()));
228242 } else {
229243 return PlaceholderResult .invalid ("No player!" );
230244 }
231245 });
232246
233247 Placeholders .register (new Identifier ("player" , "hunger" ), (ctx , arg ) -> {
234- if (ctx .player () != null ) {
248+ if (ctx .hasPlayer () ) {
235249 return PlaceholderResult .value (String .format ("%.0f" , ctx .player ().getHungerManager ().getFoodLevel ()));
236250 } else {
237251 return PlaceholderResult .invalid ("No player!" );
238252 }
239253 });
240254
241255 Placeholders .register (new Identifier ("player" , "saturation" ), (ctx , arg ) -> {
242- if (ctx .player () != null ) {
256+ if (ctx .hasPlayer () ) {
243257 return PlaceholderResult .value (String .format ("%.0f" , ctx .player ().getHungerManager ().getSaturationLevel ()));
244258 } else {
245259 return PlaceholderResult .invalid ("No player!" );
0 commit comments