Implementing Chris's scripting engine and dropping the old one.
Author: UnAfraid Source: L2jUnity free release.
This commit is contained in:
@@ -16,12 +16,13 @@
|
||||
*/
|
||||
package handlers.admincommandhandlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
|
||||
import com.l2jmobius.gameserver.instancemanager.QuestManager;
|
||||
@@ -38,6 +39,7 @@ import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
public class AdminQuest implements IAdminCommandHandler
|
||||
{
|
||||
public static final Logger LOGGER = Logger.getLogger(AdminQuest.class.getName());
|
||||
private static final String[] ADMIN_COMMANDS =
|
||||
{
|
||||
"admin_quest_reload",
|
||||
@@ -47,137 +49,89 @@ public class AdminQuest implements IAdminCommandHandler
|
||||
"admin_quest_info"
|
||||
};
|
||||
|
||||
private Quest findScript(String script)
|
||||
{
|
||||
if (Util.isDigit(script))
|
||||
{
|
||||
return QuestManager.getInstance().getQuest(Integer.parseInt(script));
|
||||
}
|
||||
return QuestManager.getInstance().getQuest(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAdminCommand(String command, L2PcInstance activeChar)
|
||||
{
|
||||
if (activeChar == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// syntax will either be:
|
||||
// //quest_reload <id>
|
||||
// //quest_reload <questName>
|
||||
// The questName MUST start with a non-numeric character for this to work,
|
||||
// regardless which of the two formats is used.
|
||||
// Example: //quest_reload orc_occupation_change_1
|
||||
// Example: //quest_reload chests
|
||||
// Example: //quest_reload SagasSuperclass
|
||||
// Example: //quest_reload 12
|
||||
if (command.startsWith("admin_quest_reload"))
|
||||
{
|
||||
final String[] parts = command.split(" ");
|
||||
if (parts.length < 2)
|
||||
StringTokenizer st = new StringTokenizer(command);
|
||||
st.nextToken(); // skip command token
|
||||
|
||||
if (!st.hasMoreTokens())
|
||||
{
|
||||
activeChar.sendMessage("Usage: //quest_reload <questFolder>.<questSubFolders...>.questName> or //quest_reload <id>");
|
||||
activeChar.sendMessage("Usage: //quest_reload <questName> or <questId>");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
String script = st.nextToken();
|
||||
Quest quest = findScript(script);
|
||||
if (quest == null)
|
||||
{
|
||||
// try the first param as id
|
||||
try
|
||||
{
|
||||
if (QuestManager.getInstance().reload(Integer.parseInt(parts[1])))
|
||||
{
|
||||
activeChar.sendMessage("Quest Reloaded Successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
activeChar.sendMessage("Quest Reloaded Failed");
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
if (QuestManager.getInstance().reload(parts[1]))
|
||||
{
|
||||
activeChar.sendMessage("Quest Reloaded Successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
activeChar.sendMessage("Quest Reloaded Failed");
|
||||
}
|
||||
}
|
||||
activeChar.sendMessage("The script " + script + " couldn't be found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!quest.reload())
|
||||
{
|
||||
activeChar.sendMessage("Failed to reload " + script + "!");
|
||||
return false;
|
||||
}
|
||||
|
||||
activeChar.sendMessage("Script successful reloaded.");
|
||||
}
|
||||
// script load should NOT be used in place of reload. If a script is already loaded
|
||||
// successfully, quest_reload ought to be used. The script_load command should only
|
||||
// be used for scripts that failed to load altogether (eg. due to errors) or that
|
||||
// did not at all exist during server boot. Using script_load to re-load a previously
|
||||
// loaded script may cause unpredictable script flow, minor loss of data, and more.
|
||||
// This provides a way to load new scripts without having to reboot the server.
|
||||
else if (command.startsWith("admin_script_load"))
|
||||
{
|
||||
final String[] parts = command.split(" ");
|
||||
if (parts.length < 2)
|
||||
StringTokenizer st = new StringTokenizer(command);
|
||||
st.nextToken(); // skip command token
|
||||
|
||||
if (!st.hasMoreTokens())
|
||||
{
|
||||
// activeChar.sendMessage("Example: //script_load <questFolder>/<questSubFolders...>/<filename>.<ext> ");
|
||||
activeChar.sendMessage("Example: //script_load quests/SagasSuperclass/__init__.py");
|
||||
activeChar.sendMessage("Usage: //script_load path/to/script.java");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
String script = st.nextToken();
|
||||
try
|
||||
{
|
||||
File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, parts[1]);
|
||||
// Trying to reload by script name.
|
||||
if (!file.exists())
|
||||
{
|
||||
final Quest quest = QuestManager.getInstance().getQuest(parts[1]);
|
||||
if (quest != null)
|
||||
{
|
||||
file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, quest.getClass().getName().replaceAll("\\.", "/") + ".java");
|
||||
}
|
||||
}
|
||||
|
||||
// Reloading by full path
|
||||
if (file.isFile())
|
||||
{
|
||||
try
|
||||
{
|
||||
L2ScriptEngineManager.getInstance().executeScript(file);
|
||||
|
||||
// This part should be called only when the script is successfully loaded.
|
||||
activeChar.sendMessage("Script Successfully Loaded.");
|
||||
}
|
||||
catch (ScriptException e)
|
||||
{
|
||||
activeChar.sendMessage("Failed loading: " + parts[1]);
|
||||
L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
activeChar.sendMessage("Failed loading: " + parts[1]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
activeChar.sendMessage("File Not Found: " + parts[1]);
|
||||
}
|
||||
L2ScriptEngineManager.getInstance().executeScript(Paths.get(script));
|
||||
activeChar.sendMessage("Script loaded seccessful!");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
activeChar.sendMessage("Failed to load script!");
|
||||
LOGGER.log(Level.WARNING, "Failed to load script " + script + "!", e);
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("admin_script_unload"))
|
||||
{
|
||||
final String[] parts = command.split(" ");
|
||||
if (parts.length < 2)
|
||||
StringTokenizer st = new StringTokenizer(command);
|
||||
st.nextToken(); // skip command token
|
||||
|
||||
if (!st.hasMoreTokens())
|
||||
{
|
||||
activeChar.sendMessage("Example: //script_unload questName/questId");
|
||||
activeChar.sendMessage("Usage: //script_load path/to/script.java");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
String script = st.nextToken();
|
||||
Quest quest = findScript(script);
|
||||
if (quest == null)
|
||||
{
|
||||
final Quest q = Util.isDigit(parts[1]) ? QuestManager.getInstance().getQuest(Integer.parseInt(parts[1])) : QuestManager.getInstance().getQuest(parts[1]);
|
||||
|
||||
if (q != null)
|
||||
{
|
||||
if (q.unload())
|
||||
{
|
||||
activeChar.sendMessage("Script Successfully Unloaded [" + q.getName() + "/" + q.getId() + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
activeChar.sendMessage("Failed unloading [" + q.getName() + "/" + q.getId() + "].");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
activeChar.sendMessage("The quest [" + parts[1] + "] was not found!.");
|
||||
}
|
||||
activeChar.sendMessage("The script " + script + " couldn't be found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
quest.unload();
|
||||
activeChar.sendMessage("Script successful unloaded!");
|
||||
}
|
||||
else if (command.startsWith("admin_show_quests"))
|
||||
{
|
||||
@@ -212,7 +166,7 @@ public class AdminQuest implements IAdminCommandHandler
|
||||
}
|
||||
|
||||
final NpcHtmlMessage msg = new NpcHtmlMessage(0, 1);
|
||||
msg.setFile(activeChar.getHtmlPrefix(), "html/admin/npc-quests.htm");
|
||||
msg.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npc-quests.htm");
|
||||
msg.replace("%quests%", sb.toString());
|
||||
msg.replace("%objid%", character.getObjectId());
|
||||
msg.replace("%questName%", "");
|
||||
@@ -318,7 +272,7 @@ public class AdminQuest implements IAdminCommandHandler
|
||||
}
|
||||
|
||||
final NpcHtmlMessage msg = new NpcHtmlMessage(0, 1);
|
||||
msg.setFile(activeChar.getHtmlPrefix(), "html/admin/npc-quests.htm");
|
||||
msg.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npc-quests.htm");
|
||||
msg.replace("%quests%", sb.toString());
|
||||
msg.replace("%questName%", "<table><tr><td width=\"50\" align=\"left\"><a action=\"bypass -h admin_script_load " + quest.getName() + "\">Reload</a></td> <td width=\"150\" align=\"center\"><a action=\"bypass -h admin_quest_info " + quest.getName() + "\">" + quest.getName() + "</a></td> <td width=\"50\" align=\"right\"><a action=\"bypass -h admin_script_unload " + quest.getName() + "\">Unload</a></tr></td></table>");
|
||||
activeChar.sendPacket(msg);
|
||||
@@ -331,4 +285,4 @@ public class AdminQuest implements IAdminCommandHandler
|
||||
{
|
||||
return ADMIN_COMMANDS;
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,8 +18,8 @@ package handlers.admincommandhandlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.cache.HtmCache;
|
||||
@@ -55,6 +55,8 @@ import com.l2jmobius.gameserver.util.Util;
|
||||
*/
|
||||
public class AdminReload implements IAdminCommandHandler
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(AdminReload.class.getName());
|
||||
|
||||
private static final String[] ADMIN_COMMANDS =
|
||||
{
|
||||
"admin_reload"
|
||||
@@ -217,31 +219,29 @@ public class AdminReload implements IAdminCommandHandler
|
||||
}
|
||||
case "effect":
|
||||
{
|
||||
final File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "handlers/EffectMasterHandler.java");
|
||||
try
|
||||
{
|
||||
L2ScriptEngineManager.getInstance().executeScript(file);
|
||||
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Effects.");
|
||||
L2ScriptEngineManager.getInstance().executeEffectMasterHandler();
|
||||
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded effect master handler.");
|
||||
}
|
||||
catch (ScriptException e)
|
||||
catch (Exception e)
|
||||
{
|
||||
L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
|
||||
activeChar.sendMessage("There was an error while loading handlers.");
|
||||
LOGGER.log(Level.WARNING, "Failed executing effect master handler!", e);
|
||||
activeChar.sendMessage("Error reloading effect master handler!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "handler":
|
||||
{
|
||||
final File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "handlers/MasterHandler.java");
|
||||
try
|
||||
{
|
||||
L2ScriptEngineManager.getInstance().executeScript(file);
|
||||
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Handlers.");
|
||||
L2ScriptEngineManager.getInstance().executeMasterHandler();
|
||||
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded master handler.");
|
||||
}
|
||||
catch (ScriptException e)
|
||||
catch (Exception e)
|
||||
{
|
||||
L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
|
||||
activeChar.sendMessage("There was an error while loading handlers.");
|
||||
LOGGER.log(Level.WARNING, "Failed executing master handler!", e);
|
||||
activeChar.sendMessage("Error reloading master handler!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -16,12 +16,11 @@
|
||||
*/
|
||||
package handlers.telnethandlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.l2jmobius.gameserver.cache.HtmCache;
|
||||
import com.l2jmobius.gameserver.data.sql.impl.TeleportLocationTable;
|
||||
@@ -116,29 +115,16 @@ public class ReloadHandler implements ITelnetHandler
|
||||
{
|
||||
try
|
||||
{
|
||||
final String questPath = st.hasMoreTokens() ? st.nextToken() : "";
|
||||
String questPath = st.hasMoreTokens() ? st.nextToken() : "";
|
||||
|
||||
final File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, questPath);
|
||||
if (file.isFile())
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
L2ScriptEngineManager.getInstance().executeScript(file);
|
||||
_print.println(file.getName() + " was successfully loaded!\n");
|
||||
}
|
||||
catch (ScriptException e)
|
||||
{
|
||||
_print.println("Failed loading: " + questPath);
|
||||
L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_print.println("Failed loading: " + questPath);
|
||||
}
|
||||
L2ScriptEngineManager.getInstance().executeScript(Paths.get(questPath));
|
||||
_print.println(questPath + " was successfully loaded!\n");
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
_print.println(file.getName() + " is not a file in: " + questPath);
|
||||
_log.log(Level.WARNING, "Failed to execute script!", e);
|
||||
}
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
|
Reference in New Issue
Block a user