Quantcast
Channel: L2JBrasil RSS
Viewing all articles
Browse latest Browse all 543

Remover Item do inventario do Player [Adaptado aCis]

$
0
0

Boa noite galera, meu primeiro conteúdo aqui na L2JBrasil.

 

Vendo que uso a Rev e que muitos não conseguiram adaptar para aCis o código deste MOD, resolvi faze-lo.

 

Endereço original do MOD,https://www.l2jbrasil.com/index.php?/topic/107810-remover-item-do-inventario-do-player

 

Créditos para a criação: Zealar.

 

 

A parte que mais vi pessoas pedirem foi a classe: AdminInventory.java


/*
* Copyright (C) 2004-2014 L2J DataPack
* 
* This file is part of L2J DataPack.
* 
* L2J DataPack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* L2J DataPack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sf.l2j.gameserver.handler.admincommandhandlers;


import java.util.ArrayList;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.logging.Logger;


import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;


import net.sf.l2j.commons.logging.handler.GMAuditLogHandler;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.WorldObject;
import net.sf.l2j.gameserver.model.actor.instance.Player;
import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;


/**
* This class handles following admin commands:
* <ul>
* <li>show_invetory</li>
* <li>delete_item</li>
* <li> Edited by: LegendFlavioBR, LFBRxD
* </ul>
* @author Zealar
* 
* Edited to aCis by
*/
public class AdminInventory implements IAdminCommandHandler
{
    private static Logger _log = Logger.getLogger(AdminInventory.class.getName());
    private static final String[] _adminCommands = new String[]
    {
        "admin_show_inventory",
        "admin_delete_item"
    };
    
    @Override
    public boolean useAdminCommand(String command, Player activeChar)
    {       
        if ((activeChar.getTarget() == null))
        {
            activeChar.sendMessage("Please select a target");
            return false;
        }       
    
        if (!(activeChar.getTarget() instanceof Player))
        {
            activeChar.sendMessage("Target need to be player");
            return false;
        }       


        Player player = activeChar.getTarget().getActingPlayer();


        StringTokenizer st = new StringTokenizer(command);
        st.nextToken();
        if (command.startsWith(_adminCommands[0]))
        {
            if(st.hasMoreTokens()){
                int page = Integer.parseInt(st.nextToken());
                showItemsPage(activeChar, page);
            }           
            else
            {               
                showItemsPage(activeChar, 0);
            }
        }
        else if (command.contains(_adminCommands[1]))
        {
            String val = command.substring(_adminCommands[1].length() + 1);         
            player.destroyItem(activeChar.getName() + ": Destroy",
             Integer.parseInt(val), player.getInventory().getItemByObjectId(Integer.parseInt(val)).getCount(),
             null, true);
            showItemsPage(activeChar, 0);
        }
        _log.warning(activeChar.getName()+" destroy an item from: "+ activeChar.getTarget().getName());
        return true;
        
    }   
    
    private static void showItemsPage(Player activeChar, int page)
    {
        final Player target = activeChar.getTarget().getActingPlayer();
        
        Set<ItemInstance> items = target.getInventory().getItems();
        
        int maxItemsPerPage = 15;


        int maxPages = items.size() / maxItemsPerPage;
        if (items.size() > (maxItemsPerPage * maxPages))
        {
            maxPages++;
        }
        
        if (page > maxPages)
        {
            page = maxPages;
        }


        
        int itemsStart = maxItemsPerPage * page;
        int itemsEnd = items.size();
        if ((itemsEnd - itemsStart) > maxItemsPerPage)
        {
            itemsEnd = itemsStart + maxItemsPerPage;
        }
        
        final NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
        adminReply.setFile("data/html/admin/inventory.htm");
        adminReply.replace("%PLAYER_NAME%", target.getName());      
        
        StringBuilder sbPages = new StringBuilder();
        for (int x = 0; x < maxPages; x++)
        {
            int pagenr = x + 1;
            sbPages.append("<td><button value=\"" + String.valueOf(pagenr) +
             "\" action=\"bypass -h admin_show_inventory " + String.valueOf(x) + 
             "\" width=20 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
        }
        
        adminReply.replace("%PAGES%", sbPages.toString());      


        StringBuilder sbItems = new StringBuilder();
        int cont = 0;       
        for (ItemInstance temp : items)
        {
            cont++;
            if(cont>=itemsStart && cont<=(itemsStart+maxItemsPerPage)){
            //sbItems.append("<tr><td><img src=\"" + temp.getItem().getIcon() + "\" width=32 height=32></td>");
            sbItems.append("<tr><td width=30>"+ temp.getName() + "</td>");
            sbItems.append("<td><button action=\"bypass -h admin_delete_item " + String.valueOf(temp.getObjectId()) + "\" width=16 height=16 back=\"L2UI_ct1.Button_DF_Delete\" fore=\"L2UI_ct1.Button_DF_Delete\">" + "</td></tr>");
            }
        }       
        adminReply.replace("%ITEMS%", sbItems.toString());      
        activeChar.sendPacket(adminReply); 
    }
    
    @Override
    public String[] getAdminCommandList()
    {
        return _adminCommands;
    }
}

Viewing all articles
Browse latest Browse all 543

Trending Articles