Skip to content

Featured Replies

I'm trying to create search types, but I come across a problem in the substring when I create a switch I don't get all my search data.

 

Code base : 

 

Old:

+   @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%", "<center><br><br><br>Set first an key word</center>");
+       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%", "<center><br><br><br>Set first an key word</center>");
+       }
+       activeChar.sendPacket(html);
+       return true;
+   }
+   

 

New :

@Override
	public void useAdminCommand(String command, Player player)
	{
		final StringTokenizer st = new StringTokenizer(command, " ");
		st.nextToken();
		
		final NpcHtmlMessage html = new NpcHtmlMessage(0);
		html.setFile("data/html/admin/search.htm");
		
		if (command.equals("admin_search"))
			html.replace("%list%", "<center><br><br><br>Set first an key word</center>");
		else if (command.startsWith("admin_search"))
		{
			if (!st.hasMoreTokens())
			{
				player.sendMessage("Usage: //search <item>");
				return;
			}
			
			int page = Integer.valueOf(st.nextToken());
			switch (st.nextToken())
			{
				case "item":
					if (st.hasMoreTokens())
					{
						StringBuilder sb = new StringBuilder(String.valueOf(page));
						StringBuilder list = getListItem(player, page, command.substring(14 + sb.length()));
						html.replace("%list%", list == null ? "" : list.toString());
					}
					else
						html.replace("%list%", "<center><br><br><br>Set first an key word</center>");
					break;
			}
		}
		player.sendPacket(html);
	}

 

Html :

<table width=260>
			<tr>
				<td><combobox width=65 height=21 var="param" list=item;skill></td>
				<td><edit width=130 var="search"></td>
				<td><button value="Search" action="bypass -h admin_search 1 $param $search" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
			</tr>
		</table><br>

 

You can just debug the next token to see it's value.

 

Edit:

Quote
command.substring(14 + sb.length()));

The word "skill" consists of 5 letters and "item" consists of 4, you'd better find another way to parse the search phrase (like using nextToken a bunch of times)

Edited by Zake

easy way with org.apache.commons.lang.StringUtils

action="bypass admin_test [a] $var [/a] [b] $var2 [/b] [c] $var3 [/c]"
String text = StringUtils.substringBetween(command, "[a] ", " [/a]");

String text2 = StringUtils.substringBetween(command, "[b] ", " [/b]");

String text3 = StringUtils.substringBetween(command, "[c] ", " [/c]");

 

Edited by wongerlt

  • Author
5 hours ago, wongerlt said:

easy way with org.apache.commons.lang.StringUtils

action="bypass admin_test [a] $var [/a] [b] $var2 [/b] [c] $var3 [/c]"
String text = StringUtils.substringBetween(command, "[a] ", " [/a]");

String text2 = StringUtils.substringBetween(command, "[b] ", " [/b]");

String text3 = StringUtils.substringBetween(command, "[c] ", " [/c]");

 

 

8 hours ago, Zake said:

You can just debug the next token to see it's value.

 

Edit:

The word "skill" consists of 5 letters and "item" consists of 4, you'd better find another way to parse the search phrase (like using nextToken a bunch of times)

 

I didn't realize that there was already a search system at acis. I'm using it now and I run into a problem, when searching my items if the number of pages is more than 1 if I go to page 2 the search is canceled and I go back to the home page without any search. I'm using the " admin help " system.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.