Factions/src/com/massivecraft/factions/engine/EngineChat.java

141 lines
3.7 KiB
Java
Raw Normal View History

package com.massivecraft.factions.engine;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
2013-04-18 15:18:47 +02:00
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.Factions;
2013-04-18 15:18:47 +02:00
import com.massivecraft.factions.chat.ChatFormatter;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.EngineAbstract;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
public class EngineChat extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineChat i = new EngineChat();
public static EngineChat get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return Factions.get();
}
@Override
public void activate()
{
super.activate();
if (MConf.get().chatSetFormat)
{
Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatSetFormatAt, new SetFormatEventExecutor(), Factions.get(), true);
}
if (MConf.get().chatParseTags)
{
Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatParseTagsAt, new ParseTagsEventExecutor(), Factions.get(), true);
}
2013-08-22 13:37:08 +02:00
if (MConf.get().chatParseTags)
{
2014-06-04 14:02:23 +02:00
Bukkit.getPluginManager().registerEvent(EventMassiveCorePlayerToRecipientChat.class, this, EventPriority.NORMAL, new ParseRelcolorEventExecutor(), Factions.get(), true);
}
}
// -------------------------------------------- //
2013-04-18 15:18:47 +02:00
// SET FORMAT
// -------------------------------------------- //
private class SetFormatEventExecutor implements EventExecutor
2013-04-18 15:18:47 +02:00
{
@Override
public void execute(Listener listener, Event event) throws EventException
{
try
{
if (!(event instanceof AsyncPlayerChatEvent)) return;
setFormat((AsyncPlayerChatEvent)event);
}
catch (Throwable t)
{
throw new EventException(t);
}
}
2013-04-18 15:18:47 +02:00
}
public static void setFormat(AsyncPlayerChatEvent event)
2013-08-22 13:37:08 +02:00
{
event.setFormat(MConf.get().chatSetFormatTo);
2013-04-18 15:18:47 +02:00
}
// -------------------------------------------- //
// PARSE TAGS
// -------------------------------------------- //
private class ParseTagsEventExecutor implements EventExecutor
{
@Override
public void execute(Listener listener, Event event) throws EventException
{
try
{
if (!(event instanceof AsyncPlayerChatEvent)) return;
parseTags((AsyncPlayerChatEvent)event);
}
catch (Throwable t)
{
throw new EventException(t);
}
}
}
public static void parseTags(AsyncPlayerChatEvent event)
2013-04-18 15:18:47 +02:00
{
String format = event.getFormat();
2013-04-25 13:25:15 +02:00
format = ChatFormatter.format(format, event.getPlayer(), null);
2013-04-18 15:18:47 +02:00
event.setFormat(format);
}
// -------------------------------------------- //
// PARSE RELCOLOR
// -------------------------------------------- //
private class ParseRelcolorEventExecutor implements EventExecutor
{
@Override
public void execute(Listener listener, Event event) throws EventException
{
try
{
2014-06-04 14:02:23 +02:00
if (!(event instanceof EventMassiveCorePlayerToRecipientChat)) return;
parseRelcolor((EventMassiveCorePlayerToRecipientChat)event);
}
catch (Throwable t)
{
throw new EventException(t);
}
}
}
2014-06-04 14:02:23 +02:00
public static void parseRelcolor(EventMassiveCorePlayerToRecipientChat event)
{
2013-08-22 13:37:08 +02:00
String format = event.getFormat();
format = ChatFormatter.format(format, event.getSender(), event.getRecipient());
event.setFormat(format);
}
}