Easier way to test your plugins

Hello!

I present you an automatic solution for:
-Building your plugin with gradle
-Copying the .jar into the mods folder
-Stopping a running server
-Starting the server(with your plugin to test)

(Designed for Windows)

There are 4 parts:
-In your build.gradle the copying
-start.bat - starts your server
-stop.vbs - stops the server that was started with start.bat
-runPlugin.bat - Puts all things together so you only have to execute the runPlugin.bat

My project structure:

-SpongeThings
	-Server
		-start.bat
		-stop.vbs
	-Project1
		-build.gradle
		-runPlugin.bat
	-Project2
		-also
	-Project3
		-also

Of course you can modify the paths so it fits for you.

How to do it yourself:

-Add this to your build.gradle to let gradle copy the output .jar(s):

tasks.assemble.doLast {
    FileTree tree = fileTree("build/libs").include("*.jar")
    tree.each {File file ->
        copy {
            from file
            into "../Server/mods"
        }
        println("Copied: " + file)
    }
}

-You probably already have a start.bat to start the server. You have to add the following to set the title(you can modify this too):

title MinecraftServer
java -jar ...

-stop.vbs - The argument in AppActivate has to be the same as the title in the start.bat:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.AppActivate("MinecraftServer")
WshShell.SendKeys("/stop")
WshShell.SendKeys("{ENTER}")

-runPlugin.bat - assembles the plugin(which also copies the .jar), stops existing server, waits 3 seconds for saving(may vary, 3 seconds are enough for my server), starts the server:

call gradlew.bat assemble
cd ../Server/
cscript stopServer.vbs
timeout /T 3 /nobreak
call start.bat

The is absolutely not a masterpiece, it is not complex and you have to insert this in every project.
Suggestions are welcome! Maybe some one-file solution? How to do that?

I don’t like the fact that I simulate user input by focusing the server-prompt-window and entering the stop command. I firstly tried to terminate the task(by WMIC) but then the server had no time to shutdown(Think before doing something…). Another try was to get the PID(ProcessId) of the server and the give it to “taskkill.exe” to ask the server for shutting down. But Mojang hasn’t implemented this feature… I spent a lot of time. What I’ve learned: WMIC is cool.

I hope it helps someone. :blush:

RandomByte

1 Like

another (and probably less tedious) way is to run Sponge within your IDE and let your plugin in the classpath. just hit run and your plugin will be loaded. with this method, you can also use hotswapping to change your code on the fly, without having to restart the server. generally more efficient.

i should make a tutorial on that later.

7 Likes

You can just run
gradle startServer or gradle startClient if you’re using ForgeGradle

I’d love to see a tutorial on this.

Is that even possible? That would be the best way!