Herochat null pointer check (invalid channel)

This commit is contained in:
cnaude 2016-04-10 15:35:14 -07:00
parent 155b1467cc
commit fddf4f8377
3 changed files with 31 additions and 18 deletions

View File

@ -96,16 +96,16 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot-19</artifactId>
<version>1.9</version>
<artifactId>spigot-184</artifactId>
<version>1.8.4</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot-184</artifactId>
<version>1.8.4</version>
<artifactId>spigot-19</artifactId>
<version>1.9</version>
<type>jar</type>
<scope>provided</scope>
</dependency>

View File

@ -2763,6 +2763,9 @@ public final class PurpleBot {
String rawHCMessage = filterMessage(
plugin.tokenizer.ircChatToHeroChatTokenizer(this, user, channel, tmpl, message, Herochat.getChannelManager(), hChannel), channelName);
if (!rawHCMessage.isEmpty()) {
if (Herochat.getChannelManager().getChannel(hChannel) == null) {
plugin.logError("Herochat channel is invalid: " + hChannel);
} else {
Herochat.getChannelManager().getChannel(hChannel).sendRawMessage(rawHCMessage);
messageSent = true;
if (logIrcToHeroChat.containsKey(channelName)) {
@ -2772,6 +2775,7 @@ public final class PurpleBot {
}
}
}
}
/*
Send messages to VentureChat if enabled

View File

@ -206,17 +206,26 @@ public class ChatTokenizer {
*/
public String ircChatToHeroChatTokenizer(PurpleBot ircBot, User user, org.pircbotx.Channel channel, String template, String message, ChannelManager channelManager, String hChannel) {
String ircNick = user.getNick();
String heroNick = "";
String heroColor = "";
String tmpl;
if (channelManager.getChannel(hChannel) == null) {
plugin.logError("Herochat channel is invalid: " + hChannel);
} else {
heroNick = channelManager.getChannel(hChannel).getNick();
heroColor = channelManager.getChannel(hChannel).getColor().toString();
}
Player player = this.getPlayer(ircNick);
if (player != null) {
tmpl = playerTokenizer(player, template);
} else {
tmpl = playerTokenizer(ircNick, template);
}
plugin.logDebug(message);
return plugin.colorConverter.ircColorsToGame(ircUserTokenizer(tmpl, user, ircBot)
.replace("%HEROCHANNEL%", hChannel)
.replace("%HERONICK%", channelManager.getChannel(hChannel).getNick())
.replace("%HEROCOLOR%", channelManager.getChannel(hChannel).getColor().toString())
.replace("%HERONICK%", heroNick)
.replace("%HEROCOLOR%", heroColor)
.replace("%NICKPREFIX%", ircBot.getNickPrefix(user, channel))
.replace("%CHANNELPREFIX%", ircBot.getChannelPrefix(channel))
.replace("%MESSAGE%", message)