Class NmsBridge

java.lang.Object
com.github.pinont.singularitylib.api.nms.NmsBridge

public final class NmsBridge extends Object
Soft-loading bridge to the optional SingularityNMS module.

The lib is designed to run WITHOUT SingularityNMS installed: all NMS access is funneled through this class, which reflectively probes for com.github.pinont.singularitynms.* at runtime. When the NMS plugin (or jar) is present on the server, deep vanilla-NBT operations become available; otherwise the bridge reports isAvailable() == false and callers degrade gracefully (e.g. fall back to PersistentDataContainer).

Bootstrap-model note: SingularityNMS ships as its own jar; on a server with both plugins installed, consumers get NMS-backed item/entity NBT through this neutral seam with no compile-time dependency.

  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.inventory.ItemStack
    applyItemNbt(org.bukkit.inventory.ItemStack item, Object nbt)
    Writes processed NBT back to an item via the NMS applyTo(ItemStack); returns the new ItemStack (NMS treats Bukkit stacks as value copies) or the original when NMS is unavailable.
    static boolean
    hasVanillaNbt(org.bukkit.inventory.ItemStack item)
    Convenience: whether an item currently carries vanilla custom_data (best-effort; only meaningful when NMS is available).
    static boolean
     
    static @Nullable Object
    readItemNbt(org.bukkit.inventory.ItemStack item)
    Reads the vanilla NBT of an item as a raw Object (actually singularitynms.nbt.NbtCompound) — usable via reflection only, or null when NMS is unavailable.
    static Map<String,String>
    readItemNbtAsMap(org.bukkit.inventory.ItemStack item)
    Returns a map of the item's vanilla NBT keys to their SNBT string values (best-effort via reflection on the NMS NbtCompound; empty when NMS is absent).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isAvailable

      public static boolean isAvailable()
      Returns:
      true if the SingularityNMS classes are loadable on this runtime
    • readItemNbt

      @Nullable public static @Nullable Object readItemNbt(org.bukkit.inventory.ItemStack item)
      Reads the vanilla NBT of an item as a raw Object (actually singularitynms.nbt.NbtCompound) — usable via reflection only, or null when NMS is unavailable.
    • applyItemNbt

      public static org.bukkit.inventory.ItemStack applyItemNbt(org.bukkit.inventory.ItemStack item, Object nbt)
      Writes processed NBT back to an item via the NMS applyTo(ItemStack); returns the new ItemStack (NMS treats Bukkit stacks as value copies) or the original when NMS is unavailable.
    • hasVanillaNbt

      public static boolean hasVanillaNbt(org.bukkit.inventory.ItemStack item)
      Convenience: whether an item currently carries vanilla custom_data (best-effort; only meaningful when NMS is available).
    • readItemNbtAsMap

      public static Map<String,String> readItemNbtAsMap(org.bukkit.inventory.ItemStack item)
      Returns a map of the item's vanilla NBT keys to their SNBT string values (best-effort via reflection on the NMS NbtCompound; empty when NMS is absent). Used by the DevTool inspector to display raw NBT without compile-time NMS deps.