Adding in chat listener content.

This commit is contained in:
Olof Larsson 2013-04-18 15:18:47 +02:00
parent 170edc5811
commit e9b2b4ee66
5 changed files with 127 additions and 24 deletions

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions;
import java.util.*; import java.util.*;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.event.EventPriority;
import com.massivecraft.mcore.SimpleConfig; import com.massivecraft.mcore.SimpleConfig;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
@ -105,15 +106,19 @@ public class ConfServer extends SimpleConfig
// CHAT // CHAT
// -------------------------------------------- // // -------------------------------------------- //
// Configuration on the Faction tag in chat messages. // We offer a simple standard way to set the format
public static boolean chatSetFormat = false; public static boolean chatSetFormat = false;
public static String chatSetFormatTo = "<{faction_relcolor}§l{faction_roleprefix}§r{faction_relcolor}{faction_tag_pr}"+ChatColor.WHITE.toString()+"%s> %s"; public static EventPriority chatSetFormatAt = EventPriority.LOWEST;
public static String chatSetFormatTo = "<{faction_relcolor}§l{faction_roleprefix}§r{faction_relcolor}{faction_tag_pr}§f%s> %s";
// We offer a simple standard way to parse the chat tags
public static boolean chatParseTags = true; public static boolean chatParseTags = true;
public static EventPriority chatParseTagsAt = EventPriority.LOW;
// TODO: What is this line and can I get rid of it?
public static String chatTagFormat = "%s"+ChatColor.WHITE; // This one is almost deprecated now right? or is it? public static String chatTagFormat = "%s"+ChatColor.WHITE; // This one is almost deprecated now right? or is it?
// Herochat // HeroChat: The Faction Channel
public static String herochatFactionName = "Faction"; public static String herochatFactionName = "Faction";
public static String herochatFactionNick = "F"; public static String herochatFactionNick = "F";
public static String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{faction_roleprefix}&r{color}{faction_title_pr}{sender}{color}] &f{msg}"; public static String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{faction_roleprefix}&r{color}{faction_title_pr}{sender}{color}] &f{msg}";
@ -124,6 +129,7 @@ public class ConfServer extends SimpleConfig
public static boolean herochatFactionMuted = false; public static boolean herochatFactionMuted = false;
public static Set<String> herochatFactionWorlds = new HashSet<String>(); public static Set<String> herochatFactionWorlds = new HashSet<String>();
// HeroChat: The Allies Channel
public static String herochatAlliesName = "Allies"; public static String herochatAlliesName = "Allies";
public static String herochatAlliesNick = "A"; public static String herochatAlliesNick = "A";
public static String herochatAlliesFormat = "{color}[&l{nick}&r&f {faction_relcolor}&l{faction_roleprefix}&r{faction_relcolor}{faction_tag_pr}{sender}{color}] &f{msg}"; public static String herochatAlliesFormat = "{color}[&l{nick}&r&f {faction_relcolor}&l{faction_roleprefix}&r{faction_relcolor}{faction_tag_pr}{sender}{color}] &f{msg}";
@ -133,8 +139,6 @@ public class ConfServer extends SimpleConfig
public static boolean herochatAlliesCrossWorld = true; public static boolean herochatAlliesCrossWorld = true;
public static boolean herochatAlliesMuted = false; public static boolean herochatAlliesMuted = false;
public static Set<String> herochatAlliesWorlds = new HashSet<String>(); public static Set<String> herochatAlliesWorlds = new HashSet<String>();
public static String herochatAllyName = "Allies";
// -------------------------------------------- // // -------------------------------------------- //
// AUTO LEAVE // AUTO LEAVE

View File

