Advertisement
Guest User

aCis - Admin Search Item

a guest
Sep 27th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.67 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_datapack
  3. Index: data/html/admin/main_menu.htm
  4. ===================================================================
  5. --- data/html/admin/main_menu.htm   (revision 3)
  6. +++ data/html/admin/main_menu.htm   (working copy)
  7. @@ -43,7 +43,7 @@
  8.             <td><button value="Set Name" action="bypass -h admin_setname $menu_command" width=55 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
  9.             <td><button value="Set Title" action="bypass -h admin_settitle $menu_command" width=55 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
  10.             <td><button value="Get Buffs" action="bypass -h admin_getbuffs $menu_command" width=55 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
  11. -           <td></td>
  12. +           <td><button value="Search" action="bypass -h admin_search" width=55 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
  13.         </tr>
  14.     </table>
  15.     <br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
  16. Index: data/html/admin/search.htm
  17. ===================================================================
  18. --- data/html/admin/search.htm  (revision 0)
  19. +++ data/html/admin/search.htm  (working copy)
  20. @@ -0,0 +1,20 @@
  21. +<html><title>Search menu</title><body><center>
  22. +<table width=260>
  23. +   <tr>
  24. +       <td><button value="Main" action="bypass -h admin_admin" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
  25. +       <td><button value="Game" action="bypass -h admin_admin 2" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
  26. +       <td><button value="Effects" action="bypass -h admin_admin 3" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
  27. +       <td><button value="Server" action="bypass -h admin_admin 4" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
  28. +   </tr>
  29. +</table>
  30. +<img src="l2ui.SquareWhite" width=275 height=1><br>
  31. +<table width=274>
  32. +   <tr>
  33. +       <td width=204><multiedit var="search" width=204 height=15></td>
  34. +       <td width=70><button value="Search" action="bypass -h admin_search 1 $search" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
  35. +   </tr>
  36. +</table><br>
  37. +<img src=L2UI.SquareGray width=280 height=1>
  38. +%list%
  39. +</body></html>
  40. \ No newline at end of file
  41. Index: data/xml/adminCommands.xml
  42. ===================================================================
  43. --- data/xml/adminCommands.xml  (revision 4)
  44. +++ data/xml/adminCommands.xml  (working copy)
  45. @@ -251,6 +251,9 @@
  46.     <aCar name="admin_ride" accessLevel="7"/>
  47.     <aCar name="admin_unride" accessLevel="7"/>
  48.  
  49. +   <!-- SEARCH -->
  50. +   <aCar name="admin_search" accessLevel="7"/>
  51. +  
  52.     <!-- SHOP -->
  53.     <aCar name="admin_buy" accessLevel="7"/>
  54.     <aCar name="admin_gmshop" accessLevel="7"/>
  55. #P aCis_gameserver
  56. Index: java/net/sf/l2j/gameserver/data/xml/ItemData.java
  57. ===================================================================
  58. --- java/net/sf/l2j/gameserver/data/xml/ItemData.java   (revision 3)
  59. +++ java/net/sf/l2j/gameserver/data/xml/ItemData.java   (working copy)
  60. @@ -75,6 +75,14 @@
  61.     }
  62.    
  63.     /**
  64. +    * @return the list of all {@link Item} templates.
  65. +    */
  66. +   public Item[] getTemplates()
  67. +   {
  68. +       return _templates;
  69. +   }
  70. +  
  71. +   /**
  72.      * @param id : the item id to check.
  73.      * @return the {@link Item} corresponding to the item id.
  74.      */
  75. Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  76. ===================================================================
  77. --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 3)
  78. +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
  79. @@ -38,6 +38,7 @@
  80.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminPolymorph;
  81.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRes;
  82.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRideWyvern;
  83. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSearch;
  84.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminShop;
  85.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSiege;
  86.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSkill;
  87. @@ -87,6 +88,7 @@
  88.         registerHandler(new AdminPolymorph());
  89.         registerHandler(new AdminRes());
  90.         registerHandler(new AdminRideWyvern());
  91. +       registerHandler(new AdminSearch());
  92.         registerHandler(new AdminShop());
  93.         registerHandler(new AdminSiege());
  94.         registerHandler(new AdminSkill());
  95. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java
  96. ===================================================================
  97. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java    (revision 0)
  98. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSearch.java    (working copy)
  99. @@ -0,0 +1,123 @@
  100. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  101. +
  102. +import java.util.ArrayList;
  103. +import java.util.List;
  104. +import java.util.StringTokenizer;
  105. +
  106. +import net.sf.l2j.commons.math.MathUtil;
  107. +
  108. +import net.sf.l2j.gameserver.data.xml.ItemData;
  109. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  110. +import net.sf.l2j.gameserver.model.actor.Player;
  111. +import net.sf.l2j.gameserver.model.item.kind.Item;
  112. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  113. +
  114. +public class AdminSearch implements IAdminCommandHandler
  115. +{
  116. +   private static final int PAGE_LIMIT = 6;
  117. +  
  118. +   private static final String[] ADMIN_COMMANDS =
  119. +   {
  120. +       "admin_search"
  121. +   };
  122. +  
  123. +   @Override
  124. +   public boolean useAdminCommand(String command, Player activeChar)
  125. +   {
  126. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  127. +       html.setFile("data/html/admin/search.htm");
  128. +      
  129. +       if (command.equals("admin_search"))
  130. +           html.replace("%list%", "<center><br><br><br>Set first an key word</center>");
  131. +       else if (command.startsWith("admin_search"))
  132. +       {
  133. +           StringTokenizer st = new StringTokenizer(command, " ");
  134. +           st.nextToken();
  135. +      
  136. +           int page = Integer.valueOf(st.nextToken());
  137. +           StringBuilder sb = new StringBuilder(String.valueOf(page));
  138. +           html.replace("%list%", getList(activeChar, page, command.substring(14 + sb.length())).toString());
  139. +       }
  140. +       activeChar.sendPacket(html);
  141. +       return true;
  142. +   }
  143. +  
  144. +   public StringBuilder getList(Player activeChar, int page, String search)
  145. +   {
  146. +       List<Item> items = new ArrayList<>();
  147. +      
  148. +       for (Item item : ItemData.getInstance().getTemplates())
  149. +           if (item != null)
  150. +               if (item.getName().toLowerCase().contains(search.toLowerCase()))
  151. +                   items.add(item);
  152. +      
  153. +       if (items.isEmpty())
  154. +           return null;
  155. +      
  156. +       final int max = Math.min(100, MathUtil.countPagesNumber(items.size(), PAGE_LIMIT));
  157. +       items = items.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, items.size()));
  158. +      
  159. +       final StringBuilder sb = new StringBuilder();
  160. +      
  161. +       int row = 0;
  162. +       for (Item item : items)
  163. +       {
  164. +           String name = item.getName();
  165. +      
  166. +           if (name.length() >= 45)
  167. +               name = name.substring(0, 42) + "...";
  168. +      
  169. +           sb.append("<table width=280 bgcolor=000000><tr>");
  170. +           sb.append("<td width=44 height=41 align=center><table bgcolor=FFFFFF cellpadding=6 cellspacing=\"-5\"><tr><td><button width=32 height=32 back=" + item.getIcon() + " fore=" + item.getIcon() + "></td></tr></table></td>");
  171. +           sb.append("<td width=256>" + name + "<br1><font color=B09878>Item ID : " + item.getItemId() + "</font></td>");
  172. +           sb.append("</tr></table><img src=L2UI.SquareGray width=280 height=1>");
  173. +           row++;
  174. +       }
  175. +      
  176. +       for (int i = PAGE_LIMIT; i > row; i--)
  177. +           sb.append("<img height=42>");
  178. +      
  179. +       // Build page footer.
  180. +       sb.append("<img height=2><img src=L2UI.SquareGray width=280 height=1><table width=280 bgcolor=000000><tr>");
  181. +       sb.append("<td align=right width=70>" + (page > 1 ? "<button value=\"< PREV\" action=\"bypass admin_search " + (page - 1) + " " + search + "\" width=65 height=19 back=L2UI_ch3.smallbutton2_over fore=L2UI_ch3.smallbutton2>" : "") + "</td>");
  182. +       sb.append("<td align=center width=100>Page " + page + "</td>");
  183. +       sb.append("<td align=left width=70>" + (page < max ? "<button value=\"NEXT >\" action=\"bypass admin_search " + (page + 1) + " " + search + "\" width=65 height=19 back=L2UI_ch3.smallbutton2_over fore=L2UI_ch3.smallbutton2>" : "") + "</td>");
  184. +       sb.append("</tr></table><img src=L2UI.SquareGray width=280 height=1>");
  185. +       return sb;
  186. +   }
  187. +  
  188. +   @Override
  189. +   public String[] getAdminCommandList()
  190. +   {
  191. +       return ADMIN_COMMANDS;
  192. +   }
  193. +}
  194. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement