From 972446e552f87d006a7cf9450183cdf020028d26 Mon Sep 17 00:00:00 2001
From: Rumen Nikiforov <unafraid89@gmail.com>
Date: Thu, 10 Jul 2014 00:17:37 +0000
Subject: [PATCH] BETA: Minor admin commands update: 	* Reworking
 !//show_quests command to work on all `L2Character` objects. 		*
 Removing listeners size based restrictions and handling this better. 	*
 Reworking !//quest_info to work without any target requirement by just using
 name example !//quest_info NonTalkingNpcs 		* Removing listeners
 size based restrictions and handling this better. 		* Sorting
 event type and npc ids.

---
 .../dist/game/data/html/admin/npc-quests.htm  |  14 --
 .../admincommandhandlers/AdminQuest.java      | 188 +++++++++---------
 2 files changed, 96 insertions(+), 106 deletions(-)

diff --git a/L2J_DataPack_BETA/dist/game/data/html/admin/npc-quests.htm b/L2J_DataPack_BETA/dist/game/data/html/admin/npc-quests.htm
index b9cab406c8..10a54ca168 100644
--- a/L2J_DataPack_BETA/dist/game/data/html/admin/npc-quests.htm
+++ b/L2J_DataPack_BETA/dist/game/data/html/admin/npc-quests.htm
@@ -1,19 +1,5 @@
 <html><title>NPC Info</title><body>
 <center>
-<table width=270 border=0 bgcolor="444444">
-<tr>
-<td><button value="Kill" action="bypass -h admin_kill" width=60 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
-<td><button value="Delete" action="bypass -h admin_delete" width=60 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
-<td><button value="Recall" action="bypass -h admin_recall_npc" width=60 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
-<td><button value="Buffs" action="bypass admin_getbuffs" width=60 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
-</tr>
-<tr>
-<td><button value="Quests" action="bypass admin_show_quests %tmplid%" width=60 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
-<td><button value="NpcViewMod" action="bypass NpcViewMod view %objid%" width=60 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
-<td></td>
-<td></td>
-</tr>
-</table>
 <br><img src="L2UI.SquareWhite" width=260 height=1><br>
 %questName%
 <table width=270 border=0>
diff --git a/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminQuest.java b/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminQuest.java
index 0aff3ec512..761b71dda0 100644
--- a/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminQuest.java
+++ b/L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminQuest.java
@@ -19,15 +19,15 @@
 package handlers.admincommandhandlers;
 
 import java.io.File;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.TreeSet;
 
 import javax.script.ScriptException;
 
 import com.l2jserver.gameserver.handler.IAdminCommandHandler;
 import com.l2jserver.gameserver.instancemanager.QuestManager;
-import com.l2jserver.gameserver.model.actor.L2Npc;
+import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.events.EventType;
 import com.l2jserver.gameserver.model.events.ListenerRegisterType;
@@ -189,139 +189,143 @@ public class AdminQuest implements IAdminCommandHandler
 			{
 				activeChar.sendMessage("Get a target first.");
 			}
