API to unify protection plugins for minecraft bukkit servers to allow easy protection queries without having to import 10 different plugin apis with separate implementations.
If you're looking for a plugin implementing YardWatchAPI for common protection plugins, see YardWatch plugin.
In any case of usage you will need to import the API. Replace VERSION
with current version tag. You should also adjust your <scope>
to provided
if you're not implementing the api and just querying it.
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.github.YouHaveTrouble</groupId>
<artifactId>YardWatchAPI</artifactId>
<version>VERSION</version>
<scope>compile</scope>
</dependency>
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.YouHaveTrouble:YardWatchAPI:VERSION'
}
Example handling of block breaking check. There's no need to depend on any plugins for this.
public boolean canBreakBlock(Player player, Block block) {
ServicesManager servicesManager = getServer().getServicesManager();
Collection<RegisteredServiceProvider<Protection>> protections = servicesManager.getRegistrations(Protection.class);
for (RegisteredServiceProvider<Protection> protection : protections) {
if (protection.getProvider().canBreakBlock(player, block.getState(true))) continue;
return false; // if any protection plugin disallowed breaking the block, return false
}
// If all protection plugins allowed breaking the block, return true
return true;
}
Implement all the methods required by the interface
public class YourPluginProtection implements Protection {}
@Override
public void onEnable() {
getServer().getServicesManager().register(
Protection.class,
new YourPluginProtection(),
this,
ServicePriority.Normal
);
}