From ede66bac6b776ee4607e50b3e63518f9f3eab3b7 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 18 Apr 2013 17:20:42 +0200 Subject: [PATCH] Move out and clean even more listener content. --- .../listeners/FactionsListenerMain.java | 43 +++++++++++++++++++ .../listeners/TodoFactionsPlayerListener.java | 35 --------------- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index dfda1cbe..84ad4442 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -36,6 +36,8 @@ import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.server.PluginDisableEvent; @@ -52,7 +54,9 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.mcore.ps.PS; +import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.Txt; public class FactionsListenerMain implements Listener @@ -74,6 +78,45 @@ public class FactionsListenerMain implements Listener Bukkit.getPluginManager().registerEvents(this, Factions.get()); } + // -------------------------------------------- // + // REMOVE PLAYER DATA WHEN BANNED + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerKick(PlayerKickEvent event) + { + // If a player was kicked from the server ... + Player player = event.getPlayer(); + FPlayer fplayer = FPlayerColl.get().get(player); + + // ... and if the if player was banned (not just kicked) ... + if (!event.getReason().equals("Banned by admin.")) return; + + // ... and we remove player data when banned ... + if (!ConfServer.removePlayerDataWhenBanned) return; + + // ... get rid of their stored info. + if (fplayer.getRole() == Rel.LEADER) + { + fplayer.getFaction().promoteNewLeader(); + } + fplayer.leave(false); + fplayer.detach(); + + } + + // -------------------------------------------- // + // VISUALIZE UTIL + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerMoveClearVisualizations(PlayerMoveEvent event) + { + if (MUtil.isSameBlock(event)) return; + + VisualizeUtil.clear(event.getPlayer()); + } + // -------------------------------------------- // // DENY COMMANDS // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java index 1e2da05f..bf881aac 100644 --- a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java @@ -12,7 +12,6 @@ import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerMoveEvent; import com.massivecraft.factions.BoardColl; @@ -21,10 +20,8 @@ import com.massivecraft.factions.Const; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; -import com.massivecraft.factions.Rel; import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.integration.SpoutFeatures; -import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.mcore.event.MCorePlayerLeaveEvent; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.util.MUtil; @@ -200,36 +197,4 @@ public class TodoFactionsPlayerListener implements Listener } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerKick(PlayerKickEvent event) - { - FPlayer badGuy = FPlayerColl.get().get(event.getPlayer()); - if (badGuy == null) return; - - SpoutFeatures.playerDisconnect(badGuy); - - // if player was banned (not just kicked), get rid of their stored info - if (ConfServer.removePlayerDataWhenBanned && event.getReason().equals("Banned by admin.")) - { - if (badGuy.getRole() == Rel.LEADER) - badGuy.getFaction().promoteNewLeader(); - badGuy.leave(false); - badGuy.detach(); - } - } - - // -------------------------------------------- // - // VisualizeUtil - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerMoveClearVisualizations(PlayerMoveEvent event) - { - Block blockFrom = event.getFrom().getBlock(); - Block blockTo = event.getTo().getBlock(); - if (blockFrom.equals(blockTo)) return; - - VisualizeUtil.clear(event.getPlayer()); - } }