Add main listener and move the first listener content into it.

This commit is contained in:
Olof Larsson 2013-04-10 12:25:46 +02:00
parent fc64136380
commit 75ec92fb7d
3 changed files with 101 additions and 94 deletions

View File

@ -20,7 +20,6 @@ import com.massivecraft.factions.listeners.FactionsBlockListener;
import com.massivecraft.factions.listeners.FactionsChatListener; import com.massivecraft.factions.listeners.FactionsChatListener;
import com.massivecraft.factions.listeners.FactionsEntityListener; import com.massivecraft.factions.listeners.FactionsEntityListener;
import com.massivecraft.factions.listeners.FactionsExploitListener; import com.massivecraft.factions.listeners.FactionsExploitListener;
import com.massivecraft.factions.listeners.FactionsAppearanceListener;
import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.listeners.FactionsPlayerListener;
import com.massivecraft.factions.listeners.FactionsServerListener; import com.massivecraft.factions.listeners.FactionsServerListener;
import com.massivecraft.factions.util.AutoLeaveTask; import com.massivecraft.factions.util.AutoLeaveTask;
@ -55,7 +54,6 @@ public class Factions extends MPlugin
public FactionsExploitListener exploitListener; public FactionsExploitListener exploitListener;
public FactionsBlockListener blockListener; public FactionsBlockListener blockListener;
public FactionsServerListener serverListener; public FactionsServerListener serverListener;
public FactionsAppearanceListener appearanceListener;
// Persistance related // Persistance related
private boolean locked = false; private boolean locked = false;
@ -109,6 +107,8 @@ public class Factions extends MPlugin
startEconLandRewardTask(false); startEconLandRewardTask(false);
// Register Event Handlers // Register Event Handlers
MainListener.get().setup();
this.playerListener = new FactionsPlayerListener(this); this.playerListener = new FactionsPlayerListener(this);
getServer().getPluginManager().registerEvents(this.playerListener, this); getServer().getPluginManager().registerEvents(this.playerListener, this);
@ -127,9 +127,6 @@ public class Factions extends MPlugin
this.serverListener = new FactionsServerListener(this); this.serverListener = new FactionsServerListener(this);
getServer().getPluginManager().registerEvents(this.serverListener, this); getServer().getPluginManager().registerEvents(this.serverListener, this);
this.appearanceListener = new FactionsAppearanceListener(this);
getServer().getPluginManager().registerEvents(this.appearanceListener, this);
postEnable(); postEnable();
this.loadSuccessful = true; this.loadSuccessful = true;
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.listeners; package com.massivecraft.factions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -11,24 +12,34 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
public class MainListener implements Listener
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public class FactionsAppearanceListener implements Listener private static MainListener i = new MainListener();
public static MainListener get() { return i; }
public MainListener() {}
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
public void setup()
{ {
public Factions p; Bukkit.getPluginManager().registerEvents(this, Factions.get());
public FactionsAppearanceListener(Factions p)
{
this.p = p;
} }
// -------------------------------------------- // // -------------------------------------------- //
// FULL TWO-WAYS // SPOUT
// -------------------------------------------- // // -------------------------------------------- //
public void fullTwoWay(Player player) // Standard
public static void spoutStandard(Player player)
{ {
SpoutFeatures.updateTitleShortly(player, null); SpoutFeatures.updateTitleShortly(player, null);
SpoutFeatures.updateTitleShortly(null, player); SpoutFeatures.updateTitleShortly(null, player);
@ -37,29 +48,27 @@ public class FactionsAppearanceListener implements Listener
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) public void spoutStandard(PlayerJoinEvent event)
{ {
fullTwoWay(event.getPlayer()); spoutStandard(event.getPlayer());
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) public void spoutStandard(PlayerTeleportEvent event)
{ {
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) return; if (event.getFrom().getWorld().equals(event.getTo().getWorld())) return;
fullTwoWay(event.getPlayer()); spoutStandard(event.getPlayer());
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerRespawn(PlayerRespawnEvent event) public void spoutStandard(PlayerRespawnEvent event)
{ {
fullTwoWay(event.getPlayer()); spoutStandard(event.getPlayer());
} }
// -------------------------------------------- // // Health Bar
// HEALTH BAR
// -------------------------------------------- //
public static void possiblyUpdateHealthBar(Entity entity) public static void spoutHealthBar(Entity entity)
{ {
if ( ! ConfServer.spoutHealthBarUnderNames) return; if ( ! ConfServer.spoutHealthBarUnderNames) return;
if ( ! (entity instanceof Player)) return; if ( ! (entity instanceof Player)) return;
@ -68,21 +77,21 @@ public class FactionsAppearanceListener implements Listener
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void monitorEntityDamageEvent(EntityDamageEvent event) public void spoutHealthBar(EntityDamageEvent event)
{ {
possiblyUpdateHealthBar(event.getEntity()); spoutHealthBar(event.getEntity());
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void monitorEntityRegainHealthEvent(EntityRegainHealthEvent event) public void spoutHealthBar(EntityRegainHealthEvent event)
{ {
possiblyUpdateHealthBar(event.getEntity()); spoutHealthBar(event.getEntity());
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void monitorPlayerRespawnEvent(PlayerRespawnEvent event) public void spoutHealthBar(PlayerRespawnEvent event)
{ {
possiblyUpdateHealthBar(event.getPlayer()); spoutHealthBar(event.getPlayer());
} }
} }

View File

@ -93,6 +93,7 @@ public class FactionsEntityListener implements Listener
{ {
fplayer.onDeath(); fplayer.onDeath();
} }
// Send the message from the powerLossEvent // Send the message from the powerLossEvent
final String msg = powerLossEvent.getMessage(); final String msg = powerLossEvent.getMessage();
if (msg != null && !msg.isEmpty()) if (msg != null && !msg.isEmpty())