Move the temporary spout stuff to a temporary listener like we did with Econ.

This commit is contained in:
Olof Larsson 2013-04-19 12:48:29 +02:00
parent 87ee57e004
commit f22ea3300f
3 changed files with 121 additions and 87 deletions

View File

@ -28,6 +28,7 @@ import com.massivecraft.factions.listeners.FactionsListenerChat;
import com.massivecraft.factions.listeners.FactionsListenerEcon; import com.massivecraft.factions.listeners.FactionsListenerEcon;
import com.massivecraft.factions.listeners.FactionsListenerExploit; import com.massivecraft.factions.listeners.FactionsListenerExploit;
import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.factions.listeners.FactionsListenerMain;
import com.massivecraft.factions.listeners.FactionsListenerSpout;
import com.massivecraft.factions.listeners.TodoFactionsPlayerListener; import com.massivecraft.factions.listeners.TodoFactionsPlayerListener;
import com.massivecraft.factions.task.AutoLeaveTask; import com.massivecraft.factions.task.AutoLeaveTask;
import com.massivecraft.factions.task.EconLandRewardTask; import com.massivecraft.factions.task.EconLandRewardTask;
@ -83,11 +84,14 @@ public class Factions extends MPlugin
FactionsListenerChat.get().setup(); FactionsListenerChat.get().setup();
FactionsListenerExploit.get().setup(); FactionsListenerExploit.get().setup();
// NOTE: This listener is a work in progress. // TODO: This listener is a work in progress.
// The goal is that the Econ integration should be completely based on listening to our own events. // The goal is that the Econ integration should be completely based on listening to our own events.
// Right now only a few situations are handled through this listener. // Right now only a few situations are handled through this listener.
FactionsListenerEcon.get().setup(); FactionsListenerEcon.get().setup();
// TODO: The same goes for this one:
FactionsListenerSpout.get().setup();
// TODO: Get rid of this one // TODO: Get rid of this one
this.playerListener = new TodoFactionsPlayerListener(); this.playerListener = new TodoFactionsPlayerListener();
getServer().getPluginManager().registerEvents(this.playerListener, this); getServer().getPluginManager().registerEvents(this.playerListener, this);

View File

@ -33,7 +33,6 @@ import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
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.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent;
@ -42,13 +41,8 @@ import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
@ -61,7 +55,6 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FactionsEventPowerLoss; import com.massivecraft.factions.event.FactionsEventPowerLoss;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
@ -680,83 +673,4 @@ public class FactionsListenerMain implements Listener
blockFireSpread(event.getBlock(), event); blockFireSpread(event.getBlock(), event);
} }
// -------------------------------------------- //
// SPOUT
// -------------------------------------------- //
// TODO: These spout related methods should not be in here.
// The spout integration needs to be moved elsewhere.
// NOTE: Also the spout integration should not have method calls from within FactionsCore code,
// we should instead listen to FactionsCore events. And send client updates upon non-cancelled monitor.
// Setup
@EventHandler(priority = EventPriority.MONITOR)
public void spoutSetup(PluginDisableEvent event)
{
SpoutFeatures.setup();
}
@EventHandler(priority = EventPriority.MONITOR)
public void spoutSetup(PluginEnableEvent event)
{
SpoutFeatures.setup();
}
// 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());
}
} }

View File

@ -0,0 +1,116 @@
package com.massivecraft.factions.listeners;
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 org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.SpoutFeatures;
public class FactionsListenerSpout implements Listener
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static FactionsListenerSpout i = new FactionsListenerSpout();
public static FactionsListenerSpout get() { return i; }
public FactionsListenerSpout() {}
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
public void setup()
{
Bukkit.getPluginManager().registerEvents(this, Factions.get());
}
// TODO: These spout related methods should not be in here.
// The spout integration needs to be moved elsewhere.
// NOTE: Also the spout integration should not have method calls from within FactionsCore code,
// we should instead listen to FactionsCore events. And send client updates upon non-cancelled monitor.
// Setup
@EventHandler(priority = EventPriority.MONITOR)
public void spoutSetup(PluginDisableEvent event)
{
SpoutFeatures.setup();
}
@EventHandler(priority = EventPriority.MONITOR)
public void spoutSetup(PluginEnableEvent event)
{
SpoutFeatures.setup();
}
// 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());
}
}