Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Updating javadocs. #116
Browse files Browse the repository at this point in the history
Code merge with Spigot version.
Added game-first-join message template.
  • Loading branch information
cnaude committed Nov 22, 2015
1 parent 72415c3 commit 5e8f705
Show file tree
Hide file tree
Showing 42 changed files with 1,234 additions and 141 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/cnaude/purpleirc/BotWatcher.java
Expand Up @@ -22,16 +22,16 @@
* This thread checks each bot for connectivity and reconnects when appropriate.
*
* @author Chris Naude
*
*/
* */
public class BotWatcher {

private final PurpleIRC plugin;
private final BukkitTask bt;

/**
* Run the BotWatcher thread asynchronously at configured interval.
*
* @param plugin
* @param plugin the PurpleIRC plugin
*/
public BotWatcher(final PurpleIRC plugin) {
this.plugin = plugin;
Expand All @@ -55,7 +55,8 @@ public void run() {
}

/**
*
* Cancel the scheduled BukkitTask. Call this when
* shutting down.
*/
public void cancel() {
bt.cancel();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/cnaude/purpleirc/ChannelWatcher.java
Expand Up @@ -19,9 +19,10 @@
import org.bukkit.scheduler.BukkitTask;

/**
*
* @author Chris Naude This thread checks each for users and updates the
* This thread checks each for users and updates the
* internal lists.
*
* @author Chris Naude
*/
public class ChannelWatcher {

Expand All @@ -30,7 +31,7 @@ public class ChannelWatcher {

/**
*
* @param plugin
* @param plugin the PurpleIRC plugin
*/
public ChannelWatcher(final PurpleIRC plugin) {
this.plugin = plugin;
Expand All @@ -46,7 +47,8 @@ public void run() {
}

/**
*
* Cancel the scheduled BukkitTask. Call this when
* shutting down.
*/
public void cancel() {
bt.cancel();
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/com/cnaude/purpleirc/CommandHandlers.java
Expand Up @@ -28,7 +28,7 @@

/**
*
* @author cnaude
* @author Chris Naude
*/
public class CommandHandlers implements CommandExecutor {

Expand All @@ -38,14 +38,16 @@ public class CommandHandlers implements CommandExecutor {

/**
*
* @param plugin
* @param plugin the PurpleIRC plugin
*/
public CommandHandlers(PurpleIRC plugin) {

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));
Expand All @@ -61,6 +63,7 @@ public CommandHandlers(PurpleIRC plugin) {
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));
Expand All @@ -78,6 +81,7 @@ public CommandHandlers(PurpleIRC plugin) {
commands.put("reloadbotconfigs", new ReloadBotConfigs(plugin));
commands.put("reloadbots", new ReloadBots(plugin));
commands.put("reloadconfig", new ReloadConfig(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));
Expand All @@ -88,6 +92,7 @@ public CommandHandlers(PurpleIRC plugin) {
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));
Expand All @@ -106,11 +111,11 @@ public CommandHandlers(PurpleIRC plugin) {

/**
*
* @param sender
* @param cmd
* @param commandLabel
* @param args
* @return
* @param sender sender of the command
* @param cmd the actual command
* @param commandLabel the command label
* @param args the command arguments
* @return always return true
*/
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java
Expand Up @@ -19,6 +19,7 @@
import com.cnaude.purpleirc.Events.IRCCommandEvent;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandException;

/**
Expand All @@ -33,7 +34,7 @@ public class CommandQueueWatcher {

/**
*
* @param plugin
* @param plugin the PurpleIRC plugin
*/
public CommandQueueWatcher(final PurpleIRC plugin) {
this.plugin = plugin;
Expand All @@ -54,8 +55,25 @@ private void queueAndSend() {
IRCCommand ircCommand = queue.poll();
if (ircCommand != null) {
try {
plugin.logDebug("Dispatching command as IRCCommandSender: " + ircCommand.getGameCommand());
plugin.getServer().dispatchCommand(ircCommand.getIRCCommandSender(), ircCommand.getGameCommand());
String cmd = ircCommand.getGameCommand().split(" ")[0];
boolean isCommandBookCommand = false;
plugin.logDebug("CMD: " + cmd);
if (plugin.commandBookHook != null) {
isCommandBookCommand = plugin.commandBookHook.isCommandBookCommand(cmd);
plugin.logDebug("Is this is a CommandBook command? " + Boolean.toString(isCommandBookCommand));
}
if (plugin.getServer().getVersion().contains("MC: 1.8")
&& plugin.getServer().getVersion().contains("Spigot")
&& plugin.getServer().getPluginCommand(cmd) == null
&& !isCommandBookCommand) {
plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand());

plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), ircCommand.getGameCommand());
ircCommand.getIRCConsoleCommandSender().sendMessage("Command sent: " + ircCommand.getGameCommand());
} else {
plugin.logDebug("Dispatching command as IRCCommandSender: " + ircCommand.getGameCommand());
plugin.getServer().dispatchCommand(ircCommand.getIRCCommandSender(), ircCommand.getGameCommand());
}
} catch (CommandException ce) {
plugin.logError("Error running command: " + ce.getMessage());
}
Expand Down
109 changes: 109 additions & 0 deletions 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 <http://www.gnu.org/licenses/>.
*/
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 Chris Naude
*/
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 the PurpleIRC 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;
}
}
67 changes: 40 additions & 27 deletions src/main/java/com/cnaude/purpleirc/Commands/AddOp.java
Expand Up @@ -17,26 +17,27 @@
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
* @author Chris Naude
*/
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;

/**
*
* @param plugin
* @param plugin the PurpleIRC plugin
*/
public AddOp(PurpleIRC plugin) {
this.plugin = plugin;
Expand All @@ -49,34 +50,46 @@ public AddOp(PurpleIRC plugin) {
*/
@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
Expand All @@ -93,4 +106,4 @@ public String desc() {
public String usage() {
return usage;
}
}
}

0 comments on commit 5e8f705

Please sign in to comment.