diff --git a/src/main/java/com/cnaude/purpleirc/CommandHandlers.java b/src/main/java/com/cnaude/purpleirc/CommandHandlers.java
index 26dd3e4..f951a24 100644
--- a/src/main/java/com/cnaude/purpleirc/CommandHandlers.java
+++ b/src/main/java/com/cnaude/purpleirc/CommandHandlers.java
@@ -44,8 +44,10 @@ public class CommandHandlers implements CommandExecutor {
this.plugin = plugin;
+ commands.put("addban", new AddBan(plugin));
commands.put("addop", new AddOp(plugin));
commands.put("addvoice", new AddVoice(plugin));
+ commands.put("ban", new Ban(plugin));
commands.put("connect", new Connect(plugin));
commands.put("ctcp", new CTCP(plugin));
commands.put("deop", new DeOp(plugin));
@@ -61,6 +63,7 @@ public class CommandHandlers implements CommandExecutor {
commands.put("list", new List(plugin));
commands.put("listbots", new ListBots(plugin));
commands.put("listops", new ListOps(plugin));
+ commands.put("listbans", new ListBans(plugin));
commands.put("listvoices", new ListVoices(plugin));
commands.put("login", new Login(plugin));
commands.put("load", new Load(plugin));
@@ -78,7 +81,8 @@ public class CommandHandlers implements CommandExecutor {
commands.put("reloadbotconfigs", new ReloadBotConfigs(plugin));
commands.put("reloadbots", new ReloadBots(plugin));
commands.put("reloadconfig", new ReloadConfig(plugin));
- commands.put("removeop", new RemoveOp(plugin));
+ commands.put("removeban", new RemoveBan(plugin));
+ commands.put("removeop", new RemoveOp(plugin));
commands.put("removevoice", new RemoveVoice(plugin));
commands.put("save", new Save(plugin));
commands.put("say", new Say(plugin));
@@ -88,6 +92,7 @@ public class CommandHandlers implements CommandExecutor {
commands.put("slist", new SList(plugin));
commands.put("smsg", new SMsg(plugin));
commands.put("topic", new Topic(plugin));
+ commands.put("unban", new UnBan(plugin));
commands.put("unmute", new UnMute(plugin));
commands.put("updatecheck", new UpdateCheck(plugin));
commands.put("unload", new Unload(plugin));
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/AddBan.java b/src/main/java/com/cnaude/purpleirc/Commands/AddBan.java
new file mode 100644
index 0000000..b4460a5
--- /dev/null
+++ b/src/main/java/com/cnaude/purpleirc/Commands/AddBan.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2014 cnaude
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.cnaude.purpleirc.Commands;
+
+import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.pircbotx.Channel;
+import org.pircbotx.User;
+
+/**
+ *
+ * @author cnaude
+ */
+public class AddBan implements IRCCommandInterface {
+
+ private final PurpleIRC plugin;
+ private final String usage = "([bot]) ([channel]) [user|mask]";
+ private final String desc = "Add IRC users to the ban list.";
+ private final String name = "addban";
+ private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
+
+ /**
+ *
+ * @param plugin
+ */
+ public AddBan(PurpleIRC plugin) {
+ this.plugin = plugin;
+ }
+
+ /**
+ *
+ * @param sender
+ * @param args
+ */
+ @Override
+ public void dispatch(CommandSender sender, String[] args) {
+ BotsAndChannels bac;
+ int idx;
+
+ if (args.length >= 4) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ idx = 3;
+ } else if (args.length == 2) {
+ bac = new BotsAndChannels(plugin, sender);
+ idx = 1;
+ } else {
+ sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ for (int i = idx; i < args.length; i++) {
+
+ String nick = args[i];
+ String mask = nick;
+ Channel channel = plugin.ircBots.get(botName).getChannel(channelName);
+ if (channel != null) {
+ for (User user : channel.getUsers()) {
+ if (user.getNick().equalsIgnoreCase(nick)) {
+ mask = "*!*" + user.getLogin() + "@" + user.getHostmask();
+ }
+ }
+ }
+ if (mask.split("[\\!\\@]", 3).length == 3) {
+ plugin.ircBots.get(botName).addBan(channelName, mask, sender);
+ plugin.ircBots.get(botName).ban(channelName, mask);
+ } else {
+ sender.sendMessage(ChatColor.RED + "Invalid user or mask: "
+ + ChatColor.WHITE + mask);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public String desc() {
+ return desc;
+ }
+
+ @Override
+ public String usage() {
+ return usage;
+ }
+}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/AddOp.java b/src/main/java/com/cnaude/purpleirc/Commands/AddOp.java
index f3a1bc1..42aae9b 100644
--- a/src/main/java/com/cnaude/purpleirc/Commands/AddOp.java
+++ b/src/main/java/com/cnaude/purpleirc/Commands/AddOp.java
@@ -17,6 +17,7 @@
package com.cnaude.purpleirc.Commands;
import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.pircbotx.Channel;
@@ -29,7 +30,7 @@ import org.pircbotx.User;
public class AddOp implements IRCCommandInterface {
private final PurpleIRC plugin;
- private final String usage = "[bot] [channel] [user|mask]";
+ private final String usage = "([bot]) ([channel]) [user|mask]";
private final String desc = "Add IRC users to IRC auto op list.";
private final String name = "addop";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
@@ -49,34 +50,46 @@ public class AddOp implements IRCCommandInterface {
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
- if (args.length == 4) {
- String bot = args[1];
- String channelName = args[2];
- if (plugin.ircBots.containsKey(bot)) {
- // #channel, user
- String nick = args[3];
- String mask = nick;
- Channel channel = plugin.ircBots.get(bot).getChannel(channelName);
- if (channel != null) {
- for (User user : channel.getUsers()) {
- if (user.getNick().equalsIgnoreCase(nick)) {
- mask = "*!*" + user.getLogin() + "@" + user.getHostmask();
+ BotsAndChannels bac;
+ int idx;
+
+ if (args.length >= 4) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ idx = 3;
+ } else if (args.length == 2) {
+ bac = new BotsAndChannels(plugin, sender);
+ idx = 1;
+ } else {
+ sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ for (int i = idx; i < args.length; i++) {
+
+ String nick = args[i];
+ String mask = nick;
+ Channel channel = plugin.ircBots.get(botName).getChannel(channelName);
+ if (channel != null) {
+ for (User user : channel.getUsers()) {
+ if (user.getNick().equalsIgnoreCase(nick)) {
+ mask = "*!*" + user.getLogin() + "@" + user.getHostmask();
+ }
+ }
+ }
+ if (mask.split("[\\!\\@]", 3).length == 3) {
+ plugin.ircBots.get(botName).addOp(channelName, mask, sender);
+ plugin.ircBots.get(botName).opIrcUsers(channelName);
+ } else {
+ sender.sendMessage(ChatColor.RED + "Invalid user or mask: "
+ + ChatColor.WHITE + mask);
}
}
}
- if (mask.split("[\\!\\@]", 3).length == 3) {
- plugin.ircBots.get(bot).addOp(channelName, mask, sender);
- plugin.ircBots.get(bot).opIrcUsers(channelName);
- } else {
- sender.sendMessage(ChatColor.RED + "Invalid user or mask: "
- + ChatColor.WHITE + mask);
- }
- } else {
- sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
}
- } else {
- sender.sendMessage(fullUsage);
}
+
}
@Override
@@ -93,4 +106,4 @@ public class AddOp implements IRCCommandInterface {
public String usage() {
return usage;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/AddVoice.java b/src/main/java/com/cnaude/purpleirc/Commands/AddVoice.java
index 6a9e09b..134d9d5 100644
--- a/src/main/java/com/cnaude/purpleirc/Commands/AddVoice.java
+++ b/src/main/java/com/cnaude/purpleirc/Commands/AddVoice.java
@@ -17,6 +17,7 @@
package com.cnaude.purpleirc.Commands;
import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.pircbotx.Channel;
@@ -29,7 +30,7 @@ import org.pircbotx.User;
public class AddVoice implements IRCCommandInterface {
private final PurpleIRC plugin;
- private final String usage = "[bot] [channel] [user|mask]";
+ private final String usage = "([bot]) ([channel]) [user|mask]";
private final String desc = "Add IRC users to IRC auto voice list.";
private final String name = "addvoice";
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
@@ -49,33 +50,44 @@ public class AddVoice implements IRCCommandInterface {
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
- if (args.length == 4) {
- String bot = args[1];
- String channelName = args[2];
- if (plugin.ircBots.containsKey(bot)) {
- // #channel, user
- String nick = args[3];
- String mask = nick;
- Channel channel = plugin.ircBots.get(bot).getChannel(channelName);
- if (channel != null) {
- for (User user : channel.getUsers()) {
- if (user.getNick().equalsIgnoreCase(nick)) {
- mask = "*!*" + user.getLogin() + "@" + user.getHostmask();
+ BotsAndChannels bac;
+ int idx;
+
+ if (args.length >= 4) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ idx = 3;
+ } else if (args.length == 2) {
+ bac = new BotsAndChannels(plugin, sender);
+ idx = 1;
+ } else {
+ sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ for (int i = idx; i < args.length; i++) {
+
+ String nick = args[i];
+ String mask = nick;
+ Channel channel = plugin.ircBots.get(botName).getChannel(channelName);
+ if (channel != null) {
+ for (User user : channel.getUsers()) {
+ if (user.getNick().equalsIgnoreCase(nick)) {
+ mask = "*!*" + user.getLogin() + "@" + user.getHostmask();
+ }
+ }
+ }
+ if (mask.split("[\\!\\@]", 3).length == 3) {
+ plugin.ircBots.get(botName).addVoice(channelName, mask, sender);
+ plugin.ircBots.get(botName).voiceIrcUsers(channelName);
+ } else {
+ sender.sendMessage(ChatColor.RED + "Invalid user or mask: "
+ + ChatColor.WHITE + mask);
}
}
}
- if (mask.split("[\\!\\@]", 3).length == 3) {
- plugin.ircBots.get(bot).addVoice(channelName, mask, sender);
- plugin.ircBots.get(bot).voiceIrcUsers(channelName);
- } else {
- sender.sendMessage(ChatColor.RED + "Invalid user or mask: "
- + ChatColor.WHITE + mask);
- }
- } else {
- sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
}
- } else {
- sender.sendMessage(fullUsage);
}
}
@@ -93,4 +105,4 @@ public class AddVoice implements IRCCommandInterface {
public String usage() {
return usage;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/Ban.java b/src/main/java/com/cnaude/purpleirc/Commands/Ban.java
new file mode 100644
index 0000000..b402b7a
--- /dev/null
+++ b/src/main/java/com/cnaude/purpleirc/Commands/Ban.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2014 cnaude
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.cnaude.purpleirc.Commands;
+
+import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.pircbotx.Channel;
+import org.pircbotx.User;
+
+/**
+ *
+ * @author cnaude
+ */
+public class Ban implements IRCCommandInterface {
+
+ private final PurpleIRC plugin;
+ private final String usage = "([bot]) ([channel]) [user(s)]";
+ private final String desc = "Ban an IRC user from a channel.";
+ private final String name = "ban";
+ private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
+
+ /**
+ *
+ * @param plugin
+ */
+ public Ban(PurpleIRC plugin) {
+ this.plugin = plugin;
+ }
+
+ /**
+ *
+ * @param sender
+ * @param args
+ */
+ @Override
+ public void dispatch(CommandSender sender, String[] args) {
+ BotsAndChannels bac;
+ int idx;
+
+ if (args.length >= 4) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ idx = 3;
+ } else if (args.length == 2) {
+ bac = new BotsAndChannels(plugin, sender);
+ idx = 1;
+ } else {
+ sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ for (int i = idx; i < args.length; i++) {
+
+ String nick = args[i];
+ String mask = nick;
+ Channel channel = plugin.ircBots.get(botName).getChannel(channelName);
+ if (channel != null) {
+ for (User user : channel.getUsers()) {
+ if (user.getNick().equalsIgnoreCase(nick)) {
+ mask = "*!*" + user.getLogin() + "@" + user.getHostmask();
+ }
+ }
+ }
+ if (mask.split("[\\!\\@]", 3).length == 3) {
+ plugin.ircBots.get(botName).ban(channelName, mask);
+ plugin.ircBots.get(botName).kick(channelName, nick, "Banned");
+ sender.sendMessage("Setting +b for "
+ + ChatColor.WHITE + mask
+ + ChatColor.RESET + " on "
+ + ChatColor.WHITE + channelName);
+ } else {
+ sender.sendMessage(ChatColor.RED + "Invalid user or mask: "
+ + ChatColor.WHITE + mask);
+ }
+
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public String desc() {
+ return desc;
+ }
+
+ @Override
+ public String usage() {
+ return usage;
+ }
+}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/ListBans.java b/src/main/java/com/cnaude/purpleirc/Commands/ListBans.java
new file mode 100644
index 0000000..99fd512
--- /dev/null
+++ b/src/main/java/com/cnaude/purpleirc/Commands/ListBans.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2014 cnaude
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.cnaude.purpleirc.Commands;
+
+import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+
+/**
+ *
+ * @author cnaude
+ */
+public class ListBans implements IRCCommandInterface {
+
+ private final PurpleIRC plugin;
+ private final String usage = "([bot]) ([channel])";
+ private final String desc = "List IRC user mask in ban list.";
+ private final String name = "listbans";
+ private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
+
+ /**
+ *
+ * @param plugin
+ */
+ public ListBans(PurpleIRC plugin) {
+ this.plugin = plugin;
+ }
+
+ /**
+ *
+ * @param sender
+ * @param args
+ */
+ @Override
+ public void dispatch(CommandSender sender, String[] args) {
+ BotsAndChannels bac;
+
+ if (args.length >= 3) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ } else if (args.length >= 2) {
+ bac = new BotsAndChannels(plugin, sender, args[1]);
+ } else if (args.length == 1) {
+ bac = new BotsAndChannels(plugin, sender);
+ } else {
+ sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ if (plugin.ircBots.get(botName).banList.containsKey(channelName)) {
+ sender.sendMessage(ChatColor.LIGHT_PURPLE + "-----[ " + ChatColor.WHITE + channelName
+ + ChatColor.LIGHT_PURPLE + " - " + ChatColor.WHITE + "Ban Masks" + ChatColor.LIGHT_PURPLE + " ]-----");
+ for (String userMask : plugin.ircBots.get(botName).banList.get(channelName)) {
+ sender.sendMessage(" - " + userMask);
+ }
+ } else {
+ sender.sendMessage(plugin.invalidChannel.replace("%CHANNEL%", channelName));
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public String desc() {
+ return desc;
+ }
+
+ @Override
+ public String usage() {
+ return usage;
+ }
+}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/ListOps.java b/src/main/java/com/cnaude/purpleirc/Commands/ListOps.java
index c9f4b4a..82932dc 100644
--- a/src/main/java/com/cnaude/purpleirc/Commands/ListOps.java
+++ b/src/main/java/com/cnaude/purpleirc/Commands/ListOps.java
@@ -17,6 +17,7 @@
package com.cnaude.purpleirc.Commands;
import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -27,10 +28,10 @@ import org.bukkit.command.CommandSender;
public class ListOps implements IRCCommandInterface {
private final PurpleIRC plugin;
- private final String usage = "[bot] [channel]";
+ private final String usage = "([bot]) ([channel])";
private final String desc = "List IRC user mask in auto-op list.";
private final String name = "listops";
- private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
+ private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
/**
*
@@ -47,24 +48,32 @@ public class ListOps implements IRCCommandInterface {
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
- if (args.length == 3) {
- String bot = args[1];
- String channelName = args[2];
- if (plugin.ircBots.containsKey(bot)) {
- if (plugin.ircBots.get(bot).opsList.containsKey(channelName)) {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "-----[ " + ChatColor.WHITE + channelName
- + ChatColor.LIGHT_PURPLE + " - " + ChatColor.WHITE + "Auto Op Masks" + ChatColor.LIGHT_PURPLE + " ]-----");
- for (String userMask : plugin.ircBots.get(bot).opsList.get(channelName)) {
- sender.sendMessage(" - " + userMask);
- }
- } else {
- sender.sendMessage(plugin.invalidChannel.replace("%CHANNEL%", channelName));
- }
- } else {
- sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
- }
+ BotsAndChannels bac;
+
+ if (args.length >= 3) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ } else if (args.length >= 2) {
+ bac = new BotsAndChannels(plugin, sender, args[1]);
+ } else if (args.length == 1) {
+ bac = new BotsAndChannels(plugin, sender);
} else {
sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ if (plugin.ircBots.get(botName).opsList.containsKey(channelName)) {
+ sender.sendMessage(ChatColor.LIGHT_PURPLE + "-----[ " + ChatColor.WHITE + channelName
+ + ChatColor.LIGHT_PURPLE + " - " + ChatColor.WHITE + "Auto Op Masks" + ChatColor.LIGHT_PURPLE + " ]-----");
+ for (String userMask : plugin.ircBots.get(botName).opsList.get(channelName)) {
+ sender.sendMessage(" - " + userMask);
+ }
+ } else {
+ sender.sendMessage(plugin.invalidChannel.replace("%CHANNEL%", channelName));
+ }
+ }
+ }
}
}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/ListVoices.java b/src/main/java/com/cnaude/purpleirc/Commands/ListVoices.java
index 0d24b81..dfbe300 100644
--- a/src/main/java/com/cnaude/purpleirc/Commands/ListVoices.java
+++ b/src/main/java/com/cnaude/purpleirc/Commands/ListVoices.java
@@ -17,6 +17,7 @@
package com.cnaude.purpleirc.Commands;
import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -27,10 +28,10 @@ import org.bukkit.command.CommandSender;
public class ListVoices implements IRCCommandInterface {
private final PurpleIRC plugin;
- private final String usage = "[bot] [channel]";
+ private final String usage = "([bot]) ([channel])";
private final String desc = "List IRC user mask in auto-voice list.";
private final String name = "listvoices";
- private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
+ private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
/**
*
@@ -47,24 +48,30 @@ public class ListVoices implements IRCCommandInterface {
*/
@Override
public void dispatch(CommandSender sender, String[] args) {
- if (args.length == 3) {
- String bot = args[1];
- String channelName = args[2];
- if (plugin.ircBots.containsKey(bot)) {
- if (plugin.ircBots.get(bot).voicesList.containsKey(channelName)) {
- sender.sendMessage(ChatColor.LIGHT_PURPLE + "-----[ " + ChatColor.WHITE + channelName
- + ChatColor.LIGHT_PURPLE + " - " + ChatColor.WHITE + "Auto Voice Masks" + ChatColor.LIGHT_PURPLE + " ]-----");
- for (String userMask : plugin.ircBots.get(bot).voicesList.get(channelName)) {
- sender.sendMessage(" - " + userMask);
- }
- } else {
- sender.sendMessage(plugin.invalidChannel.replace("%CHANNEL%", channelName));
- }
- } else {
- sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
- }
+ BotsAndChannels bac;
+
+ if (args.length >= 3) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ } else if (args.length >= 2) {
+ bac = new BotsAndChannels(plugin, sender, args[1]);
+ } else if (args.length == 1) {
+ bac = new BotsAndChannels(plugin, sender);
} else {
sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ if (plugin.ircBots.get(botName).voicesList.containsKey(channelName)) {
+ sender.sendMessage(ChatColor.LIGHT_PURPLE + "-----[ " + ChatColor.WHITE + channelName
+ + ChatColor.LIGHT_PURPLE + " - " + ChatColor.WHITE + "Auto Voice Masks" + ChatColor.LIGHT_PURPLE + " ]-----");
+ for (String userMask : plugin.ircBots.get(botName).voicesList.get(channelName)) {
+ sender.sendMessage(" - " + userMask);
+ }
+ }
+ }
+ }
}
}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/RemoveBan.java b/src/main/java/com/cnaude/purpleirc/Commands/RemoveBan.java
new file mode 100644
index 0000000..cbbfc4c
--- /dev/null
+++ b/src/main/java/com/cnaude/purpleirc/Commands/RemoveBan.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2014 cnaude
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.cnaude.purpleirc.Commands;
+
+import com.cnaude.purpleirc.PurpleIRC;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+
+/**
+ *
+ * @author cnaude
+ */
+public class RemoveBan implements IRCCommandInterface {
+
+ private final PurpleIRC plugin;
+ private final String usage = "[bot] [channel] [user mask]";
+ private final String desc = "Remove a user mask from the ban list.";
+ private final String name = "removeban";
+ private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
+
+ /**
+ *
+ * @param plugin
+ */
+ public RemoveBan(PurpleIRC plugin) {
+ this.plugin = plugin;
+ }
+
+ /**
+ *
+ * @param sender
+ * @param args
+ */
+ @Override
+ public void dispatch(CommandSender sender, String[] args) {
+ if (args.length == 4) {
+ String bot = args[1];
+ String channel = args[2];
+ if (plugin.ircBots.containsKey(bot)) {
+ // #channel, user
+ plugin.ircBots.get(bot).removeBan(channel, args[3], sender);
+ plugin.ircBots.get(bot).unBan(channel, args[3]);
+ } else {
+ sender.sendMessage(plugin.invalidBotName.replace("%BOT%", bot));
+ }
+ } else {
+ sender.sendMessage(fullUsage);
+ }
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public String desc() {
+ return desc;
+ }
+
+ @Override
+ public String usage() {
+ return usage;
+ }
+}
diff --git a/src/main/java/com/cnaude/purpleirc/Commands/UnBan.java b/src/main/java/com/cnaude/purpleirc/Commands/UnBan.java
new file mode 100644
index 0000000..84f8136
--- /dev/null
+++ b/src/main/java/com/cnaude/purpleirc/Commands/UnBan.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2014 cnaude
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.cnaude.purpleirc.Commands;
+
+import com.cnaude.purpleirc.PurpleIRC;
+import com.cnaude.purpleirc.Utilities.BotsAndChannels;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+
+/**
+ *
+ * @author cnaude
+ */
+public class UnBan implements IRCCommandInterface {
+
+ private final PurpleIRC plugin;
+ private final String usage = "([bot]) ([channel]) [user(s)]";
+ private final String desc = "Unban IRC user(s).";
+ private final String name = "unban";
+ private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
+
+ /**
+ *
+ * @param plugin
+ */
+ public UnBan(PurpleIRC plugin) {
+ this.plugin = plugin;
+ }
+
+ /**
+ *
+ * @param sender
+ * @param args
+ */
+ @Override
+ public void dispatch(CommandSender sender, String[] args) {
+ BotsAndChannels bac;
+ int idx;
+
+ if (args.length >= 4) {
+ bac = new BotsAndChannels(plugin, sender, args[1], args[2]);
+ idx = 3;
+ } else if (args.length == 2) {
+ bac = new BotsAndChannels(plugin, sender);
+ idx = 1;
+ } else {
+ sender.sendMessage(fullUsage);
+ return;
+ }
+ if (bac.bot.size() > 0 && bac.channel.size() > 0) {
+ for (String botName : bac.bot) {
+ for (String channelName : bac.channel) {
+ for (int i = idx; i < args.length; i++) {
+ plugin.ircBots.get(botName).unBan(channelName, args[i]);
+ sender.sendMessage("Setting -b for "
+ + ChatColor.WHITE + args[i]
+ + ChatColor.RESET + " on "
+ + ChatColor.WHITE + channelName);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public String desc() {
+ return desc;
+ }
+
+ @Override
+ public String usage() {
+ return usage;
+ }
+}
diff --git a/src/main/java/com/cnaude/purpleirc/PurpleBot.java b/src/main/java/com/cnaude/purpleirc/PurpleBot.java
index 1552e54..f16b46d 100644
--- a/src/main/java/com/cnaude/purpleirc/PurpleBot.java
+++ b/src/main/java/com/cnaude/purpleirc/PurpleBot.java
@@ -147,6 +147,7 @@ public final class PurpleBot {
public CaseInsensitiveMap heroChannel;
public CaseInsensitiveMap townyChannel;
public CaseInsensitiveMap> opsList;
+ public CaseInsensitiveMap> banList;
public CaseInsensitiveMap> voicesList;
public CaseInsensitiveMap> worldList;
public CaseInsensitiveMap> muteList;
@@ -213,6 +214,7 @@ public final class PurpleBot {
this.muteList = new CaseInsensitiveMap<>();
this.worldList = new CaseInsensitiveMap<>();
this.opsList = new CaseInsensitiveMap<>();
+ this.banList = new CaseInsensitiveMap<>();
this.voicesList = new CaseInsensitiveMap<>();
this.heroChannel = new CaseInsensitiveMap<>();
this.townyChannel = new CaseInsensitiveMap<>();
@@ -711,6 +713,7 @@ public final class PurpleBot {
plugin.logDebug("Quit Message => " + quitMessage);
botChannels.clear();
opsList.clear();
+ banList.clear();
voicesList.clear();
muteList.clear();
enabledMessages.clear();
@@ -872,6 +875,19 @@ public final class PurpleBot {
if (opsList.isEmpty()) {
plugin.logInfo("No channel ops defined.");
}
+
+ // build channel ban list
+ Collection cBans = new ArrayList<>();
+ for (String channelBan : config.getStringList("channels." + enChannelName + ".banlist")) {
+ if (!cBans.contains(channelBan)) {
+ cBans.add(channelBan);
+ }
+ plugin.logDebug(" Channel Ban => " + channelBan);
+ }
+ banList.put(channelName, cBans);
+ if (banList.isEmpty()) {
+ plugin.logInfo("No channel bans defined.");
+ }
// build channel voice list
Collection cVoices = new ArrayList<>();
@@ -1849,6 +1865,24 @@ public final class PurpleBot {
}
saveConfig("channels." + encodeChannel(getConfigChannelName(channelName)) + ".ops", opsList.get(channelName));
}
+
+ /**
+ *
+ * @param channelName
+ * @param userMask
+ * @param sender
+ */
+ public void addBan(String channelName, String userMask, CommandSender sender) {
+ if (banList.get(channelName).contains(userMask)) {
+ sender.sendMessage("User mask " + ChatColor.WHITE + userMask
+ + ChatColor.RESET + " is already in the ban list.");
+ } else {
+ sender.sendMessage("User mask " + ChatColor.WHITE + userMask
+ + ChatColor.RESET + " has been added to the ban list.");
+ banList.get(channelName).add(userMask);
+ }
+ saveConfig("channels." + encodeChannel(getConfigChannelName(channelName)) + ".ops", opsList.get(channelName));
+ }
/**
*
@@ -1877,7 +1911,7 @@ public final class PurpleBot {
public void removeOp(String channelName, String userMask, CommandSender sender) {
if (opsList.get(channelName).contains(userMask)) {
sender.sendMessage("User mask " + ChatColor.WHITE + userMask
- + ChatColor.RESET + " has been removed to the ops list.");
+ + ChatColor.RESET + " has been removed from the ops list.");
opsList.get(channelName).remove(userMask);
} else {
sender.sendMessage("User mask " + ChatColor.WHITE + userMask
@@ -1885,6 +1919,24 @@ public final class PurpleBot {
}
saveConfig("channels." + encodeChannel(getConfigChannelName(channelName)) + ".ops", opsList.get(channelName));
}
+
+ /**
+ *
+ * @param channelName
+ * @param userMask
+ * @param sender
+ */
+ public void removeBan(String channelName, String userMask, CommandSender sender) {
+ if (banList.get(channelName).contains(userMask)) {
+ sender.sendMessage("User mask " + ChatColor.WHITE + userMask
+ + ChatColor.RESET + " has been removed from the ban list.");
+ banList.get(channelName).remove(userMask);
+ } else {
+ sender.sendMessage("User mask " + ChatColor.WHITE + userMask
+ + ChatColor.RESET + " is not in the ban list.");
+ }
+ saveConfig("channels." + encodeChannel(getConfigChannelName(channelName)) + ".banlist", banList.get(channelName));
+ }
/**
*
@@ -1922,6 +1974,32 @@ public final class PurpleBot {
}
}
+ /**
+ *
+ * @param channelName
+ * @param mask
+ */
+ public void ban(String channelName, String mask) {
+ Channel channel;
+ channel = getChannel(channelName);
+ if (channel != null) {
+ channel.send().ban(mask);
+ }
+ }
+
+ /**
+ *
+ * @param channelName
+ * @param mask
+ */
+ public void unBan(String channelName, String mask) {
+ Channel channel;
+ channel = getChannel(channelName);
+ if (channel != null) {
+ channel.send().unBan(mask);
+ }
+ }
+
/**
*
* @param channelName
@@ -1993,6 +2071,25 @@ public final class PurpleBot {
}
}
}
+
+ /**
+ *
+ * @param channelName
+ * @param nick
+ * @param reason
+ */
+ public void kick(String channelName, String nick, String reason) {
+ Channel channel;
+ channel = getChannel(channelName);
+ if (channel != null) {
+ for (User user : channel.getUsers()) {
+ if (user.getNick().equals(nick)) {
+ channel.send().kick(user, reason);
+ return;
+ }
+ }
+ }
+ }
private String encodeChannel(String s) {
return s.replace(".", "%2E");
@@ -2366,6 +2463,26 @@ public final class PurpleBot {
}
}
}
+
+ /**
+ *
+ * @param channel
+ * @param user
+ */
+ public void banIrcUser(Channel channel, User user) {
+ String channelName = channel.getName();
+ if (user.getNick().equals(botNick)) {
+ return;
+ }
+ for (String userMask : banList.get(channelName)) {
+ if (checkUserMask(user, userMask)) {
+ plugin.logInfo("Setting +b for " + userMask + " on " + channelName);
+ ban(channelName, userMask);
+ kick(channelName, user.getNick(), "Banned");
+ break;
+ }
+ }
+ }
/**
*
diff --git a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java
index 0027ff0..ba5c2b1 100644
--- a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java
+++ b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java
@@ -832,10 +832,10 @@ public class PurpleIRC extends JavaPlugin {
.replace("%COUNT%", Integer.toString(pl.count))
.replace("%MAX%", Integer.toString(pl.max))
.replace("%PLAYERS%", pl.list);
-
+
return colorConverter.gameColorsToIrc(msg);
}
-
+
/**
*
* @param ircBot
@@ -844,7 +844,7 @@ public class PurpleIRC extends JavaPlugin {
*/
public PlayerList getMCPlayerList(PurpleBot ircBot, String channelName) {
PlayerList pl = new PlayerList();
-
+
Map playerList = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (Player player : getServer().getOnlinePlayers()) {
if (ircBot.hideListWhenVanished.get(channelName)) {
@@ -868,15 +868,15 @@ public class PurpleIRC extends JavaPlugin {
// sort without nick prefixes
pList = Joiner.on(listSeparator).join(playerList.values());
}
-
+
pl.count = playerList.size();
pl.max = getServer().getMaxPlayers();
pl.list = pList;
-
+
return pl;
-
+
}
-
+
public String getRemotePlayers(String commandArgs) {
if (commandArgs != null) {
String host;
diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/BotsAndChannels.java b/src/main/java/com/cnaude/purpleirc/Utilities/BotsAndChannels.java
index 39bcf84..5674955 100644
--- a/src/main/java/com/cnaude/purpleirc/Utilities/BotsAndChannels.java
+++ b/src/main/java/com/cnaude/purpleirc/Utilities/BotsAndChannels.java
@@ -49,6 +49,23 @@ public class BotsAndChannels {
}
}
+ /**
+ *
+ * @param plugin
+ * @param sender
+ * @param botName
+ */
+ public BotsAndChannels(PurpleIRC plugin, CommandSender sender, String botName) {
+ if (plugin.ircBots.containsKey(botName)) {
+ bot.add(botName);
+ for (String channelName : plugin.ircBots.get(botName).botChannels) {
+ channel.add(channelName);
+ }
+ } else {
+ sender.sendMessage(plugin.invalidBotName.replace("%BOT%", botName));
+ }
+ }
+
/**
*
* @param plugin
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index cb15953..1c38e0b 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -122,4 +122,19 @@ permissions:
default: true
'irc.smsg':
description: Gives player access to the /irc smsg command.
- default: true
\ No newline at end of file
+ default: true
+ 'irc.addban':
+ description: Gives player access to the /addban link command.
+ default: op
+ 'irc.removeban':
+ description: Gives player access to the /removeban link command.
+ default: op
+ 'irc.ban':
+ description: Gives player access to the /ban link command.
+ default: op
+ 'irc.unban':
+ description: Gives player access to the /unban link command.
+ default: op
+ 'irc.listbans':
+ description: Gives player access to the /listbans link command.
+ default: op
\ No newline at end of file