This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/src/main/java/com/thebrokenrail/scriptcraft/bridge/Bridges.java

43 lines
1.3 KiB
Java
Raw Normal View History

2020-04-25 13:33:17 +00:00
package com.thebrokenrail.scriptcraft.bridge;
import com.thebrokenrail.scriptcraft.quickjs.QuickJS;
import com.thebrokenrail.scriptcraft.quickjs.QuickJSManager;
import java.util.HashMap;
@SuppressWarnings("unused")
public class Bridges {
private static final HashMap<String, Bridge> bridges = new HashMap<>();
public static void addBridge(String name, Bridge bridge) {
bridges.put(name, bridge);
}
public static Object useBridge(String name, Object... args) {
QuickJSManager.Task task = new QuickJSManager.Task() {
@Override
protected Object run(QuickJS quickjs) {
if (bridges.containsKey(name)) {
return bridges.get(name).use(args);
} else {
throw new RuntimeException("Invalid Bridge: '" + name + '\'');
}
}
};
return QuickJSManager.sendTaskFromQuickJS(task);
}
static {
BlockSettingsBridges.register();
RegistryBridge.register();
ItemStackBridges.register();
LivingEntityBridges.register();
BlockStateBridges.register();
WorldBridges.register();
ItemSettingsBridges.register();
EntityBridges.register();
DamageSourceBridges.register();
2020-04-26 01:17:59 +00:00
TagBridges.register();
2020-04-25 13:33:17 +00:00
}
}