Skip to content

Developer API

AoElite edited this page Jan 7, 2025 · 3 revisions

Developer API

  • You can find the latest API version on jitpack or look in the build.gradle of Grim.
  • API source code can be found on it's github.

Setup

Gradle

    maven("https://jitpack.io/") {
        content {
            includeGroup("com.github.grimanticheat")
        }
    }
dependencies {
    compileOnly("com.github.grimanticheat:grimapi:VERSION") // replace this with actual version
}

Maven:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io/</url>
</repository>
<dependency>
    <groupId>com.github.grimanticheat</groupId>
    <artifactId>grimapi</artifactId>
    <version>VERSION</version><!-- replace this with the actual version -->
</dependency>

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

softdepend:
  - GrimAC

Example usage

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

        if (Bukkit.getPluginManager().isPluginEnabled("GrimAC")) {
            RegisteredServiceProvider<GrimAbstractAPI> provider = Bukkit.getServicesManager().getRegistration(GrimAbstractAPI.class);
            if (provider != null) {
                GrimAbstractAPI api = provider.getProvider();
            }
        }

Bukkit Events

A list of grim bukkit events can be found on the github. Here's an example of how you can print to console when a player flags a checks.

    @EventHandler
    public void onGrimFlag(FlagEvent event) {
        GrimUser user = event.getPlayer();
        AbstractCheck check = event.getCheck();
        Bukkit.getConsoleSender().sendMessage(user.getName() + " flagged check " + check.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");
        }
    }