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

Commit

Permalink
Fix case issues related to channel name and config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 12, 2014
1 parent c7a4da0 commit a3ff0d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/cnaude/purpleirc/Commands/Topic.java
Expand Up @@ -4,7 +4,6 @@
*/
package com.cnaude.purpleirc.Commands;

import com.cnaude.purpleirc.PurpleBot;
import com.cnaude.purpleirc.PurpleIRC;
import com.cnaude.purpleirc.Utilities.BotsAndChannels;
import org.bukkit.ChatColor;
Expand Down
31 changes: 20 additions & 11 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -245,11 +245,9 @@ private void addAutoJoinChannels(Configuration.Builder configBuilder) {
if (channelAutoJoin.containsKey(channelName)) {
if (channelAutoJoin.get(channelName)) {
if (channelPassword.get(channelName).isEmpty()) {
configBuilder.addAutoJoinChannel(channelName
.toLowerCase());
configBuilder.addAutoJoinChannel(channelName);
} else {
configBuilder.addAutoJoinChannel(channelName
.toLowerCase(), channelPassword.get(channelName));
configBuilder.addAutoJoinChannel(channelName, channelPassword.get(channelName));
}
}
}
Expand Down Expand Up @@ -580,7 +578,7 @@ private void loadConfig() {
for (String enChannelName : config.getConfigurationSection("channels").getKeys(false)) {
String channelName = decodeChannel(enChannelName);
plugin.logDebug("Channel => " + channelName);
botChannels.add(channelName.toLowerCase());
botChannels.add(channelName);

channelAutoJoin.put(channelName, config.getBoolean("channels." + enChannelName + ".autojoin", true));
plugin.logDebug(" Autojoin => " + channelAutoJoin.get(channelName));
Expand Down Expand Up @@ -1341,18 +1339,27 @@ public void gameDeath(Player player, String message, String templateName) {
* @param sender
*/
public void changeTopic(String channelName, String topic, CommandSender sender) {
Channel channel = this.getChannel(channelName);
Channel channel = this.getChannel(channelName);
String tTopic = tokenizedTopic(topic);
if (channel != null) {
setTheTopic(channel, tTopic);
config.set("channels." + encodeChannel(channelName) + ".topic", topic);
config.set("channels." + encodeChannel(getConfigChannelName(channelName)) + ".topic", topic);
channelTopic.put(channelName, topic);
saveConfig();
sender.sendMessage("IRC topic for " + channelName + " changed to \"" + topic + "\"");
} else {
sender.sendMessage("Invalid channel: " + channelName);
}
}

public String getConfigChannelName(String channelName) {
for (String s : botChannels) {
if (channelName.equalsIgnoreCase(s)) {
return s;
}
}
return channelName;
}

public Channel getChannel(String channelName) {
Channel channel = null;
Expand Down Expand Up @@ -1413,7 +1420,7 @@ public void addOp(String channelName, String userMask, CommandSender sender) {
+ ChatColor.RESET + " has been added to the ops list.");
opsList.get(channelName).add(userMask);
}
config.set("channels." + encodeChannel(channelName) + ".ops", opsList.get(channelName));
config.set("channels." + encodeChannel(getConfigChannelName(channelName)) + ".ops", opsList.get(channelName));
saveConfig();
}

Expand All @@ -1432,7 +1439,7 @@ public void removeOp(String channelName, String userMask, CommandSender sender)
sender.sendMessage("User mask " + ChatColor.WHITE + userMask
+ ChatColor.RESET + " is not in the ops list.");
}
config.set("channels." + encodeChannel(channelName) + ".ops", opsList.get(channelName));
config.set("channels." + encodeChannel(getConfigChannelName(channelName)) + ".ops", opsList.get(channelName));
saveConfig();
}

Expand Down Expand Up @@ -2314,8 +2321,10 @@ public String getMotd() {
}

public boolean isValidChannel(String channelName) {
if (botChannels.contains(channelName.toLowerCase())) {
return true;
for (String s : botChannels) {
if (channelName.equalsIgnoreCase(s)) {
return true;
}
}
plugin.logDebug("Channel " + channelName + " is not valid.");
return false;
Expand Down
Expand Up @@ -22,7 +22,7 @@ public BotsAndChannels(PurpleIRC plugin, CommandSender sender,
String botName, String channelName) {
if (plugin.ircBots.containsKey(botName)) {
bot.add(botName);
if (plugin.ircBots.get(botName).botChannels.contains(channelName.toLowerCase())) {
if (plugin.ircBots.get(botName).isValidChannel(channelName)) {
channel.add(channelName);
} else {
sender.sendMessage(plugin.invalidChannelName.replace("%CHANNEL%", channelName));
Expand Down

0 comments on commit a3ff0d9

Please sign in to comment.