{"id":13690095,"url":"https://github.com/OnfireNetwork/OnsetJavaPlugin","last_synced_at":"2025-05-02T06:31:48.019Z","repository":{"id":55582660,"uuid":"230078357","full_name":"OnfireNetwork/OnsetJavaPlugin","owner":"OnfireNetwork","description":"Call Java methods from lua!","archived":false,"fork":false,"pushed_at":"2020-12-20T17:47:46.000Z","size":800,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-26T09:52:02.115Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OnfireNetwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-25T09:29:51.000Z","updated_at":"2024-02-05T14:42:42.000Z","dependencies_parsed_at":"2022-08-15T03:40:14.649Z","dependency_job_id":null,"html_url":"https://github.com/OnfireNetwork/OnsetJavaPlugin","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OnfireNetwork%2FOnsetJavaPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OnfireNetwork%2FOnsetJavaPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OnfireNetwork%2FOnsetJavaPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OnfireNetwork%2FOnsetJavaPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OnfireNetwork","download_url":"https://codeload.github.com/OnfireNetwork/OnsetJavaPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251998607,"owners_count":21678005,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T16:00:43.530Z","updated_at":"2025-05-02T06:31:47.752Z","avatar_url":"https://github.com/OnfireNetwork.png","language":"C++","funding_links":[],"categories":["Packages and Plugins"],"sub_categories":["Libraries"],"readme":"# OnsetJavaPlugin\nAuthors: JanHolger, Digital\n\n### Features\n* Create JVMs.\n* Communicate between Lua \u003c-\u003e Java.\n\n### OnsetJava\nInterested in writing your entire gamemode in java?\nYou can use our [language framework](https://github.com/OnfireNetwork/OnsetJava) with tons of features running on top of this plugin!\n\n### Installation\n1. Get OnsetJavaPlugin and place it in your plugins directory.\n**Windows:** Download OnsetJavaPlugin.dll from Releases ([HERE](https://github.com/OnfireNetwork/OnsetJavaPlugin/releases)).\n**Linux:** Make sure to have the latest versions of cmake and gcc/g++ or any other compiler that is cmake compatible and capable of building CXX17. The debian and ubuntu versions we tried for building didn't come with compatible versions in their package sources. You might need to manually install those. We recommend to do that on an unused vm as changing the gcc/g++ version might break some of your installed software packages. Then `git clone https://github.com/OnfireNetwork/OnsetJavaPlugin`, `cd OnsetJavaPlugin`, `cmake .` and `make` for building.\n2. Ensure Java 8 JDK/JRE 64bit is installed.\n3. Enable \"OnsetJavaPlugin\" as a plugin inside server_config.json.\n\n#### Compiling from source\n##### Ubuntu 18.04\n```\n# Compiling the plugin requires GCC8 because of \u003cfilesystem\u003e usage.\n\napt install openjdk-8-jdk openjdk-8-jre maven gcc-8 g++-8\n\nexport CC=/usr/bin/gcc-8\nexport CXX=/usr/bin/g++-8\n\ngit clone --recurse-submodules https://github.com/OnfireNetwork/OnsetJavaPlugin\ncd OnsetJavaPlugin\ncmake .\nmake\n\n# Copy src/OnsetJavaPlugin.so to your OnsetServer/plugins folder.\n```\n##### Compiling OnsetJavaPluginSupport\n```\ncd OnsetJavaPluginSupport\nmvn package\n\n# Copy OnsetJavaPluginSupport/target/OnsetJavaPluginSupport-1.0.jar to your OnsetServer/java folder.\n```\n\n### Data Types we support\n#### Method Parameters\n* Lua String -\u003e String (java.lang.String)\n* Lua Int -\u003e Integer (java.lang.Integer)\n* Lua Number -\u003e Double (java.lang.Double)\n* Lua Bool -\u003e Boolean (java.lang.Boolean)\n* Lua Table -\u003e Map (java.util.HashMap)\n* Lua Function -\u003e LuaFunction (lua.LuaFunction, lua function support interface required)\n\n#### Return Values\n* String (java.lang.String)\n* Integer (java.lang.Integer)\n* Double (java.lang.Double)\n* Boolean (java.lang.Boolean)\n* List (java.util.List)\n* Map (java.util.Map)\n\nWe will be adding more data types later on.\n\n#### Using the lua function support interface\n##### Maven\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003ejitpack.io\u003c/id\u003e\n        \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.github.OnfireNetwork\u003c/groupId\u003e\n        \u003cartifactId\u003eOnsetJavaPlugin\u003c/artifactId\u003e\n        \u003cversion\u003e2357546bd5\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n##### Usage\nJava:\n```java\npublic static void example(LuaFunction fn){\n    fn.call(\"Hello from Java!\");\n    fn.close(); // Always call this when you don't need the function anymore to free memory\n}\n```\nLua:\n```lua\nCallJavaStaticMethod(java, \"example/Example\", \"example\", \"(Llua/LuaFunction;)V\", function(msg)\n    print(msg)\nend)\n```\n\n### Lua Functions\n#### CreateJava\nCreate a new JVM with a jar. Returns JVM ID.\n```lua\nlocal jvmID = CreateJava(path)\n```\n* **path** Classpath for the jvm. This parameter is optional. When not provided it will include the \"java\" directory aswell as all jar files inside or \".\" when \"java\" doesn't exist.\n\n#### DestroyJava\nDestroy a JVM.\n```lua\nDestroyJava(jvmID)\n```\n* **jvmID** ID to the JVM you have created using CreateJava.\n\n#### CallJavaStaticMethod\nCall a java static method. Can return information from the Java method, check out Data Types for the types we currently support.\n```lua\nlocal dataFromJava = CallJavaStaticMethod(jvmID, className, methodName, methodSignature, args...)\n```\n* **jvmID** ID to the JVM you have created using CreateJava. Example: 1\n* **className** Class name of the class you want to call a method in, must include package path as well. Example: dev/joseph/Test (dev.joseph.Test).\n* **methodName** Static method name you want to call. Example: returnTestInt\n* **methodSignature** Signature of the method you want to call. Example: (Ljava/lang/Integer;)I\n* **args (Optional)** Pass arguments into the method.\n\n#### LinkJavaAdapter\nLinks a Java class so the native methods below can be used.\n```lua\nLinkJavaAdapter(jvmID, className)\n```\n* **jvmID** ID to the JVM you have created using CreateJava. Example: 1\n* **className** Class name of the class you want to call a method in, must include package path as well. Example: dev/joseph/Adapter (dev.joseph.Adapter).\n\n### Java Native Methods\nYou can use a native adapter to call lua functions.\n```java\npackage example;\npublic class Adapter {\n    public native static void callEvent(String event, Object... args);\n    public native static Object[] callGlobalFunction(String packageName, String functionName, Object... args);\n}\n```\n```lua\nLinkJavaAdapter(java, \"example/Adapter\")\n```\n#### callEvent\nJava:\n```java\nAdapter.callEvent(\"testCallEvent\", \"hi\", Integer.valueOf(123), Boolean.valueOf(true));\n```\nLua:\n```lua\nAddEvent('testCallEvent', function(s,i,b)\n    print(s)\n    print(i)\n    print(b)\nend)\n```\n#### callGlobalFunction\n*Make sure to use this method only on the main thread. Using it outside the mainthread can result in unexpected behavior.*  \nJava:\n```java\nAdapter.callGlobalFunction(\"AddPlayerChatAll\", \"Hello World\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOnfireNetwork%2FOnsetJavaPlugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOnfireNetwork%2FOnsetJavaPlugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOnfireNetwork%2FOnsetJavaPlugin/lists"}