From 4f4b988b42b0cfe76b51f5123f0cbcd8c47c19ef Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 2 Feb 2012 19:31:33 -0600 Subject: [PATCH] Preemptive EssentialsChat 3.x support, since they'll be removing the old local chat integration method; new implementation will need improvement to support relation coloring, but for now it otherwise works. When chat event hits an UnknownFormatConversionException which requires better chat configuration, the quick dirty fix of setting chatTagInsertIndex to 0 is now automatically applied. --- lib/EssentialsChat.jar | Bin 0 -> 12944 bytes src/com/massivecraft/factions/P.java | 33 ++++++++-- .../integration/EssentialsFeatures.java | 41 ++++++------ .../EssentialsOldVersionFeatures.java | 59 ++++++++++++++++++ .../listeners/FactionsPlayerListener.java | 9 +-- 5 files changed, 115 insertions(+), 27 deletions(-) create mode 100644 lib/EssentialsChat.jar create mode 100644 src/com/massivecraft/factions/integration/EssentialsOldVersionFeatures.java diff --git a/lib/EssentialsChat.jar b/lib/EssentialsChat.jar new file mode 100644 index 0000000000000000000000000000000000000000..ec0a3cfa2fbb5e0ecdfa995533e8e292afad37a5 GIT binary patch literal 12944 zcmb_@byS?ovhP4}cXxMp3-0dj?!h$)HrU|q?u6hD!QC~u1`V!(Kpwd{`|Q2*?m6ea zw{EYQHQyg){dHGYb=7Z_b2r z11NtX9b}R8@_Zo=dHG_zeE&(RAfhNEDWRs$q#&sf*#XzXg7W@OczsKf5X}@d$+5xB z`GBH%1Xn3t^&_PxlE3fH-ow-N(4j>Bsie-#80S~N>f)`}GYmM;fjtod-$v58(CGx% zyq|8MiBIR(1$$7r7LmnrOtUR8i<-JZ3O16>MB^acOY_i47lIS+QR_Gt{J{P&6!2e$ z{$)xpGXen2oE(_{H3i~7C@f4|+^pFgEdC8C&hMlauC5l2ZZ;-N#ASp0+;bL#$VPXGILBG~({Oy=f3OE4J3JCx({3k(TFNUbOIk{Lcnc17T zx<;w3D59%i7?d>Ggl=h~inoM))`c3OS%*}y;UF!0P$t>x4i)pAK}t@u^eMmKz6Tij z_lwJtg%fW|;oha;isa1+jkS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os&FDc;9lNJRK_JZ5K{Q0j0 G!2bc-)2Ipn literal 0 HcmV?d00001 diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 2cd9fb6b..1b63ce63 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -21,7 +21,10 @@ import com.massivecraft.factions.adapters.FPermTypeAdapter; import com.massivecraft.factions.adapters.LocationTypeAdapter; import com.massivecraft.factions.adapters.RelTypeAdapter; import com.massivecraft.factions.cmd.*; +import com.massivecraft.factions.integration.capi.CapiFeatures; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.integration.EssentialsFeatures; +import com.massivecraft.factions.integration.EssentialsOldVersionFeatures; import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.integration.SpoutFeatures; //import com.massivecraft.factions.integration.Worldguard; @@ -40,8 +43,6 @@ import com.griefcraft.lwc.LWCPlugin; import com.earth2me.essentials.chat.EssentialsChat; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.massivecraft.factions.integration.EssentialsFeatures; -import com.massivecraft.factions.integration.capi.CapiFeatures; public class P extends MPlugin @@ -184,7 +185,25 @@ public class P extends MPlugin if (test != null && test.isEnabled()) { essChat = (EssentialsChat)test; - EssentialsFeatures.integrateChat(essChat); + + // try newer Essentials 3.x integration method + try + { + Class.forName("com.earth2me.essentials.chat.EssentialsLocalChatEvent"); + EssentialsFeatures.integrateChat(essChat); + } + catch (ClassNotFoundException ex) + { + // no? try older Essentials 2.x integration method + try + { + EssentialsOldVersionFeatures.integrateChat(essChat); + } + catch (NoClassDefFoundError ex2) + { + // no known method for hooking into Essentials chat stuff + } + } } } @@ -192,7 +211,13 @@ public class P extends MPlugin { if (essChat != null) { - EssentialsFeatures.unhookChat(); + try + { + EssentialsOldVersionFeatures.unhookChat(); + } + catch (NoClassDefFoundError ex) + { + } } } diff --git a/src/com/massivecraft/factions/integration/EssentialsFeatures.java b/src/com/massivecraft/factions/integration/EssentialsFeatures.java index a642f8a1..d8f63406 100644 --- a/src/com/massivecraft/factions/integration/EssentialsFeatures.java +++ b/src/com/massivecraft/factions/integration/EssentialsFeatures.java @@ -1,15 +1,22 @@ package com.massivecraft.factions.integration; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import com.massivecraft.factions.Conf; import com.massivecraft.factions.P; import com.earth2me.essentials.chat.EssentialsChat; -import com.earth2me.essentials.chat.IEssentialsChatListener; +import com.earth2me.essentials.chat.EssentialsLocalChatEvent; +/* + * This Essentials integration handler is for newer 3.x.x versions of Essentials which don't have "IEssentialsChatListener" + */ + public class EssentialsFeatures { private static EssentialsChat essChat; @@ -19,21 +26,11 @@ public class EssentialsFeatures essChat = instance; try { - essChat.addEssentialsChatListener("Factions", new IEssentialsChatListener() - { - public boolean shouldHandleThisChat(PlayerChatEvent event) - { - return P.p.shouldLetFactionsHandleThisChat(event); - } - public String modifyMessage(PlayerChatEvent event, Player target, String message) - { - return message.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTagRelation(event.getPlayer(), target)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(event.getPlayer())); - } - }); - P.p.log("Found and will integrate chat with "+essChat.getDescription().getFullName()); + Bukkit.getServer().getPluginManager().registerEvents(new LocalChatListener(), P.p); + P.p.log("Found and will integrate chat with newer "+essChat.getDescription().getFullName()); - // 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("{")) + // curly braces used to be accepted by the format string EssentialsChat but no longer are, so... deal with chatTagReplaceString which might need updating + if (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."); @@ -45,11 +42,17 @@ public class EssentialsFeatures } } - public static void unhookChat() + private static class LocalChatListener implements Listener { - if (essChat != null) + @EventHandler(priority = EventPriority.NORMAL) + public void onPlayerChat(EssentialsLocalChatEvent event) { - essChat.removeEssentialsChatListener("Factions"); + Player speaker = event.getPlayer(); + String format = event.getFormat(); + format = format.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTag(speaker)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(speaker)); + event.setFormat(format); + // NOTE: above doesn't do relation coloring. if/when we can get a local recipient list from EssentialsLocalChatEvent, we'll probably + // want to pass it on to FactionsPlayerListener.onPlayerChat(PlayerChatEvent event) rather than duplicating code } } } diff --git a/src/com/massivecraft/factions/integration/EssentialsOldVersionFeatures.java b/src/com/massivecraft/factions/integration/EssentialsOldVersionFeatures.java new file mode 100644 index 00000000..e867820a --- /dev/null +++ b/src/com/massivecraft/factions/integration/EssentialsOldVersionFeatures.java @@ -0,0 +1,59 @@ +package com.massivecraft.factions.integration; + +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerChatEvent; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.P; + +import com.earth2me.essentials.chat.EssentialsChat; +import com.earth2me.essentials.chat.IEssentialsChatListener; + + +/* + * This Essentials integration handler is for older 2.x.x versions of Essentials which have "IEssentialsChatListener" + */ + +public class EssentialsOldVersionFeatures +{ + private static EssentialsChat essChat; + + public static void integrateChat(EssentialsChat instance) + { + essChat = instance; + try + { + essChat.addEssentialsChatListener("Factions", new IEssentialsChatListener() + { + public boolean shouldHandleThisChat(PlayerChatEvent event) + { + return P.p.shouldLetFactionsHandleThisChat(event); + } + public String modifyMessage(PlayerChatEvent event, Player target, String message) + { + return message.replace(Conf.chatTagReplaceString, P.p.getPlayerFactionTagRelation(event.getPlayer(), target)).replace("[FACTION_TITLE]", P.p.getPlayerTitle(event.getPlayer())); + } + }); + P.p.log("Found and will integrate chat with "+essChat.getDescription().getFullName()); + + // 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."); + } + } + catch (NoSuchMethodError ex) + { + essChat = null; + } + } + + public static void unhookChat() + { + if (essChat != null) + { + essChat.removeEssentialsChatListener("Factions"); + } + } +} diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index c97d5dc4..ce62424c 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -73,10 +73,10 @@ public class FactionsPlayerListener implements Listener if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString)) { // we're using the "replace" method of inserting the faction tags - // if they stuck "{FACTION_TITLE}" in there, go ahead and do it too - if (eventFormat.contains("{FACTION_TITLE}")) + // if they stuck "[FACTION_TITLE]" in there, go ahead and do it too + if (eventFormat.contains("[FACTION_TITLE]")) { - eventFormat = eventFormat.replace("{FACTION_TITLE}", me.getTitle()); + eventFormat = eventFormat.replace("[FACTION_TITLE]", me.getTitle()); } InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString); eventFormat = eventFormat.replace(Conf.chatTagReplaceString, ""); @@ -123,8 +123,9 @@ public class FactionsPlayerListener implements Listener } catch (UnknownFormatConversionException ex) { + Conf.chatTagInsertIndex = 0; P.p.log(Level.SEVERE, "Critical error in chat message formatting!"); - P.p.log(Level.SEVERE, "NOTE: To fix this quickly, running this command should work: f config chatTagInsertIndex 0"); + P.p.log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0."); P.p.log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration"); return; }