Reworked chat completely. Added Herochat integration. New tag-parsing system. Non-monitor-breaking relation colored chat.

This commit is contained in:
Olof Larsson
2012-05-02 04:45:10 +02:00
parent 06d22549e2
commit 1459c9c057
14 changed files with 316 additions and 326 deletions

View File

@ -11,6 +11,7 @@ import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.listeners.FactionsChatListener;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.Teleport;
@ -105,13 +106,6 @@ public class EssentialsFeatures
{
Bukkit.getServer().getPluginManager().registerEvents(new LocalChatListener(), P.p);
P.p.log("Found and will integrate chat with newer "+essChat.getDescription().getFullName());
// curly braces used to be accepted by the format string EssentialsChat but no longer are, so... deal with chatTagReplaceString which might need updating
if (Conf.chatTagReplaceString.contains("{"))
{
Conf.chatTagReplaceString = Conf.chatTagReplaceString.replace("{", "[").replace("}", "]");
P.p.log("NOTE: as of Essentials 2.8+, we've had to switch the default chat replacement tag from \"{FACTION}\" to \"[FACTION]\". This has automatically been updated for you.");
}
}
catch (NoSuchMethodError ex)
{
@ -127,7 +121,9 @@ public class EssentialsFeatures
{
Player speaker = event.getPlayer();
String format = event.getFormat();
format = format.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTag(speaker)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(speaker));
format = FactionsChatListener.parseTags(format, speaker);
event.setFormat(format);
// NOTE: above doesn't do relation coloring. if/when we can get a local recipient list from EssentialsLocalChatEvent, we'll probably
// want to pass it on to FactionsPlayerListener.onPlayerChat(PlayerChatEvent event) rather than duplicating code

View File

@ -3,8 +3,8 @@ package com.massivecraft.factions.integration;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.listeners.FactionsChatListener;
import com.earth2me.essentials.chat.EssentialsChat;
import com.earth2me.essentials.chat.IEssentialsChatListener;
@ -31,17 +31,11 @@ public class EssentialsOldVersionFeatures
}
public String modifyMessage(PlayerChatEvent event, Player target, String message)
{
return message.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTagRelation(event.getPlayer(), target)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(event.getPlayer()));
return FactionsChatListener.parseTags(message, event.getPlayer());
//return message.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTagRelation(event.getPlayer(), target)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(event.getPlayer()));
}
});
P.p.log("Found and will integrate chat with "+essChat.getDescription().getFullName());
// As of Essentials 2.8+, curly braces are not accepted and are instead replaced with square braces, so... deal with it
if (essChat.getDescription().getVersion().startsWith("2.8.") && Conf.chatTagReplaceString.contains("{"))
{
Conf.chatTagReplaceString = Conf.chatTagReplaceString.replace("{", "[").replace("}", "]");
P.p.log("NOTE: as of Essentials 2.8+, we've had to switch the default chat replacement tag from \"{FACTION}\" to \"[FACTION]\". This has automatically been updated for you.");
}
}
catch (NoSuchMethodError ex)
{

View File

@ -0,0 +1,71 @@
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());
}
}
}
}
}

View File

@ -77,13 +77,6 @@ public class PluginCapiListener implements Listener
if (event.getChannel().getId().equals("faction") && myFaction.isNormal())
{
event.getThem().addAll(myFaction.getOnlinePlayers());
// Send to any players who are spying chat... could probably be implemented better than this
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if(fplayer.isSpyingChat() && fplayer.getFaction() != myFaction)
fplayer.sendMessage("[FCspy] "+myFaction.getTag()+": "+event.getMessage());
}
}
else if (event.getChannel().getId().equals("allies"))
{
@ -92,9 +85,6 @@ public class PluginCapiListener implements Listener
FPlayer someFPlayer = FPlayers.i.get(somePlayer);
if (someFPlayer.getRelationTo(fme).isAtLeast(Rel.ALLY))
event.getThem().add(somePlayer);
// Send to any players who are spying chat
else if(someFPlayer.isSpyingChat())
someFPlayer.sendMessage("[ACspy]: " + event.getMessage());
}
}
}