From 1ee9f2bba3bcbc6a4cfb38e8259b0e9eb0f90551 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 18 Apr 2013 15:40:58 +0200 Subject: [PATCH] Modernizing the Herochat integration, it may still be outdated with newer Herochat versions though. --- src/com/massivecraft/factions/ConfServer.java | 2 +- src/com/massivecraft/factions/Factions.java | 5 ++- .../herochat/HerochatFeatures.java | 39 +++++++++++++------ .../herochat/HerochatListener.java | 36 ++++++++++++----- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index fc37ccbd..164e8899 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -109,7 +109,7 @@ public class ConfServer extends SimpleConfig // We offer a simple standard way to set the format public static boolean chatSetFormat = false; public static EventPriority chatSetFormatAt = EventPriority.LOWEST; - public static String chatSetFormatTo = "<§l{factions_roleprefix}§r{factions_relcolor}{factions_tag|rp}§f%1$s> %2$s"; + public static String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_tag|rp}§f%1$s> %2$s"; // We offer a simple standard way to parse the chat tags public static boolean chatParseTags = true; diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 2ac3ed3a..e30132e5 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -19,11 +19,11 @@ import com.massivecraft.factions.chat.tag.ChatTagTag; import com.massivecraft.factions.chat.tag.ChatTagTagforce; import com.massivecraft.factions.chat.tag.ChatTagTitle; import com.massivecraft.factions.cmd.*; -import com.massivecraft.factions.integration.herochat.HerochatFeatures; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.Worldguard; +import com.massivecraft.factions.integration.herochat.HerochatFeatures; import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.factions.listeners.TodoFactionsEntityListener; import com.massivecraft.factions.listeners.FactionsListenerExploit; @@ -112,9 +112,10 @@ public class Factions extends MPlugin ChatTagTitle.get().register(); // Integrate + this.integrate(HerochatFeatures.get()); + SpoutFeatures.setup(); Econ.setup(); - HerochatFeatures.setup(); LWCFeatures.setup(); if (ConfServer.worldGuardChecking) diff --git a/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java b/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java index 9f9b6b80..e0b2b0af 100644 --- a/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java +++ b/src/com/massivecraft/factions/integration/herochat/HerochatFeatures.java @@ -1,19 +1,34 @@ package com.massivecraft.factions.integration.herochat; -import org.bukkit.Bukkit; -import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; +import com.dthielke.herochat.Herochat; +import com.massivecraft.mcore.integration.IntegrationFeaturesAbstract; -import com.massivecraft.factions.Factions; - -public class HerochatFeatures implements Listener +public class HerochatFeatures extends IntegrationFeaturesAbstract { - public static void setup() + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static HerochatFeatures i = new HerochatFeatures(); + public static HerochatFeatures get() { return i; } + private HerochatFeatures() { super("Herochat"); } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void activate() { - Plugin plug = Bukkit.getServer().getPluginManager().getPlugin("Herochat"); - if (plug == null) return; - if (!plug.getClass().getName().equals("com.dthielke.herochat.Herochat")) return; - Bukkit.getPluginManager().registerEvents(new HerochatListener(Factions.get()), Factions.get()); - Factions.get().log("Integration with Herochat successful"); + Herochat.getChannelManager().addChannel(new FactionChannel()); + Herochat.getChannelManager().addChannel(new AlliesChannel()); + HerochatListener.get().activate(); } + + @Override + public void deactivate() + { + HerochatListener.get().deactivate(); + } + } diff --git a/src/com/massivecraft/factions/integration/herochat/HerochatListener.java b/src/com/massivecraft/factions/integration/herochat/HerochatListener.java index eaf39573..601c91f0 100644 --- a/src/com/massivecraft/factions/integration/herochat/HerochatListener.java +++ b/src/com/massivecraft/factions/integration/herochat/HerochatListener.java @@ -1,28 +1,45 @@ package com.massivecraft.factions.integration.herochat; +import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import com.dthielke.herochat.ChannelChatEvent; -import com.dthielke.herochat.Herochat; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.chat.ChatFormatter; + public class HerochatListener implements Listener { - Factions p; - public HerochatListener(Factions p) + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static HerochatListener i = new HerochatListener(); + public static HerochatListener get() { return i; } + private HerochatListener() {} + + // -------------------------------------------- // + // ACTIVATE & DEACTIVATE + // -------------------------------------------- // + + public void activate() { - this.p = p; - Herochat.getChannelManager().addChannel(new FactionChannel()); - Herochat.getChannelManager().addChannel(new AlliesChannel()); + Bukkit.getPluginManager().registerEvents(this, Factions.get()); } - /** - * Due to limitations in the new version of Herochat we can not offer relation colored tags. - */ + public void deactivate() + { + HandlerList.unregisterAll(this); + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + @EventHandler(priority = EventPriority.NORMAL) public void onChannelChatEvent(ChannelChatEvent event) { @@ -34,4 +51,5 @@ public class HerochatListener implements Listener format = ChatFormatter.format(format, event.getSender().getName(), null, null); event.setFormat(format); } + }