diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 71d058cb..4c9f0367 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -20,7 +20,6 @@ import com.massivecraft.factions.listeners.FactionsBlockListener; import com.massivecraft.factions.listeners.FactionsChatListener; import com.massivecraft.factions.listeners.FactionsEntityListener; import com.massivecraft.factions.listeners.FactionsExploitListener; -import com.massivecraft.factions.listeners.FactionsAppearanceListener; import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.listeners.FactionsServerListener; import com.massivecraft.factions.util.AutoLeaveTask; @@ -55,7 +54,6 @@ public class Factions extends MPlugin public FactionsExploitListener exploitListener; public FactionsBlockListener blockListener; public FactionsServerListener serverListener; - public FactionsAppearanceListener appearanceListener; // Persistance related private boolean locked = false; @@ -109,6 +107,8 @@ public class Factions extends MPlugin startEconLandRewardTask(false); // Register Event Handlers + MainListener.get().setup(); + this.playerListener = new FactionsPlayerListener(this); getServer().getPluginManager().registerEvents(this.playerListener, this); @@ -127,9 +127,6 @@ public class Factions extends MPlugin this.serverListener = new FactionsServerListener(this); getServer().getPluginManager().registerEvents(this.serverListener, this); - this.appearanceListener = new FactionsAppearanceListener(this); - getServer().getPluginManager().registerEvents(this.appearanceListener, this); - postEnable(); this.loadSuccessful = true; } diff --git a/src/com/massivecraft/factions/listeners/FactionsAppearanceListener.java b/src/com/massivecraft/factions/MainListener.java similarity index 56% rename from src/com/massivecraft/factions/listeners/FactionsAppearanceListener.java rename to src/com/massivecraft/factions/MainListener.java index 9516e1be..a8f3c6b9 100644 --- a/src/com/massivecraft/factions/listeners/FactionsAppearanceListener.java +++ b/src/com/massivecraft/factions/MainListener.java @@ -1,88 +1,97 @@ -package com.massivecraft.factions.listeners; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; - -import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.integration.SpoutFeatures; - - -public class FactionsAppearanceListener implements Listener -{ - public Factions p; - public FactionsAppearanceListener(Factions p) - { - this.p = p; - } - - // -------------------------------------------- // - // FULL TWO-WAYS - // -------------------------------------------- // - - public void fullTwoWay(Player player) - { - SpoutFeatures.updateTitleShortly(player, null); - SpoutFeatures.updateTitleShortly(null, player); - SpoutFeatures.updateCapeShortly(player, null); - SpoutFeatures.updateCapeShortly(null, player); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoin(PlayerJoinEvent event) - { - fullTwoWay(event.getPlayer()); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerTeleport(PlayerTeleportEvent event) - { - if (event.getFrom().getWorld().equals(event.getTo().getWorld())) return; - fullTwoWay(event.getPlayer()); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerRespawn(PlayerRespawnEvent event) - { - fullTwoWay(event.getPlayer()); - } - - // -------------------------------------------- // - // HEALTH BAR - // -------------------------------------------- // - - public static void possiblyUpdateHealthBar(Entity entity) - { - if ( ! ConfServer.spoutHealthBarUnderNames) return; - if ( ! (entity instanceof Player)) return; - Player player = (Player)entity; - SpoutFeatures.updateTitle(player, null); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void monitorEntityDamageEvent(EntityDamageEvent event) - { - possiblyUpdateHealthBar(event.getEntity()); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void monitorEntityRegainHealthEvent(EntityRegainHealthEvent event) - { - possiblyUpdateHealthBar(event.getEntity()); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void monitorPlayerRespawnEvent(PlayerRespawnEvent event) - { - possiblyUpdateHealthBar(event.getPlayer()); - } - -} +package com.massivecraft.factions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +import com.massivecraft.factions.integration.SpoutFeatures; + +public class MainListener implements Listener +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MainListener i = new MainListener(); + public static MainListener get() { return i; } + public MainListener() {} + + // -------------------------------------------- // + // SETUP + // -------------------------------------------- // + + public void setup() + { + Bukkit.getPluginManager().registerEvents(this, Factions.get()); + } + + // -------------------------------------------- // + // SPOUT + // -------------------------------------------- // + + // Standard + + public static void spoutStandard(Player player) + { + SpoutFeatures.updateTitleShortly(player, null); + SpoutFeatures.updateTitleShortly(null, player); + SpoutFeatures.updateCapeShortly(player, null); + SpoutFeatures.updateCapeShortly(null, player); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void spoutStandard(PlayerJoinEvent event) + { + spoutStandard(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void spoutStandard(PlayerTeleportEvent event) + { + if (event.getFrom().getWorld().equals(event.getTo().getWorld())) return; + spoutStandard(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void spoutStandard(PlayerRespawnEvent event) + { + spoutStandard(event.getPlayer()); + } + + // Health Bar + + public static void spoutHealthBar(Entity entity) + { + if ( ! ConfServer.spoutHealthBarUnderNames) return; + if ( ! (entity instanceof Player)) return; + Player player = (Player)entity; + SpoutFeatures.updateTitle(player, null); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void spoutHealthBar(EntityDamageEvent event) + { + spoutHealthBar(event.getEntity()); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void spoutHealthBar(EntityRegainHealthEvent event) + { + spoutHealthBar(event.getEntity()); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void spoutHealthBar(PlayerRespawnEvent event) + { + spoutHealthBar(event.getPlayer()); + } + +} diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 0ee5a930..fd3f91ce 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -89,10 +89,11 @@ public class FactionsEntityListener implements Listener Bukkit.getPluginManager().callEvent(powerLossEvent); // Call player onDeath if the event is not cancelled - if(!powerLossEvent.isCancelled()) + if ( ! powerLossEvent.isCancelled()) { fplayer.onDeath(); } + // Send the message from the powerLossEvent final String msg = powerLossEvent.getMessage(); if (msg != null && !msg.isEmpty())