Navigation Menu

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

Commit

Permalink
Add new channel option custom-tab-ignore-duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 8, 2015
1 parent 61b25a1 commit 5162a98
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -118,6 +118,7 @@ public final class PurpleBot {
public ArrayList<String> botChannels;
public CaseInsensitiveMap<Collection<String>> channelNicks;
public CaseInsensitiveMap<Collection<String>> tabIgnoreNicks;
public CaseInsensitiveMap<Boolean> tabIgnoreDuplicates;
public CaseInsensitiveMap<Collection<String>> filters;
public CaseInsensitiveMap<String> channelPassword;
public CaseInsensitiveMap<String> channelTopic;
Expand Down Expand Up @@ -210,6 +211,7 @@ public PurpleBot(File file, PurpleIRC plugin) {
this.channelTopic = new CaseInsensitiveMap<>();
this.channelPassword = new CaseInsensitiveMap<>();
this.tabIgnoreNicks = new CaseInsensitiveMap<>();
this.tabIgnoreDuplicates = new CaseInsensitiveMap<>();
this.filters = new CaseInsensitiveMap<>();
this.channelNicks = new CaseInsensitiveMap<>();
this.channelTopicChanserv = new CaseInsensitiveMap<>();
Expand Down Expand Up @@ -812,7 +814,10 @@ private boolean loadConfig() {

channelPrefix.put(channelName, config.getString("channels." + enChannelName + ".prefix", ""));
plugin.logDebug(" ChannelPrefix => " + channelPrefix.get(channelName));


tabIgnoreDuplicates.put(channelName, config.getBoolean("channels." + enChannelName + ".custom-tab-ignore-duplicates", false));
plugin.logDebug(" TabIgnoreDuplicates => " + tabIgnoreDuplicates.get(channelName));

// build channel op list
Collection<String> cOps = new ArrayList<>();
for (String channelOper : config.getStringList("channels." + enChannelName + ".ops")) {
Expand Down Expand Up @@ -888,7 +893,7 @@ private boolean loadConfig() {
}
tabIgnoreNicks.put(channelName, t);
if (tabIgnoreNicks.isEmpty()) {
plugin.logInfo("World list is empty!");
plugin.logInfo("Tab ignore list is empty!");
}

// build valid world list
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java
Expand Up @@ -27,13 +27,7 @@
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.common.base.Charsets;
import com.mojang.authlib.GameProfile;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R2.PlayerInteractManager;
import org.bukkit.entity.Player;
import org.pircbotx.Channel;
import org.pircbotx.User;
Expand Down Expand Up @@ -67,6 +61,9 @@ public void addToTabList(String name, PurpleBot ircBot, Channel channel) {
if (!plugin.customTabList) {
return;
}
if (isPlayerOnline(name, ircBot, channel.getName())) {
return;
}
String channelName = channel.getName();
if (ircBot.tabIgnoreNicks.containsKey(channelName)) {
if (ircBot.tabIgnoreNicks.get(channelName).contains(name)) {
Expand Down Expand Up @@ -131,7 +128,7 @@ private PacketContainer tabPacket(String name, boolean add) {
return NetPacket_183.add(displayName);
} else {
plugin.logDebug("T: Removing: " + name);
return NetPacket_183.rem(displayName);
return NetPacket_183.rem(displayName);
}
} catch (Exception ex) {
plugin.logError("tabPacket: " + ex.getMessage());
Expand Down Expand Up @@ -188,4 +185,17 @@ private String truncateName(String name) {
return name;
}
}

private boolean isPlayerOnline(String name, PurpleBot ircBot, String channel) {
if (ircBot.tabIgnoreDuplicates.containsKey(channel)) {
if (ircBot.tabIgnoreDuplicates.get(channel)) {
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (name.equalsIgnoreCase(player.getName())) {
return true;
}
}
}
}
return false;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/SampleBot.yml
Expand Up @@ -217,6 +217,8 @@ channels:
# ignore list for custom tab list
custom-tab-ignore-list:
- AwesomeBot
# Don't add IRC users to tab list when a matching player is online.
custom-tab-ignore-duplicates: false
# Hide join message when player is invisible (VanishNoPacket)
hide-join-when-vanished: true
# Hide quit message when player is invisible (VanishNoPacket)
Expand Down

0 comments on commit 5162a98

Please sign in to comment.