use of javax.script.Invocable in project HeavenMS by ronancpl.
the class QuestScriptManager method end.
public void end(MapleClient c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("end", mode, type, selection);
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
}
use of javax.script.Invocable in project HeavenMS by ronancpl.
the class QuestScriptManager method start.
public void start(MapleClient c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("start", mode, type, selection);
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
}
use of javax.script.Invocable in project HeavenMS by ronancpl.
the class ReactorScriptManager method touching.
public synchronized void touching(MapleClient c, MapleReactor reactor, boolean touching) {
try {
Invocable iv = getInvocable("reactor/" + reactor.getId() + ".js", c);
if (iv == null)
return;
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
engine.put("rm", rm);
if (touching) {
iv.invokeFunction("touch");
} else {
iv.invokeFunction("untouch");
}
} catch (final ScriptException | NoSuchMethodException | NullPointerException ute) {
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", ute);
}
}
use of javax.script.Invocable in project HeavenMS by ronancpl.
the class ReactorScriptManager method act.
public void act(MapleClient c, MapleReactor reactor) {
try {
Invocable iv = getInvocable("reactor/" + reactor.getId() + ".js", c);
if (iv == null)
return;
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
engine.put("rm", rm);
iv.invokeFunction("act");
} catch (final ScriptException | NoSuchMethodException | NullPointerException e) {
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
}
}
use of javax.script.Invocable in project HeavenMS by ronancpl.
the class ItemScriptManager method getItemScript.
public void getItemScript(MapleClient c, String scriptName) {
if (scripts.containsKey(scriptName)) {
try {
scripts.get(scriptName).invokeFunction("start", new ItemScriptMethods(c));
} catch (ScriptException | NoSuchMethodException ex) {
FilePrinter.printError(FilePrinter.ITEM + scriptName + ".txt", ex);
}
return;
}
File scriptFile = new File("scripts/item/" + scriptName + ".js");
if (!scriptFile.exists()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
FileReader fr = null;
ScriptEngine portal = sef.getScriptEngine();
try {
fr = new FileReader(scriptFile);
CompiledScript compiled = ((Compilable) portal).compile(fr);
compiled.eval();
final Invocable script = ((Invocable) portal);
scripts.put(scriptName, script);
script.invokeFunction("start", new ItemScriptMethods(c));
} catch (final UndeclaredThrowableException | ScriptException ute) {
FilePrinter.printError(FilePrinter.ITEM + scriptName + ".txt", ute);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.ITEM + scriptName + ".txt", e);
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Aggregations