小更新,实现了动作传参,现在创建一个阵型起码50行json TvT
This commit is contained in:
@@ -5,6 +5,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import top.sunsetlab.PluginMain;
|
||||
import top.sunsetlab.actions.ActionParam;
|
||||
import top.sunsetlab.actions.IActionBase;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -12,6 +13,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
|
||||
class ActionData {
|
||||
String id;
|
||||
@@ -45,7 +47,7 @@ public class JsonAction {
|
||||
* @param caller 执行者
|
||||
* @return 动作是否成功运行,sync动作始终为true
|
||||
*/
|
||||
public boolean run(Location location, Player caller) {
|
||||
public boolean run(Location location, Player caller, ActionParam param) {
|
||||
try {
|
||||
// 通过反射加载动作类
|
||||
Class<?> clazz = Class.forName(data.classname);
|
||||
@@ -55,15 +57,17 @@ public class JsonAction {
|
||||
// 获取构造器
|
||||
Constructor<?> constructor = clazz.getConstructor();
|
||||
IActionBase action = (IActionBase) constructor.newInstance();
|
||||
|
||||
ActionParam p = param == null ? new ActionParam(new HashMap<>()): param;
|
||||
if (data.sync) {
|
||||
// 在Minecraft线程内执行,一般用于世界交互
|
||||
Bukkit.getScheduler().runTask(PluginMain.plugin, () -> {
|
||||
action.call(location, caller);
|
||||
action.call(location, caller, p);
|
||||
});
|
||||
return true;
|
||||
}else {
|
||||
// 异步执行
|
||||
return action.call(location, caller);
|
||||
return action.call(location, caller, p);
|
||||
}
|
||||
}catch (ClassNotFoundException
|
||||
| NoSuchMethodException
|
||||
|
||||
Reference in New Issue
Block a user