From bc0647e51b0b72e03e50cf9a341c5ec4d60652fe Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sun, 26 Aug 2012 02:12:02 +0200 Subject: [PATCH] Fixing the recipients for HeroChat integration. --- .../integration/herochat/AlliesChannel.java | 7 +++- .../integration/herochat/FactionChannel.java | 7 +++- .../herochat/FactionsChannelAbstract.java | 32 +++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java b/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java index 222af2db..2e615d27 100644 --- a/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java +++ b/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java @@ -1,13 +1,18 @@ package com.massivecraft.factions.integration.herochat; +import java.util.EnumSet; import java.util.Set; import org.bukkit.ChatColor; import com.massivecraft.factions.Conf; +import com.massivecraft.factions.struct.Rel; public class AlliesChannel extends FactionsChannelAbstract -{ +{ + public static final Set targetRelations = EnumSet.of(Rel.MEMBER, Rel.ALLY); + @Override public Set getTargetRelations() { return targetRelations; } + @Override public String getName() { return Conf.herochatAlliesName; } @Override public String getNick() { return Conf.herochatAlliesNick; } diff --git a/src/com/massivecraft/factions/integration/herochat/FactionChannel.java b/src/com/massivecraft/factions/integration/herochat/FactionChannel.java index ff78fb64..62a2d653 100644 --- a/src/com/massivecraft/factions/integration/herochat/FactionChannel.java +++ b/src/com/massivecraft/factions/integration/herochat/FactionChannel.java @@ -1,14 +1,19 @@ package com.massivecraft.factions.integration.herochat; +import java.util.EnumSet; import java.util.HashSet; import java.util.Set; import org.bukkit.ChatColor; import com.massivecraft.factions.Conf; +import com.massivecraft.factions.struct.Rel; public class FactionChannel extends FactionsChannelAbstract -{ +{ + public static final Set targetRelations = EnumSet.of(Rel.MEMBER); + @Override public Set getTargetRelations() { return targetRelations; } + @Override public String getName() { return Conf.herochatFactionName; } @Override public String getNick() { return Conf.herochatFactionNick; } diff --git a/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java b/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java index fbd65d61..0730dd5e 100644 --- a/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java +++ b/src/com/massivecraft/factions/integration/herochat/FactionsChannelAbstract.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.integration.herochat; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -23,6 +22,10 @@ import com.dthielke.herochat.Herochat; import com.dthielke.herochat.MessageFormatSupplier; import com.dthielke.herochat.MessageNotFoundException; import com.dthielke.herochat.util.Messaging; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.Rel; public abstract class FactionsChannelAbstract implements Channel { @@ -35,6 +38,8 @@ public abstract class FactionsChannelAbstract implements Channel } + + @Override public boolean addMember(Chatter chatter, boolean announce, boolean flagUpdate) { @@ -201,6 +206,29 @@ public abstract class FactionsChannelAbstract implements Channel return this.getMutes().contains(name.toLowerCase()); } + + public abstract Set getTargetRelations(); + + public Set getRecipients(Player sender) + { + Set ret = new HashSet(); + + FPlayer fpsender = FPlayers.i.get(sender); + Faction faction = fpsender.getFaction(); + ret.addAll(faction.getOnlinePlayers()); + + for (FPlayer fplayer : FPlayers.i.getOnline()) + { + if(this.getTargetRelations().contains(faction.getRelationTo(fplayer))) + { + ret.add(fplayer.getPlayer()); + } + } + + return ret; + } + + @Override public void processChat(ChannelChatEvent event) { @@ -209,7 +237,7 @@ public abstract class FactionsChannelAbstract implements Channel String format = applyFormat(event.getFormat(), event.getBukkitFormat(), player); Chatter sender = Herochat.getChatterManager().getChatter(player); - Set recipients = new HashSet(Arrays.asList(Bukkit.getOnlinePlayers())); + Set recipients = this.getRecipients(player); trimRecipients(recipients, sender); String msg = String.format(format, player.getDisplayName(), event.getMessage());