2014-10-08 06:38:26 +02:00
|
|
|
package com.massivecraft.factions.engine;
|
2013-04-18 14:57:56 +02:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2015-05-16 12:19:36 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2013-04-23 12:54:34 +02:00
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.event.EventException;
|
2013-08-21 09:51:43 +02:00
|
|
|
import org.bukkit.event.EventPriority;
|
2013-04-18 14:57:56 +02:00
|
|
|
import org.bukkit.event.Listener;
|
2013-04-18 15:18:47 +02:00
|
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
2013-04-23 12:54:34 +02:00
|
|
|
import org.bukkit.plugin.EventExecutor;
|
2014-10-08 06:24:37 +02:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2013-04-18 14:57:56 +02:00
|
|
|
|
|
|
|
import com.massivecraft.factions.Factions;
|
2013-04-18 15:18:47 +02:00
|
|
|
import com.massivecraft.factions.chat.ChatFormatter;
|
2013-04-22 09:51:19 +02:00
|
|
|
import com.massivecraft.factions.entity.MConf;
|
2014-10-08 06:24:37 +02:00
|
|
|
import com.massivecraft.massivecore.EngineAbstract;
|
2014-06-04 14:02:23 +02:00
|
|
|
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
|
2015-05-16 12:19:36 +02:00
|
|
|
import com.massivecraft.massivecore.util.MUtil;
|
2013-04-18 14:57:56 +02:00
|
|
|
|
2014-10-08 06:38:26 +02:00
|
|
|
public class EngineChat extends EngineAbstract
|
2013-04-18 14:57:56 +02:00
|
|
|
{
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// INSTANCE & CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2014-10-08 06:38:26 +02:00
|
|
|
private static EngineChat i = new EngineChat();
|
|
|
|
public static EngineChat get() { return i; }
|
2013-04-18 14:57:56 +02:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
2014-10-08 06:24:37 +02:00
|
|
|
// OVERRIDE
|
2013-04-18 14:57:56 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2014-10-08 06:24:37 +02:00
|
|
|
@Override
|
|
|
|
public Plugin getPlugin()
|
2013-04-18 14:57:56 +02:00
|
|
|
{
|
2014-10-08 06:24:37 +02:00
|
|
|
return Factions.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void activate()
|
|
|
|
{
|
|
|
|
super.activate();
|
2013-04-23 12:54:34 +02:00
|
|
|
|
|
|
|
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-21 09:51:43 +02:00
|
|
|
|
2013-08-22 13:37:08 +02:00
|
|
|
if (MConf.get().chatParseTags)
|
2013-08-21 09:51:43 +02:00
|
|
|
{
|
2014-06-04 14:02:23 +02:00
|
|
|
Bukkit.getPluginManager().registerEvent(EventMassiveCorePlayerToRecipientChat.class, this, EventPriority.NORMAL, new ParseRelcolorEventExecutor(), Factions.get(), true);
|
2013-08-21 09:51:43 +02:00
|
|
|
}
|
2013-04-18 14:57:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
2013-04-18 15:18:47 +02:00
|
|
|
// SET FORMAT
|
2013-04-18 14:57:56 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-23 12:54:34 +02:00
|
|
|
private class SetFormatEventExecutor implements EventExecutor
|
2013-04-18 15:18:47 +02:00
|
|
|
{
|
2013-04-23 12:54:34 +02:00
|
|
|
@Override
|
|
|
|
public void execute(Listener listener, Event event) throws EventException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-21 10:02:40 +02:00
|
|
|
if (!(event instanceof AsyncPlayerChatEvent)) return;
|
2013-04-23 12:54:34 +02:00
|
|
|
setFormat((AsyncPlayerChatEvent)event);
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
throw new EventException(t);
|
|
|
|
}
|
|
|
|
}
|
2013-04-18 15:18:47 +02:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:54:34 +02:00
|
|
|
public static void setFormat(AsyncPlayerChatEvent event)
|
2013-08-22 13:37:08 +02:00
|
|
|
{
|
2013-04-23 12:54:34 +02:00
|
|
|
event.setFormat(MConf.get().chatSetFormatTo);
|
2013-04-18 15:18:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// PARSE TAGS
|
|
|
|
// -------------------------------------------- //
|
2013-04-23 12:54:34 +02:00
|
|
|
|
|
|
|
private class ParseTagsEventExecutor implements EventExecutor
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void execute(Listener listener, Event event) throws EventException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-21 10:02:40 +02:00
|
|
|
if (!(event instanceof AsyncPlayerChatEvent)) return;
|
2013-04-23 12:54:34 +02:00
|
|
|
parseTags((AsyncPlayerChatEvent)event);
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
throw new EventException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void parseTags(AsyncPlayerChatEvent event)
|
2013-04-18 15:18:47 +02:00
|
|
|
{
|
2015-05-16 12:19:36 +02:00
|
|
|
Player player = event.getPlayer();
|
|
|
|
if (MUtil.isNpc(player)) return;
|
|
|
|
|
2013-04-18 15:18:47 +02:00
|
|
|
String format = event.getFormat();
|
2015-05-16 12:19:36 +02:00
|
|
|
format = ChatFormatter.format(format, player, null);
|
2013-04-18 15:18:47 +02:00
|
|
|
event.setFormat(format);
|
|
|
|
}
|
|
|
|
|
2013-08-21 09:51:43 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// 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);
|
2013-08-21 09:51:43 +02:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
throw new EventException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 14:02:23 +02:00
|
|
|
public static void parseRelcolor(EventMassiveCorePlayerToRecipientChat event)
|
2013-08-21 09:51:43 +02:00
|
|
|
{
|
2013-08-22 13:37:08 +02:00
|
|
|
String format = event.getFormat();
|
|
|
|
format = ChatFormatter.format(format, event.getSender(), event.getRecipient());
|
|
|
|
event.setFormat(format);
|
2013-08-21 09:51:43 +02:00
|
|
|
}
|
|
|
|
|
2013-04-18 14:57:56 +02:00
|
|
|
}
|