Advertisement
tobaJK

aCis search

Jul 25th, 2017
1,168
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.12 KB | None | 1 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 3)
  6. +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
  7. @@ -40,6 +40,7 @@
  8.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminPolymorph;
  9.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRes;
  10.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRideWyvern;
  11. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSearch;
  12.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminShop;
  13.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSiege;
  14.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSkill;
  15. @@ -103,6 +104,7 @@
  16.         registerAdminCommandHandler(new AdminTarget());
  17.         registerAdminCommandHandler(new AdminTeleport());
  18.         registerAdminCommandHandler(new AdminZone());
  19. +       registerAdminCommandHandler(new AdminSearch());
  20.     }
  21.    
  22.     public void registerAdminCommandHandler(IAdminCommandHandler handler)
  23. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java
  24. ===================================================================
  25. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java    (nonexistent)
  26. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java    (working copy)
  27. @@ -0,0 +1,130 @@
  28. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  29. +
  30. +import java.util.ArrayList;
  31. +import java.util.List;
  32. +import java.util.StringTokenizer;
  33. +
  34. +import net.sf.l2j.commons.lang.StringUtil;
  35. +import net.sf.l2j.commons.math.MathUtil;
  36. +
  37. +import net.sf.l2j.gameserver.data.ItemTable;
  38. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  39. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  40. +import net.sf.l2j.gameserver.model.item.kind.Item;
  41. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  42. +
  43. +public class AdminSearch implements IAdminCommandHandler
  44. +{
  45. +   private static final String[] ADMIN_COMMANDS =
  46. +   {
  47. +       "admin_search"
  48. +   };
  49. +   private static final int PAGE_LIMIT = 15;
  50. +  
  51. +   @Override
  52. +   public boolean useAdminCommand(String command, Player activeChar)
  53. +   {
  54. +       if (command.startsWith("admin_search"))
  55. +       {
  56. +           StringTokenizer st = new StringTokenizer(command, " ");
  57. +           st.nextToken();
  58. +          
  59. +           if (!st.hasMoreTokens())
  60. +           {
  61. +               final NpcHtmlMessage html = new NpcHtmlMessage(0);
  62. +               html.setFile("data/html/admin/search.htm");
  63. +               html.replace("%items%", "");
  64. +               html.replace("%pages%", "");
  65. +               activeChar.sendPacket(html);
  66. +              
  67. +           }
  68. +           else
  69. +           {
  70. +               final String item = st.nextToken();
  71. +               int page = 1;
  72. +               if (st.hasMoreTokens())
  73. +               {
  74. +                  
  75. +                   try
  76. +                   {
  77. +                       page = Integer.parseInt(st.nextToken());
  78. +                   }
  79. +                   catch (NumberFormatException e)
  80. +                   {
  81. +                       page = 1;
  82. +                   }
  83. +               }
  84. +               results(activeChar, item, page);
  85. +           }
  86. +       }
  87. +       return true;
  88. +   }
  89. +  
  90. +   private static void results(Player activeChar, String item, int page)
  91. +   {
  92. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  93. +       html.setFile("data/html/admin/search.htm");
  94. +      
  95. +       List<Item> items = new ArrayList<>();
  96. +      
  97. +       for (Item itemName : ItemTable.getInstance().getAllItems())
  98. +           if (itemName != null)
  99. +               if (itemName.getName().toLowerCase().contains(item.toLowerCase()))
  100. +                   items.add(itemName);
  101. +              
  102. +       if (items.isEmpty())
  103. +       {
  104. +           html.replace("%items%", "<tr><td>No items found with word " + item + ".</td></tr>");
  105. +           html.replace("%pages%", "");
  106. +           activeChar.sendPacket(html);
  107. +           return;
  108. +       }
  109. +      
  110. +       final int max = Math.min(100, MathUtil.countPagesNumber(items.size(), PAGE_LIMIT));
  111. +       items = items.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, items.size()));
  112. +      
  113. +       final StringBuilder sb = new StringBuilder();
  114. +      
  115. +       for (Item itemName : items)
  116. +       {
  117. +           String actualName = getFontedWord(item, itemName.getName());
  118. +           StringUtil.append(sb, "<tr><td>", actualName, " (", itemName.getItemId(), ")", "</td></tr>");
  119. +       }
  120. +       html.replace("%items%", sb.toString());
  121. +      
  122. +       sb.setLength(0);
  123. +      
  124. +       for (int i = 0; i < max; i++)
  125. +       {
  126. +           final int pagenr = i + 1;
  127. +           if (page == pagenr)
  128. +               StringUtil.append(sb, pagenr, "&nbsp;");
  129. +           else
  130. +               StringUtil.append(sb, "<a action=\"bypass -h admin_search ", item, " ", pagenr, "\">", pagenr, "</a>&nbsp;");
  131. +          
  132. +       }
  133. +      
  134. +       html.replace("%pages%", sb.toString());
  135. +       activeChar.sendPacket(html);
  136. +   }
  137. +  
  138. +   private static String getFontedWord(String word, String tt)
  139. +   {
  140. +      
  141. +       int position = tt.toLowerCase().indexOf(word.toLowerCase());
  142. +       StringBuilder str = new StringBuilder(tt);
  143. +      
  144. +       String font = "<FONT COLOR=\"LEVEL\">";
  145. +       str.insert(position, font);
  146. +       str.insert(position + (font.length() + word.length()), "</FONT>");
  147. +      
  148. +       return str.toString();
  149. +   }
  150. +  
  151. +   @Override
  152. +   public String[] getAdminCommandList()
  153. +   {
  154. +       return ADMIN_COMMANDS;
  155. +   }
  156. +}
  157. \ No newline at end of file
  158. Index: java/net/sf/l2j/gameserver/data/ItemTable.java
  159. ===================================================================
  160. --- java/net/sf/l2j/gameserver/data/ItemTable.java  (revision 3)
  161. +++ java/net/sf/l2j/gameserver/data/ItemTable.java  (working copy)
  162. @@ -3,7 +3,10 @@
  163.  import java.io.File;
  164.  import java.sql.Connection;
  165.  import java.sql.PreparedStatement;
  166. +import java.util.ArrayList;
  167. +import java.util.Collections;
  168.  import java.util.HashMap;
  169. +import java.util.List;
  170.  import java.util.Map;
  171.  import java.util.logging.Level;
  172.  import java.util.logging.LogRecord;
  173. @@ -119,6 +122,7 @@
  174.      * @param id : int designating the item
  175.      * @return the item corresponding to the item ID.
  176.      */
  177. +  
  178.     public Item getTemplate(int id)
  179.     {
  180.         if (id >= _allTemplates.length)
  181. @@ -127,6 +131,10 @@
  182.         return _allTemplates[id];
  183.     }
  184.    
  185. +   public Item[] getAllItems()
  186. +   {
  187. +       return _allTemplates;
  188. +   }
  189.     /**
  190.      * Create the ItemInstance corresponding to the Item Identifier and quantitiy add logs the activity.
  191.      * @param process : String Identifier of process triggering this action
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement