/
AccountRemoveAllowedChannelCommand.java
49 lines (45 loc) · 1.78 KB
/
AccountRemoveAllowedChannelCommand.java
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
package de.cubeside.globalserver.command;
import de.cubeside.globalserver.ClientConfig;
import de.cubeside.globalserver.GlobalServer;
import de.cubeside.globalserver.ServerCommand;
import de.iani.cubesideutils.commands.ArgsParser;
import java.util.ArrayList;
import java.util.Collection;
public class AccountRemoveAllowedChannelCommand extends ServerCommand {
public AccountRemoveAllowedChannelCommand() {
super("accountremoveallowedchannel");
}
@Override
public void execute(GlobalServer server, ArgsParser args) {
if (args.remaining() != 2) {
GlobalServer.LOGGER.info("/accountremoveallowedchannel <name> <channel>");
return;
}
String accountName = args.getNext().toLowerCase().trim();
String channel = args.getNext();
ClientConfig account = server.getAccount(accountName);
if (account == null) {
GlobalServer.LOGGER.info("Account " + accountName + " does not exist!");
return;
}
account.getAllowedChannels().remove(channel);
server.saveConfig();
GlobalServer.LOGGER.info("Channel " + channel + " is no longer allowed for account " + accountName);
}
@Override
public Collection<String> tabComplete(GlobalServer server, ArgsParser argsParser) {
if (argsParser.remaining() == 1) {
ArrayList<String> result = new ArrayList<>();
for (ClientConfig e : server.getAccounts()) {
result.add(e.getLogin());
}
return result;
} else if (argsParser.remaining() == 2) {
ClientConfig account = server.getAccount(argsParser.getNext());
if (account != null) {
return account.getAllowedChannels();
}
}
return null;
}
}