diff --git a/lib/Essentials.jar b/lib/Essentials.jar new file mode 100644 index 00000000..d022397b Binary files /dev/null and b/lib/Essentials.jar differ diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 8081e294..1d96c13c 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -91,6 +91,7 @@ public class Conf public static boolean homesTeleportToOnDeath = true; public static boolean homesRespawnFromNoPowerLossWorlds = true; public static boolean homesTeleportCommandEnabled = true; + public static boolean homesTeleportCommandEssentialsIntegration = true; public static boolean homesTeleportCommandSmokeEffectEnabled = true; public static float homesTeleportCommandSmokeEffectThickness = 3f; public static boolean homesTeleportAllowedFromEnemyTerritory = true; diff --git a/src/com/massivecraft/factions/cmd/CmdHome.java b/src/com/massivecraft/factions/cmd/CmdHome.java index 4ee4909f..42224a21 100644 --- a/src/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/com/massivecraft/factions/cmd/CmdHome.java @@ -13,11 +13,13 @@ import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.integration.EssentialsFeatures; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.util.SmokeUtil; + public class CmdHome extends FCommand { @@ -123,6 +125,9 @@ public class CmdHome extends FCommand } } + // if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown) + if (EssentialsFeatures.handleTeleport(me, myFaction.getHome())) return; + // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) return; diff --git a/src/com/massivecraft/factions/integration/EssentialsFeatures.java b/src/com/massivecraft/factions/integration/EssentialsFeatures.java index a2ea246b..6a7d7d54 100644 --- a/src/com/massivecraft/factions/integration/EssentialsFeatures.java +++ b/src/com/massivecraft/factions/integration/EssentialsFeatures.java @@ -1,15 +1,20 @@ package com.massivecraft.factions.integration; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.Location; import org.bukkit.plugin.Plugin; import com.massivecraft.factions.Conf; import com.massivecraft.factions.P; +import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.Teleport; +import com.earth2me.essentials.Trade; import com.earth2me.essentials.chat.EssentialsChat; import com.earth2me.essentials.chat.EssentialsLocalChatEvent; @@ -22,9 +27,21 @@ import com.earth2me.essentials.chat.EssentialsLocalChatEvent; public class EssentialsFeatures { private static EssentialsChat essChat; + private static IEssentials essentials; + @SuppressWarnings("deprecation") public static void setup() { + // integrate main essentials plugin + // TODO: this is the old Essentials method not supported in 3.0... probably needs to eventually be moved to EssentialsOldVersionFeatures and new method implemented + if (essentials == null) + { + Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials"); + if (ess != null && ess.isEnabled()) + essentials = (IEssentials)ess; + } + + // integrate chat if (essChat != null) return; Plugin test = Bukkit.getServer().getPluginManager().getPlugin("EssentialsChat"); @@ -61,6 +78,25 @@ public class EssentialsFeatures } + // return false if feature is disabled or Essentials isn't available + @SuppressWarnings("deprecation") + public static boolean handleTeleport(Player player, Location loc) + { + if ( ! Conf.homesTeleportCommandEssentialsIntegration || essentials == null) return false; + + Teleport teleport = (Teleport) essentials.getUser(player).getTeleport(); + Trade trade = new Trade(Conf.econCostHome, essentials); + try + { + teleport.teleport(loc, trade); + } + catch (Exception e) + { + player.sendMessage(ChatColor.RED.toString()+e.getMessage()); + } + return true; + } + public static void integrateChat(EssentialsChat instance) {