Jump to content
  • 0

Search


Williams

Question

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>

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

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
Link to comment
Share on other sites

  • 0

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.



  • Posts

    • DRESSME MANAGER.! COBA-LTD IS BRING YOU NEW SKIN MANAGER new skin manager placed on our server with lot of Skin's     Anakim Suit     White Knight     Archer Suit B     Beleth Suit     Cat Suit     CowBoy Suit     Dark Assassin Suit     Dragon Born Suit     Dark Knight Suit     Light Assassin Suit     Ninja Suit     Red Zaken Suit     Blue Zaken Suit     King Setim Suit     King White Setim Suit     Black Samurai Suit     Brown Wizard Suit     Legendary Suit     Pink Wizard Suit based on Vote coin's for more fun and unique dress skin code. Have fun by you Admin COBA.
    • You mentioned that you've fixed the issues, but how it would be ready for a live server when only a few fixes have been shared. It would be helpful and appreciated if you could share more information about the fixes or the process. It's always great when everyone can collaborate and learn from each other. If you choose not to share this information, it is unreasonable to expect others to. I, along with @Tryskell(I believe), am completely fed up with the arrogance of these so-called "developers." They perform half-baked fixes on critical issues and have the audacity to call it a major accomplishment. You all deserve your fate!
    • Most L2 developers are not willing to work remotely through Team Viewer or AnyDesk due to the low income and their moody nature. Therefore, it is highly unlikely to find an L2 developer willing to work under these conditions.
    • Hello all,   Looking for a developer who would be able working on my new project. Only experienced can apply for this paid job. There will be no direct access to my sources. You will work though teamviewer or anydesk. Interested can contact me here or through skype: Waleess.    Kind regards, Wales
    • Is the latest version suitable for live servers? Have you heard stories that aren't what you tell me? Na 401 tem travamentos bug or auto consumption of memory and CPU usage is constant. I fixed those things in my aCis.
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock