Discord

Hook into Parties

SecurityVillagers offers a developer API to get information about protected entities and handle plugin events.


Importing SecurityVillagers

To add the API to your project you can use use Maven, Gradle or manual adding in classpath.

Maven

<repositories>
<repository>
<id>alessiodp-repo</id>
<url>https://repo.alessiodp.com/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.alessiodp.securityvillagers</groupId>
<artifactId>securityvillagers-api</artifactId>
<version>2.14.8</version>
<scope>provided</scope>
</dependency>
</dependencies>

Gradle

repositories {
maven {
name = 'alessiodp-repo'
url = 'https://repo.alessiodp.com/releases/'
}
}
dependencies {
compileOnly group: 'com.alessiodp.securityvillagers', name: 'securityvillagers-api', version: '2.14.8'
}

Usage

Your plugin must loaded after Parties so you have to define this behavior in plugin.yml of your plugin by inserting Parties as depend (or soft-depend):

depend: [SecurityVillagers]
softdepend: [SecurityVillagers]

Before hook into it, be sure its enabled!

if (getServer().getPluginManager().getPlugin("SecurityVillagers") != null) {
if (getServer().getPluginManager().getPlugin("SecurityVillagers").isEnabled()) {
// SecurityVillagers is enabled
}
}

Then you can take the instance of SecurityVillagers:

SecurityVillagersAPI api = SecurityVillagers.getApi();

API Methods

SecurityVillagers offers a class called SecurityVillagersAPI, you can declare it to call API methods. This is how you can use it:

SecurityVillagersAPI api = SecurityVillagers.getApi();
// Get a list of protected entities
List<UUID> entities = api.getProtectedEntities();
// Get the entity selected by a player
Entity entity = api.getSelectedEntity(simplePlayer);

Event handlers

SecurityVillagers offers some events open to handle, you can hook into them like every Bukkit listener.

@EventHandler
public void onPlayerChat(SecurityVillagersDamageEvent event) {
if (event.getAttackResult() == AttackResult.SUCCESS) {
// Even if the attack is gonna be a success, prevent it by changing it into MELEE deny result
event.setAttackResult(AttackResult.MELEE);
// The user will receive a message like "you cannot hit X"
}
}
@EventHandler
public void onPlayerChat(SecurityVillagersProtectionChangeEvent event) {
// Prevent protection change
event.setCancelled(true);
}

JavaDoc

You can find the JavaDoc here.