Jump to content

Acis Search For Item


Recommended Posts

Hello, I am adapting it to acis 401, and when I run it in the game it tells me:

No rights defined for admin command 'admin_search'.
Admin tried to use admin command 'admin_search', but has no access to use it.

 

Also try to adapt it in AdminAdmin.java with else in the last lines using it as admin_buscar (buscar = search in spanish)
and I get the same error:
No rights defined for admin command 'admin_buscar'.
Admin tried to use admin command 'admin_search', but has no access to use it.


I have the AdminSearch.java like this:

package net.sf.l2j.gameserver.handler.admincommandhandlers;

import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

import net.sf.l2j.commons.lang.StringUtil;
import net.sf.l2j.commons.math.MathUtil;

import net.sf.l2j.gameserver.data.xml.ItemData;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.WorldObject;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.model.item.kind.Item;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;

public class AdminSearch implements IAdminCommandHandler
{
	private static final String[] ADMIN_COMMANDS =
	{
		"admin_search"
	};
	private static final int PAGE_LIMIT = 15;
	
	@Override
	public void useAdminCommand(String command, Player activeChar)
	{
		if (command.startsWith("admin_search"))
		{
			StringTokenizer st = new StringTokenizer(command, " ");
			st.nextToken();
			
			if (!st.hasMoreTokens())
			{
				final NpcHtmlMessage html = new NpcHtmlMessage(0);
				html.setFile("data/html/admin/search.htm");
				html.replace("%items%", "");
				html.replace("%pages%", "");
				activeChar.sendPacket(html);
				
			}
			else
			{
				final String item = st.nextToken();
				int page = 1;
				if (st.hasMoreTokens())
				{
					
					try
					{
						page = Integer.parseInt(st.nextToken());
					}
					catch (NumberFormatException e)
					{
						page = 1;
					}
				}
				results(activeChar, item, page);
			}
		}
		return;
	}
	
	private static void results(Player activeChar, String item, int page)
	{
		final NpcHtmlMessage html = new NpcHtmlMessage(0);
		html.setFile("data/html/admin/search.htm");
		
		//List<Item> items = new ArrayList<>();//no sirvio
		List<Object> items = Arrays.asList(ItemData.getInstance().getAllItems());
		
		for (Object itemName : items)
			if (itemName != null)
				if (((WorldObject) itemName).getName().toLowerCase().contains(item.toLowerCase()))
					items.add(itemName);
				
		if (items.isEmpty())
		{
			html.replace("%items%", "<tr><td>No items found with word " + item + ".</td></tr>");
			html.replace("%pages%", "");
			activeChar.sendPacket(html);
			return;
		}
		
		final int max = Math.min(100, MathUtil.countPagesNumber(items.size(), PAGE_LIMIT));
		items = items.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, items.size()));
		
		final StringBuilder sb = new StringBuilder();
		
		for (Object itemName : items)
		{
			String actualName = getFontedWord(item, ((WorldObject) itemName).getName());
			StringUtil.append(sb, "<tr><td>", actualName, " (", ((Item) itemName).getItemId(), ")", "</td></tr>");
		}
		html.replace("%items%", sb.toString());
		
		sb.setLength(0);
		
		for (int i = 0; i < max; i++)
		{
			final int pagenr = i + 1;
			if (page == pagenr)
				StringUtil.append(sb, pagenr, "&nbsp;");
			else
				StringUtil.append(sb, "<a action=\"bypass -h admin_search ", item, " ", pagenr, "\">", pagenr, "</a>&nbsp;");
			
		}
		
		html.replace("%pages%", sb.toString());
		activeChar.sendPacket(html);
	}
	
	private static String getFontedWord(String word, String tt)
	{
		
		int position = tt.toLowerCase().indexOf(word.toLowerCase());
		StringBuilder str = new StringBuilder(tt);
		
		String font = "<FONT COLOR=\"LEVEL\">";
		str.insert(position, font);
		str.insert(position + (font.length() + word.length()), "</FONT>");
		
		return str.toString();
	}
	
	@Override
	public String[] getAdminCommandList()
	{
		return ADMIN_COMMANDS;
	}
}

Can someone give me a hand and tell me what I'm doing wrong?

 

Link to comment
Share on other sites

On 4/30/2024 at 2:57 AM, luzzifer said:

Hello, I am adapting it to acis 401, and when I run it in the game it tells me:

No rights defined for admin command 'admin_search'.
Admin tried to use admin command 'admin_search', but has no access to use it.

 

