Move "place against liquids" to block-place listener.

This commit is contained in:
asofold 2012-10-07 00:00:32 +02:00
parent f913beba1f
commit f6d34f36f0
2 changed files with 33 additions and 29 deletions

View File

@ -15,6 +15,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
import fr.neatmonster.nocheatplus.checks.combined.Combined; import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.Improbable; 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 * M#"""""""'M dP dP MM"""""""`YM dP
@ -71,15 +73,24 @@ public class BlockPlaceListener implements Listener {
* | |_) | | (_) | (__| < | __/| | (_| | (_| __/ * | |_) | | (_) | (__| < | __/| | (_| | (_| __/
* |____/|_|\___/ \___|_|\_\ |_| |_|\__,_|\___\___| * |____/|_|\___/ \___|_|\_\ |_| |_|\__,_|\___\___|
*/ */
final Block block = event.getBlockPlaced();
final Block blockAgainst = event.getBlockAgainst();
// We don't care about null blocks. // We don't care about null blocks.
if (event.getBlock() == null || event.getBlockAgainst() == null) if (block == null || blockAgainst == null)
return; return;
final Material mat = block.getType();
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final Block block = event.getBlockPlaced();
boolean cancelled = false; 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. // First, the fast place check.
if (fastPlace.isEnabled(player)){ if (fastPlace.isEnabled(player)){
if (fastPlace.check(player, block)) if (fastPlace.check(player, block))
@ -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). // 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)) && noSwing.check(player))
cancelled = true; cancelled = true;
@ -100,7 +111,7 @@ public class BlockPlaceListener implements Listener {
// Fourth, the direction check. // Fourth, the direction check.
if (!cancelled && direction.isEnabled(player) if (!cancelled && direction.isEnabled(player)
&& direction.check(player, block.getLocation(), event.getBlockAgainst().getLocation())) && direction.check(player, block.getLocation(), blockAgainst.getLocation()))
cancelled = true; cancelled = true;
// If one of the checks requested to cancel the event, do so. // If one of the checks requested to cancel the event, do so.

View File

@ -113,12 +113,6 @@ public class MovingListener implements Listener {
final Material mat = block.getType(); 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); final MovingData data = MovingData.getData(player);
if (!creativeFly.isEnabled(player) && !survivalFly.isEnabled(player)) return; if (!creativeFly.isEnabled(player) && !survivalFly.isEnabled(player)) return;
@ -136,7 +130,6 @@ public class MovingListener implements Listener {
data.survivalFlyJumpPhase = 0; data.survivalFlyJumpPhase = 0;
} }
} }
}
/** /**
* We listen to this event to prevent player from flying by sending bed leaving packets. * We listen to this event to prevent player from flying by sending bed leaving packets.