mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-02 13:57:49 +01:00
Move "place against liquids" to block-place listener.
This commit is contained in:
parent
f913beba1f
commit
f6d34f36f0
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user