-
Notifications
You must be signed in to change notification settings - Fork 365
Developer API
AoElite edited this page Jan 7, 2025
·
3 revisions
- 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.
maven("https://jitpack.io/") {
content {
includeGroup("com.github.grimanticheat")
}
}
dependencies {
compileOnly("com.github.grimanticheat:grimapi:VERSION") // replace this with actual version
}
<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
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();
}
}
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());
}
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");
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");
}
}
More information in the readme.