New beta herochat integration and fixing the slow load time. This may require Java7.
This commit is contained in:
@ -1,71 +0,0 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.dthielke.herochat.Channel;
|
||||
import com.dthielke.herochat.ChannelChatEvent;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.struct.Rel;
|
||||
|
||||
public class HerochatFeatures implements Listener
|
||||
{
|
||||
P p;
|
||||
public HerochatFeatures(P p)
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static void setup()
|
||||
{
|
||||
Plugin plug = Bukkit.getServer().getPluginManager().getPlugin("Herochat");
|
||||
if (plug != null && plug.getClass().getName().equals("com.dthielke.herochat.Herochat"))
|
||||
{
|
||||
P.p.log("Integration with Herochat successful");
|
||||
Bukkit.getPluginManager().registerEvents(new HerochatFeatures(P.p), P.p);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onChannelChatEvent(ChannelChatEvent event)
|
||||
{
|
||||
Channel ch = event.getChannel();
|
||||
boolean isFactionChat = ch.getName().equals(Conf.herochatFactionChannelName);
|
||||
boolean isAllyChat = ch.getName().equals(Conf.herochatAllyChannelName);
|
||||
if ( ! isFactionChat && ! isAllyChat) return;
|
||||
|
||||
// Do common setup
|
||||
Player sender = event.getSender().getPlayer();
|
||||
FPlayer fpsender = FPlayers.i.get(sender);
|
||||
event.getBukkitEvent().getRecipients().clear();
|
||||
if ( ! fpsender.hasFaction())
|
||||
{
|
||||
sender.sendMessage(ChatColor.YELLOW.toString()+"You must join a faction to use the "+ch.getColor().toString()+ch.getName()+ChatColor.YELLOW.toString()+"-channel.");
|
||||
event.getBukkitEvent().setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = fpsender.getFaction();
|
||||
event.getBukkitEvent().getRecipients().addAll(faction.getOnlinePlayers());
|
||||
|
||||
if (isAllyChat)
|
||||
{
|
||||
for (FPlayer fplayer : FPlayers.i.getOnline())
|
||||
{
|
||||
if(faction.getRelationTo(fplayer) == Rel.ALLY)
|
||||
{
|
||||
event.getBukkitEvent().getRecipients().add(fplayer.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.massivecraft.factions.integration.herochat;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
|
||||
public class AlliesChannel extends FactionsChannelAbstract
|
||||
{
|
||||
@Override public String getName() { return Conf.herochatAlliesName; }
|
||||
|
||||
@Override public String getNick() { return Conf.herochatAlliesNick; }
|
||||
@Override public void setNick(String nick) { Conf.herochatAlliesNick = nick; }
|
||||
|
||||
@Override public String getFormat() { return Conf.herochatAlliesFormat; }
|
||||
@Override public void setFormat(String format) { Conf.herochatAlliesFormat = format; }
|
||||
|
||||
@Override public ChatColor getColor() { return Conf.herochatAlliesColor; }
|
||||
@Override public void setColor(ChatColor color) { Conf.herochatAlliesColor = color; }
|
||||
|
||||
@Override public int getDistance() { return Conf.herochatAlliesDistance; }
|
||||
@Override public void setDistance(int distance) { Conf.herochatAlliesDistance = distance; }
|
||||
|
||||
@Override public void addWorld(String world) { Conf.herochatAlliesWorlds.add(world); }
|
||||
@Override public Set<String> getWorlds() { return Conf.herochatAlliesWorlds; }
|
||||
@Override public void setWorlds(Set<String> worlds) { Conf.herochatAlliesWorlds = worlds; }
|
||||
|
||||
@Override public boolean isShortcutAllowed() { return Conf.herochatAlliesIsShortcutAllowed; }
|
||||
@Override public void setShortcutAllowed(boolean shortcutAllowed) { Conf.herochatAlliesIsShortcutAllowed = shortcutAllowed; }
|
||||
|
||||
@Override public boolean isCrossWorld() { return Conf.herochatAlliesCrossWorld; }
|
||||
@Override public void setCrossWorld(boolean crossWorld) { Conf.herochatAlliesCrossWorld = crossWorld; }
|
||||
|
||||
@Override public boolean isMuted() { return Conf.herochatAlliesMuted; }
|
||||
@Override public void setMuted(boolean value) { Conf.herochatAlliesMuted = value; }
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.massivecraft.factions.integration.herochat;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
|
||||
public class FactionChannel extends FactionsChannelAbstract
|
||||
{
|
||||
@Override public String getName() { return Conf.herochatFactionName; }
|
||||
|
||||
@Override public String getNick() { return Conf.herochatFactionNick; }
|
||||
@Override public void setNick(String nick) { Conf.herochatFactionNick = nick; }
|
||||
|
||||
@Override public String getFormat() { return Conf.herochatFactionFormat; }
|
||||
@Override public void setFormat(String format) { Conf.herochatFactionFormat = format; }
|
||||
|
||||
@Override public ChatColor getColor() { return Conf.herochatFactionColor; }
|
||||
@Override public void setColor(ChatColor color) { Conf.herochatFactionColor = color; }
|
||||
|
||||
@Override public int getDistance() { return Conf.herochatFactionDistance; }
|
||||
@Override public void setDistance(int distance) { Conf.herochatFactionDistance = distance; }
|
||||
|
||||
@Override public void addWorld(String world) { Conf.herochatFactionWorlds.add(world); }
|
||||
@Override public Set<String> getWorlds() { return new HashSet<String>(Conf.herochatFactionWorlds); }
|
||||
@Override public void setWorlds(Set<String> worlds) { Conf.herochatFactionWorlds = worlds; }
|
||||
|
||||
@Override public boolean isShortcutAllowed() { return Conf.herochatFactionIsShortcutAllowed; }
|
||||
@Override public void setShortcutAllowed(boolean shortcutAllowed) { Conf.herochatFactionIsShortcutAllowed = shortcutAllowed; }
|
||||
|
||||
@Override public boolean isCrossWorld() { return Conf.herochatFactionCrossWorld; }
|
||||
@Override public void setCrossWorld(boolean crossWorld) { Conf.herochatFactionCrossWorld = crossWorld; }
|
||||
|
||||
@Override public boolean isMuted() { return Conf.herochatFactionMuted; }
|
||||
@Override public void setMuted(boolean value) { Conf.herochatFactionMuted = value; }
|
||||
}
|
@ -0,0 +1,390 @@
|
||||
package com.massivecraft.factions.integration.herochat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.dthielke.herochat.Channel;
|
||||
import com.dthielke.herochat.ChannelChatEvent;
|
||||
import com.dthielke.herochat.ChannelStorage;
|
||||
import com.dthielke.herochat.Chatter;
|
||||
import com.dthielke.herochat.Herochat;
|
||||
import com.dthielke.herochat.MessageFormatSupplier;
|
||||
import com.dthielke.herochat.MessageNotFoundException;
|
||||
import com.dthielke.herochat.util.Messaging;
|
||||
|
||||
public abstract class FactionsChannelAbstract implements Channel
|
||||
{
|
||||
private static final Pattern msgPattern = Pattern.compile("(.*)<(.*)%1\\$s(.*)> %2\\$s");
|
||||
private final ChannelStorage storage = Herochat.getChannelManager().getStorage();
|
||||
private final MessageFormatSupplier formatSupplier = Herochat.getChannelManager();
|
||||
|
||||
public FactionsChannelAbstract()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMember(Chatter chatter, boolean announce, boolean flagUpdate)
|
||||
{
|
||||
if (chatter.hasChannel(this)) return false;
|
||||
chatter.addChannel(this, announce, flagUpdate);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean kickMember(Chatter chatter, boolean announce)
|
||||
{
|
||||
if (!chatter.hasChannel(this)) return false;
|
||||
this.removeMember(chatter, false, true);
|
||||
|
||||
if (announce)
|
||||
{
|
||||
try
|
||||
{
|
||||
announce(Herochat.getMessage("channel_kick").replace("$1", chatter.getPlayer().getDisplayName()));
|
||||
}
|
||||
catch (MessageNotFoundException e)
|
||||
{
|
||||
Herochat.severe("Messages.properties is missing: channel_kick");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeMember(Chatter chatter, boolean announce, boolean flagUpdate)
|
||||
{
|
||||
if (!chatter.hasChannel(this)) return false;
|
||||
chatter.removeChannel(this, announce, flagUpdate);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Chatter> getMembers()
|
||||
{
|
||||
Set<Chatter> ret = new HashSet<Chatter>();
|
||||
for (Chatter chatter : Herochat.getChatterManager().getChatters())
|
||||
{
|
||||
if(chatter.hasChannel(this)) ret.add(chatter);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void announce(String message)
|
||||
{
|
||||
message = applyFormat(this.formatSupplier.getAnnounceFormat(), "").replace("%2$s", message);
|
||||
for (Chatter member : this.getMembers())
|
||||
{
|
||||
member.getPlayer().sendMessage(message);
|
||||
}
|
||||
Herochat.logChat(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String applyFormat(String format, String originalFormat)
|
||||
{
|
||||
format = format.replace("{default}", this.formatSupplier.getStandardFormat());
|
||||
format = format.replace("{name}", this.getName());
|
||||
format = format.replace("{nick}", this.getNick());
|
||||
format = format.replace("{color}", this.getColor().toString());
|
||||
format = format.replace("{msg}", "%2$s");
|
||||
|
||||
Matcher matcher = msgPattern.matcher(originalFormat);
|
||||
if ((matcher.matches()) && (matcher.groupCount() == 3))
|
||||
{
|
||||
format = format.replace("{sender}", matcher.group(1) + matcher.group(2) + "%1$s" + matcher.group(3));
|
||||
}
|
||||
else
|
||||
{
|
||||
format = format.replace("{sender}", "%1$s");
|
||||
}
|
||||
|
||||
format = format.replaceAll("(?i)&([a-fklmno0-9])", "§$1");
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String applyFormat(String format, String originalFormat, Player sender)
|
||||
{
|
||||
format = applyFormat(format, originalFormat);
|
||||
format = format.replace("{plainsender}", sender.getName());
|
||||
format = format.replace("{world}", sender.getWorld().getName());
|
||||
Chat chat = Herochat.getChatService();
|
||||
if (chat != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
String prefix = chat.getPlayerPrefix(sender);
|
||||
String suffix = chat.getPlayerSuffix(sender);
|
||||
String group = chat.getPrimaryGroup(sender);
|
||||
String groupPrefix = group == null ? "" : chat.getGroupPrefix(sender.getWorld(), group);
|
||||
String groupSuffix = group == null ? "" : chat.getGroupSuffix(sender.getWorld(), group);
|
||||
format = format.replace("{prefix}", prefix == null ? "" : prefix.replace("%", "%%"));
|
||||
format = format.replace("{suffix}", suffix == null ? "" : suffix.replace("%", "%%"));
|
||||
format = format.replace("{group}", group == null ? "" : group.replace("%", "%%"));
|
||||
format = format.replace("{groupprefix}", groupPrefix == null ? "" : groupPrefix.replace("%", "%%"));
|
||||
format = format.replace("{groupsuffix}", groupSuffix == null ? "" : groupSuffix.replace("%", "%%"));
|
||||
}
|
||||
catch (UnsupportedOperationException ignored) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
format = format.replace("{prefix}", "");
|
||||
format = format.replace("{suffix}", "");
|
||||
format = format.replace("{group}", "");
|
||||
format = format.replace("{groupprefix}", "");
|
||||
format = format.replace("{groupsuffix}", "");
|
||||
}
|
||||
format = format.replaceAll("(?i)&([a-fklmno0-9])", "§$1");
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emote(Chatter sender, String message)
|
||||
{
|
||||
message = applyFormat(this.formatSupplier.getEmoteFormat(), "").replace("%2$s", message);
|
||||
Set<Player> recipients = new HashSet<Player>();
|
||||
for (Chatter member : this.getMembers())
|
||||
{
|
||||
recipients.add(member.getPlayer());
|
||||
}
|
||||
|
||||
trimRecipients(recipients, sender);
|
||||
|
||||
final Player player = sender.getPlayer();
|
||||
|
||||
if (!isMessageHeard(recipients, sender))
|
||||
{
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Herochat.getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Messaging.send(player, Herochat.getMessage("channel_alone"));
|
||||
}
|
||||
catch (MessageNotFoundException e)
|
||||
{
|
||||
Herochat.severe("Messages.properties is missing: channel_alone");
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player p : recipients)
|
||||
{
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMuted(String name)
|
||||
{
|
||||
if (this.isMuted()) return true;
|
||||
return this.getMutes().contains(name.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processChat(ChannelChatEvent event)
|
||||
{
|
||||
final Player player = event.getSender().getPlayer();
|
||||
|
||||
String format = applyFormat(event.getFormat(), event.getBukkitFormat(), player);
|
||||
|
||||
Chatter sender = Herochat.getChatterManager().getChatter(player);
|
||||
Set<Player> recipients = new HashSet<Player>(Arrays.asList(Bukkit.getOnlinePlayers()));
|
||||
|
||||
trimRecipients(recipients, sender);
|
||||
String msg = String.format(format, player.getDisplayName(), event.getMessage());
|
||||
if (!isMessageHeard(recipients, sender))
|
||||
{
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Herochat.getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Messaging.send(player, Herochat.getMessage("channel_alone"));
|
||||
}
|
||||
catch (MessageNotFoundException e)
|
||||
{
|
||||
Herochat.severe("Messages.properties is missing: channel_alone");
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
for (Player recipient : recipients)
|
||||
{
|
||||
recipient.sendMessage(msg);
|
||||
}
|
||||
|
||||
Herochat.logChat(msg);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void processChat(ChannelChatEvent event)
|
||||
{
|
||||
final Player player = event.getSender().getPlayer();
|
||||
|
||||
String format = applyFormat(event.getFormat(), event.getBukkitFormat(), player);
|
||||
|
||||
Chatter sender = Herochat.getChatterManager().getChatter(player);
|
||||
Set<Player> recipients = new HashSet<Player>(Arrays.asList(Bukkit.getOnlinePlayers()));
|
||||
|
||||
trimRecipients(recipients, sender);
|
||||
if (!isMessageHeard(recipients, sender))
|
||||
{
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Herochat.getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Messaging.send(player, Herochat.getMessage("channel_alone"));
|
||||
}
|
||||
catch (MessageNotFoundException e)
|
||||
{
|
||||
Herochat.severe("Messages.properties is missing: channel_alone");
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
FPlayer fplayer = FPlayers.i.get(player);
|
||||
|
||||
String formatWithoutColor = FactionsChatListener.parseTags(format, player, fplayer);
|
||||
|
||||
//String msg = String.format(format, player.getDisplayName(), event.getMessage());
|
||||
|
||||
|
||||
for (Player recipient : recipients)
|
||||
{
|
||||
String finalFormat;
|
||||
if ( ! Conf.chatParseTags || Conf.chatTagHandledByAnotherPlugin)
|
||||
{
|
||||
finalFormat = format;
|
||||
}
|
||||
else if (! Conf.chatParseTagsColored)
|
||||
{
|
||||
finalFormat = formatWithoutColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
FPlayer frecipient = FPlayers.i.get(recipient);
|
||||
finalFormat = FactionsChatListener.parseTags(format, player, fplayer, recipient, frecipient);
|
||||
}
|
||||
String msg = String.format(finalFormat, player.getDisplayName(), event.getMessage());
|
||||
recipient.sendMessage(msg);
|
||||
}
|
||||
|
||||
Herochat.logChat(String.format(formatWithoutColor, player.getDisplayName(), event.getMessage()));
|
||||
}*/
|
||||
|
||||
public boolean isMessageHeard(Set<Player> recipients, Chatter sender)
|
||||
{
|
||||
if (!isLocal()) return true;
|
||||
|
||||
Player senderPlayer = sender.getPlayer();
|
||||
for (Player recipient : recipients)
|
||||
{
|
||||
if (recipient.equals(senderPlayer)) continue;
|
||||
if (recipient.hasPermission("herochat.admin.stealth")) continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void trimRecipients(Set<Player> recipients, Chatter sender)
|
||||
{
|
||||
World world = sender.getPlayer().getWorld();
|
||||
|
||||
Set<Chatter> members = this.getMembers();
|
||||
Iterator<Player> iterator = recipients.iterator();
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Chatter recipient = Herochat.getChatterManager().getChatter(iterator.next());
|
||||
if (recipient == null) continue;
|
||||
World recipientWorld = recipient.getPlayer().getWorld();
|
||||
|
||||
if (!members.contains(recipient))
|
||||
iterator.remove();
|
||||
else if ((isLocal()) && (!sender.isInRange(recipient, this.getDistance())))
|
||||
iterator.remove();
|
||||
else if (!hasWorld(recipientWorld))
|
||||
iterator.remove();
|
||||
else if (recipient.isIgnoring(sender))
|
||||
iterator.remove();
|
||||
else if ((!this.isCrossWorld()) && (!world.equals(recipientWorld)))
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (other == this) return true;
|
||||
if (other == null) return false;
|
||||
if (!(other instanceof Channel)) return false;
|
||||
Channel channel = (Channel)other;
|
||||
return (this.getName().equalsIgnoreCase(channel.getName())) || (this.getName().equalsIgnoreCase(channel.getNick()));
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (this.getName() == null ? 0 : this.getName().toLowerCase().hashCode());
|
||||
result = prime * result + (this.getNick() == null ? 0 : this.getNick().toLowerCase().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override public boolean isTransient() { return false; }
|
||||
@Override public String getPassword() { return ""; }
|
||||
@Override public void setPassword(String password) {}
|
||||
@Override public boolean isVerbose() { return false; }
|
||||
@Override public void setVerbose(boolean verbose) {}
|
||||
@Override public boolean isHidden() { return false; }
|
||||
@Override public boolean isLocal() { return this.getDistance() != 0; }
|
||||
@Override public void attachStorage(ChannelStorage storage) { }
|
||||
@Override public boolean banMember(Chatter chatter, boolean announce) { return false; }
|
||||
@Override public Set<String> getBans() { return Collections.emptySet(); }
|
||||
@Override public Set<String> getModerators() { return Collections.emptySet(); }
|
||||
@Override public Set<String> getMutes() { return Collections.emptySet(); }
|
||||
@Override public ChannelStorage getStorage() { return this.storage; }
|
||||
@Override public boolean hasWorld(String world) { return (this.getWorlds().isEmpty()) || (this.getWorlds().contains(world)); }
|
||||
@Override public boolean hasWorld(World world) { return this.hasWorld(world.getName()); }
|
||||
@Override public boolean isBanned(String name) { return this.getBans().contains(name.toLowerCase()); }
|
||||
@Override public boolean isMember(Chatter chatter) { return this.getMembers().contains(chatter); }
|
||||
@Override public boolean isModerator(String name) { return this.getModerators().contains(name.toLowerCase()); }
|
||||
|
||||
@Override public void onFocusGain(Chatter chatter) {}
|
||||
@Override public void onFocusLoss(Chatter chatter) {}
|
||||
|
||||
|
||||
|
||||
@Override public void removeWorld(String world) { this.getWorlds().remove(world); }
|
||||
@Override public void setBanned(String name, boolean banned) {}
|
||||
@Override public void setBans(Set<String> bans) {}
|
||||
@Override public void setModerator(String name, boolean moderator) {}
|
||||
@Override public void setModerators(Set<String> moderators) { }
|
||||
@Override public void setMuted(String name, boolean muted) {}
|
||||
@Override public void setMutes(Set<String> mutes) {}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.massivecraft.factions.integration.herochat;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.dthielke.herochat.ChannelChatEvent;
|
||||
import com.dthielke.herochat.Herochat;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.listeners.FactionsChatListener;
|
||||
|
||||
public class HerochatFeatures implements Listener
|
||||
{
|
||||
P p;
|
||||
public HerochatFeatures(P p)
|
||||
{
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static void setup()
|
||||
{
|
||||
Plugin plug = Bukkit.getServer().getPluginManager().getPlugin("Herochat");
|
||||
if (plug == null) return;
|
||||
if (!plug.getClass().getName().equals("com.dthielke.herochat.Herochat")) return;
|
||||
Bukkit.getPluginManager().registerEvents(new HerochatFeatures(P.p), P.p);
|
||||
Herochat.getChannelManager().addChannel(new FactionChannel());
|
||||
Herochat.getChannelManager().addChannel(new AlliesChannel());
|
||||
P.p.log("Integration with Herochat successful");
|
||||
}
|
||||
|
||||
/**
|
||||
* Due to limitations in the new version of Herochat we can not offer relation colored tags.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onChannelChatEvent(ChannelChatEvent event)
|
||||
{
|
||||
// Should we even parse?
|
||||
if ( ! Conf.chatParseTags) return;
|
||||
if (Conf.chatTagHandledByAnotherPlugin) return;
|
||||
|
||||
Player from = event.getSender().getPlayer();
|
||||
FPlayer fpfrom = FPlayers.i.get(from);
|
||||
String format = event.getFormat();
|
||||
|
||||
format = format.replaceAll("&r", "§r");
|
||||
|
||||
String formatWithoutColor = FactionsChatListener.parseTags(format, from, fpfrom);
|
||||
|
||||
event.setFormat(formatWithoutColor);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public static Chatter getChatter(Player player)
|
||||
{
|
||||
ChatterManager chatterManager = Herochat.getChatterManager();
|
||||
if (!chatterManager.hasChatter(player)) chatterManager.addChatter(player);
|
||||
Chatter ret = chatterManager.getChatter(player);
|
||||
if (ret == null) throw new RuntimeException("Chatter (" + player.getName() + ") not found.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
Chatter sender = getChatter(player);
|
||||
Channel ch = sender.getActiveChannel();
|
||||
if (ch == null) return;
|
||||
|
||||
boolean isFactionChat = ch.getName().equals(Conf.herochatFactionChannelName);
|
||||
boolean isAllyChat = ch.getName().equals(Conf.herochatAllyChannelName);
|
||||
if ( ! isFactionChat && ! isAllyChat) return;
|
||||
|
||||
// Do common setup
|
||||
Player sender = event.getSender().getPlayer();
|
||||
FPlayer fpsender = FPlayers.i.get(sender);
|
||||
|
||||
event.getRecipients().clear();
|
||||
|
||||
if ( ! fpsender.hasFaction())
|
||||
{
|
||||
sender.sendMessage(ChatColor.YELLOW.toString()+"You must join a faction to use the "+ch.getColor().toString()+ch.getName()+ChatColor.YELLOW.toString()+"-channel.");
|
||||
event.getBukkitEvent().setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = fpsender.getFaction();
|
||||
event.getBukkitEvent().getRecipients().addAll(faction.getOnlinePlayers());
|
||||
|
||||
if (isAllyChat)
|
||||
{
|
||||
for (FPlayer fplayer : FPlayers.i.getOnline())
|
||||
{
|
||||
if(faction.getRelationTo(fplayer) == Rel.ALLY)
|
||||
{
|
||||
event.getBukkitEvent().getRecipients().add(fplayer.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user