]> jfr.im git - irc/rizon/acid.git/blob - vizon/src/main/java/net/rizon/acid/plugins/vizon/commands/BanCommand.java
WIP: Allow barring of users from VIzon
[irc/rizon/acid.git] / vizon / src / main / java / net / rizon / acid / plugins / vizon / commands / BanCommand.java
1 /*
2 * Copyright (c) 2021, Dwarf <dwarf@rizon.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26 package net.rizon.acid.plugins.vizon.commands;
27
28 import net.rizon.acid.core.*;
29 import net.rizon.acid.plugins.vizon.Vizon;
30 import net.rizon.acid.plugins.vizon.db.VizonDatabase;
31
32 import java.util.Arrays;
33
34 /**
35 *
36 * @author Dwarf <dwarf@rizon.net>
37 */
38 public class BanCommand extends Command
39 {
40 public BanCommand()
41 {
42 super(1, 1);
43 }
44
45 @Override
46 public void Run(User source, AcidUser to, Channel c, String[] args)
47 {
48 String[] parts = args[0].split(" ");
49 String nick = parts[0];
50 String reason = String.join(" ", Arrays.copyOfRange(parts, 1, parts.length));
51
52 VizonDatabase database = Vizon.getVizonDatabase();
53 if (database.findBanByNick(nick) != null)
54 {
55 Acidictive.reply(source, to, c, "Nickname is already banned.");
56 return;
57 }
58
59 if (database.insertBan(nick, source.getNick(), reason))
60 {
61 Acidictive.reply(source, to, c, "Nickname banned from playing.");
62 }
63 else
64 {
65 Acidictive.reply(source, to, c, "Couldn't create a ban, contact a dev.");
66 }
67 }
68 }