Skip to content
Mohron edited this page Apr 20, 2018 · 14 revisions

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 its use in plugin/mod development.

build.gradle

Below is an example of the repositories and dependencies block of your build.gradle that targets the GP API v0.8.

repositories {
    jcenter()
    maven {
        name = "Sponge"
        url = "http://repo.spongepowered.org/maven"
    }
    maven {
        name = "Forge"
        url = "http://files.minecraftforge.net/maven"
    }
}
dependencies {
    compile('org.spongepowered:spongeapi:5.1.0')
    compile('me.ryanhamshire:griefprevention:1.10.2-4.0.1.451: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", version = "4.0.1")
    })

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;

import java.util.Optional;

/* Insert @Plugin annotation from above example */
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.ClaimResult;
import me.ryanhamshire.griefprevention.api.claim.ClaimType;

public class MyClaimMaker {

    private static final MyAddon INSTANCE = MyAddon.getInstance();
    private static final GriefPreventionApi GP_INSTANCE = INSTANCE.getGriefPrevention();
    
    public static Optional<Claim> createBasicClaim(World world, Vector3i lesserBound, Vector3i greaterBound, UUID owner, boolean cuboid) {
        // Create a ClaimResult by supplying the required data
        ClaimResult claimResult = Claim.builder()
                                  .type(ClaimType.BASIC)
                                  .world(world)
                                  .bounds(lesserBound, greaterBound)
                                  .cause(Cause.source(INSTANCE).build())
                                  .owner(owner)
                                  .build();
        // Return the Claim object from the result, if sucessful
        return claimResult.successful() ? claimResult.getClaim() : Optional.empty();
    }
}