fr.quatrevieux.araknemu.game.chat.channel.PrivateChannel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A PrivateChannel(PlayerService) 0 2 1
A type() 0 3 1
A authorized(GamePlayer) 0 3 1
A send(GamePlayer,Message) 0 16 3
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.chat.channel;
21
22
import fr.quatrevieux.araknemu.game.chat.ChannelType;
23
import fr.quatrevieux.araknemu.game.chat.ChatException;
24
import fr.quatrevieux.araknemu.game.chat.event.ConcealedMessage;
25
import fr.quatrevieux.araknemu.game.player.GamePlayer;
26
import fr.quatrevieux.araknemu.game.player.PlayerService;
27
import fr.quatrevieux.araknemu.network.game.in.chat.Message;
28
29
/**
30
 * Channel for private messages
31
 */
32
public final class PrivateChannel implements Channel {
33
    private final PlayerService service;
34
35 1
    public PrivateChannel(PlayerService service) {
36 1
        this.service = service;
37 1
    }
38
39
    @Override
40
    public ChannelType type() {
41 1
        return ChannelType.PRIVATE;
42
    }
43
44
    @Override
45
    public boolean authorized(GamePlayer from) {
46 1
        return true;
47
    }
48
49
    @Override
50
    public void send(GamePlayer from, Message message) throws ChatException {
51 1
        if (message.target() == null || !service.isOnline(message.target())) {
52 1
            throw new ChatException(ChatException.Error.USER_NOT_CONNECTED);
53
        }
54
55 1
        final GamePlayer to = service.get(message.target());
56 1
        final ConcealedMessage event = new ConcealedMessage(
57
            from,
58
            to,
59 1
            message.message(),
60 1
            message.items()
61
        );
62
63 1
        from.dispatch(event);
64 1
        to.dispatch(event);
65 1
    }
66
}
67