Getting Started

这个 Wiki 页面将会引导你使用 GriefPrevention 的 API 到你的 Sponge 插件中。 你至少需要有基础的 Java 开发 Sponge 插件技能,以理解一下文字。 如果你第一次接触 Sponge API,请在 Sponge Docs 获取更多信息。

Gradle

Sponge 和 Forge 的开发者应该熟悉 Gradle 的使用和在 Forge 和 Sponge 方面的用途。

build.gradle - 依赖项

下方是一个在 build.gradle 使用 GP API v0.6 的实例代码块。

dependencies {
    compile('org.spongepowered:spongeapi:5.1.0')
    compile('me.ryanhamshire:griefprevention:1.10.2-4.0.0.379:api')
}

Sponge API

插件 Annotation

如果想、你正在开发一个和 GriefPrevention 协同工作的插件,你需要将其添加为 @Plugin 中的依赖。

@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")
        })

创建一个实例

实力插件主类:

import me.ryanhamshire.griefprevention.GriefPrevention;
import me.ryanhamshire.griefprevention.api.GriefPreventionApi;
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;

import java.util.Optional;

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;
    }
}

使用 GriefPrevention API

使用 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 {

    public static final MyAddon INSTANCE = MyAddon.getInstance();
    public 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();
    }
}

results matching ""

    No results matching ""