42 lines
1.3 KiB
Java
42 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();
|
||
|
}
|
||
|
}
|