summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/commands/KickCommand.java
blob: 96b2731e1b7afc24d8b396c8b18128bbcf8ca692 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package f00f.net.irc.martyr.commands;

import f00f.net.irc.martyr.InCommand;
import f00f.net.irc.martyr.clientstate.Channel;
import f00f.net.irc.martyr.clientstate.ClientState;
import f00f.net.irc.martyr.util.FullNick;
import java.util.logging.Logger;


/**
 * Defines KICK command.
 */
public class KickCommand extends AbstractCommand
{

    static Logger log = Logger.getLogger(KickCommand.class.getName());

    private String channel;
    private FullNick userKicker;
    private FullNick userKicked;
    private String comment;

    /** For use as a factory */
    public KickCommand()
    {
        this( null, null, null, null );
    }

    public KickCommand( FullNick userKicker, String channel,
        String userKicked, String comment )
    {
        this.userKicker = userKicker;
        this.channel = channel;
        this.userKicked = new FullNick( userKicked );
        this.comment = comment;
    }

    public KickCommand( String channel, String userToKick, String comment )
    {
        this( null, channel, userToKick, comment );
    }

    public InCommand parse( String prefix, String identifier, String params )
    {
        return new KickCommand(
            new FullNick( prefix ),
            getParameter( params, 0 ),
            getParameter( params, 1 ),
            getParameter( params, 2 )
        );
    }

    public String getIrcIdentifier()
    {
        return "KICK";
    }

    public String renderParams()
    {
        return channel + " " + userKicked + " :" + comment;
    }

    public String getChannel()
    {
        return channel;
    }

    public FullNick getKicker()
    {
        return userKicker;
    }

    public FullNick getKicked()
    {
        return userKicked;
    }

    public String getComment()
    {
        return comment;
    }

    public boolean kickedUs( ClientState state )
    {
        return userKicked.equals( state.getNick() );
    }

    public boolean updateClientState( ClientState state )
    {
        if( kickedUs( state ) )
        {
            // We've been kicked.
            //log.debug("KICK: We've been kicked " + channel);
            state.removeChannel( channel );
            return true;
        }
        else
        {
            // Someone else was kicked.
            //log.debug("KICK: " + userKicked.getNick() + " kicked " + channel);
            // 1) Grab group
            Channel channelObj = state.getChannel( channel );
            channelObj.removeMember( userKicked, this );
            return true;
        }
    }

}