use of org.dragonet.rhino.CustomMethod in project Dragonet-Legacy by DragonetMC.
the class ScriptAPI method addMethod.
@JSFunction
public static void addMethod(String method, String handler, String ownerUID) {
//Check if ownerUID belongs to a valid script
Script scr = null;
try {
for (Script s : DragonetServer.instance().getRhino().getScripts()) {
if (s.getUID().equals(ownerUID)) {
scr = s;
}
}
} catch (WrappedException e) {
DragonetServer.instance().getLogger().error("[DragonetAPI] Script tried to add a method before initialization finished! Please use postInit for this.");
}
if (scr == null) {
DragonetServer.instance().getLogger().error("[DragonetAPI] Script doesn't have a valid UID but is trying to register method " + method + "! Received '" + ownerUID + "', this does not belong to any script!");
DragonetServer.instance().getLogger().error("[DragonetAPI] Method " + method + " will not be defined. This will cause issues with other scripts.");
return;
}
//Check if method name is already taken
for (CustomMethod m : CustomMethod.methods) {
if (m.method.equals(method)) {
DragonetServer.instance().getLogger().error("[DragonetAPI] Script " + scr.getUID() + " (" + scr.getName() + ")" + " tried to reserve method " + method + ", but this has already been reserved by " + m.owner.getName() + "!");
DragonetServer.instance().getLogger().error("[DragonetAPI] Method " + method + " will not be defined. This will cause issues with other scripts.");
}
}
//Finally, add method
CustomMethod.methods.add(new CustomMethod(method, handler, scr));
DragonetServer.instance().getLogger().info("[DragonetAPI] Script " + scr.getUID() + " (" + scr.getName() + ") added API method " + method + " sucessfully.");
}
Aggregations