mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-20 10:22:14 +00:00
Merge pull request #8 from Brettflan/master
Implemented Factions plugin hooks to EssentialsChat for proper chat integration between them (master/dev branch)
This commit is contained in:
commit
4eb94e7fac
|
@ -27,11 +27,13 @@ dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
endorsed.classpath=
|
endorsed.classpath=
|
||||||
excludes=
|
excludes=
|
||||||
file.reference.bukkit-0.0.1-SNAPSHOT.jar=../lib/bukkit-0.0.1-SNAPSHOT.jar
|
file.reference.bukkit-0.0.1-SNAPSHOT.jar=../lib/bukkit-0.0.1-SNAPSHOT.jar
|
||||||
|
file.reference.Factions.jar=../lib/Factions.jar
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
javac.classpath=\
|
javac.classpath=\
|
||||||
${reference.Essentials.jar}:\
|
${reference.Essentials.jar}:\
|
||||||
${file.reference.bukkit-0.0.1-SNAPSHOT.jar}
|
${file.reference.bukkit-0.0.1-SNAPSHOT.jar}:\
|
||||||
|
${file.reference.Factions.jar}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=
|
javac.compilerargs=
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
|
|
|
@ -17,6 +17,9 @@ public class EssentialsChat extends JavaPlugin
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
final PluginManager pluginManager = getServer().getPluginManager();
|
final PluginManager pluginManager = getServer().getPluginManager();
|
||||||
|
|
||||||
|
EssentialsChatPlayerListener.checkFactions(pluginManager);
|
||||||
|
|
||||||
final EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer());
|
final EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer());
|
||||||
pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Lowest, this);
|
pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Lowest, this);
|
||||||
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
|
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
|
||||||
|
|
|
@ -13,6 +13,10 @@ import org.bukkit.event.player.PlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
|
import org.mcteam.factions.Factions;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsChatPlayerListener extends PlayerListener
|
public class EssentialsChatPlayerListener extends PlayerListener
|
||||||
|
@ -20,6 +24,7 @@ public class EssentialsChatPlayerListener extends PlayerListener
|
||||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
private final transient IEssentials ess = Essentials.getStatic();
|
private final transient IEssentials ess = Essentials.getStatic();
|
||||||
private final transient Server server;
|
private final transient Server server;
|
||||||
|
private static Factions factions = null;
|
||||||
|
|
||||||
public EssentialsChatPlayerListener(final Server server)
|
public EssentialsChatPlayerListener(final Server server)
|
||||||
{
|
{
|
||||||
|
@ -48,6 +53,10 @@ public class EssentialsChatPlayerListener extends PlayerListener
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (factions != null && (factions.shouldLetFactionsHandleThisChat(event)))
|
||||||
|
return;
|
||||||
|
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
updateDisplayName(user);
|
updateDisplayName(user);
|
||||||
|
|
||||||
|
@ -118,8 +127,39 @@ public class EssentialsChatPlayerListener extends PlayerListener
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String message = String.format(event.getFormat(), user.getDisplayName(), event.getMessage());
|
||||||
|
|
||||||
u.sendMessage(String.format(event.getFormat(), user.getDisplayName(), event.getMessage()));
|
if (factions != null)
|
||||||
|
message = message.replace("{FACTION}", factions.getPlayerFactionTagRelation(event.getPlayer(), p)).replace("{FACTION_TITLE}", factions.getPlayerTitle(event.getPlayer()));
|
||||||
|
|
||||||
|
u.sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void checkFactions(PluginManager pm)
|
||||||
|
{
|
||||||
|
if (factions != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Plugin factionsPlugin = pm.getPlugin("Factions");
|
||||||
|
if (factionsPlugin == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
factions = (Factions)factionsPlugin;
|
||||||
|
try
|
||||||
|
{ // make sure Factions is sufficiently up-to-date
|
||||||
|
if (factions.hookSupportVersion() < 1)
|
||||||
|
factions = null;
|
||||||
|
}
|
||||||
|
catch (NoSuchMethodError ex)
|
||||||
|
{ // if not, we can't work with it, so don't bother
|
||||||
|
factions = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (factions == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// normally a good thing, but we'll skip it to let Factions handle faction tags for global messages
|
||||||
|
//factions.handleFactionTagExternally(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
lib/Factions.jar
Normal file
BIN
lib/Factions.jar
Normal file
Binary file not shown.
Loading…
Reference in a new issue