2011-10-05 12:13:54 +02:00
package com.massivecraft.factions.integration ;
import org.bukkit.entity.Player ;
import org.bukkit.event.player.PlayerChatEvent ;
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 ;
import com.earth2me.essentials.chat.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
{
essChat . addEssentialsChatListener ( " Factions " , new IEssentialsChatListener ( )
{
2011-10-05 12:13:54 +02:00
public boolean shouldHandleThisChat ( PlayerChatEvent event )
{
2011-10-08 22:03:44 +02:00
return P . p . shouldLetFactionsHandleThisChat ( event ) ;
2011-10-05 12:13:54 +02:00
}
public String modifyMessage ( PlayerChatEvent event , Player target , String message )
{
2012-02-02 14:29:00 +01:00
return message . replace ( Conf . chatTagReplaceString , P . p . getPlayerFactionTagRelation ( event . getPlayer ( ) , target ) ) . replace ( " [FACTION_TITLE] " , P . p . getPlayerTitle ( event . getPlayer ( ) ) ) ;
2011-10-05 12:13:54 +02:00
}
} ) ;
2011-10-08 22:03:44 +02:00
P . p . log ( " Found and will integrate chat with " + essChat . getDescription ( ) . getFullName ( ) ) ;
2012-02-02 14:29:00 +01:00
// 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. " ) ;
}
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 ;
}
}
2011-10-08 22:03:44 +02:00
public static void unhookChat ( )
{
if ( essChat ! = null )
{
2011-10-05 12:13:54 +02:00
essChat . removeEssentialsChatListener ( " Factions " ) ;
}
}
}