Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_gameserver
- Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 3)
- +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
- @@ -40,6 +40,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;
- @@ -103,6 +104,7 @@
- registerAdminCommandHandler(new AdminTarget());
- registerAdminCommandHandler(new AdminTeleport());
- registerAdminCommandHandler(new AdminZone());
- + registerAdminCommandHandler(new AdminSearch());
- }
- public void registerAdminCommandHandler(IAdminCommandHandler handler)
- Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java (nonexistent)
- +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java (working copy)
- @@ -0,0 +1,130 @@
- +package net.sf.l2j.gameserver.handler.admincommandhandlers;
- +
- +import java.util.ArrayList;
- +import java.util.List;
- +import java.util.StringTokenizer;
- +
- +import net.sf.l2j.commons.lang.StringUtil;
- +import net.sf.l2j.commons.math.MathUtil;
- +
- +import net.sf.l2j.gameserver.data.ItemTable;
- +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
- +import net.sf.l2j.gameserver.model.actor.instance.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 String[] ADMIN_COMMANDS =
- + {
- + "admin_search"
- + };
- + private static final int PAGE_LIMIT = 15;
- +
- + @Override
- + public boolean useAdminCommand(String command, Player activeChar)
- + {
- + if (command.startsWith("admin_search"))
- + {
- + StringTokenizer st = new StringTokenizer(command, " ");
- + st.nextToken();
- +
- + if (!st.hasMoreTokens())
- + {
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + html.setFile("data/html/admin/search.htm");
- + html.replace("%items%", "");
- + html.replace("%pages%", "");
- + activeChar.sendPacket(html);
- +
- + }
- + else
- + {
- + final String item = st.nextToken();
- + int page = 1;
- + if (st.hasMoreTokens())
- + {
- +
- + try
- + {
- + page = Integer.parseInt(st.nextToken());
- + }
- + catch (NumberFormatException e)
- + {
- + page = 1;
- + }
- + }
- + results(activeChar, item, page);
- + }
- + }
- + return true;
- + }
- +
- + private static void results(Player activeChar, String item, int page)
- + {
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + html.setFile("data/html/admin/search.htm");
- +
- + List<Item> items = new ArrayList<>();
- +
- + for (Item itemName : ItemTable.getInstance().getAllItems())
- + if (itemName != null)
- + if (itemName.getName().toLowerCase().contains(item.toLowerCase()))
- + items.add(itemName);
- +
- + if (items.isEmpty())
- + {
- + html.replace("%items%", "<tr><td>No items found with word " + item + ".</td></tr>");
- + html.replace("%pages%", "");
- + activeChar.sendPacket(html);
- + return;
- + }
- +
- + 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();
- +
- + for (Item itemName : items)
- + {
- + String actualName = getFontedWord(item, itemName.getName());
- + StringUtil.append(sb, "<tr><td>", actualName, " (", itemName.getItemId(), ")", "</td></tr>");
- + }
- + html.replace("%items%", sb.toString());
- +
- + sb.setLength(0);
- +
- + for (int i = 0; i < max; i++)
- + {
- + final int pagenr = i + 1;
- + if (page == pagenr)
- + StringUtil.append(sb, pagenr, " ");
- + else
- + StringUtil.append(sb, "<a action=\"bypass -h admin_search ", item, " ", pagenr, "\">", pagenr, "</a> ");
- +
- + }
- +
- + html.replace("%pages%", sb.toString());
- + activeChar.sendPacket(html);
- + }
- +
- + private static String getFontedWord(String word, String tt)
- + {
- +
- + int position = tt.toLowerCase().indexOf(word.toLowerCase());
- + StringBuilder str = new StringBuilder(tt);
- +
- + String font = "<FONT COLOR=\"LEVEL\">";
- + str.insert(position, font);
- + str.insert(position + (font.length() + word.length()), "</FONT>");
- +
- + return str.toString();
- + }
- +
- + @Override
- + public String[] getAdminCommandList()
- + {
- + return ADMIN_COMMANDS;
- + }
- +}
- \ No newline at end of file
- Index: java/net/sf/l2j/gameserver/data/ItemTable.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/data/ItemTable.java (revision 3)
- +++ java/net/sf/l2j/gameserver/data/ItemTable.java (working copy)
- @@ -3,7 +3,10 @@
- import java.io.File;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- +import java.util.ArrayList;
- +import java.util.Collections;
- import java.util.HashMap;
- +import java.util.List;
- import java.util.Map;
- import java.util.logging.Level;
- import java.util.logging.LogRecord;
- @@ -119,6 +122,7 @@
- * @param id : int designating the item
- * @return the item corresponding to the item ID.
- */
- +
- public Item getTemplate(int id)
- {
- if (id >= _allTemplates.length)
- @@ -127,6 +131,10 @@
- return _allTemplates[id];
- }
- + public Item[] getAllItems()
- + {
- + return _allTemplates;
- + }
- /**
- * Create the ItemInstance corresponding to the Item Identifier and quantitiy add logs the activity.
- * @param process : String Identifier of process triggering this action
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement