View difference between Paste ID: F5nzQcwh and QQ2YCSw4
SHOW: | | - or go back to the newest paste.
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 30)
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,19 @@
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 30)
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 30)
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 30)
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,101 @@
100
+package net.sf.l2j.gameserver.handler.admincommandhandlers;
101
+
102
+import java.util.Arrays;
103
+import java.util.List;
104
+import java.util.StringTokenizer;
105
+import java.util.stream.Collectors;
106
+
107
+import net.sf.l2j.commons.math.MathUtil;
108
+
109
+import net.sf.l2j.gameserver.data.xml.ItemData;
110
+import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
111
+import net.sf.l2j.gameserver.model.actor.Player;
112
+import net.sf.l2j.gameserver.model.item.kind.Item;
113
+import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
114
+
115
+public class AdminSearch implements IAdminCommandHandler
116
+{
117
+	private static final int PAGE_LIMIT = 6;
118
+	
119
+	private static final String[] ADMIN_COMMANDS =
120
+	{
121
+		"admin_search"
122
+	};
123
+	
124
+	@Override
125
+	public boolean useAdminCommand(String command, Player activeChar)
126
+	{
127
+		final NpcHtmlMessage html = new NpcHtmlMessage(0);
128
+		html.setFile("data/html/admin/search.htm");
129
+		
130
+		if (command.equals("admin_search"))
131
+			html.replace("%list%", "<center><br><br><br>Set first an key word</center>");
132
+		else if (command.startsWith("admin_search"))
133
+		{
134
+			StringTokenizer st = new StringTokenizer(command, " ");
135
+			st.nextToken();
136
+			
137
+			int page = Integer.valueOf(st.nextToken());
138
+			if (st.hasMoreTokens())
139
+			{
140
+				StringBuilder sb = new StringBuilder(String.valueOf(page));
141
+				StringBuilder list = getList(activeChar, page, command.substring(14 + sb.length()));
142
+				html.replace("%list%", list == null ? "" : list.toString());
143
+			}
144
+			else
145
+				html.replace("%list%", "<center><br><br><br>Set first an key word</center>");
146
+		}
147
+		activeChar.sendPacket(html);
148
+		return true;
149
+	}
150
+	
151
+	public StringBuilder getList(Player activeChar, int page, String search)
152
+	{
153
+		List<Item> items = Arrays.asList(ItemData.getInstance().getTemplates()).stream().filter(item -> item != null && matches(item.getName(), search)).collect(Collectors.toList());
154
+		
155
+		if (items == null || items.isEmpty())
156
+			return new StringBuilder("<center><br><br><br>There its no item : <font color=LEVEL>" + search + "</font></center>");
157
+		
158
+		final int max = Math.min(100, MathUtil.countPagesNumber(items.size(), PAGE_LIMIT));
159
+		items = items.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, items.size()));
160
+		
161
+		final StringBuilder sb = new StringBuilder();
162
+		
163
+		int row = 0;
164
+		for (Item item : items)
165
+		{
166
+			String name = item.getName();
167
+			
168
+			if (name.length() >= 43)
169
+				name = name.substring(0, 40) + "...";
170
+			
171
+			sb.append("<table width=280 bgcolor=000000><tr>");
172
+			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>");
173
+			sb.append("<td width=236>" + name + "<br1><font color=B09878>Item ID : " + item.getItemId() + " " + (item.isQuestItem() ? "(Quest Item)" : "") + "</font></td>");
174
+			sb.append("</tr></table><img src=L2UI.SquareGray width=280 height=1>");
175
+			row++;
176
+		}
177
+		
178
+		for (int i = PAGE_LIMIT; i > row; i--)
179
+			sb.append("<img height=42>");
180
+		
181
+		// Build page footer.
182
+		sb.append("<img height=2><img src=L2UI.SquareGray width=280 height=1><table width=280 bgcolor=000000><tr>");
183
+		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>");
184
+		sb.append("<td align=center width=100>Page " + page + "</td>");
185
+		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>");
186
+		sb.append("</tr></table><img src=L2UI.SquareGray width=280 height=1>");
187
+		return sb;
188
+	}
189
+	
190
+	public static boolean matches(String name, String search)
191
+	{
192
+		return Arrays.stream(search.toLowerCase().split(" ")).allMatch(result -> name.toLowerCase().contains(result));
193
+	}
194
+	
195
+	@Override
196
+	public String[] getAdminCommandList()
197
+	{
198
+		return ADMIN_COMMANDS;
199
+	}
200
+}
201
\ No newline at end of file