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
TheBrokenRail d2ba0b6cf2
All checks were successful
ScriptCraft/pipeline/head This commit looks good
Add Tag Bindings
2020-04-25 21:17:59 -04:00

43 lines
1.3 KiB
Java

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();
TagBridges.register();
}
}