初始化并且写了些东西

This commit is contained in:
Starrysky
2026-02-16 18:51:24 +08:00
commit 65f516a11f
24 changed files with 849 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
package top.sunsetlab.utils;
import com.google.gson.Gson;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import top.sunsetlab.PluginMain;
import top.sunsetlab.actions.IActionBase;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
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));
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);
}
PluginMain.LOGGER.info("Loaded " + actions.size() + " actions.");
}
public boolean call(String actionId, Location location, Player caller) {
JsonAction action = actions.get(actionId);
if (action == null) {
throw new RuntimeException("Invalid action id " + actionId);
}
return action.run(location, caller);
}
}