83 lines
2.7 KiB
Java
83 lines
2.7 KiB
Java
/*
|
|
This file is part of the OdinMS Maple Story Server
|
|
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
|
Matthias Butz <matze@odinms.de>
|
|
Jan Christian Meyer <vimes@odinms.de>
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation version 3 as published by
|
|
the Free Software Foundation. You may not use, modify or distribute
|
|
this program under any other version of the GNU Affero General Public
|
|
License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package scripting.map;
|
|
|
|
import client.MapleCharacter;
|
|
import client.MapleClient;
|
|
import scripting.AbstractScriptManager;
|
|
import tools.FilePrinter;
|
|
|
|
import javax.script.Invocable;
|
|
import javax.script.ScriptException;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class MapScriptManager extends AbstractScriptManager {
|
|
private static final MapScriptManager instance = new MapScriptManager();
|
|
|
|
private final Map<String, Invocable> scripts = new HashMap<>();
|
|
|
|
public static MapScriptManager getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
public void reloadScripts() {
|
|
scripts.clear();
|
|
}
|
|
|
|
public boolean runMapScript(MapleClient c, String mapScriptPath, boolean firstUser) {
|
|
if (firstUser) {
|
|
MapleCharacter chr = c.getPlayer();
|
|
int mapid = chr.getMapId();
|
|
if (chr.hasEntered(mapScriptPath, mapid)) {
|
|
return false;
|
|
} else {
|
|
chr.enteredScript(mapScriptPath, mapid);
|
|
}
|
|
}
|
|
|
|
Invocable iv = scripts.get(mapScriptPath);
|
|
if (iv != null) {
|
|
try {
|
|
iv.invokeFunction("start", new MapScriptMethods(c));
|
|
return true;
|
|
} catch (final ScriptException | NoSuchMethodException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
try {
|
|
iv = (Invocable) getInvocableScriptEngine("map/" + mapScriptPath + ".js");
|
|
if (iv == null) {
|
|
return false;
|
|
}
|
|
|
|
scripts.put(mapScriptPath, iv);
|
|
iv.invokeFunction("start", new MapScriptMethods(c));
|
|
return true;
|
|
} catch (final Exception e) {
|
|
FilePrinter.printError(FilePrinter.MAP_SCRIPT + mapScriptPath + ".txt", e);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |