Getting Started
This wiki page will guide you through the steps of adding and utilizing the GriefPrevention developer API to your Sponge plugin. You will be expected to have at least basic knowledge of developing Java plugins for Sponge API in order to apply this information. If you are new to Sponge API more information can be found on the Sponge Docs.
Gradle
Sponge and Forge developers should be familiar with Gradle and it’s use in plugin/mod development.
build.gradle - Dependencies
Below is an example of the dependencies block of your build.gradle that targets the GP API v0.3.
dependencies {
compile('org.spongepowered:spongeapi:5.1.0')
compile('me.ryanhamshire:griefprevention:1.10.2-2.3.1.288:api')
}
Sponge API
Plugin Annotation
If you are developing a plugin that will work with GriefPrevention, you must include
it as a dependency in your @Plugin
declaration.
@Plugin(id = "gpapiexample",
name = "My GP Addon",
version = "1.0.0",
description = "The best addon to the greatest protection plugin ever conceived",
authors = {"bloodshot"},
dependencies = {
@Dependency(id = "griefprevention")
})
Creating an Instance
Example plugin main class:
import me.ryanhamshire.griefprevention.GriefPrevention;
import me.ryanhamshire.griefprevention.api.GriefPreventionApi;
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
public class MyAddon {
private static MyAddon instance;
private static GriefPreventionApi griefPrevention;
@Listener
public void onPostInitialization(GamePostInitializationEvent event) {
instance = this;
MyAddon.griefPrevention = GriefPrevention.getApi();
}
public static MyAddon getInstance() {
return instance;
}
public GriefPreventionApi getGriefPrevention() {
return griefPrevention;
}
}
Using the GriefPrevention API
Example method on creating and saving a claim using the GP API:
import me.ryanhamshire.griefprevention.api.claim.Claim;
import me.ryanhamshire.griefprevention.api.claim.ClaimManager;
import me.ryanhamshire.griefprevention.api.claim.ClaimResult;
import me.ryanhamshire.griefprevention.api.claim.ClaimResultType;
import me.ryanhamshire.griefprevention.api.claim.ClaimType;
public class MyClaimMaker {
public static final MyAddon INSTANCE = MyAddon.getInstance();
public static final GriefPreventionApi GP_INSTANCE = INSTANCE.getGriefPrevention();
public static Claim createBasicClaim(World world, Vector3i lesserBound, Vector3i greaterBound, UUID owner, boolean cuboid) {
// Get a ClaimManager for the world you want to claim in
final ClaimManager CLAIM_MANAGER = GP_INSTANCE.getClaimManager(world);
// Create a ClaimResult by supplying the required data
ClaimResult claimResult = Claim.builder()
.world(world)
.bounds(lesserBound, greaterBound)
.owner(owner)
.type(ClaimType.BASIC)
.cause(Cause.source(INSTANCE).build())
.cuboid(cuboid)
.build();
// Attempt to retrieve the Claim object from the result
Claim claim = (claimResult.getClaim().isPresent()) ? claimResult.getClaim().get() : null;
// With a vaild Claim object, add it to the DataStore using the ClaimManager
if (claim != null) CLAIM_MANAGER.addClaim(claim, Cause.source(INSTANCE).build());
return claim;
}
}