Skip to content
Alexander Gottwald edited this page Sep 9, 2017 · 1 revision

The callback API is a way for mods to add callbacks to their code into server methods.

A callback is set of methods which are exposed to the server through an automaticly generated interface. The callback API exposes all methods annotated with @CallbackApi or all methods of the callback object if the annotation is not used. So it's possible to create standalone callback objects or expose methods from the Mod object itself.

@CallbackApi
public long getAdjustedLastPolledAge(CreatureStatus creatureStatus, boolean reborn) {
	return creatureStatus.lastPolledAge + 5;
}

A mod can add a callback to any server class. The callback will be added with the supplied name:

CtClass ctCreatureStatus = classPool.get("com.wurmonline.server.creatures.CreatureStatus");
HookManager.getInstance().addCallback(ctCreatureStatus, "creatureagemod", callback);

The callback will be added as the static field creatureagemod to the class and can be accessed from modified code:

CtMethod method = ctClass.getMethod("pollAge", "(I)Z");
method.instrument(new ExprEditor() {
	@Override
	public void edit(FieldAccess f) throws CannotCompileException {
		f.replace("$_ = creatureagemod.getAdjustedLastPolledAge(this, reborn);");
	}
});

The callback method creatureagemod.getAdjustedLastPolledAge() can be called directly from the modified server code.

Clone this wiki locally