2011-10-05 12:13:54 +02:00
package com.massivecraft.factions.integration ;
2012-02-03 02:31:33 +01:00
import org.bukkit.Bukkit ;
2011-10-05 12:13:54 +02:00
import org.bukkit.entity.Player ;
2012-02-03 02:31:33 +01:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
import org.bukkit.event.Listener ;
2011-10-05 12:13:54 +02:00
2012-02-02 14:29:00 +01:00
import com.massivecraft.factions.Conf ;
2011-10-08 22:03:44 +02:00
import com.massivecraft.factions.P ;
2011-10-05 12:13:54 +02:00
import com.earth2me.essentials.chat.EssentialsChat ;
2012-02-03 02:31:33 +01:00
import com.earth2me.essentials.chat.EssentialsLocalChatEvent ;
2011-10-05 12:13:54 +02:00
2012-02-03 02:31:33 +01:00
/ *
* This Essentials integration handler is for newer 3 . x . x versions of Essentials which don ' t have " IEssentialsChatListener "
* /
2011-10-08 22:03:44 +02:00
public class EssentialsFeatures
{
2011-10-05 12:13:54 +02:00
private static EssentialsChat essChat ;
2011-10-08 22:03:44 +02:00
public static void integrateChat ( EssentialsChat instance )
{
2011-10-05 12:13:54 +02:00
essChat = instance ;
2011-10-08 22:03:44 +02:00
try
{
2012-02-03 02:31:33 +01:00
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 ( " { " ) )
2012-02-02 14:29:00 +01:00
{
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. " ) ;
}
2011-10-05 12:13:54 +02:00
}
2011-10-08 22:03:44 +02:00
catch ( NoSuchMethodError ex )
{
2011-10-05 12:13:54 +02:00
essChat = null ;
}
}
2012-02-03 02:31:33 +01:00
private static class LocalChatListener implements Listener
2011-10-08 22:03:44 +02:00
{
2012-02-03 02:31:33 +01:00
@EventHandler ( priority = EventPriority . NORMAL )
public void onPlayerChat ( EssentialsLocalChatEvent event )
2011-10-08 22:03:44 +02:00
{
2012-02-03 02:31:33 +01:00
Player speaker = event . getPlayer ( ) ;
String format = event . getFormat ( ) ;
format = format . replace ( Conf . chatTagReplaceString , P . p . getPlayerFactionTag ( speaker ) ) . replace ( " [FACTION_TITLE] " , P . p . getPlayerTitle ( 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
2011-10-05 12:13:54 +02:00
}
}
}