BKCommonLib

repository·master·Indexed 42 days ago

https://github.com/bergerhealer/bkcommonlib

A utility library and plugin for Minecraft server software (Spigot, Paper, Bukkit, and others) that abstracts NMS to provide stable, version-independent APIs. It includes features such as the PluginBase framework, a custom YAML library, ForcedChunk API, Map Display API, and integration with the Cloud Command Framework. Compatible with Minecraft versions 1.8 and above.

Tokens
10.9K
Snippets
17
Records
28
Agent score
53%

What's inside BKCommonLib

  1. Overview of BKCommonLib features

    master

    BKCommonLib is a comprehensive utility library for Minecraft server development, providing high-level abstractions for complex tasks. Core features include:

    • Mountiplex: A reflection and code generation library that uses templates to support multiple Minecraft versions and Forge simultaneously.
    • Cloud Command Framework: A modern command API with annotations and builders.
    • Protocol API: A multi-version compatible packet API for creating fake entities and modifying packets.
    • Entity Controllers: Allows overriding entity behavior (like onTick or onMove) at runtime.
    • NBT - CommonTag API: A user-friendly wrapper for interacting with the server's internal NBT library.
    • Block Utilities: Includes OfflineBlock, OfflineWorld, SignChangeTracker, and a cross-version BlockData API.
  2. Overview of BKCommonLib

    master

    BKCommonLib is a utility library and plugin for Paper, Spigot, and Bukkit servers. It provides a wide range of APIs, frameworks, and performance-critical code designed to abstract away Minecraft Server Code (NMS).

    By using BKCommonLib, plugin developers can avoid direct NMS dependencies, which improves plugin stability and reduces the need for frequent updates when Minecraft versions change. Instead of updating every plugin when Minecraft updates, you typically only need to update BKCommonLib.

  3. Use the Map Display API for interactive maps

    master

    The Map Display API allows you to draw 2D/3D content onto Minecraft maps or texture buffers. It is designed to be much more powerful than the standard Bukkit Map API.

    Key capabilities:

    • Automatic Loading: Uses Item Metadata to load displays automatically.
    • Rendering: Supports Minecraft assets (blocks, items), resource packs, and scientific RGB to Map Color conversion.
    • Interaction: Handles left/right-click events with pixel coordinates.
    • Widgets: Includes built-in menu navigation, buttons, text, and tab views using vehicle steering controls (W/A/S/D/Space/Sneak).
  4. Understand BKCommonLib version compatibility

    master

    BKCommonLib is designed to be backwards-compatible. The latest version of BKCommonLib is compatible with all Minecraft versions 1.8 and above.

    For example, BKCommonLib version 1.19 can be used on Spigot 1.12.2, Paper 1.16.5, or Pufferfish 1.18.2.

    Important: Do not install an older version of BKCommonLib specifically to support an older version of Minecraft; always aim for the latest version to maintain compatibility.

  5. Implement the PluginBase framework

    master

    Instead of extending JavaPlugin, you can implement PluginBase. This provides several advanced features:

    • Plugin Preloader support.
    • Lifecycle Callbacks: Handle logic when other plugins enable/disable.
    • Metadata: Read custom metadata from plugin.yml.
    • Dependency Validation: Ensures all required plugins are enabled.
    • Permission API: Supports * wildcards, configurable defaults via PermissionDefaults.yml, and simple enum/static based constants.
    • Localization API: Automatically generates Localization.yml with placeholder support (%0%, %1%, etc.).
  6. Add BKCommonLib as a Maven dependency

    master

    To use BKCommonLib in your Maven project, add the MG-Dev Jenkins CI Maven Repository to your <repositories> section and include the BKCommonLib dependency with a provided scope. Note that you should update the version string to the latest available version as necessary.

    <repositories>
        <repository>
            <id>MG-Dev Jenkins CI Maven Repository</id>
            <url>https://ci.mg-dev.eu/plugin/repository/everything</url>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>com.bergerkiller.bukkit</groupId>
            <artifactId>BKCommonLib</artifactId>
            <version>1.20.4-v1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
  7. Migrate from Spigot to Mojang mappings

    master

    As of BKCommonLib v2.0.0 (released 2026-03-31), the generated NMS Handle class names have migrated from Spigot-style mappings to Mojang (mojmap) mappings.

    If your project relies on net.minecraft.server imports or uses custom generated templates that reference these handles, you must update your imports, code references, and templates to match the new Mojang-style naming convention to maintain compatibility with BKCommonLib v2.0.0 and later.

    # Migration applies to BKCommonLib v2.0.0 onwards
  8. Configure Gradle (Groovy) to use Cloud Command Framework via BKCommonLib

    master

    To use Cloud in a Gradle project using Groovy DSL (build.gradle), follow these steps:

    1. Add plugins: Ensure java, java-library, and com.github.johnrengelman.shadow (version 8.1.1) are applied.
    2. Add the repository: Include https://ci.mg-dev.eu/plugin/repository/everything.
    3. Add dependencies: Use compileOnlyApi for BKCommonLib and compileOnly for the Cloud dependencies. Note that if you use Adventure MiniMessage, you may need to add net.kyori:adventure-api and net.kyori:adventure-text-minimessage as implementation dependencies.
    4. Shadow/Relocate: Use the shadowJar task to relocate the packages to the com.bergerkiller.bukkit.common.dep prefix.
    plugins {
        id "java"
        id "com.github.johnrengelman.shadow" version "8.1.1"
        id "java-library"
    }
    
    repositories {
        mavenCentral()
        maven {
            url = "https://ci.mg-dev.eu/plugin/repository/everything"
        }
    }
    
    dependencies {
        // BKCommonLib
        compileOnlyApi("com.bergerkiller.bukkit:BKCommonLib:1.21.1-v1")
    
        // Cloud integrated in BKCommonLib
        compileOnly("org.incendo:cloud-paper")
        compileOnly("org.incendo:cloud-annotations")
        compileOnly("org.incendo:cloud-minecraft-extras")
    
        // Adventure MiniMessage
        implementation("net.kyori:adventure-api:4.14.0")
        implementation("net.kyori:adventure-text-minimessage:4.14.0")
    }
    
    tasks.shadowJar {
        def commonPrefix = "com.bergerkiller.bukkit.common.dep"
        relocate("org.incendo.cloud", "${commonPrefix}.cloud")
        relocate("io.leangen.geantyref", "${commonPrefix}.typetoken")
        relocate("me.lucko.commodore", "${commonPrefix}.me.lucko.commodore")
        relocate("net.kyori", "${commonPrefix}.net.kyori")
    }
  9. Check BKCommonLib server compatibility

    master

    BKCommonLib is compatible with the following server implementations:

    Primary Support

    • Spigot, PaperMC, Pufferfish, Purpur, Tuinity, TacoSpigot
    • Most other forks of the above are expected to work.

    Forge Paper Hybrids (with limitations)

    • Mohist: 1.12.2 and 1.16.5
    • Magma: 1.12.2
    • Arclight: 1.12.2, 1.15.2, 1.16.5, and 1.18.2
    • CatServer: 1.12.2
  10. Visualize Spigot to Mojang mappings using SpigotMappingTest

    master

    If you cannot find a matching Mojang-style name for a Spigot class (handle or otherwise), use the SpigotMappingTest.testVisualizeMappings() helper to find the mapping.

    1. Open src/test/java/com/bergerkiller/bukkit/common/SpigotMappingTest.java.
    2. Locate the testVisualizeMappings() method.
    3. Replace the example argument with the fully-qualified Spigot class name (or a keyword) you wish to investigate.
    4. Run the test via your IDE or Gradle.

    The visualization will print the known mappings, showing the associated Mojang name(s) and versions. For more specific lookups, you can use visualizeMappingsForSpigotClass or visualizeMappingsForMojangClass.

    // example: visualize the mapping for the old Spigot packet class
    mappings.visualizeMapping("net.minecraft.network.protocol.game.PacketPlayOutStatistic");

    To run via Gradle:

    ./gradlew test --tests "com.bergerkiller.bukkit.common.SpigotMappingTest.testVisualizeMappings"
  11. Configure Gradle (Kotlin) to use Cloud Command Framework via BKCommonLib

    master

    To use Cloud in a Gradle project using Kotlin DSL (build.gradle.kts), follow these steps:

    1. Requirement: Use Gradle 8.5 or newer.
    2. Add the repository: Include https://ci.mg-dev.eu/plugin/repository/everything/.
    3. Add dependencies: Use compileOnlyApi for BKCommonLib and compileOnly for the Cloud dependencies (cloud-paper, cloud-annotations, cloud-minecraft-extras). Do not specify versions for Cloud; they are provided by BKCommonLib.
    4. Shadow/Relocate: Use the com.github.johnrengelman.shadow plugin to relocate the packages to the com.bergerkiller.bukkit.common.dep prefix.
    repositories {
        maven("https://ci.mg-dev.eu/plugin/repository/everything/")
    }
    
    dependencies {
        compileOnlyApi("com.bergerkiller.bukkit:BKCommonLib:1.21.1-v1")
    
        // Cloud integrated in BKCommonLib
        compileOnly("org.incendo:cloud-paper")
        compileOnly("org.incendo:cloud-annotations")
        compileOnly("org.incendo:cloud-minecraft-extras")
    }
    
    plugins {
        id("com.github.johnrengelman.shadow") version "8.1.1"
        id("java-library")
    }
    
    tasks {
        shadowJar {
            val commonPrefix = "com.bergerkiller.bukkit.common.dep"
            relocate("org.incendo.cloud", "$commonPrefix.cloud")
            relocate("io.leangen.geantyref", "$commonPrefix.typetoken")
            relocate("me.lucko.commodore", "$commonPrefix.me.lucko.commodore")
            relocate("net.kyori", "$commonPrefix.net.kyori")
        }
    }
  12. Configure Maven to use Cloud Command Framework via BKCommonLib

    master

    To use Cloud in a Maven project, follow these steps:

    1. Add the BKCommonLib repository to your pom.xml.
    2. Import the BKCommonLib-bom in the <dependencyManagement> section to manage versions automatically.
    3. Add the dependencies (BKCommonLib, cloud-paper, cloud-annotations, and cloud-minecraft-extras) with provided scope.
    4. Configure the maven-shade-plugin to relocate the Cloud and related packages to the BKCommonLib shaded paths. This step is mandatory for runtime stability.

    Required Relocations:

    • org.incendo.cloud $\rightarrow$ com.bergerkiller.bukkit.common.dep.cloud
    • io.leangen.geantyref $\rightarrow$ com.bergerkiller.bukkit.common.dep.typetoken
    • me.lucko.commodore $\rightarrow$ com.bergerkiller.bukkit.common.dep.me.lucko.commodore
    • net.kyori $\rightarrow$ com.bergerkiller.bukkit.common.dep.net.kyori
    <!-- See full Maven configuration in documentation -->