Jump to content

Question

Posted

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>

 

3 answers to this question

Recommended Posts

  • 0
Posted (edited)

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
  • 0
Posted (edited)

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
  • 0
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...