All pastes #20872 Raw Edit

Someone

public text v1 · immutable
#20872 ·published 2005-08-23 16:53 UTC
rendered paste body
package net.sf.l2j.gameserver.clientpackets;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.logging.Logger;

import net.sf.l2j.gameserver.ClientThread;
import net.sf.l2j.gameserver.model.L2PcInstance;
import net.sf.l2j.gameserver.model.L2World;
import net.sf.l2j.gameserver.serverpackets.SystemMessage;

public class RequestBlock extends ClientBasePacket
{
    private static final String _C__A0_REQUESTBLOCK = "[C] A0 RequestBlock";
    private static Logger _log = Logger.getLogger(L2PcInstance.class.getName());
    
    private final static int BLOCK = 0;
    private final static int UNBLOCK = 1;
    private final static int BLOCKLIST = 2;
    private final static int ALLBLOCK = 3;
    private final static int ALLUNBLOCK = 4;
    
    public RequestBlock(ByteBuffer buf, ClientThread client)
    {
        super(buf, client);
        _type = readD(); //0x00 - block, 0x01 - unblock, 0x03 - allblock, 0x04 - allunblock

        if( _type == BLOCK || _type == UNBLOCK )
        {
            _name = readS();
            _target = L2World.getInstance().getPlayer(_name);
        }
    }
    
    void runImpl()
    {
        L2PcInstance activeChar = getClient().getActiveChar();
                
//      FIXME: need to send message like 'Character blah added to blocklist'?
            switch(_type)
            {
                case BLOCK:
                    if(_target != null)
                    {
                        activeChar.addToBlockList(_target);
                    }
                    break;
                case UNBLOCK:
                    if(_target != null)
                    {
                        activeChar.removeFromBlockList(_target);
                    }
                    break;
                case BLOCKLIST:
                    ArrayList<String> blockList = activeChar.getBlockList();
                    
                    if(blockList != null)
                    {
                        SystemMessage sm = new SystemMessage(614);
                        sm.addString("Blocked characters list:");
                        activeChar.sendPacket(sm);
                    
                        for(String name : blockList)
                        {
                            sm = new SystemMessage(614);
                            sm.addString(name);
                            activeChar.sendPacket(sm);
                        }
                    }
                    
                    break;
                case ALLBLOCK:
                    activeChar.setBlockAll(true);
                    break;
                case ALLUNBLOCK:
                    activeChar.setBlockAll(false);
                    break;
                default:
                    _log.info("Unknown 0x0a block type: " + _type);
            }
    }
    
    public String getType()
    {
        return _C__A0_REQUESTBLOCK;
    }
    private String _name;
    private Integer _type;
    private L2PcInstance _target;
}