Skip to content

Developer API

AoElite edited this page Aug 29, 2025 · 10 revisions

Developer API

Setup

Gradle

repositories {
    maven {
        name = "grimacSnapshots"
        url = uri("https://repo.grim.ac/snapshots")
    }
}
dependencies {
    // replace %VERSION% with the latest API version
    compileOnly("ac.grim.grimac:GrimAPI:%VERSION%")
}

Maven:

<repository>
  <id>grimac-snapshots</id>
  <name>GrimAC's Maven Repository</name>
  <url>https://repo.grim.ac/snapshots</url>
</repository>
<!-- replace %VERSION% with the latest API version -->
<dependency>
  <groupId>ac.grim.grimac</groupId>
  <artifactId>GrimAPI</artifactId>
  <version>%VERSION%</version>
  <scope>provided</scope>
</dependency>

Usage

Note

Most of the examples here are assuming you are using a bukkit based environment.

Ensure that your plugin depends on GrimAC in your plugin.yml.

softdepend:
  - GrimAC

Listener example

You can retrieve an instance of the API implementation using Bukkit's service provider whenever your plugin starts.

public class Test extends JavaPlugin {

    @Override
    public void onEnable() {
        // check if GrimAC is loaded
        if (Bukkit.getPluginManager().isPluginEnabled("GrimAC")) {
            // get the provider
            RegisteredServiceProvider<GrimAbstractAPI> provider = Bukkit.getServicesManager().getRegistration(GrimAbstractAPI.class);
            if (provider != null) {
                // create a GrimPlugin instance from this plugin
                GrimPlugin plugin = new BasicGrimPlugin(
                        this.getLogger(),
                        this.getDataFolder(),
                        this.getDescription().getVersion(),
                        this.getDescription().getDescription(),
                        this.getDescription().getAuthors()
                );
                GrimAbstractAPI api = provider.getProvider();
                // use the event bus to subscribe to FlagEvent
                api.getEventBus().subscribe(plugin, FlagEvent.class, event -> {
                    // broadcast to all players when a player flags a check
                    Bukkit.broadcast(Component.text(
                            event.getPlayer().getName() + " flagged " + event.getCheck().getCheckName()));
                });
            }
        }
    }
    
}

Registering variables

You can use the API to register variables you can use within the configuration files of Grim.

// get a instance of the API
GrimAbstractAPI api = getInstance();

// registers a variable based on the user
api.registerVariable("%keep_alive_ping%", user -> user.getKeepAlivePing() + "");

// registers a static variable
api.registerVariable("%server%", user -> "Server Name");

Player features

You can use the FeatureManager to enable specific features per player that persist between reloads.

// example method to enable experimental checks for a player
    public void enableExperimentalChecks(Player player, GrimAbstractAPI api) {
        GrimUser user = api.getGrimUser(player);
        if (user == null) return;
        if (user.getFeatureManager().setFeatureState("ExperimentalChecks", FeatureState.ENABLED)) {
            player.sendMessage("Experimental checks enabled");
        } else {
            player.sendMessage("Failed to enable experimental checks");
        }
    }

Clone this wiki locally