Fixing the recipients for HeroChat integration.

This commit is contained in:
Olof Larsson 2012-08-26 02:12:02 +02:00
parent 48c5131ea4
commit bc0647e51b
3 changed files with 42 additions and 4 deletions

View File

@ -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<Rel> targetRelations = EnumSet.of(Rel.MEMBER, Rel.ALLY);
@Override public Set<Rel> getTargetRelations() { return targetRelations; }
@Override public String getName() { return Conf.herochatAlliesName; }
@Override public String getNick() { return Conf.herochatAlliesNick; }

View File

@ -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<Rel> targetRelations = EnumSet.of(Rel.MEMBER);
@Override public Set<Rel> getTargetRelations() { return targetRelations; }
@Override public String getName() { return Conf.herochatFactionName; }
@Override public String getNick() { return Conf.herochatFactionNick; }

View File

@ -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<Rel> getTargetRelations();
public Set<Player> getRecipients(Player sender)
{
Set<Player> ret = new HashSet<Player>();
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<Player> recipients = new HashSet<Player>(Arrays.asList(Bukkit.getOnlinePlayers()));
Set<Player> recipients = this.getRecipients(player);
trimRecipients(recipients, sender);
String msg = String.format(format, player.getDisplayName(), event.getMessage());