WurmArgsMod
Mthec edited this page Nov 18, 2015
·
3 revisions
This is the interface that will allow you to get any arguments passed to the launcher. You may have used start=foldername
to start a server without bringing up the official UI.
You also need to implement WurmMod when implementing WurmArgsMod.
import java.util.HashSet;
import java.util.Set;
import mod.wurmonline.serverlauncher.ServerController;
import org.gotti.wurmunlimited.modloader.interfaces.WurmArgsMod;
import org.gotti.wurmunlimited.modloader.interfaces.WurmMod;
public class Example implements WurmMod, WurmArgsMod {
public Set<String> getArgs() {
Set<String> args = new HashSet<>();
args.add("animals");
return args;
}
public void parseArgs(ServerController controller) {
String animals = controller.arguments.getOptionValue("animals");
// Code that does something.
System.out.println(animals + " animals created.");
}
}
Which would result in:
>serverlauncher.bat animals=1000
1000 animals created.
You can specify as many arguments as you want. parseArgs
is optional, you only need it if you're not using WurmUIMod as well, or if you need the controller at all. getArgs
is called quite early on, but still after configure.
Here is an example that fetches the arguments from the mod.properties
file using configure
and uses them with WurmUIMod:
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import mod.wurmonline.serverlauncher.gui.ServerGuiController;
import org.gotti.wurmunlimited.modloader.interfaces.Configurable;
import org.gotti.wurmunlimited.modloader.interfaces.WurmArgsMod;
import org.gotti.wurmunlimited.modloader.interfaces.WurmMod;
import org.gotti.wurmunlimited.modloader.interfaces.WurmUIMod;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
public class Example implements WurmMod, WurmUIMod, Configurable, WurmArgsMod {
Set<String> args;
String name;
public String getName() {
return name;
}
public Set<String> getArgs () { return args; }
public void configure (Properties properties) {
args = new HashSet<>(Arrays.asList(properties.getProperty("args").split(",")));
name = properties.getProperty("name");
}
public Region getRegion(ServerGuiController controller) {
VBox vbox = new VBox();
for (String arg : args) {
Label label = new Label(controller.arguments.getOptionValue(arg));
vbox.getChildren().add(label);
}
return vbox;
}
}