Made a sepparate health bar listener, reduced duplicate code and added respawn listener.

This commit is contained in:
Olof Larsson 2012-04-01 15:08:20 +02:00
parent 3eed72783b
commit 10522e7048
4 changed files with 60 additions and 29 deletions

View File

@ -31,6 +31,7 @@ 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.FactionsHealthBarListener;
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.struct.ChatMode; import com.massivecraft.factions.struct.ChatMode;
@ -58,6 +59,7 @@ public class P extends MPlugin
public final FactionsExploitListener exploitListener; public final FactionsExploitListener exploitListener;
public final FactionsBlockListener blockListener; public final FactionsBlockListener blockListener;
public final FactionsServerListener serverListener; public final FactionsServerListener serverListener;
public final FactionsHealthBarListener healthBarListener;
// Persistance related // Persistance related
private boolean locked = false; private boolean locked = false;
@ -78,6 +80,7 @@ public class P extends MPlugin
this.exploitListener = new FactionsExploitListener(); this.exploitListener = new FactionsExploitListener();
this.blockListener = new FactionsBlockListener(this); this.blockListener = new FactionsBlockListener(this);
this.serverListener = new FactionsServerListener(this); this.serverListener = new FactionsServerListener(this);
this.healthBarListener = new FactionsHealthBarListener(this);
} }

View File

@ -1,7 +1,6 @@
package com.massivecraft.factions.listeners; package com.massivecraft.factions.listeners;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;

View File

@ -26,7 +26,6 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.painting.PaintingBreakByEntityEvent; import org.bukkit.event.painting.PaintingBreakByEntityEvent;
@ -42,7 +41,6 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
@ -407,30 +405,4 @@ public class FactionsEntityListener implements Listener
event.setCancelled(true); event.setCancelled(true);
} }
// -------------------------------------------- //
// HEALTH BAR
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR)
public void monitorEntityDamageEvent(EntityDamageEvent event)
{
if (event.isCancelled()) return;
if ( ! Conf.spoutHealthBarUnderNames) return;
Entity entity = event.getEntity();
if ( ! (entity instanceof Player)) return;
Player player = (Player)entity;
SpoutFeatures.updateMyAppearance(player);
}
@EventHandler(priority = EventPriority.MONITOR)
public void monitorEntityRegainHealthEvent(EntityRegainHealthEvent event)
{
if (event.isCancelled()) return;
if ( ! Conf.spoutHealthBarUnderNames) return;
Entity entity = event.getEntity();
if ( ! (entity instanceof Player)) return;
Player player = (Player)entity;
SpoutFeatures.updateMyAppearance(player);
}
} }

View File

@ -0,0 +1,57 @@
package com.massivecraft.factions.listeners;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
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.PlayerRespawnEvent;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures;
public class FactionsHealthBarListener implements Listener
{
public P p;
public FactionsHealthBarListener(P p)
{
this.p = p;
}
// -------------------------------------------- //
// HEALTH BAR
// -------------------------------------------- //
public static void possiblyUpdateHealthBar(Entity entity, Cancellable event)
{
if (event != null && event.isCancelled()) return;
if ( ! Conf.spoutHealthBarUnderNames) return;
if ( ! (entity instanceof Player)) return;
Player player = (Player)entity;
SpoutFeatures.updateMyAppearance(player);
}
@EventHandler(priority = EventPriority.MONITOR)
public void monitorEntityDamageEvent(EntityDamageEvent event)
{
possiblyUpdateHealthBar(event.getEntity(), event);
}
@EventHandler(priority = EventPriority.MONITOR)
public void monitorEntityRegainHealthEvent(EntityRegainHealthEvent event)
{
possiblyUpdateHealthBar(event.getEntity(), event);
}
@EventHandler(priority = EventPriority.MONITOR)
public void monitorPlayerRespawnEvent(PlayerRespawnEvent event)
{
possiblyUpdateHealthBar(event.getPlayer(), null);
}
}