Class CompatibilityUtil
java.lang.Object
me.mehboss.utils.CompatibilityUtil
Utility class providing cross-version compatibility helpers that rely on
reflection to handle differences between Minecraft / Bukkit versions.
This includes:
- Accessing InventoryView methods safely across versions
- Retrieving players, titles, and top inventories without relying on version-specific classes
- Reflection helpers for invoking private methods and fields
- Base64 decoding for skin texture analysis
- Item name getters/setters supporting 1.20.5+ name changes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringextractUrlFromBase64(String base64Texture) Extracts the skin texture URL from a Base64-encoded JSON texture payload.static StringgetDisplayname(org.bukkit.inventory.meta.ItemMeta item) Retrieves the display name from an item.static ObjectgetInventoryView(org.bukkit.event.inventory.InventoryEvent event) Retrieves the InventoryView from anInventoryEventusing reflection.static Methodstatic org.bukkit.entity.PlayergetPlayerFromView(Object view) Extracts thePlayerfrom an InventoryView instance using reflection.static StringgetTitle(org.bukkit.event.inventory.InventoryEvent event) Retrieves an inventory's title reflectively.static org.bukkit.inventory.InventorygetTopInventory(org.bukkit.event.inventory.InventoryEvent event) Retrieves the top inventory from anInventoryEventusing reflection.static booleanhasDisplayname(org.bukkit.inventory.meta.ItemMeta item) Checks if an item has a display name.static voidinvokeMethod(Method method, Object instance, Object... args) static org.bukkit.inventory.meta.ItemMetasetDisplayname(org.bukkit.inventory.ItemStack item, String name) Sets an item's display name using version-aware APIs.static voidsetFieldValue(Object instance, String fieldName, Object value)
-
Constructor Details
-
CompatibilityUtil
public CompatibilityUtil()
-
-
Method Details
-
getInventoryView
Retrieves the InventoryView from anInventoryEventusing reflection.Different server versions may change how InventoryView is exposed, so this reflective access ensures compatibility.
- Parameters:
event- The inventory event.- Returns:
- The InventoryView object (returned as
Objectfor compatibility).
-
getPlayerFromView
Extracts thePlayerfrom an InventoryView instance using reflection.- Parameters:
view- The InventoryView object.- Returns:
- The player who opened the inventory, or
nullif unavailable.
-
getTopInventory
public static org.bukkit.inventory.Inventory getTopInventory(org.bukkit.event.inventory.InventoryEvent event) Retrieves the top inventory from anInventoryEventusing reflection.- Parameters:
event- The inventory event.- Returns:
- The top inventory (e.g. chest, crafting grid).
-
getTitle
Retrieves an inventory's title reflectively.Some Bukkit versions moved
getTitle()into subclasses, so this method uses superclass traversal for compatibility.- Parameters:
event- The inventory event.- Returns:
- Title of the inventory window.
-
getMethod
-
invokeMethod
-
setFieldValue
-
extractUrlFromBase64
-
hasDisplayname
public static boolean hasDisplayname(org.bukkit.inventory.meta.ItemMeta item) Checks if an item has a display name. Supports Bukkit name API changes introduced in Minecraft 1.20.5.- Parameters:
item- ItemMeta to inspect.- Returns:
- True if the item has a custom name.
-
getDisplayname
Retrieves the display name from an item.- Parameters:
item- ItemMeta from which to read the name.- Returns:
- The custom display name.
-
setDisplayname
public static org.bukkit.inventory.meta.ItemMeta setDisplayname(org.bukkit.inventory.ItemStack item, String name) Sets an item's display name using version-aware APIs.In 1.20.5+:
- New naming system applies to all items except potion variants.
- Parameters:
item- The item whose meta should be modified.name- The new display name (supports color codes).- Returns:
- The updated ItemMeta with the new name applied.
-