# YardWatch (服务器管理员)
对常见保护插件实现[YardWatchAPI](https://github.com/YouHaveTrouble/YardWatchAPI)。如果任何受支持的插件本身实现了API,则此插件将停止提供其实现,以允许插件接管。
如果您是一位开发者,正在寻找有关如何在您的插件中实现YardWatchAPI的信息,请参阅
[YardWatchAPI](https://github.com/YouHaveTrouble/YardWatchAPI)
## 要求
- Java 17
- Minecraft 1.16+
## 实现:
- GriefPrevention (v16+)
- WorldGuard (7.0.0+)
- LWCX
- FactionsUUID
- SuperiorSkyBlock
- Towny
- PlotSquared (6.0.0+)
## 您正在使用的插件没有实现YardWatchAPI?
请联系插件开发者并向他们[在此处](https://github.com/YouHaveTrouble/YardWatchAPI/blob/master/readme.md)发送!
您也可以在此插件中请求临时实现[在此处](https://github.com/YouHaveTrouble/YardWatch/issues/new?assignees=&labels=enhancement&projects=&template=implementation-request.yml&title=%5BNEW+IMPLEMENTATION%5D%3A+).
# YardWatchAPI (开发者)
API 用于统一 Minecraft Bukkit 服务器上的保护插件,以便轻松进行保护查询,而无需导入
10 种具有单独实现的插件 API。
当前版本:[](https://jitpack.io/#YouHaveTrouble/YardWatchAPI)
如果您正在寻找实现 YardWatchAPI 以供常用保护插件使用的插件,请参阅 [YardWatch 插件](https://github.com/YouHaveTrouble/YardWatch)。
# 使用方法
### 使用依赖管理导入 API
在使用任何情况下,您都需要导入 API。将 `VERSION` 替换为当前版本标记。如果您只是查询 API,则还应将您的 `` 调整为 `provided`。
#### Maven
```xml
jitpack.io
https://jitpack.io
com.github.YouHaveTrouble
YardWatchAPI
VERSION
compile
```
#### Gradle
```gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
compileOnly 'com.github.YouHaveTrouble:YardWatchAPI:VERSION'
}
```
## 针对希望查看某事物是否受保护的插件
### 检查玩家是否可以破坏一个方块
破坏方块检查的示例处理。无需依赖任何插件。
```java
public boolean canBreakBlock(Player player, Block block) {
ServicesManager servicesManager = getServer().getServicesManager();
Collection> protections = servicesManager.getRegistrations(Protection.class);
for (RegisteredServiceProvider protection : protections) {
if (protection.getProvider().canBreakBlock(player, block.getState(true))) continue;
return false; // 如果任何保护插件禁止破坏方块,则返回 false
}
// 如果所有保护插件都允许破坏方块,则返回 true
return true;
}
```
## 针对保护插件
### 依赖 YardWatch 插件
您可以选择性地软依赖并检查 YardWatch 是否存在,以添加可选的集成。
```yml
depend:
- "YardWatch"
```
### 实现 Protection 接口
实现接口中所需的所有方法
```java
public class YourPluginProtection implements Protection {}
```
### 将您的实现注册为服务
```java
@Override
public void onEnable() {
getServer().getServicesManager().register(
Protection.class,
new YourPluginProtection(),
this,
ServicePriority.Normal
);
}
```