@ -13,10 +13,10 @@ import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.factions.listeners.FactionsListenerChat;
import com.massivecraft.factions.listeners.FactionsEntityListener; import com.massivecraft.factions.listeners.TodoFactionsEntityListener;
import com.massivecraft.factions.listeners.FactionsListenerExploit; import com.massivecraft.factions.listeners.FactionsListenerExploit;
import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.factions.listeners.FactionsListenerMain;
import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.listeners.TodoFactionsPlayerListener;
import com.massivecraft.factions.task.AutoLeaveTask; import com.massivecraft.factions.task.AutoLeaveTask;
import com.massivecraft.factions.task.EconLandRewardTask; import com.massivecraft.factions.task.EconLandRewardTask;
@ -43,9 +43,8 @@ public class Factions extends MPlugin
public CmdFactions getOuterCmdFactions() { return this.outerCmdFactions; } public CmdFactions getOuterCmdFactions() { return this.outerCmdFactions; }
// Listeners // Listeners
public FactionsPlayerListener playerListener; public TodoFactionsPlayerListener playerListener;
public FactionsListenerChat chatListener; public TodoFactionsEntityListener entityListener;
public FactionsEntityListener entityListener;
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
@ -84,22 +83,16 @@ public class Factions extends MPlugin
// Register Event Handlers // Register Event Handlers
FactionsListenerMain.get().setup(); FactionsListenerMain.get().setup();
// TODO: Chat goes here FactionsListenerChat.get().setup();
FactionsListenerExploit.get().setup(); FactionsListenerExploit.get().setup();
// TODO: Get rid of these // TODO: Get rid of these
this.playerListener = new FactionsPlayerListener(); this.playerListener = new TodoFactionsPlayerListener();
getServer().getPluginManager().registerEvents(this.playerListener, this); getServer().getPluginManager().registerEvents(this.playerListener, this);
this.chatListener = new FactionsListenerChat(); this.entityListener = new TodoFactionsEntityListener();
getServer().getPluginManager().registerEvents(this.chatListener, this);
this.entityListener = new FactionsEntityListener();
getServer().getPluginManager().registerEvents(this.entityListener, this); getServer().getPluginManager().registerEvents(this.entityListener, this);
postEnable(); postEnable();
} }

View File

@ -1,9 +1,15 @@
package com.massivecraft.factions.listeners; package com.massivecraft.factions.listeners;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.chat.ChatFormatter;
import com.massivecraft.mcore.util.SenderUtil;
public class FactionsListenerChat implements Listener public class FactionsListenerChat implements Listener
{ {
@ -24,9 +30,109 @@ public class FactionsListenerChat implements Listener
} }
// -------------------------------------------- // // -------------------------------------------- //
// LISTENER // SET FORMAT
// -------------------------------------------- // // -------------------------------------------- //
// TODO: public static void setFormat(AsyncPlayerChatEvent event, EventPriority currentPriority)
{
// If we are setting the chat format ...
if (!ConfServer.chatSetFormat) return;
// ... and this is the right priority ...
if (currentPriority != ConfServer.chatSetFormatAt) return;
// ... then set the format.
event.setFormat(ConfServer.chatSetFormatTo);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void setFormatLowest(AsyncPlayerChatEvent event)
{
setFormat(event, EventPriority.LOWEST);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void setFormatLow(AsyncPlayerChatEvent event)
{
setFormat(event, EventPriority.LOW);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void setFormatNormal(AsyncPlayerChatEvent event)
{
setFormat(event, EventPriority.NORMAL);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void setFormatHigh(AsyncPlayerChatEvent event)
{
setFormat(event, EventPriority.HIGH);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void setFormatHighest(AsyncPlayerChatEvent event)
{
setFormat(event, EventPriority.HIGHEST);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setFormatMonitor(AsyncPlayerChatEvent event)
{
setFormat(event, EventPriority.MONITOR);
}
// -------------------------------------------- //
// PARSE TAGS
// -------------------------------------------- //
public static void parseTags(AsyncPlayerChatEvent event, EventPriority currentPriority)
{
// If we are setting the chat format ...
if (!ConfServer.chatParseTags) return;
// ... and this is the right priority ...
if (currentPriority != ConfServer.chatParseTagsAt) return;
// ... then parse tags a.k.a. "format the format".
String format = event.getFormat();
format = ChatFormatter.format(format, SenderUtil.getSenderId(event.getPlayer()), null, null);
event.setFormat(format);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void parseTagsLowest(AsyncPlayerChatEvent event)
{
parseTags(event, EventPriority.LOWEST);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void parseTagsLow(AsyncPlayerChatEvent event)
{
parseTags(event, EventPriority.LOW);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void parseTagsNormal(AsyncPlayerChatEvent event)
{
parseTags(event, EventPriority.NORMAL);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void parseTagsHigh(AsyncPlayerChatEvent event)
{
parseTags(event, EventPriority.HIGH);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void parseTagsHighest(AsyncPlayerChatEvent event)
{
parseTags(event, EventPriority.HIGHEST);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void parseTagsMonitor(AsyncPlayerChatEvent event)
{
parseTags(event, EventPriority.MONITOR);
}
} }

View File

@ -42,7 +42,7 @@ import com.massivecraft.factions.event.PowerLossEvent;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
public class FactionsEntityListener implements Listener public class TodoFactionsEntityListener implements Listener
{ {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)

View File

@ -35,7 +35,7 @@ import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
public class FactionsPlayerListener implements Listener public class TodoFactionsPlayerListener implements Listener
{ {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) public void onPlayerJoin(PlayerJoinEvent event)