增加一些动作/结构并且补注释:( 呜呜呜补注释好累头号疼

This commit is contained in:
Starrysky
2026-02-17 00:07:42 +08:00
parent 65f516a11f
commit 67e286981e
26 changed files with 572 additions and 34 deletions

View File

@@ -16,20 +16,29 @@ class ActionList {
ArrayList<String> locations;
}
/**
* 动作管理器
*/
public class ActionManager {
private final HashMap<String, JsonAction> actions;
public ActionManager() {
actions = new HashMap<>();
}
/**
* 初始化
*/
public void load() {
// 从本地文件读取
InputStream is = ActionManager.class.getResourceAsStream("/actions.json");
if (is == null) {
throw new RuntimeException("actions.json file not found!");
}
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// 解析json
Gson gson = new Gson();
ActionList actionList = gson.fromJson(reader, ActionList.class);
// 加载单个动作
for (String location : actionList.locations) {
JsonAction action = new JsonAction(location);
actions.put(action.getId(), action);
@@ -37,7 +46,15 @@ public class ActionManager {
PluginMain.LOGGER.info("Loaded " + actions.size() + " actions.");
}
/**
* 调用动作
* @param actionId 动作id
* @param location 执行位置
* @param caller 执行者
* @return 动作是否执行成功sync动作始终返回true
*/
public boolean call(String actionId, Location location, Player caller) {
// 获取动作
JsonAction action = actions.get(actionId);
if (action == null) {
throw new RuntimeException("Invalid action id " + actionId);