Using reloadplugins

  • Hello there,


    first of all: Impressive work you guys have done with Rising World and the Plugin API in particular.


    I've tried to create a plugin directly inside the game's directory (C:\Program Files (x86)\Steam\steamapps\common\RisingWorld\plugins in my case)
    and I'm wondering about the correct directory structure to make use of the new 'reloadplugins' feature.


    I assumed, the game would look inside plugins/Guestbook/src and compile all files in there and then use a new classloader to reload the class files,
    but I wasn't able to get that to work.
    Any hints?


    Thanks,
    Jochen

  • So you want to let the server build your plugin?


    Have you created the "projectinfo.txt" file inside the empty folder of your plugin?


    In this file the following must inside of it:


    Name: (Name of your plugin)
    path: (The path to the src directory of the project directory of your plugin)



    I hope I understood your problem correctly.

  • The patch node of the latest release are saying:

    • [New] Plugin sourcefiles can be compiled "on the fly" and will be loaded directly from your project folder
    • [New] Added command "reloadplugins" to reload plugins during runtime (also added permission)


    I guess I'd like to see more information about that very useful feature. Otherwise you would have to compile your plugin, deploy it to the game, start the game, check if the plugin works, which can be a rather long cycle.
    If - however - the dynamic class loading works, development will be easier.


    (In the best possible scenario I'd love to attach the debugger to the running game and use breakpoints to step through things, which I understand might not be possible)


    And to answer your question, a resource/plugin.yml is in place. Not sure what projectinfo.txt is though.


    Thanks!

  • There are basically three ways to load a plugin:

    • You deploy a compiled jar file in your plugin subfolder
    • You deploy class files in the plugin subfolder. Then it's necessary to put a "classinfo.txt" file in your main plugin subfolder (e.g. game/plugins/MyPlugin/classinfo.txt)
    • You put a "projectinfo.txt" file into an empty plugin subfolder, which has a reference to your source files. Then the game will compile the project on the fly


    If you use a jar, just put the jar file into your plugin subfolder, nothing else you have to do. If you want to load class files, you have to put a "classinfo.txt" file into your project subfolder which contains the name of your plugin: name: MyPlugin.


    If you want to compile a project, you need to put a "projectinfo.txt" file there (as @TheMrMik mentioned), you have to put these information into the file:

    Code
    name: Projectname
    path: <path to your project src folder>
    assets: (optional) <path to your project assets>
    //EXAMPLE:
    name: MyPlugin
    path: C:/Projects/RW/MyPluginProject/src


    Important: Unfortunately you have to run the game with the JDK in order to be able to compile your projects. We are still working on a better solution for that.


    ______________________


    About reloading your plugins: You can just open console (key ^ or `) and type "reloadplugins", this will unload and reload all existing plugins. This is only intended for testing purposes. When running a multiplayer server, you can alternatively just type "reloadplugins" into server console ;)

  • Thanks a lot! That's what I was looking for.
    Not sure how to start the game with the JDK since I'm using the steam version, but I'll check the forum for that. I'm sure someone has documented that.
    Thanks again!

  • Hmm... this might be a little bit tricky with the Steam version :| I'm afraid it doesn't work properly, since the Steam version is delivered with an own JVM. We are looking for a solution for that!
    As a workaround, you could use the dedicated server instead (set server_hive_verification in the server.properties to false, and connect to it to "localhost")

  • Another question (well, two!) about "reloadplugins":


    1) While unloading, does the system call the onDisable() method of each plugin? I am not sure the method is called when the player 'closes' the world (only tried single player so far).


    2) When loading the plug-ins again, does the system 'reconnect' each player to the plug-in? I mean: a plug-in may have some setup to do when a player connect to the game; when a plug-in is restarted all players are already connected, how does the plug-in knows about them?

  • 1) While unloading, does the system call the onDisable() method of each plugin? I am not sure the method is called when the player 'closes' the world (only tried single player so far).

    Right now it isn't called, but this will be changed ;) However, the method is not fully reliable, because if the application gets terminated forcefully (i.e. the process gets killed), or if it crashes, there is no way to call the "onDisable()" method. Currently it's only called when the plugins get reloaded.


    2) When loading the plug-ins again, does the system 'reconnect' each player to the plug-in? I mean: a plug-in may have some setup to do when a player connect to the game; when a plug-in is restarted all players are already connected, how does the plug-in knows about them?

    When you reload the plugins, the "PlayerConnectEvent" and "PlayerSpawnEvent" will be called again for every plugin (so basically it's just like a server restart) :)

  • Ok, got it working with the dedicated server files and the Steam client connecting to localhost.
    I can also debug the dedicated server from the plugin project and set breakpoints, yay!
    (I can provide instructions for IntelliJ if desired).


    Thanks for your help!

  • Right now it (i.e. onDisabled() ) isn't called, but this will be changed ;) However, the method is not fully reliable, because if the application gets terminated forcefully (i.e. the process gets killed), or if it crashes, there is no way to call the "onDisable()" method. Currently it's only called when the plugins get reloaded.


    When you reload the plugins, the "PlayerConnectEvent" and "PlayerSpawnEvent" will be called again for every plugin (so basically it's just like a server restart) :)


    Great! Currently I use onDisable() mostly to be sure resources are released properly, should the plug-in be restarted (i.e. exactly in a "reloadplugins" perspective); if the process is killed (or crashes), nothing can be assumed anyway.


    I can also debug the dedicated server from the plugin project and set breakpoints, yay!
    (I can provide instructions for IntelliJ if desired).

    I didn't try very hard, but so far I could not set my Eclipse to debug the plug-in .jar (I use Eclipse as I already use it for other tasks).


    EDIT / UPDATE: Eventually I was able to debug a plug-in running inside RW with Eclipse. I'll post details soon, but the summary is to use the 'usual' way for Java remote debugging (where 'remote' means another process, not necessarily another machine), but modifying the RW dedicated server startup script to launch Java with the debug command line options.

  • About compiling a plugin during runtime: It's possible now to set the path to the JDK ("plugins_jdk_path") in the config.properties file (or when running a server, in the server.properties file accordingly). Keep in mind that you have to escape colons and backslashes, e.g. plugins_jdk_path=C\:\\\\Program Files\\Java\\jdk1.8.0_91

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!