From 521218cd6d48c22b274595d6958bd5a781950a43 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 24 Apr 2013 15:19:49 +0200 Subject: [PATCH] Chunk change logic is now good enough. Moving it to the MainListener. --- .../listeners/FactionsListenerMain.java | 77 +++++++++++++++++ .../listeners/TodoFactionsPlayerListener.java | 82 ------------------- 2 files changed, 77 insertions(+), 82 deletions(-) diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 57435774..399812c3 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -49,11 +49,13 @@ import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.UConf; +import com.massivecraft.factions.entity.UPlayerColls; import com.massivecraft.factions.event.FactionsEventPowerChange; import com.massivecraft.factions.event.FactionsEventPowerChange.PowerChangeReason; import com.massivecraft.factions.util.VisualizeUtil; @@ -80,6 +82,81 @@ public class FactionsListenerMain implements Listener Bukkit.getPluginManager().registerEvents(this, Factions.get()); } + // -------------------------------------------- // + // CHUNK CHANGE: DETECT + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void chunkChangeDetect(PlayerMoveEvent event) + { + // If the player is moving from one chunk to another ... + if (MUtil.isSameChunk(event)) return; + + // ... gather info on the player and the move ... + Player player = event.getPlayer(); + UPlayer uplayer = UPlayerColls.get().get(event.getTo()).get(player); + + PS chunkFrom = PS.valueOf(event.getFrom()).getChunk(true); + PS chunkTo = PS.valueOf(event.getTo()).getChunk(true); + + Faction factionFrom = BoardColls.get().getFactionAt(chunkFrom); + Faction factionTo = BoardColls.get().getFactionAt(chunkTo); + + // ... and send info onwards. + this.chunkChangeTerritoryInfo(uplayer, player, chunkFrom, chunkTo, factionFrom, factionTo); + this.chunkChangeAutoClaim(uplayer, chunkTo); + } + + // -------------------------------------------- // + // CHUNK CHANGE: TERRITORY INFO + // -------------------------------------------- // + + public void chunkChangeTerritoryInfo(UPlayer uplayer, Player player, PS chunkFrom, PS chunkTo, Faction factionFrom, Faction factionTo) + { + // send host faction info updates + if (uplayer.isMapAutoUpdating()) + { + uplayer.sendMessage(BoardColls.get().getMap(uplayer, chunkTo, player.getLocation().getYaw())); + } + else if (factionFrom != factionTo) + { + String msg = Txt.parse("") + " ~ " + factionTo.getTag(uplayer); + if (factionTo.hasDescription()) + { + msg += " - " + factionTo.getDescription(); + } + player.sendMessage(msg); + } + + // show access info message if needed + TerritoryAccess accessTo = BoardColls.get().getTerritoryAccessAt(chunkTo); + if (!accessTo.isDefault()) + { + if (accessTo.subjectHasAccess(uplayer)) + { + uplayer.msg("You have access to this area."); + } + else if (accessTo.subjectAccessIsRestricted(uplayer)) + { + uplayer.msg("This area has restricted access."); + } + } + } + + // -------------------------------------------- // + // CHUNK CHANGE: AUTO CLAIM + // -------------------------------------------- // + + public void chunkChangeAutoClaim(UPlayer uplayer, PS chunkTo) + { + // If the player is auto claiming ... + Faction autoClaimFaction = uplayer.getAutoClaimFaction(); + if (autoClaimFaction == null) return; + + // ... try claim. + uplayer.tryClaim(autoClaimFaction, chunkTo, true, true); + } + // -------------------------------------------- // // POWER LOSS ON DEATH // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java index a2d0f5ef..89e62d67 100644 --- a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java @@ -10,98 +10,16 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; import com.massivecraft.factions.Const; import com.massivecraft.factions.FPerm; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.BoardColls; -import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.UPlayerColls; import com.massivecraft.mcore.ps.PS; -import com.massivecraft.mcore.util.MUtil; -import com.massivecraft.mcore.util.Txt; public class TodoFactionsPlayerListener implements Listener { - // -------------------------------------------- // - // CHUNK CHANGE: DETECT - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void chunkChangeDetect(PlayerMoveEvent event) - { - // If the player is moving from one chunk to another ... - if (MUtil.isSameChunk(event)) return; - - // ... gather info on the player and the move ... - Player player = event.getPlayer(); - UPlayer uplayer = UPlayerColls.get().get(event.getTo()).get(player); - - PS chunkFrom = PS.valueOf(event.getFrom()).getChunk(true); - PS chunkTo = PS.valueOf(event.getTo()).getChunk(true); - - Faction factionFrom = BoardColls.get().getFactionAt(chunkFrom); - Faction factionTo = BoardColls.get().getFactionAt(chunkTo); - - // ... and send info onwards. - this.chunkChangeTerritoryInfo(uplayer, player, chunkFrom, chunkTo, factionFrom, factionTo); - this.chunkChangeAutoClaim(uplayer, chunkTo); - } - - // -------------------------------------------- // - // CHUNK CHANGE: TERRITORY INFO - // -------------------------------------------- // - - public void chunkChangeTerritoryInfo(UPlayer uplayer, Player player, PS chunkFrom, PS chunkTo, Faction factionFrom, Faction factionTo) - { - // send host faction info updates - if (uplayer.isMapAutoUpdating()) - { - uplayer.sendMessage(BoardColls.get().getMap(uplayer, chunkTo, player.getLocation().getYaw())); - } - else if (factionFrom != factionTo) - { - String msg = Txt.parse("") + " ~ " + factionTo.getTag(uplayer); - if (factionTo.hasDescription()) - { - msg += " - " + factionTo.getDescription(); - } - player.sendMessage(msg); - } - - // show access info message if needed - TerritoryAccess accessTo = BoardColls.get().getTerritoryAccessAt(chunkTo); - if (!accessTo.isDefault()) - { - if (accessTo.subjectHasAccess(uplayer)) - { - uplayer.msg("You have access to this area."); - } - else if (accessTo.subjectAccessIsRestricted(uplayer)) - { - uplayer.msg("This area has restricted access."); - } - } - } - - // -------------------------------------------- // - // CHUNK CHANGE: AUTO CLAIM - // -------------------------------------------- // - - public void chunkChangeAutoClaim(UPlayer uplayer, PS chunkTo) - { - // If the player is auto claiming ... - Faction autoClaimFaction = uplayer.getAutoClaimFaction(); - if (autoClaimFaction == null) return; - - // ... try claim. - uplayer.tryClaim(autoClaimFaction, chunkTo, true, true); - } - // -------------------------------------------- // // ASSORTED BUILD AND INTERACT // -------------------------------------------- //