Class NmsAPI
This class serves as the primary entry point for accessing version-independent NMS operations, providing a unified interface that abstracts away the complexity of Minecraft's evolving internal APIs. It integrates all provider systems and wrapper components to deliver consistent functionality across 13+ years of Minecraft evolution.
The API is built on a sophisticated provider system that automatically detects the current Minecraft version and selects appropriate implementations for:
- High-performance block manipulation and world operations
- Advanced entity management and spawner mechanics
- Interactive message systems with hover events and click actions
- Direct packet manipulation for custom client-server communication
- Command registration and management systems
- Item manipulation and metadata editing
- Cross-version teleportation without event triggers
- Dual-wielding and main/off-hand item management
Version Support: This API supports Minecraft versions 1.8 through 1.21+, automatically adapting to major API changes including the 1.13 "flattening" update, 1.17 NMS restructuring, and 1.20.5+ Mojang-mapped implementations.
Performance: All NMS operations provided by this API are optimized for performance and bypass normal Bukkit overhead where appropriate, making them suitable for high-frequency operations and bulk world modifications.
Example usage:
// High-performance block operations
AbstractBlockUtil blockUtil = NmsAPI.getBlockUtil();
blockUtil.setBlockSuperFast(block, XMaterial.STONE, PlaceType.NMS);
// Interactive messaging
AbstractMessageManager messageManager = NmsAPI.getMessageManager();
KMessage message = KMessageSingle.ofClickRunCommand("Click me!", "/help");
messageManager.processAndSend(player, message);
// Direct world access
NMSWorld nmsWorld = NmsAPI.getNMSWorld(bukkitWorld);
nmsWorld.refreshBlockAt(player, x, y, z);
// Cross-version item handling
ItemStack mainHand = NmsAPI.getItemInMainHand(player);
NmsAPI.setItemInOffHand(player, itemStack);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractBlockUtil
Retrieves the version-appropriate block utility implementation.static CommandMapModifier
Retrieves the version-appropriate command map modifier implementation.static AbstractEntityMethods
Retrieves the version-appropriate entity methods implementation.static AbstractItemEditor
Retrieves the version-appropriate item editor implementation.static @Nullable ItemStack
getItemInMainHand
(@NotNull Player player) Retrieves the item in the player's main hand.static @Nullable ItemStack
getItemInOffHand
(@NotNull Player player) Retrieves the item in the player's off-hand.static AbstractItemTextPre_1_17
Retrieves the pre-1.17 item text implementation.static Color
getJavaColor
(ChatColor chatColor) Converts a Bukkit ChatColor to an AWT Color object.static AbstractMessageManager
Retrieves the version-appropriate message manager implementation.static String
getNamespaced
(Enchantment enchantment) Retrieves the namespaced identifier for an enchantment.static NmsItemMethods
Retrieves the version-appropriate NMS item methods implementation.static @NotNull NMSWorld
getNMSWorld
(@NotNull World world) Creates an NMS world wrapper for the specified Bukkit world.static NMSPacketHandler
Retrieves the version-appropriate packet handler implementation.static AbstractTeleporter
Retrieves the version-appropriate teleporter implementation.static void
setItemInMainHand
(@NotNull Player player, @Nullable ItemStack itemStack) Sets the item in the player's main hand.static void
setItemInOffHand
(@NotNull Player player, @Nullable ItemStack itemStack) Sets the item in the player's off-hand.
-
Constructor Details
-
NmsAPI
public NmsAPI()
-
-
Method Details
-
getJavaColor
Converts a Bukkit ChatColor to an AWT Color object.This method provides cross-version conversion from Minecraft's chat color system to Java's AWT Color representation. On versions 1.16.2+, this uses native color methods for accurate conversion. On earlier versions, it uses approximated RGB values.
-
getBlockUtil
Retrieves the version-appropriate block utility implementation.Block utilities provide high-performance block manipulation methods that significantly outperform standard Bukkit operations, particularly for bulk modifications like world generation or schematic pasting.
- Returns:
- the
AbstractBlockUtil
for the current Minecraft version
-
getItemText
Retrieves the pre-1.17 item text implementation.This method provides access to item text and tooltip generation systems for Minecraft versions before 1.17. For 1.17+ versions, use the message manager's integrated text components instead.
- Returns:
- the
AbstractItemTextPre_1_17
for pre-1.17 versions
-
getTeleporter
Retrieves the version-appropriate teleporter implementation.Teleporters provide direct NMS-based player teleportation that bypasses Bukkit events, offering improved performance for scenarios requiring rapid or silent player movement.
- Returns:
- the
AbstractTeleporter
for the current Minecraft version
-
getMessageManager
Retrieves the version-appropriate message manager implementation.Message managers handle interactive message processing with support for hover events, click actions, and rich text formatting across different text component systems (Bungee/MD5 vs Kyori Adventure).
- Returns:
- the
AbstractMessageManager
for the current Minecraft version
-
getItemEditor
Retrieves the version-appropriate item editor implementation.Item editors provide advanced ItemMeta manipulation capabilities that extend beyond standard Bukkit API functionality, including properties like unbreakable flags and custom attributes.
- Returns:
- the
AbstractItemEditor
for the current Minecraft version
-
getNmsItemMethods
Retrieves the version-appropriate NMS item methods implementation.NMS item methods provide access to internal item names, translation keys, and other properties that are essential for plugins requiring deep item inspection or compatibility with external systems.
- Returns:
- the
NmsItemMethods
for the current Minecraft version
-
getEntityMethods
Retrieves the version-appropriate entity methods implementation.Entity methods provide advanced entity manipulation capabilities including dimension handling, AI control, persistence settings, and spawner item management across different Minecraft versions.
- Returns:
- the
AbstractEntityMethods
for the current Minecraft version
-
getPacketHandler
Retrieves the version-appropriate packet handler implementation.Packet handlers provide advanced packet manipulation capabilities for custom client-server communication, entity effects, and network operations that go beyond standard Bukkit capabilities.
- Returns:
- the
NMSPacketHandler
for the current Minecraft version
-
getCommandMapModifier
Retrieves the version-appropriate command map modifier implementation.Command map modifiers enable dynamic command registration and unregistration without requiring plugin reloads, supporting features like command aliasing and runtime command modifications.
- Returns:
- the
CommandMapModifier
for the current Minecraft version
-
getItemInMainHand
Retrieves the item in the player's main hand.This method provides cross-version access to main hand items, properly handling the transition from single-hand (1.8) to dual-wielding (1.9+) systems.
-
setItemInMainHand
public static void setItemInMainHand(@NotNull @NotNull Player player, @Nullable @Nullable ItemStack itemStack) Sets the item in the player's main hand.This method provides cross-version main hand item setting, ensuring compatibility across both single-hand and dual-wielding versions.
-
getItemInOffHand
Retrieves the item in the player's off-hand.This method provides cross-version access to off-hand items. On versions before 1.9 (which lack dual-wielding), this always returns
null
. -
setItemInOffHand
public static void setItemInOffHand(@NotNull @NotNull Player player, @Nullable @Nullable ItemStack itemStack) throws UnsupportedOperationException Sets the item in the player's off-hand.This method provides cross-version off-hand item setting. On versions before 1.9 (which lack dual-wielding), this throws an
UnsupportedOperationException
.- Parameters:
player
- thePlayer
to modifyitemStack
- theItemStack
to place in the off-hand, ornull
to clear- Throws:
UnsupportedOperationException
- if called on versions before 1.9
-
getNamespaced
Retrieves the namespaced identifier for an enchantment.This method provides cross-version access to enchantment identifiers, handling the transition from numeric IDs (pre-1.13) to namespaced identifiers (1.13+) introduced by the "flattening" update.
- Parameters:
enchantment
- theEnchantment
to identify- Returns:
- the namespaced identifier string (e.g., "minecraft:sharpness")
-
getNMSWorld
Creates an NMS world wrapper for the specified Bukkit world.This method creates a version-appropriate NMS world wrapper that provides direct access to Minecraft's internal world representation, enabling high-performance world operations, chunk management, and entity spawning.
-