From d7a6ee4ff879fa39222a292c570cd2ceffb13b63 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 15 Dec 2015 18:04:50 +0100 Subject: [PATCH] Block liquid flow --- .../factions/engine/EngineMain.java | 54 ++++++++++++++++--- .../massivecraft/factions/entity/Board.java | 1 + 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index 3e9225cb..49c354d6 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -34,13 +34,16 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockSpreadEvent; -import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityBreakDoorEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -49,12 +52,10 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PotionSplashEvent; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.event.entity.EntityBreakDoorEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; +import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -72,20 +73,21 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.PlayerRoleComparator; import com.massivecraft.factions.Rel; import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.entity.Board; import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.factions.event.EventFactionsChunksChange; import com.massivecraft.factions.event.EventFactionsFactionShowAsync; -import com.massivecraft.factions.event.EventFactionsPvpDisallowed; import com.massivecraft.factions.event.EventFactionsPowerChange; import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; +import com.massivecraft.factions.event.EventFactionsPvpDisallowed; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.spigot.SpigotFeatures; import com.massivecraft.factions.util.VisualizeUtil; @@ -1535,6 +1537,44 @@ public class EngineMain extends EngineAbstract event.getPlayer().sendBlockChange(potentialBlock.getLocation(), potentialBlock.getType(), potentialBlock.getState().getRawData()); } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockLiquidFlow(BlockFromToEvent event) + { + // Prepare fields + Block fromBlock = event.getBlock(); + int fromCX = fromBlock.getX() >> 4; + int fromCZ = fromBlock.getZ() >> 4; + BlockFace face = event.getFace(); + int toCX = (fromBlock.getX() + face.getModX()) >> 4; + int toCZ = (fromBlock.getZ() + face.getModZ()) >> 4; + + // If a liquid (or dragon egg) moves from one chunk to another ... + if (toCX == fromCX && toCZ == fromCZ) return; + + Board board = BoardColl.get().getFixed(fromBlock.getWorld().getName().toLowerCase(), false); + if (board == null) return; + Map map = board.getMapRaw(); + if (map.isEmpty()) return; + + PS fromPs = PS.valueOf(fromCX, fromCZ); + PS toPs = PS.valueOf(toCX, toCZ); + TerritoryAccess fromTa = map.get(fromPs); + TerritoryAccess toTa = map.get(toPs); + String fromId = fromTa != null ? fromTa.getHostFactionId() : Factions.ID_NONE; + String toId = toTa != null ? toTa.getHostFactionId() : Factions.ID_NONE; + + // ... and the chunks belong to different factions ... + if (toId.equals(fromId)) return; + + // ... and the faction "from" can not build at "to" ... + Faction fromFac = FactionColl.get().getFixed(fromId); + Faction toFac = FactionColl.get().getFixed(toId); + if (MPerm.getPermBuild().has(fromFac, toFac)) return; + + // ... cancel! + event.setCancelled(true); + } + // -------------------------------------------- // // ASSORTED BUILD AND INTERACT // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index 6702a5a1..8a265f21 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -65,6 +65,7 @@ public class Board extends Entity implements BoardInterface private ConcurrentSkipListMap map; public Map getMap() { return Collections.unmodifiableMap(this.map); } + public Map getMapRaw() { return this.map; } // -------------------------------------------- // // CONSTRUCT