-
Notifications
You must be signed in to change notification settings - Fork 1
Usage (Sponge API‐7)
Bartłomiej Stępień edited this page Apr 15, 2024
·
1 revision
The first thing you need to do to use EagleFactionsAPI is to depend on it. The easiest way to achieve it is to use Jitpack.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.Aquerr</groupId>
<artifactId>EagleFactionsAPI</artifactId>
<version>v0.16.0</version>
</dependency>
</dependencies>
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compileOnly "com.github.Aquerr:EagleFactionsAPI:v0.16.0"
}
Now you are ready to use EagleFactionsAPI in your own project.
Firstly, add the EagleFactions dependency to your plugin instance by specifying it in the @Plugin annotation. It is not required but it is a good practice to do it so that Sponge knows what is needed by your plugin.
@Plugin(id = "myawesomeplugin", name = "My awesome addon plugin",
dependencies = {@Dependency(id = "eaglefactions")})
Then, you can access EagleFactions instance in GamePostInitilaizationEvent.
@Listener
public void onPostInitialization(final GamePostInitializationEvent event) {
//Prints information to the server console about connecting to Eagle Factions.
Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.YELLOW, "Establishing connection with Eagle Factions..."));
//Accessing EagleFactions instance
EagleFactions eagleFactions = null;
Optional<?> optionalEagleFactionsInstance = Sponge.getPluginManager().getPlugin("eaglefactions").get().getInstance();
if(optionalEagleFactionsInstance.isPresent()) {
eagleFactions = (EagleFactions) optionalEagleFactionsInstance.get();
}
//Do something with EagleFactions
this.powerManager = eaglefactions.getPowerManager();
this.factionLogic = eaglefactions.getFactionLogic();
//You can also ask Sponge for EagleFactions services instead of getting an instance of EagleFactions.
//Normally, all services that EagleFactions distributes should be registered in Sponge Service Manager so you can use provideUnchecked(Class<T> service) instead but it is safer to use provide(Class<T> service) because there may still be some new services that are not yet registered.
this.factionLogic = Sponge.getServiceManager().provide(FactionLogic.class).orElse(null);
this.powerManager = Sponge.getServiceManager().provide(PowerManager.class).orElse(null);
if (this.factionLogic == null || this.powerManager == null) {
Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.RED, "No Eagle Factions found!"));
return;
}
Sponge.getServer().getConsole().sendMessage(Text.of(TextColors.GREEN, "Successfully established connection with Eagle Factions!"));
}
Want to see an example plugin that is using EagleFactionsAPI? Take a look at EagleFactions-Mobs.
- Open an issue here on Github if you want to report a bug or suggest an enhancement
- Write to me on Spongepowered Forum
- Join my Discord server and contact me there