From f6d34f36f08c0fe80abbcbd6b37065957ec1a022 Mon Sep 17 00:00:00 2001 From: asofold Date: Sun, 7 Oct 2012 00:00:32 +0200 Subject: [PATCH] Move "place against liquids" to block-place listener. --- .../checks/blockplace/BlockPlaceListener.java | 25 +++++++++---- .../checks/moving/MovingListener.java | 37 ++++++++----------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java index e4eb2fbe..4a560408 100644 --- a/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/blockplace/BlockPlaceListener.java @@ -15,6 +15,8 @@ import org.bukkit.event.player.PlayerInteractEvent; import fr.neatmonster.nocheatplus.checks.combined.Combined; import fr.neatmonster.nocheatplus.checks.combined.Improbable; +import fr.neatmonster.nocheatplus.players.Permissions; +import fr.neatmonster.nocheatplus.utilities.BlockProperties; /* * M#"""""""'M dP dP MM"""""""`YM dP @@ -71,14 +73,23 @@ public class BlockPlaceListener implements Listener { * | |_) | | (_) | (__| < | __/| | (_| | (_| __/ * |____/|_|\___/ \___|_|\_\ |_| |_|\__,_|\___\___| */ - // We don't care about null blocks. - if (event.getBlock() == null || event.getBlockAgainst() == null) - return; - final Player player = event.getPlayer(); + final Block block = event.getBlockPlaced(); - + final Block blockAgainst = event.getBlockAgainst(); + // We don't care about null blocks. + if (block == null || blockAgainst == null) + return; + + final Material mat = block.getType(); + final Player player = event.getPlayer(); boolean cancelled = false; + + if (BlockProperties.isLiquid(blockAgainst.getTypeId()) + && mat != Material.WATER_LILY && !player.hasPermission(Permissions.BLOCKPLACE_AGAINST_LIQUIDS)) + // The block was placed against a liquid block, cancel its + // placement. + cancelled = true; // First, the fast place check. if (fastPlace.isEnabled(player)){ @@ -90,7 +101,7 @@ public class BlockPlaceListener implements Listener { } // Second, the no swing check (player doesn't swing his arm when placing a lily pad). - if (!cancelled && event.getBlockPlaced().getType() != Material.WATER_LILY && noSwing.isEnabled(player) + if (!cancelled && mat != Material.WATER_LILY && noSwing.isEnabled(player) && noSwing.check(player)) cancelled = true; @@ -100,7 +111,7 @@ public class BlockPlaceListener implements Listener { // Fourth, the direction check. if (!cancelled && direction.isEnabled(player) - && direction.check(player, block.getLocation(), event.getBlockAgainst().getLocation())) + && direction.check(player, block.getLocation(), blockAgainst.getLocation())) cancelled = true; // If one of the checks requested to cancel the event, do so. diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 41914a2c..01a2be4c 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -113,28 +113,21 @@ public class MovingListener implements Listener { final Material mat = block.getType(); - if (BlockProperties.isLiquid(event.getBlockAgainst().getTypeId()) - && mat != Material.WATER_LILY && !player.hasPermission(Permissions.BLOCKPLACE_AGAINST_LIQUIDS)) - // The block was placed against a liquid block, cancel its - // placement. - event.setCancelled(true); - else { - final MovingData data = MovingData.getData(player); - if (!creativeFly.isEnabled(player) && !survivalFly.isEnabled(player)) return; - - if (data.setBack == null || blockY + 1D < data.setBack.getY()) return; - - final Location loc = player.getLocation(); - if (Math.abs(loc.getX() - 0.5 - block.getX()) <= 1D - && Math.abs(loc.getZ() - 0.5 - block.getZ()) <= 1D - && loc.getY() - blockY > 0D && loc.getY() - blockY < 2D - && (BlockProperties.i(mat.getId()) || BlockProperties.isLiquid(mat.getId()))) { - // The creative fly and/or survival fly check is enabled, the - // block was placed below the player and is - // solid, so do what we have to do. - data.setBack.setY(blockY + 1D); - data.survivalFlyJumpPhase = 0; - } + final MovingData data = MovingData.getData(player); + if (!creativeFly.isEnabled(player) && !survivalFly.isEnabled(player)) return; + + if (data.setBack == null || blockY + 1D < data.setBack.getY()) return; + + final Location loc = player.getLocation(); + if (Math.abs(loc.getX() - 0.5 - block.getX()) <= 1D + && Math.abs(loc.getZ() - 0.5 - block.getZ()) <= 1D + && loc.getY() - blockY > 0D && loc.getY() - blockY < 2D + && (BlockProperties.i(mat.getId()) || BlockProperties.isLiquid(mat.getId()))) { + // The creative fly and/or survival fly check is enabled, the + // block was placed below the player and is + // solid, so do what we have to do. + data.setBack.setY(blockY + 1D); + data.survivalFlyJumpPhase = 0; } }