Also try to adapt it in AdminAdmin.java with else in the last lines using it as admin_buscar (buscar = search in spanish)
and I get the same error:
No rights defined for admin command 'admin_buscar'.
Admin tried to use admin command 'admin_search', but has no access to use it.


I have the AdminSearch.java like this:

package net.sf.l2j.gameserver.handler.admincommandhandlers;

import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

import net.sf.l2j.commons.lang.StringUtil;
import net.sf.l2j.commons.math.MathUtil;

import net.sf.l2j.gameserver.data.xml.ItemData;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.WorldObject;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.model.item.kind.Item;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;

public class AdminSearch implements IAdminCommandHandler
{
	private static final String[] ADMIN_COMMANDS =
	{
		"admin_search"
	};
	private static final int PAGE_LIMIT = 15;
	
	@Override
	public void useAdminCommand(String command, Player activeChar)
	{
		if (command.startsWith("admin_search"))
		{
			StringTokenizer st = new StringTokenizer(command, " ");
			st.nextToken();
			
			if (!st.hasMoreTokens())
			{
				final NpcHtmlMessage html = new NpcHtmlMessage(0);
				html.setFile("data/html/admin/search.htm");
				html.replace("%items%", "");
				html.replace("%pages%", "");
				activeChar.sendPacket(html);
				
			}
			else
			{
				final String item = st.nextToken();
				int page = 1;
				if (st.hasMoreTokens())
				{
					
					try
					{
						page = Integer.parseInt(st.nextToken());
					}
					catch (NumberFormatException e)
					{
						page = 1;
					}
				}
				results(activeChar, item, page);
			}
		}
		return;
	}
	
	private static void results(Player activeChar, String item, int page)
	{
		final NpcHtmlMessage html = new NpcHtmlMessage(0);
		html.setFile("data/html/admin/search.htm");
		
		//List<Item> items = new ArrayList<>();//no sirvio
		List<Object> items = Arrays.asList(ItemData.getInstance().getAllItems());
		
		for (Object itemName : items)
			if (itemName != null)
				if (((WorldObject) itemName).getName().toLowerCase().contains(item.toLowerCase()))
					items.add(itemName);
				
		if (items.isEmpty())
		{
			html.replace("%items%", "<tr><td>No items found with word " + item + ".</td></tr>");
			html.replace("%pages%", "");
			activeChar.sendPacket(html);
			return;
		}
		
		final int max = Math.min(100, MathUtil.countPagesNumber(items.size(), PAGE_LIMIT));
		items = items.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, items.size()));
		
		final StringBuilder sb = new StringBuilder();
		
		for (Object itemName : items)
		{
			String actualName = getFontedWord(item, ((WorldObject) itemName).getName());
			StringUtil.append(sb, "<tr><td>", actualName, " (", ((Item) itemName).getItemId(), ")", "</td></tr>");
		}
		html.replace("%items%", sb.toString());
		
		sb.setLength(0);
		
		for (int i = 0; i < max; i++)
		{
			final int pagenr = i + 1;
			if (page == pagenr)
				StringUtil.append(sb, pagenr, "&nbsp;");
			else
				StringUtil.append(sb, "<a action=\"bypass -h admin_search ", item, " ", pagenr, "\">", pagenr, "</a>&nbsp;");
			
		}
		
		html.replace("%pages%", sb.toString());
		activeChar.sendPacket(html);
	}
	
	private static String getFontedWord(String word, String tt)
	{
		
		int position = tt.toLowerCase().indexOf(word.toLowerCase());
		StringBuilder str = new StringBuilder(tt);
		
		String font = "<FONT COLOR=\"LEVEL\">";
		str.insert(position, font);
		str.insert(position + (font.length() + word.length()), "</FONT>");
		
		return str.toString();
	}
	
	@Override
	public String[] getAdminCommandList()
	{
		return ADMIN_COMMANDS;
	}
}

Can someone give me a hand and tell me what I'm doing wrong?

 

add <aCar name="admin_search" accessLevel="7" params="" desc=""/> to data/xml/adminCommands

  • Like 1
Link to comment
Share on other sites

As a sidenote, it was added in aCis 408, under //find subcategory :

AdminCommands
- Revamp //tele panels.
- Introduce //find item [name]. Ty melron for initial idea, StinkyMadness/CUCU23 for improvements.
- Introduce //find npc [name], delete 6 related admincommands :
- admin_show_spawns
- admin_spawn_index
- admin_spawn_reload
- admin_npc_index
- admin_spawn_once
- admin_show_npcs
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   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...