3333import org .bukkit .entity .Player ;
3434import org .bukkit .potion .PotionEffectType ;
3535
36- import java .util .Date ;
37- import java .util .HashMap ;
38- import java .util .Map ;
39- import java .util .Optional ;
40-
36+ import java .util .*;
37+ import java .util .regex .Matcher ;
38+ import java .util .regex .Pattern ;
39+ import static com .extendedclip .papi .expansion .player .PlayerUtil .durability ;
4140import static com .extendedclip .papi .expansion .player .PlayerUtil .format12 ;
4241import static com .extendedclip .papi .expansion .player .PlayerUtil .format24 ;
4342import static com .extendedclip .papi .expansion .player .PlayerUtil .getBiome ;
4443import static com .extendedclip .papi .expansion .player .PlayerUtil .getCapitalizedBiome ;
45- import static com .extendedclip .papi .expansion .player .PlayerUtil .getCardinalDirection ;
4644import static com .extendedclip .papi .expansion .player .PlayerUtil .getEmptySlots ;
45+ import static com .extendedclip .papi .expansion .player .PlayerUtil .getDirection ;
4746import static com .extendedclip .papi .expansion .player .PlayerUtil .getTotalExperience ;
4847import static com .extendedclip .papi .expansion .player .PlayerUtil .getXZDirection ;
4948import static com .extendedclip .papi .expansion .player .PlayerUtil .itemInHand ;
5049
5150public final class PlayerExpansion extends PlaceholderExpansion implements Configurable {
52-
53- private final String VERSION = getClass ().getPackage ().getImplementationVersion ();
54-
5551 private String low ;
5652 private String medium ;
5753 private String high ;
5854
55+ private int mediumValue ;
56+ private int highValue ;
57+
58+ private String north ;
59+ private String northEast ;
60+ private String east ;
61+ private String southEast ;
62+ private String south ;
63+ private String southWest ;
64+ private String west ;
65+ private String northWest ;
66+
5967 @ Override
6068 public String getIdentifier () {
6169 return "player" ;
@@ -68,7 +76,7 @@ public String getAuthor() {
6876
6977 @ Override
7078 public String getVersion () {
71- return VERSION ;
79+ return "2.0.2" ;
7280 }
7381
7482 @ Override
@@ -77,6 +85,16 @@ public Map<String, Object> getDefaults() {
7785 defaults .put ("ping_color.high" , "&c" );
7886 defaults .put ("ping_color.medium" , "&e" );
7987 defaults .put ("ping_color.low" , "&a" );
88+ defaults .put ("ping_value.medium" , 50 );
89+ defaults .put ("ping_value.high" , 100 );
90+ defaults .put ("direction.north" , "N" );
91+ defaults .put ("direction.north_east" , "NE" );
92+ defaults .put ("direction.east" , "E" );
93+ defaults .put ("direction.south_east" , "SE" );
94+ defaults .put ("direction.south" , "S" );
95+ defaults .put ("direction.south_west" , "SW" );
96+ defaults .put ("direction.west" , "W" );
97+ defaults .put ("direction.north_west" , "NW" );
8098 return defaults ;
8199 }
82100
@@ -131,6 +149,7 @@ public String onRequest(OfflinePlayer player, String identifier) {
131149 case "bed_world" :
132150 return player .getBedSpawnLocation () != null ? player .getBedSpawnLocation ().getWorld ()
133151 .getName () : "" ;
152+
134153 }
135154
136155 // online placeholders
@@ -140,6 +159,11 @@ public String onRequest(OfflinePlayer player, String identifier) {
140159
141160 Player p = player .getPlayer ();
142161
162+ // to get rid of IDE warnings
163+ if (p == null ) {
164+ return "" ;
165+ }
166+
143167 if (identifier .startsWith ("has_permission_" )) {
144168 if (identifier .split ("has_permission_" ).length > 1 ) {
145169 String perm = identifier .split ("has_permission_" )[1 ];
@@ -171,7 +195,41 @@ public String onRequest(OfflinePlayer player, String identifier) {
171195 return "0" ;
172196 }
173197
198+ if (identifier .startsWith ("locale" )) {
199+ String localeStr = PlayerUtil .getLocale (p );
200+ String localeStrISO = localeStr .replace ("_" , "-" );
201+
202+ switch (identifier ) {
203+ case "locale" :
204+ return localeStr ;
205+ case "locale_country" :
206+ Locale locale = Locale .forLanguageTag (localeStrISO );
207+ if (locale == null )
208+ return "" ;
209+ return locale .getCountry ();
210+ case "locale_display_country" :
211+ locale = Locale .forLanguageTag (localeStrISO );
212+ if (locale == null )
213+ return "" ;
214+ return locale .getDisplayCountry ();
215+ case "locale_display_name" :
216+ locale = Locale .forLanguageTag (localeStrISO );
217+ if (locale == null )
218+ return "" ;
219+ return locale .getDisplayName ();
220+ case "locale_short" :
221+ return localeStr .substring (0 , localeStr .indexOf ("_" ));
222+ }
223+ }
224+
174225 switch (identifier ) {
226+ case "absorption" : {
227+ if (VersionHelper .HAS_ABSORPTION_METHODS ) {
228+ return Integer .toString ((int ) p .getAbsorptionAmount ());
229+ } else {
230+ return "-1" ;
231+ }
232+ }
175233 case "has_empty_slot" :
176234 return bool (p .getInventory ().firstEmpty () > -1 );
177235 case "empty_slots" :
@@ -183,12 +241,28 @@ public String onRequest(OfflinePlayer player, String identifier) {
183241 return p .getDisplayName ();
184242 case "list_name" :
185243 return p .getPlayerListName ();
186- case "locale" :
187- return p .getLocale ();
188244 case "gamemode" :
189245 return p .getGameMode ().name ();
190246 case "direction" :
191- return getCardinalDirection (p );
247+ switch (getDirection (p )) {
248+ case NORTH :
249+ return north ;
250+ case NORTH_EAST :
251+ return northEast ;
252+ case EAST :
253+ return east ;
254+ case SOUTH_EAST :
255+ return southEast ;
256+ case SOUTH :
257+ return south ;
258+ case SOUTH_WEST :
259+ return southWest ;
260+ case WEST :
261+ return west ;
262+ case NORTH_WEST :
263+ return northWest ;
264+ }
265+ return "" ;
192266 case "direction_xz" :
193267 return getXZDirection (p );
194268 case "world" :
@@ -205,10 +279,16 @@ public String onRequest(OfflinePlayer player, String identifier) {
205279 return "" ;
206280 case "x" :
207281 return String .valueOf (p .getLocation ().getBlockX ());
282+ case "x_long" :
283+ return String .valueOf (p .getLocation ().getX ());
208284 case "y" :
209285 return String .valueOf (p .getLocation ().getBlockY ());
286+ case "y_long" :
287+ return String .valueOf (p .getLocation ().getY ());
210288 case "z" :
211289 return String .valueOf (p .getLocation ().getBlockZ ());
290+ case "z_long" :
291+ return String .valueOf (p .getLocation ().getZ ());
212292 case "yaw" :
213293 return String .valueOf (p .getLocation ().getYaw ());
214294 case "pitch" :
@@ -233,6 +313,8 @@ public String onRequest(OfflinePlayer player, String identifier) {
233313 return p .getCompassTarget () != null ? String .valueOf (p .getCompassTarget ().getBlockZ ()) : "" ;
234314 case "compass_world" :
235315 return p .getCompassTarget () != null ? p .getCompassTarget ().getWorld ().getName () : "" ;
316+ case "block_underneath" :
317+ return String .valueOf (p .getLocation ().clone ().subtract (0 , 1 , 0 ).getBlock ().getType ());
236318 case "custom_name" :
237319 return p .getCustomName () != null ? p .getCustomName () : p .getName ();
238320 case "exp" :
@@ -261,12 +343,16 @@ public String onRequest(OfflinePlayer player, String identifier) {
261343 return itemInHand (p ).getType () != Material .AIR && itemInHand (p ).getItemMeta ().hasDisplayName () ? itemInHand (p ).getItemMeta ().getDisplayName () : "" ;
262344 case "item_in_hand_data" :
263345 return itemInHand (p ).getType () != Material .AIR ? String .valueOf (itemInHand (p ).getDurability ()) : "0" ;
346+ case "item_in_hand_durability" :
347+ return String .valueOf (durability (itemInHand (p )));
264348 case "item_in_offhand" :
265349 return String .valueOf (p .getInventory ().getItemInOffHand ().getType ());
266350 case "item_in_offhand_name" :
267351 return p .getInventory ().getItemInOffHand ().getType () != Material .AIR && p .getInventory ().getItemInOffHand ().getItemMeta ().hasDisplayName () ? p .getInventory ().getItemInOffHand ().getItemMeta ().getDisplayName () : "" ;
268352 case "item_in_offhand_data" :
269353 return p .getInventory ().getItemInOffHand ().getType () != Material .AIR ? String .valueOf (p .getInventory ().getItemInOffHand ().getDurability ()) : "0" ;
354+ case "item_in_offhand_durability" :
355+ return String .valueOf (durability (p .getInventory ().getItemInOffHand ()));
270356 case "last_damage" :
271357 return String .valueOf (p .getLastDamage ());
272358 case "max_health" :
@@ -283,18 +369,26 @@ public String onRequest(OfflinePlayer player, String identifier) {
283369 return Optional .ofNullable (p .getInventory ().getHelmet ()).map (a -> a .getItemMeta ().getDisplayName ()).orElse ("" );
284370 case "armor_helmet_data" :
285371 return p .getInventory ().getHelmet () != null ? String .valueOf (p .getInventory ().getHelmet ().getDurability ()) : "0" ;
372+ case "armor_helmet_durability" :
373+ return String .valueOf (durability (p .getInventory ().getHelmet ()));
286374 case "armor_chestplate_name" :
287375 return Optional .ofNullable (p .getInventory ().getChestplate ()).map (a -> a .getItemMeta ().getDisplayName ()).orElse ("" );
288376 case "armor_chestplate_data" :
289377 return p .getInventory ().getChestplate () != null ? String .valueOf (p .getInventory ().getChestplate ().getDurability ()) : "0" ;
378+ case "armor_chestplate_durability" :
379+ return String .valueOf (durability (p .getInventory ().getChestplate ()));
290380 case "armor_leggings_name" :
291381 return Optional .ofNullable (p .getInventory ().getLeggings ()).map (a -> a .getItemMeta ().getDisplayName ()).orElse ("" );
292382 case "armor_leggings_data" :
293383 return p .getInventory ().getLeggings () != null ? String .valueOf (p .getInventory ().getLeggings ().getDurability ()) : "0" ;
384+ case "armor_leggings_durability" :
385+ return String .valueOf (durability (p .getInventory ().getLeggings ()));
294386 case "armor_boots_name" :
295387 return Optional .ofNullable (p .getInventory ().getBoots ()).map (a -> a .getItemMeta ().getDisplayName ()).orElse ("" );
296388 case "armor_boots_data" :
297389 return p .getInventory ().getBoots () != null ? String .valueOf (p .getInventory ().getBoots ().getDurability ()) : "0" ;
390+ case "armor_boots_durability" :
391+ return String .valueOf (durability (p .getInventory ().getBoots ()));
298392 case "ping" :
299393 return retrievePing (p , false );
300394 case "colored_ping" :
@@ -314,9 +408,9 @@ public String onRequest(OfflinePlayer player, String identifier) {
314408 case "ticks_lived" :
315409 return String .valueOf (p .getTicksLived ());
316410 case "seconds_lived" :
317- return String .valueOf (p .getTicksLived () * 20 );
411+ return String .valueOf (p .getTicksLived () / 20 );
318412 case "minutes_lived" :
319- return String .valueOf ((p .getTicksLived () * 20 ) / 60 );
413+ return String .valueOf ((p .getTicksLived () / 20 ) / 60 );
320414 case "walk_speed" :
321415 return String .valueOf (p .getWalkSpeed ());
322416 case "weather_duration" :
@@ -327,6 +421,22 @@ public String onRequest(OfflinePlayer player, String identifier) {
327421 return format12 (p .getWorld ().getTime ());
328422 case "world_time_24" :
329423 return format24 (p .getWorld ().getTime ());
424+ case "is_flying" :
425+ return bool (p .isFlying ());
426+ case "is_sleeping" :
427+ return bool (p .isSleeping ());
428+ case "is_conversing" :
429+ return bool (p .isConversing ());
430+ case "is_dead" :
431+ return bool (p .isDead ());
432+ case "is_sneaking" :
433+ return bool (p .isSneaking ());
434+ case "is_sprinting" :
435+ return bool (p .isSprinting ());
436+ case "is_leashed" :
437+ return bool (p .isLeashed ());
438+ case "is_inside_vehicle" :
439+ return bool (p .isInsideVehicle ());
330440 }
331441 // return null for unknown placeholders
332442 return null ;
@@ -337,6 +447,17 @@ public boolean register() {
337447 low = this .getString ("ping_color.low" , "&a" );
338448 medium = this .getString ("ping_color.medium" , "&e" );
339449 high = this .getString ("ping_color.high" , "&c" );
450+ mediumValue = this .getInt ("ping_value.medium" , 50 );
451+ highValue = this .getInt ("ping_value.high" , 100 );
452+ north = this .getString ("direction.north" , "N" );
453+ northEast = this .getString ("direction.north_east" , "NE" );
454+ east = this .getString ("direction.east" , "E" );
455+ southEast = this .getString ("direction.south_east" , "SE" );
456+ south = this .getString ("direction.south" , "S" );
457+ southWest = this .getString ("direction.south_west" , "SW" );
458+ west = this .getString ("direction.west" , "W" );
459+ northWest = this .getString ("direction.north_west" , "NW" );
460+
340461
341462 return super .register ();
342463 }
@@ -352,7 +473,7 @@ private String retrievePing(final Player player, final boolean colored) {
352473 return String .valueOf (ping );
353474 }
354475
355- return ChatColor .translateAlternateColorCodes ('&' , ping > 100 ? high : ping > 50 ? medium : low ) + ping ;
476+ return ChatColor .translateAlternateColorCodes ('&' , ping > highValue ? high : ping > mediumValue ? medium : low ) + ping ;
356477 }
357478
358479}
0 commit comments