Updated APIv5 DataExtension API (markdown)

Risto Lahtela 2021-01-21 11:12:12 +02:00
parent 7ce742a5de
commit 4b10787cee

@ -11,7 +11,7 @@ See [APIv5](https://github.com/plan-player-analytics/Plan/wiki/APIv5#plan-api-ve
### Table of contents
- DataExtension API
- Getting Started
- [Getting Started](https://github.com/plan-player-analytics/Plan/wiki/DataExtension-API---Getting-started)
- 🔔 [How to register a DataExtension](https://github.com/plan-player-analytics/Plan/wiki/APIv5---DataExtension-API#-how-to-register-a-dataextension)
- [PluginInfo Annotation](https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki/APIv5---DataExtension-API#%E2%84%B9%EF%B8%8F-plugininfo-annotation)
- 📏 [Provider Annotations](https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki/APIv5---DataExtension-API#-provider-annotations)
@ -31,88 +31,7 @@ This makes it easier for users to reason about their server.
You can follow this step-by-step guide for getting started with the API.
There is a lot of functionality in the API so it might feel overwhelming at first. If you get stuck or can't find how to do something you can get support on [discord (#development channel)](https://discord.gg/yXKmjzT)
1. [Install Plan API as a dependency](https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki/APIv5#dependency-information)
2. [Check that the APIs are available](https://github.com/plan-player-analytics/Plan/wiki/APIv5#checking-that-needed-capabilities-of-the-api-are-available)
<details><summary>3. Create a basic DataExtension</summary>
- Create a new class that implements `DataExtension` interface.
- Add a `@PluginInfo` annotation that tells Plan information about your plugin. [PluginInfo Annotation](https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki/APIv5---DataExtension-API#%E2%84%B9%EF%B8%8F-plugininfo-annotation)
- Add a constructor to access everything you need to access your plugin's data.
- Add a `@___Provider` annotation and a method that returns data from your plugin. [Provider Annotations](https://github.com/Rsl1122/Plan-PlayerAnalytics/wiki/APIv5---DataExtension-API#-provider-annotations)
- (Optional) Override `callExtensionMethodsOn` to choose when Plan calls the methods [More about when Plan calls the methods](https://github.com/plan-player-analytics/Plan/wiki/APIv5---DataExtension-API#-provider-annotations)
</details>
4. [Register your DataExtension](https://github.com/plan-player-analytics/Plan/wiki/APIv5---DataExtension-API#-how-to-register-a-dataextension)
<details><summary>Example of a basic DataExtension</summary>
```java
@PluginInfo(name = "Test Plugin", iconName = "vial", iconFamily = Family.SOLID, color = Color.LIGHT_BLUE)
public class TestPluginExtension implements DataExtension {
private final TestPluginDatabase db;
public TestPluginExtension(TestPluginDatabase db) {
this.db = db;
}
@Override
public CallEvents[] callExtensionMethodsOn() {
return new CallEvents[]{
CallEvents.PLAYER_JOIN,
CallEvents.PLAYER_LEAVE
};
}
@NumberProvider(
text = "Completed Challenges",
description = "How many challenges has the player completed",
iconName = "bookmark",
iconColor = Color.GREEN,
priority = 100,
showInPlayerTable = true
)
public long challengesCompleted(UUID playerUUID) {
return db.getCompletedChallengeCount(playerUUID);
}
}
```
```java
public class PlanHook {
private final TestPluginDatabase db;
public PlanHook (TestPluginDatabase db) {
this.db = db;
}
public void registerExtension() {
try {
DataExtension yourExtension = new TestPluginExtension(db);
ExtensionService.getInstance().register(yourExtension);
} catch (IllegalStateException planIsNotEnabled) {
// Plan is not enabled, handle exception
} catch (IllegalArgumentException dataExtensionImplementationIsInvalid) {
// The DataExtension implementation has an implementation error, handle exception
}
}
public void registerPlanReloadListener() {
CapabilityService.getInstance().registerEnableListener(planIsEnabled -> if(planIsEnabled) registerExtension());
}
}
```
</details>
- [Getting Started](https://github.com/plan-player-analytics/Plan/wiki/DataExtension-API---Getting-started)
## 🔔 How to register a DataExtension