### Eclipse Workspace Patch 1.0
#P aCis_datapack
Index: data/html/admin/main_menu.htm
===================================================================
--- data/html/admin/main_menu.htm (revision 30)
+++ data/html/admin/main_menu.htm (working copy)
@@ -43,7 +43,7 @@
|
|
|
- |
+ |
Index: data/html/admin/search.htm
===================================================================
--- data/html/admin/search.htm (revision 0)
+++ data/html/admin/search.htm (working copy)
@@ -0,0 +1,19 @@
+Search menu
+
+
+
+
+%list%
+
\ No newline at end of file
Index: data/xml/adminCommands.xml
===================================================================
--- data/xml/adminCommands.xml (revision 30)
+++ data/xml/adminCommands.xml (working copy)
@@ -251,6 +251,9 @@
+
+
+
#P aCis_gameserver
Index: java/net/sf/l2j/gameserver/data/xml/ItemData.java
===================================================================
--- java/net/sf/l2j/gameserver/data/xml/ItemData.java (revision 30)
+++ java/net/sf/l2j/gameserver/data/xml/ItemData.java (working copy)
@@ -75,6 +75,14 @@
}
/**
+ * @return the list of all {@link Item} templates.
+ */
+ public Item[] getTemplates()
+ {
+ return _templates;
+ }
+
+ /**
* @param id : the item id to check.
* @return the {@link Item} corresponding to the item id.
*/
Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
===================================================================
--- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 30)
+++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
@@ -38,6 +38,7 @@
import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminPolymorph;
import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRes;
import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRideWyvern;
+import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSearch;
import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminShop;
import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSiege;
import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSkill;
@@ -87,6 +88,7 @@
registerHandler(new AdminPolymorph());
registerHandler(new AdminRes());
registerHandler(new AdminRideWyvern());
+ registerHandler(new AdminSearch());
registerHandler(new AdminShop());
registerHandler(new AdminSiege());
registerHandler(new AdminSkill());
Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java
===================================================================
--- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java (revision 0)
+++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java (working copy)
@@ -0,0 +1,101 @@
+package net.sf.l2j.gameserver.handler.admincommandhandlers;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.stream.Collectors;
+
+import net.sf.l2j.commons.math.MathUtil;
+
+import net.sf.l2j.gameserver.data.xml.ItemData;
+import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
+import net.sf.l2j.gameserver.model.actor.Player;
+import net.sf.l2j.gameserver.model.item.kind.Item;
+import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
+
+public class AdminSearch implements IAdminCommandHandler
+{
+ private static final int PAGE_LIMIT = 6;
+
+ private static final String[] ADMIN_COMMANDS =
+ {
+ "admin_search"
+ };
+
+ @Override
+ public boolean useAdminCommand(String command, Player activeChar)
+ {
+ final NpcHtmlMessage html = new NpcHtmlMessage(0);
+ html.setFile("data/html/admin/search.htm");
+
+ if (command.equals("admin_search"))
+ html.replace("%list%", "
Set first an key word");
+ else if (command.startsWith("admin_search"))
+ {
+ StringTokenizer st = new StringTokenizer(command, " ");
+ st.nextToken();
+
+ int page = Integer.valueOf(st.nextToken());
+ if (st.hasMoreTokens())
+ {
+ StringBuilder sb = new StringBuilder(String.valueOf(page));
+ StringBuilder list = getList(activeChar, page, command.substring(14 + sb.length()));
+ html.replace("%list%", list == null ? "" : list.toString());
+ }
+ else
+ html.replace("%list%", "
Set first an key word");
+ }
+ activeChar.sendPacket(html);
+ return true;
+ }
+
+ public StringBuilder getList(Player activeChar, int page, String search)
+ {
+ List- items = Arrays.asList(ItemData.getInstance().getTemplates()).stream().filter(item -> item != null && matches(item.getName(), search)).collect(Collectors.toList());
+
+ if (items == null || items.isEmpty())
+ return new StringBuilder("
There its no item : " + search + "");
+
+ final int max = Math.min(100, MathUtil.countPagesNumber(items.size(), PAGE_LIMIT));
+ items = items.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, items.size()));
+
+ final StringBuilder sb = new StringBuilder();
+
+ int row = 0;
+ for (Item item : items)
+ {
+ String name = item.getName();
+
+ if (name.length() >= 43)
+ name = name.substring(0, 40) + "...";
+
+ sb.append("");
+ sb.append(" | ");
+ sb.append("" + name + "Item ID : " + item.getItemId() + " " + (item.isQuestItem() ? "(Quest Item)" : "") + " | ");
+ sb.append("
");
+ row++;
+ }
+
+ for (int i = PAGE_LIMIT; i > row; i--)
+ sb.append("");
+
+ // Build page footer.
+ sb.append("");
+ sb.append("" + (page > 1 ? " | ");
+ sb.append("Page " + page + " | ");
+ sb.append("" + (page < max ? " | ");
+ sb.append("
");
+ return sb;
+ }
+
+ public static boolean matches(String name, String search)
+ {
+ return Arrays.stream(search.toLowerCase().split(" ")).allMatch(result -> name.toLowerCase().contains(result));
+ }
+
+ @Override
+ public String[] getAdminCommandList()
+ {
+ return ADMIN_COMMANDS;
+ }
+}