ActionLib 用于轻松实现基于 JSON 的数据驱动操作,例如设置玩家的饥饿值或饱和度,或随机显示一个物品栏。
更详细的文档请参阅 此处
默认操作:
trip: 将玩家的所有物品掉落至地面
teleport_player: 允许传送玩家
spawn_entity: 在指定半径内随机生成指定的实体
smite: 用闪电击中玩家
show_screen: 向玩家显示指定的屏幕(目前仅支持演示屏幕)
set_saturation: 设置玩家的饱和度等级
set_player_armor: 设置玩家的护甲
set_level: 设置玩家的 XP 等级
set_health: 设置玩家的生命值
set_gamemode: 设置玩家的游戏模式
set_food_level: 设置玩家的饱食度等级
set_fire: 点燃玩家
send_title: 向玩家发送标题
send_message: 向玩家发送消息
potion_effect: 允许添加、移除和清除玩家的状态效果
player_chat: 让玩家发送指定消息
play_sound: 向玩家播放特定音效
open_inventory: 使玩家打开随机或指定的物品栏(与 show_screen 不同)
launch_entity: 允许将所有实体(或仅玩家)发射到空中
kick_player: 踢出玩家
give_item: 给予玩家指定物品
flip_player: 将玩家旋转 180 度
drop_item: 掉落玩家主手或副手中的物品
添加自定义操作:
通过扩展 "AbstractAction" 类并使用 "ActionType" 注解来添加自定义操作
@ActionType(value = "name_of_action")
public class CustomAction extends AbstractAction {
public CustomAction(JavaPlugin plugin) {
super(plugin);
}
// 可选的 loadFromJson 方法,用于从操作的 JSON 对象中加载数据
@Override
public void execute(Player target, String[] args) {
// 执行代码在此处
}
}
注册自定义操作:
ActionRegistry.registerActionsFromPackage("com.example.package", javaPluginInstance);
使用操作:
ActionObjectManager manager = new ActionObjectManager();
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
ActionObject newAction = new ActionObject(plugin, jsonObject);
manager.addActionObject(newAction);
ActionObject action = manager.getEnabledActionObjectByName(args[1]);
action.execute(target, Arrays.copyOfRange(args, 2, args.length));
ActionLib is used to easily implement JSON based data-driven actions, e.g. setting a players health or saturation, or showing a random inventory.
Better documentation can be found here
Default Actions:
trip: Drops the player's entire inventory onto the ground
teleport_player: Allows teleporting the player
spawn_entity: Spawns the specified entity randomly within a radius
smite: Strikes the player with lightning
show_screen: Shows the player a specified screen (Currently only supports the demo screen)
set_saturation: Sets the player's saturation level
set_player_armor: Sets the player's armor
set_level: Sets the player's xp level
set_health: Sets the player's health
set_gamemode: Sets the player's gamemode
set_food_level: Sets the player's food level
set_fire: Sets the player on fire
send_title: Sends a title to the player
send_message: Sends a message to the player
potion_effect: Allows adding, removing, and clearing the player's potion effects
player_chat: Has the player send the specified message
play_sound: Plays a specific sound to the player
open_inventory: Causes the player to open a random or specified inventory (Different than show_screen)
launch_entity: Allows launching all entities (or just the player) into the air
kick_player: Kicks the player
give_item: Gives the player a specified item
flip_player: Flips the player 180 degrees
drop_item: Drops the item in either the player's main hand or the player's off hand
Adding custom actions:
Custom actions are added by extending the "AbstractAction" class and using the "ActionType" annotation
@ActionType(value = "name_of_action")
public class CustomAction extends AbstractAction {
public CustomAction(JavaPlugin plugin) {
super(plugin);
}
// Optional loadFromJson to load from the action's json object
@Override
public void execute(Player target, String[] args) {
// Execution code is here
}
}
Registering custom actions:
ActionRegistry.registerActionsFromPackage("com.example.package", javaPluginInstance);
Using actions:
ActionObjectManager manager = new ActionObjectManager();
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
ActionObject newAction = new ActionObject(plugin, jsonObject);
manager.addActionObject(newAction);
ActionObject action = manager.getEnabledActionObjectByName(args[1]);
action.execute(target, Arrays.copyOfRange(args, 2, args.length));
评论 0
登录后参与评分
还没有评论,来抢沙发吧