Navigation Menu

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

Commit

Permalink
Catch nick prefix null pointer exception. (Fixes irc-part and irc-quit)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 17, 2014
1 parent f4408bb commit 99de38f
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/cnaude/purpleirc/BotWatcher.java
Expand Up @@ -22,7 +22,7 @@ public BotWatcher(final PurpleIRC plugin) {
bt = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
plugin.logDebug("Checking connection status of IRC bots.");
//plugin.logDebug("Checking connection status of IRC bots.");
for (PurpleBot ircBot : plugin.ircBots.values()) {
if (ircBot.isConnectedBlocking()) {
plugin.logDebug("[" + ircBot.botNick + "] CONNECTED");
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java
Expand Up @@ -41,9 +41,6 @@ private void queueAndSend() {
}
}

/**
*
*/
public void cancel() {
this.plugin.getServer().getScheduler().cancelTask(bt);
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/cnaude/purpleirc/Commands/AddOp.java
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleIRC;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/cnaude/purpleirc/IRCCommand.java
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc;

/**
Expand Down
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc.IRCListeners;

import com.cnaude.purpleirc.PurpleBot;
Expand Down
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc.IRCListeners;

import com.cnaude.purpleirc.PurpleBot;
Expand Down
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc.IRCListeners;

import com.cnaude.purpleirc.PurpleIRC;
Expand Down
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc.IRCListeners;

import com.cnaude.purpleirc.PurpleBot;
Expand Down
83 changes: 47 additions & 36 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -655,7 +655,7 @@ private void loadConfig() {
if (opsList.isEmpty()) {
plugin.logInfo("No channel ops defined.");
}

// build channel voice list
Collection<String> cVoices = new ArrayList<String>();
for (String channelVoice : config.getStringList("channels." + enChannelName + ".voices")) {
Expand Down Expand Up @@ -1443,7 +1443,7 @@ public void addOp(String channelName, String userMask, CommandSender sender) {
config.set("channels." + encodeChannel(getConfigChannelName(channelName)) + ".ops", opsList.get(channelName));
saveConfig();
}

/**
*
* @param channelName
Expand Down Expand Up @@ -1481,7 +1481,7 @@ public void removeOp(String channelName, String userMask, CommandSender sender)
config.set("channels." + encodeChannel(getConfigChannelName(channelName)) + ".ops", opsList.get(channelName));
saveConfig();
}

/**
*
* @param channelName
Expand Down Expand Up @@ -1518,7 +1518,7 @@ public void op(String channelName, String nick) {
}
}
}

/**
*
* @param channelName
Expand Down Expand Up @@ -1554,7 +1554,7 @@ public void deOp(String channelName, String nick) {
}
}
}

/**
*
* @param channelName
Expand Down Expand Up @@ -1785,17 +1785,23 @@ public void sendUserList(CommandSender sender, Channel channel) {
}
}

public String getNickPrefix(User user, Channel channel) {
if (user.isIrcop()) {
return plugin.ircNickPrefixIrcOp;
} else if (user.getChannelsSuperOpIn().contains(channel)) {
return plugin.ircNickPrefixSuperOp;
} else if (user.getChannelsOpIn().contains(channel)) {
return plugin.ircNickPrefixOp;
} else if (user.getChannelsHalfOpIn().contains(channel)) {
return plugin.ircNickPrefixHalfOp;
} else if (user.getChannelsVoiceIn().contains(channel)) {
return plugin.ircNickPrefixVoice;
public String getNickPrefix(User user, Channel channel) {
try {
if (user.getChannels() != null) {
if (user.isIrcop()) {
return plugin.ircNickPrefixIrcOp;
} else if (user.getChannelsSuperOpIn().contains(channel)) {
return plugin.ircNickPrefixSuperOp;
} else if (user.getChannelsOpIn().contains(channel)) {
return plugin.ircNickPrefixOp;
} else if (user.getChannelsHalfOpIn().contains(channel)) {
return plugin.ircNickPrefixHalfOp;
} else if (user.getChannelsVoiceIn().contains(channel)) {
return plugin.ircNickPrefixVoice;
}
}
} catch (Exception ex) {
plugin.logError(ex.getMessage());
}
return "";
}
Expand Down Expand Up @@ -1862,7 +1868,7 @@ public void opFriends(String channelName) {
}
}
}

/**
*
* @param channel
Expand Down Expand Up @@ -1926,7 +1932,7 @@ public void opFriends(Channel channel, User user) {
}
}
}

/**
*
* @param channel
Expand Down Expand Up @@ -2199,8 +2205,8 @@ public void broadcastAction(User user, org.pircbotx.Channel channel, String mess
if (enabledMessages.get(myChannel).contains(TemplateName.IRC_HERO_ACTION)) {
Herochat.getChannelManager().getChannel(heroChannel.get(myChannel))
.sendRawMessage(plugin.tokenizer.ircChatToHeroChatTokenizer(
this, user,channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_HERO_ACTION), message,
this, user, channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_HERO_ACTION), message,
Herochat.getChannelManager(),
heroChannel.get(myChannel)
)
Expand Down Expand Up @@ -2293,29 +2299,36 @@ public void broadcastIRCJoin(User user, org.pircbotx.Channel channel) {
if (enabledMessages.get(channel.getName()).contains(TemplateName.IRC_HERO_JOIN)) {
Herochat.getChannelManager().getChannel(heroChannel.get(channel.getName()))
.sendRawMessage(plugin.tokenizer.ircChatToHeroChatTokenizer(
this, user, channel, plugin.getMsgTemplate(botNick,
this, user, channel, plugin.getMsgTemplate(botNick,
TemplateName.IRC_HERO_JOIN),
Herochat.getChannelManager(),
heroChannel.get(channel.getName())));
}
}

public void broadcastIRCPart(User user, org.pircbotx.Channel channel) {
plugin.logDebug("[broadcastIRCPart] A");
if (enabledMessages.get(channel.getName()).contains(TemplateName.IRC_PART)) {
plugin.logDebug("[broadcastIRCPart] B");
String message = plugin.tokenizer.chatIRCTokenizer(
this, user, channel, plugin.getMsgTemplate(botNick, TemplateName.IRC_PART));
plugin.logDebug("[broadcastIRCPart] C");
plugin.logDebug("[broadcastIRCPart] Broadcasting part message because "
+ TemplateName.IRC_PART + " is true.");
plugin.getServer().broadcast(plugin.tokenizer.chatIRCTokenizer(
this, user, channel, plugin.getMsgTemplate(botNick, TemplateName.IRC_PART)), "irc.message.part");
+ TemplateName.IRC_PART + " is true: " + message);
plugin.logDebug("[broadcastIRCPart] D");
plugin.getServer().broadcast(message, "irc.message.part");
plugin.logDebug("[broadcastIRCPart] E");
} else {
plugin.logDebug("[broadcastIRCPart] NOT broadcasting part message because "
+ TemplateName.IRC_PART + " is false.");
}
plugin.logDebug("[broadcastIRCPart] F");

if (enabledMessages.get(channel.getName()).contains(TemplateName.IRC_HERO_PART)) {
Herochat.getChannelManager().getChannel(heroChannel.get(channel.getName()))
.sendRawMessage(plugin.tokenizer.ircChatToHeroChatTokenizer(
this, user, channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_HERO_PART),
this, user, channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_HERO_PART),
Herochat.getChannelManager(),
heroChannel.get(channel.getName())));
}
Expand All @@ -2328,9 +2341,7 @@ public void broadcastIRCQuit(User user, org.pircbotx.Channel channel, String rea
+ TemplateName.IRC_QUIT + " is true.");
plugin.getServer().broadcast(plugin.tokenizer.chatIRCTokenizer(
this, user, channel, plugin.getMsgTemplate(botNick, TemplateName.IRC_QUIT))
.replace("%NAME%", user.getNick())
.replace("%REASON%", reason)
.replace("%CHANNEL%", channel.getName()), "irc.message.quit");
.replace("%REASON%", reason), "irc.message.quit");
} else {
plugin.logDebug("[broadcastIRCQuit] NOT broadcasting quit message because "
+ TemplateName.IRC_QUIT + " is false.");
Expand All @@ -2339,16 +2350,16 @@ public void broadcastIRCQuit(User user, org.pircbotx.Channel channel, String rea
if (enabledMessages.get(channel.getName()).contains(TemplateName.IRC_HERO_QUIT)) {
Herochat.getChannelManager().getChannel(heroChannel.get(channel.getName()))
.sendRawMessage(plugin.tokenizer.ircChatToHeroChatTokenizer(
this, user, channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_HERO_QUIT),
this, user, channel, plugin.getMsgTemplate(
botNick, TemplateName.IRC_HERO_QUIT),
Herochat.getChannelManager(),
heroChannel.get(channel.getName())));
}

}

// Broadcast topic changes from IRC
/**
* Broadcast topic changes from IRC
*
* @param user
* @param channel
Expand All @@ -2363,32 +2374,32 @@ public void broadcastIRCTopic(User user, org.pircbotx.Channel channel, String me
if (enabledMessages.get(channel.getName()).contains(TemplateName.IRC_HERO_TOPIC)) {
Herochat.getChannelManager().getChannel(heroChannel.get(channel.getName()))
.sendRawMessage(plugin.tokenizer.ircChatToHeroChatTokenizer(
this, user, channel, plugin.getMsgTemplate(botNick, TemplateName.IRC_HERO_TOPIC), message,
this, user, channel, plugin.getMsgTemplate(botNick, TemplateName.IRC_HERO_TOPIC), message,
Herochat.getChannelManager(),
heroChannel.get(channel.getName())));
}
}

// Broadcast disconnect messages from IRC
/**
* Broadcast disconnect messages from IRC
*
* @param nick
*/
public void broadcastIRCDisconnect(String nick) {
plugin.getServer().broadcast("[" + nick + "] Disconnected from IRC server.", "irc.message.disconnect");
}

// Broadcast connect messages from IRC
/**
* Broadcast connect messages from IRC
*
* @param nick
*/
public void broadcastIRCConnect(String nick) {
plugin.getServer().broadcast("[" + nick + "] Connected to IRC server.", "irc.message.connect");
}

// Notify when players use commands
/**
* Notify when players use commands
*
* @param player
* @param cmd
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -191,9 +191,9 @@ public void onEnable() {
try {
heroConfig.load(heroConfigFile);
} catch (IOException ex) {
Logger.getLogger(PurpleIRC.class.getName()).log(Level.SEVERE, null, ex);
logError(ex.getMessage());
} catch (InvalidConfigurationException ex) {
Logger.getLogger(PurpleIRC.class.getName()).log(Level.SEVERE, null, ex);
logError(ex.getMessage());
}
heroChatEmoteFormat = heroConfig.getString("format.emote", "");
} else {
Expand Down

0 comments on commit 99de38f

Please sign in to comment.