-			else if (!activeChar.getTarget().isNpc())
+			else if (!activeChar.getTarget().isCharacter())
 			{
 				activeChar.sendMessage("Invalid Target.");
 			}
 			else
 			{
-				L2Npc npc = L2Npc.class.cast(activeChar.getTarget());
-				final NpcHtmlMessage msg = new NpcHtmlMessage(0, 1);
-				msg.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npc-quests.htm");
-				StringBuilder sb = new StringBuilder();
-				Set<String> questset = new HashSet<>();
+				final L2Character character = (L2Character) activeChar.getTarget();
+				final StringBuilder sb = new StringBuilder();
+				final Set<String> questNames = new TreeSet<>();
 				for (EventType type : EventType.values())
 				{
-					for (AbstractEventListener listener : npc.getListeners(type))
+					for (AbstractEventListener listener : character.getListeners(type))
 					{
 						if (listener.getOwner() instanceof Quest)
 						{
 							final Quest quest = (Quest) listener.getOwner();
-							if (questset.contains(quest.getName()))
-							{
-								continue;
-							}
-							questset.add(quest.getName());
-							if (quest.getListeners().size() > 20)
+							if (questNames.contains(quest.getName()))
 							{
-								sb.append("<tr><td colspan=\"4\">" + quest.getName() + " - " + quest.getListeners().size() + " listeners.</td></tr>");
 								continue;
 							}
 							sb.append("<tr><td colspan=\"4\"><font color=\"LEVEL\"><a action=\"bypass -h admin_quest_info " + quest.getName() + "\">" + quest.getName() + "</a></font></td></tr>");
+							questNames.add(quest.getName());
 						}
 					}
 				}
+				
+				final NpcHtmlMessage msg = new NpcHtmlMessage(0, 1);
+				msg.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npc-quests.htm");
 				msg.replace("%quests%", sb.toString());
-				msg.replace("%objid%", npc.getObjectId());
-				msg.replace("%tmplid%", Integer.toString(npc.getTemplate().getId()));
+				msg.replace("%objid%", character.getObjectId());
 				msg.replace("%questName%", "");
 				activeChar.sendPacket(msg);
-				questset.clear();
 			}
 		}
 		else if (command.startsWith("admin_quest_info "))
 		{
-			if (activeChar.getTarget() == null)
+			final String questName = command.substring("admin_quest_info ".length());
+			final Quest quest = QuestManager.getInstance().getQuest(questName);
+			String events = "", npcs = "", items = "", timers = "";
+			int counter = 0;
+			if (quest == null)
 			{
-				activeChar.sendMessage("Get a target first.");
-			}
-			else if (!activeChar.getTarget().isNpc())
-			{
-				activeChar.sendMessage("Invalid Target.");
+				activeChar.sendMessage("Couldn't find quest or script with name " + questName + " !");
+				return false;
 			}
-			else
+			
+			final Set<EventType> listenerTypes = new TreeSet<>();
+			for (AbstractEventListener listener : quest.getListeners())
 			{
-				String questName = command.substring("admin_quest_info ".length());
-				Quest quest = QuestManager.getInstance().getQuest(questName);
-				if (quest == null)
+				if (!listenerTypes.contains(listener.getType()))
 				{
-					return false;
+					events += ", " + listener.getType().name();
+					listenerTypes.add(listener.getType());
+					counter++;
 				}
-				if (quest.getListeners().size() > 20)
+				if (counter > 10)
 				{
-					return false;
+					counter = 0;
+					break;
 				}
-				L2Npc npc = L2Npc.class.cast(activeChar.getTarget());
-				StringBuilder sb = new StringBuilder();
-				final NpcHtmlMessage msg = new NpcHtmlMessage(0, 1);
-				msg.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npc-quests.htm");
-				String events = "", npcs = "", items = "", timers = "";
-				
-				for (EventType type : EventType.values())
-				{
-					for (AbstractEventListener listener : npc.getListeners(type))
-					{
-						if (listener.getOwner() == quest)
-						{
-							events += ", " + type.name();
-							for (int npcId : quest.getRegisteredIds(ListenerRegisterType.NPC))
-							{
-								npcs += ", " + npcId;
-							}
-						}
-					}
-				}
-				
-				if (!events.isEmpty())
-				{
-					events = events.substring(2);
-				}
-				
-				if (!npcs.isEmpty())
+			}
+			
+			final Set<Integer> npcIds = new TreeSet<>(quest.getRegisteredIds(ListenerRegisterType.NPC));
+			for (int npcId : npcIds)
+			{
+				npcs += ", " + npcId;
+				counter++;
+				if (counter > 50)
 				{
-					npcs = npcs.substring(2);
+					counter = 0;
+					break;
 				}
-				
-				if (quest.getRegisteredItemIds() != null)
+			}
+			
+			if (!events.isEmpty())
+			{
+				events = listenerTypes.size() + ": " + events.substring(2);
+			}
+			
+			if (!npcs.isEmpty())
+			{
+				npcs = npcIds.size() + ": " + npcs.substring(2);
+			}
+			
+			if (quest.getRegisteredItemIds() != null)
+			{
+				for (int itemId : quest.getRegisteredItemIds())
 				{
-					for (int itemId : quest.getRegisteredItemIds())
+					items += ", " + itemId;
+					counter++;
+					if (counter > 20)
 					{
-						items += ", " + itemId;
+						counter = 0;
+						break;
 					}
-					items = items.substring(2);
 				}
-				
-				for (List<QuestTimer> list : quest.getQuestTimers().values())
+				items = quest.getRegisteredItemIds().length + ":" + items.substring(2);
+			}
+			
+			for (List<QuestTimer> list : quest.getQuestTimers().values())
+			{
+				for (QuestTimer timer : list)
 				{
-					for (QuestTimer timer : list)
+					timers += "<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">" + timer.getName() + ":</font> <font color=00FF00>Active: " + timer.getIsActive() + " Repeatable: " + timer.getIsRepeating() + " Player: " + timer.getPlayer() + " Npc: " + timer.getNpc() + "</font></td></tr></table></td></tr>";
+					counter++;
+					if (counter > 10)
 					{
-						timers += "<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">" + timer.getName() + ":</font> <font color=00FF00>Active: " + timer.getIsActive() + " Repeatable: " + timer.getIsRepeating() + " Player: " + timer.getPlayer() + " Npc: " + timer.getNpc() + "</font></td></tr></table></td></tr>";
+						break;
 					}
 				}
-				
-				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">ID:</font> <font color=00FF00>" + quest.getId() + "</font></td></tr></table></td></tr>");
-				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Name:</font> <font color=00FF00>" + quest.getName() + "</font></td></tr></table></td></tr>");
-				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Descr:</font> <font color=00FF00>" + quest.getDescr() + "</font></td></tr></table></td></tr>");
-				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Path:</font> <font color=00FF00>" + quest.getClass().getName().substring(0, quest.getClass().getName().lastIndexOf('.')).replaceAll("\\.", "/") + "</font></td></tr></table></td></tr>");
-				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Events:</font> <font color=00FF00>" + events + "</font></td></tr></table></td></tr>");
-				if (!npcs.isEmpty())
-				{
-					sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">NPCs:</font> <font color=00FF00>" + npcs + "</font></td></tr></table></td></tr>");
-				}
-				if (!items.isEmpty())
-				{
-					sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Items:</font> <font color=00FF00>" + items + "</font></td></tr></table></td></tr>");
-				}
-				if (!timers.isEmpty())
-				{
-					sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Timers:</font> <font color=00FF00></font></td></tr></table></td></tr>");
-					sb.append(timers);
-				}
-				msg.replace("%quests%", sb.toString());
-				msg.replace("%tmplid%", Integer.toString(npc.getId()));
-				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);
 			}
