Package dev.cwhead.GravesX.util
Class PlayerHeadUtil
java.lang.Object
dev.cwhead.GravesX.util.PlayerHeadUtil
Compact utilities for snapshotting player head (skull) blocks across versions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMinimal serialized data for a skull block.private static final classHolder for mount/orientation. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringappendFromBlock(org.bukkit.block.Block block, String existingReplaceData) Appends a head snapshot (if block is a head) toexistingReplaceData.private static StringcallString(Object target, String modern, String legacy) Invokesmodernor fallbacklegacystring accessor.private static StringKeeps only cardinal directions.private static booleanprivate static StringEscapes backslashes and quotes for JSON.static PlayerHeadUtil.HeadPayloadextract(org.bukkit.block.Block block) Extracts snapshot data from a skull block.private static StringgetBlockDataString(org.bukkit.block.Block block) GetsBlockData#getAsString(true)on 1.13+, elsenull.private static Collection<?> getTextures(Object propertyMap) ReturnsPropertyMap["textures"]as a collection when present.private static booleanisHead(org.bukkit.block.Block b) static Optional<PlayerHeadUtil.HeadPayload> parseFromReplaceData(String replaceData) Parses the last GXHEAD payload fromreplaceData.private static PlayerHeadUtil.HeadPayloadParses the compact JSON back intoPlayerHeadUtil.HeadPayload.private static PlayerHeadUtil.MountFacereadMountAndFaces(org.bukkit.block.Block block) Reads mount and facing via 1.13+ APIs or legacy material data.private static StringsafeMatName(org.bukkit.block.Block b) Returns material name ornull.private static StringSerializes a payload to compact JSON.private static Class<?> Loads a class or returnsnull.private static StringtryReadCustomNameJson(org.bukkit.block.Skull skull) Reads custom name as JSON (Adventure if available; otherwise wraps legacy name).private static StringRemoves surrounding quotes and unescapes JSON string.private static voidwriteInt(StringBuilder sb, String k, int v, boolean always) Writes an int field.private static voidwriteStr(StringBuilder sb, String k, String v) Writes a string field if non-null.
-
Field Details
-
MARKER
Delimiter used to append a GXHEAD JSON payload to replace_data.- See Also:
-
-
Constructor Details
-
PlayerHeadUtil
private PlayerHeadUtil()
-
-
Method Details
-
appendFromBlock
Appends a head snapshot (if block is a head) toexistingReplaceData.- Parameters:
block- the block to readexistingReplaceData- prior replace_data (nullable)- Returns:
- replace_data with
MARKER+JSON appended when applicable
-
parseFromReplaceData
Parses the last GXHEAD payload fromreplaceData.- Parameters:
replaceData- string containing zero or more payloads- Returns:
- last
PlayerHeadUtil.HeadPayload, if present
-
extract
Extracts snapshot data from a skull block.- Parameters:
block- block to inspect- Returns:
- payload or
nullif not a head
-
isHead
private static boolean isHead(org.bukkit.block.Block b) - Returns:
- true if block is any supported head material.
-
safeMatName
Returns material name ornull. -
empty
- Returns:
- true if
sis null/empty.
-
getBlockDataString
GetsBlockData#getAsString(true)on 1.13+, elsenull. -
readMountAndFaces
Reads mount and facing via 1.13+ APIs or legacy material data. -
cardinal
Keeps only cardinal directions. -
tryLoad
Loads a class or returnsnull. -
getTextures
ReturnsPropertyMap["textures"]as a collection when present. -
callString
Invokesmodernor fallbacklegacystring accessor. -
tryReadCustomNameJson
Reads custom name as JSON (Adventure if available; otherwise wraps legacy name). -
toJson
Serializes a payload to compact JSON. -
writeInt
Writes an int field. -
writeStr
Writes a string field if non-null. -
escape
Escapes backslashes and quotes for JSON. -
parseJson
Parses the compact JSON back intoPlayerHeadUtil.HeadPayload. -
unquote
Removes surrounding quotes and unescapes JSON string.
-