mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-26 20:26:23 +01:00
New beta herochat integration and fixing the slow load time. This may require Java7.
This commit is contained in:
parent
b0823dc5a8
commit
48c5131ea4
BIN
lib/Herochat.jar
BIN
lib/Herochat.jar
Binary file not shown.
@ -68,14 +68,33 @@ public class Conf
|
||||
public static boolean chatSetFormat = false;
|
||||
public static String chatSetFormatTo = "<{faction_relcolor}§l{faction_roleprefix}§r{faction_relcolor}{faction_tag_pr}"+ChatColor.WHITE.toString()+"%s> %s";
|
||||
public static boolean chatParseTags = true;
|
||||
public static boolean chatParseTagsColored = true;
|
||||
public static boolean chatParseTagsColored = false;
|
||||
public static Map<String, String> chatSingleFormats = new HashMap<String, String>();
|
||||
public static transient boolean chatTagHandledByAnotherPlugin = false; // Why do we need this? (Olof asks)
|
||||
public static String chatTagFormat = "%s"+ChatColor.WHITE; // This one is almost deprecated now right? or is it?
|
||||
|
||||
// Herochat
|
||||
public static String herochatFactionChannelName = "Faction";
|
||||
public static String herochatAllyChannelName = "Allies";
|
||||
public static String herochatFactionName = "Faction";
|
||||
public static String herochatFactionNick = "F";
|
||||
public static String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{faction_roleprefix}&r{color}{faction_title_pr}{sender}{color}] &f{msg}";
|
||||
public static ChatColor herochatFactionColor = ChatColor.GREEN;
|
||||
public static int herochatFactionDistance = 0;
|
||||
public static boolean herochatFactionIsShortcutAllowed = false;
|
||||
public static boolean herochatFactionCrossWorld = true;
|
||||
public static boolean herochatFactionMuted = false;
|
||||
public static Set<String> herochatFactionWorlds = new HashSet<String>();
|
||||
|
||||
public static String herochatAlliesName = "Allies";
|
||||
public static String herochatAlliesNick = "A";
|
||||
public static String herochatAlliesFormat = "{color}[&l{nick}&r&f {faction_relcolor}&l{faction_roleprefix}&r{faction_relcolor}{faction_tag_pr}{sender}{color}] &f{msg}";
|
||||
public static ChatColor herochatAlliesColor = ChatColor.DARK_PURPLE;
|
||||
public static int herochatAlliesDistance = 0;
|
||||
public static boolean herochatAlliesIsShortcutAllowed = false;
|
||||
public static boolean herochatAlliesCrossWorld = true;
|
||||
public static boolean herochatAlliesMuted = false;
|
||||
public static Set<String> herochatAlliesWorlds = new HashSet<String>();
|
||||
|
||||
public static String herochatAllyName = "Allies";
|
||||
|
||||
public static double autoLeaveAfterDaysOfInactivity = 10.0;
|
||||
public static double autoLeaveRoutineRunsEveryXMinutes = 5.0;
|
||||
|
@ -19,9 +19,9 @@ import com.massivecraft.factions.adapters.LocationTypeAdapter;
|
||||
import com.massivecraft.factions.adapters.RelTypeAdapter;
|
||||
import com.massivecraft.factions.cmd.*;
|
||||
import com.massivecraft.factions.integration.capi.CapiFeatures;
|
||||
import com.massivecraft.factions.integration.herochat.HerochatFeatures;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.EssentialsFeatures;
|
||||
import com.massivecraft.factions.integration.HerochatFeatures;
|
||||
import com.massivecraft.factions.integration.LWCFeatures;
|
||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||
import com.massivecraft.factions.integration.Worldguard;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
@ -80,7 +80,7 @@ public class FactionsChatListener implements Listener
|
||||
* The side effect is that other plugins at EventPriority.HIGHEST may experience the event as cancelled.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled=true)
|
||||
public synchronized void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
// Should we even parse?
|
||||
if ( ! Conf.chatParseTags) return;
|
||||
@ -126,7 +126,7 @@ public class FactionsChatListener implements Listener
|
||||
* This is some nasty woodo - I know :/
|
||||
* I should make a pull request to Bukkit and CraftBukkit to support this feature natively
|
||||
*/
|
||||
public static synchronized void callEventAtMonitorOnly(Event event)
|
||||
public static void callEventAtMonitorOnly(Event event)
|
||||
{
|
||||
synchronized(Bukkit.getPluginManager())
|
||||
{
|
||||
|
@ -4,30 +4,47 @@ import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class DiscUtil
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final static String UTF8 = "UTF-8";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BYTE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static byte[] readBytes(File file) throws IOException
|
||||
{
|
||||
return Files.readAllBytes(file.toPath());
|
||||
}
|
||||
|
||||
public static void writeBytes(File file, byte[] bytes) throws IOException
|
||||
{
|
||||
Files.write(file.toPath(), bytes);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STRING
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static void write(File file, String content) throws IOException
|
||||
{
|
||||
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF8"));
|
||||
out.write(content);
|
||||
out.close();
|
||||
writeBytes(file, utf8(content));
|
||||
}
|
||||
|
||||
public static String read(File file) throws IOException
|
||||
{
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||
String ret = new String(new byte[0], "UTF-8");
|
||||
|
||||
String line;
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
ret += line;
|
||||
return utf8(readBytes(file));
|
||||
}
|
||||
|
||||
in.close();
|
||||
return ret;
|
||||
}
|
||||
// -------------------------------------------- //
|
||||
// CATCH
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean writeCatch(File file, String content)
|
||||
{
|
||||
@ -54,6 +71,10 @@ public class DiscUtil
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DOWNLOAD
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean downloadUrl(String urlstring, File file)
|
||||
{
|
||||
try
|
||||
@ -75,4 +96,53 @@ public class DiscUtil
|
||||
{
|
||||
return downloadUrl(urlstring, new File(filename));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FILE DELETION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean deleteRecursive(File path) throws FileNotFoundException
|
||||
{
|
||||
if ( ! path.exists()) throw new FileNotFoundException(path.getAbsolutePath());
|
||||
boolean ret = true;
|
||||
if (path.isDirectory())
|
||||
{
|
||||
for (File f : path.listFiles())
|
||||
{
|
||||
ret = ret && deleteRecursive(f);
|
||||
}
|
||||
}
|
||||
return ret && path.delete();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTF8 ENCODE AND DECODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static byte[] utf8(String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
return string.getBytes(UTF8);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String utf8(byte[] bytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new String(bytes, UTF8);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user