+			
+			final StringBuilder sb = new StringBuilder();
+			sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">ID:</font> <font color=00FF00>" + quest.getId() + "</font></td></tr></table></td></tr>");
+			sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Name:</font> <font color=00FF00>" + quest.getName() + "</font></td></tr></table></td></tr>");
+			sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Descr:</font> <font color=00FF00>" + quest.getDescr() + "</font></td></tr></table></td></tr>");
+			sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Path:</font> <font color=00FF00>" + quest.getClass().getName().substring(0, quest.getClass().getName().lastIndexOf('.')).replaceAll("\\.", "/") + "</font></td></tr></table></td></tr>");
+			sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Events:</font> <font color=00FF00>" + events + "</font></td></tr></table></td></tr>");
+			if (!npcs.isEmpty())
+			{
+				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">NPCs:</font> <font color=00FF00>" + npcs + "</font></td></tr></table></td></tr>");
+			}
+			if (!items.isEmpty())
+			{
+				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Items:</font> <font color=00FF00>" + items + "</font></td></tr></table></td></tr>");
+			}
+			if (!timers.isEmpty())
+			{
+				sb.append("<tr><td colspan=\"4\"><table width=270 border=0 bgcolor=131210><tr><td width=270><font color=\"LEVEL\">Timers:</font> <font color=00FF00></font></td></tr></table></td></tr>");
+				sb.append(timers);
+			}
+			
+			final NpcHtmlMessage msg = new NpcHtmlMessage(0, 1);
+			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);
 		}
 		return true;
 	}
-- 
GitLab