为什么使用 PassengerAPI?
它解决了不同插件通过向玩家发送数据包并将实体设置为乘客时可能产生的兼容性问题。
这可能导致冲突和意外行为,例如其他插件设置的先前乘客被卸载。
例如,这使得这些插件能够自动相互兼容:
- Better Chat Bubbles
- ProdigyCape
- VanillaMinimaps
- PlayerMounts
该插件开箱即用!
只需将其放入你的 plugins 文件夹并重启服务器即可。
(需要 Packet Events)
展示
视频说明
正如你在视频中看到的那样:
如果没有 PassengerAPI,聊天气泡和披风无法同时作为乘客设置!
原因是它们是两个不同的插件,各自发送自己的乘客数据包。
如果你是开发者,还可以使用此 API 添加/访问/移除乘客!
(大多数兼容性问题应该会自动修复,但……)
例如,如果你想在不杀死实体的情况下从实体上移除一个乘客,这将非常有用。
命令:
权限 passengerapi.commands
/passengerapi debug
/passengerapi reload
注意
当你处于调试模式且手中拿着一个方块时
你将在聊天中获得额外的调试信息。
配置:
# 除非你完全确定自己在做什么,否则不要修改此文件中的任何内容!
AutoPassengerDetection:
SetPassengerPacket: true
EntityDestroyPacket: true
入门指南
- 将 PassengerAPI 作为仅编译依赖项添加到你的插件中。
Gradle:
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.max1mde:PassengerAPI:1.0.1'
}
(Maven: )
- 在你的
plugin.yml 文件中添加以下行:
depend:
- PassengerAPI
同时为你的服务器添加插件 Packet Events,这是本插件所必需的!
用法
获取 PassengerActions 实例
要访问 PassengerAPI 功能,你需要获取 PassengerActions 实例:
PassengerActions passengerActions = PassengerAPI.getAPI(yourPluginInstance);
将 yourPluginInstance 替换为你插件主类的实例。
(例如,如果你在类中使用它,可以使用 this)
管理乘客
以下是一些如何使用 PassengerActions 接口的示例:
请记住,你只能检索和移除你通过 addPassenger... 方法在此处设置的乘客。
例外: 当使用“全局”方法如 getGlobalPassengers 时。
// 添加单个乘客
passengerActions.addPassenger(targetEntityId, passengerEntityId);
// 添加多个乘客
passengerActions.addPassengers(targetEntityId, Set.of(passenger1Id, passenger2Id, ...));
// 移除单个乘客
passengerActions.removePassenger(targetEntityId, passengerEntityId);
// 移除多个乘客
passengerActions.removePassengers(targetEntityId, Set.of(passenger1Id, passenger2Id, ...));
// 移除目标实体的所有乘客
passengerActions.removeAllPassengers(targetEntityId);
// 获取目标实体的所有乘客
Set<Integer> passengers = passengerActions.getPassengers(targetEntityId);
// 移除全局乘客(所有插件设置的乘客)
passengerActions.removeGlobalPassengers(targetEntityId, Set.of(passenger1Id, passenger2Id, ...));
// 移除目标实体的所有全局乘客(所有插件设置的乘客)
passengerActions.removeAllGlobalPassengers(targetEntityId);
// 获取目标实体的所有全局乘客(所有插件设置的乘客)
Set<Integer> globalPassengers = passengerActions.getGlobalPassengers(targetEntityId);
注意
所有实体都通过其实体 ID 进行标识(而非 UUID)。
监听事件
PassengerAPI 还提供了你可以监听并相应处理的事件:
@EventHandler
public void onAddPassenger(AddPassengerEvent event) {
// 尝试添加这些乘客的插件名称
String pluginName = event.getPluginName();
int targetEntity = event.getTargetEntityID();
Set<Integer> passengers = event.getPassengerList();
// 对这些属性执行操作
}
@EventHandler
public void onRemovePassenger(RemovePassengerEvent event) {
// 尝试移除这些乘客的插件名称
String pluginName = event.getPluginName();
int targetEntity = event.getTargetEntityID();
Set<Integer> removedPassengers = event.getPassengerList();
// 对这些属性执行操作
}
@EventHandler
public void onPassengerPacket(PassengerPacketEvent event) {
int targetEntity = event.getTargetEntityID();
Set<Integer> passengers = event.getPassengerList();
// 哪些玩家应该接收数据包(你可以修改该列表)
List<Player> receivers = event.getPacketReceivers();
// 对这些属性执行操作
}
别忘了注册你的事件类
欢迎在 GitHub 上进行贡献!
Why Use PassengerAPI?
It solves compatibility issues that may arise when different plugins create entities
by sending packets to players and setting them as passengers.
This can lead to conflicts and unintended behavior like unmounting of previous set passengers by other plugins.
For example this makes these plugins automatically compatible with each other:
- Better Chat Bubbles
- ProdigyCape
- VanillaMinimaps
- PlayerMounts
This plugin works out-of-the-box!
Just put it into your plugins folder and restart your server.
(Requires Packet Events)
Showcase
Video explanation
As you can see in the video:
The Chat Bubbles and capes are cannot be set as a passenger at the same time without PassengerAPI!
Reason for this is that they are both two different plugins, which are sending their own passenger packet.
If you are a developer can also add/access/remove passengers using this API!
(Most compatibility problems should automatically be fixed but...)
For example if you want to remove a passenger from an entity, without killing it, this could be usefull.
Commmands:
Permission passengerapi.commands
/passengerapi debug
/passengerapi reload
Note
When you are in debug mode and holding a block in your hand
you will get additional debugging in chat.
Config:
# DO NOT TOUCH ANYTHING IN THIS FILE
# IF YOU ARE NOT 100% SURE WHAT YOU ARE DOING!
AutoPassengerDetection:
SetPassengerPacket: true
EntityDestroyPacket: true
Getting Started
- Add PassengerAPI as a compile-only dependency to your plugin.
Gradle:
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.max1mde:PassengerAPI:1.0.1'
}
(For maven: )
- Add the following line to your
plugin.yml file:
depend:
- PassengerAPI
Also add the plugin Packet Events to your server
which is required by this plugin!
Usage
Obtaining the PassengerActions Instance
To access the PassengerAPI functionality, you need to obtain the PassengerActions instance:
PassengerActions passengerActions = PassengerAPI.getAPI(yourPluginInstance);
Replace yourPluginInstance with the instance of your plugin's main class.
(For example with this if you use it in your main class)
Managing Passengers
Here are some examples of how to use the PassengerActions interface:
Keep in mind that you can only retrive and remove passengers, which you have set here by using the addPassenger... methods.
Except: when using the "global" methods like getGlobalPassengers.
// Add a single passenger
passengerActions.addPassenger(targetEntityId, passengerEntityId);
// Add multiple passengers
passengerActions.addPassengers(targetEntityId, Set.of(passenger1Id, passenger2Id, ...));
// Remove a single passenger
passengerActions.removePassenger(targetEntityId, passengerEntityId);
// Remove multiple passengers
passengerActions.removePassengers(targetEntityId, Set.of(passenger1Id, passenger2Id, ...));
// Remove all passengers for a target entity
passengerActions.removeAllPassengers(targetEntityId);
// Get all passengers for a target entity
Set<Integer> passengers = passengerActions.getPassengers(targetEntityId);
// Remove global passengers (passengers set by all plugins)
passengerActions.removeGlobalPassengers(targetEntityId, Set.of(passenger1Id, passenger2Id, ...));
// Remove all global passengers for a target entity (passengers set by all plugins)
passengerActions.removeAllGlobalPassengers(targetEntityId);
// Get all global passengers for a target entity (passengers set by all plugins)
Set<Integer> globalPassengers = passengerActions.getGlobalPassengers(targetEntityId);
Note
All entities are identified by their entity ID (not UUID).
Listening to events
PassengerAPI also provides events that you can listen to and handle accordingly:
@EventHandler
public void onAddPassenger(AddPassengerEvent event) {
// The name of the plugin which tries to add these passengers
String pluginName = event.getPluginName();
int targetEntity = event.getTargetEntityID();
Set<Integer> passengers = event.getPassengerList();
// Perform actions with these properties
}
@EventHandler
public void onRemovePassenger(RemovePassengerEvent event) {
// The name of the plugin which tries to remove these passengers
String pluginName = event.getPluginName();
int targetEntity = event.getTargetEntityID();
Set<Integer> removedPassengers = event.getPassengerList();
// Perform actions with these properties
}
@EventHandler
public void onPassengerPacket(PassengerPacketEvent event) {
int targetEntity = event.getTargetEntityID();
Set<Integer> passengers = event.getPassengerList();
// Which players should receive the packet (You can modify that list)
List<Player> receivers = event.getPacketReceivers();
// Perform actions with these properties
}
Don't forget to register your event class
Contributions on GitHub are welcome!
评论 0
登录后参与评分
还没有评论,来抢沙发吧