Move boatsanywhere to blockplace.

This commit is contained in:
asofold 2012-11-11 17:43:57 +01:00
parent c1bb11a725
commit 448ae2249b
4 changed files with 36 additions and 53 deletions

View File

@ -106,6 +106,8 @@ permissions:
description: Allow the player to place blocks against liquids.
nocheatplus.checks.blockplace.against.air:
description: Allow the player to place blocks against air.
nocheatplus.checks.blockplace.boatsanywhere:
description: Allow the player to place boats on the ground.
nocheatplus.checks.blockplace.direction:
description: Allow the player to bypass to Direction check.
nocheatplus.checks.blockplace.fastplace:
@ -170,8 +172,6 @@ permissions:
nocheatplus.checks.moving:
description: Allow the player to bypass all Moving checks.
children:
nocheatplus.checks.moving.boatsanywhere:
description: Allow the player to place boats on the ground.
nocheatplus.checks.moving.creativefly:
description: Allow the player to bypass the CreativeFly check.
nocheatplus.checks.moving.morepackets:

View File

@ -13,6 +13,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
@ -164,17 +165,38 @@ public class BlockPlaceListener implements Listener {
* |_| |_|\__,_|\__, |\___|_| |___|_| |_|\__\___|_| \__,_|\___|\__|
* |___/
*/
// We are only interested by monster eggs.
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().getItemInHand() == null
|| event.getPlayer().getItemInHand().getType() != Material.MONSTER_EGG)
return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
final Player player = event.getPlayer();
final Player player = event.getPlayer();
final ItemStack stack = player.getItemInHand();
if (stack == null) return;
// Do the actual check...
if (speed.isEnabled(player) && speed.check(player))
// If the check was positive, cancel the event.
event.setCancelled(true);
final Material type = stack.getType();
if (type == Material.BOAT){
// Check boats-anywhere.
final org.bukkit.block.Block block = event.getClickedBlock();
final Material mat = block.getType();
// TODO: allow lava ?
if (mat == Material.WATER || mat == Material.STATIONARY_WATER) return;
final org.bukkit.block.Block relBlock = block.getRelative(event.getBlockFace());
final Material relMat = relBlock.getType();
if (relMat == Material.WATER || relMat == Material.STATIONARY_WATER) return;
if (!player.hasPermission(Permissions.BLOCKPLACE_BOATSANYWHERE)){
event.setCancelled(true);
}
}
else if (type == Material.MONSTER_EGG){
// Check blockplace.speed.
if (speed.isEnabled(player) && speed.check(player))
// If the check was positive, cancel the event.
event.setCancelled(true);
}
}
/**

View File

@ -16,7 +16,6 @@ import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -25,7 +24,6 @@ import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@ -288,43 +286,6 @@ public class MovingListener implements Listener {
}
}
/**
* We listen to this event to cancel the placement of boat the ground. Boats are made to float on water, right?
*
* @param event
* the event
*/
@EventHandler(
ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInteract(final PlayerInteractEvent event) {
/*
* ____ _ ___ _ _
* | _ \| | __ _ _ _ ___ _ __ |_ _|_ __ | |_ ___ _ __ __ _ ___| |_
* | |_) | |/ _` | | | |/ _ \ '__| | || '_ \| __/ _ \ '__/ _` |/ __| __|
* | __/| | (_| | |_| | __/ | | || | | | || __/ | | (_| | (__| |_
* |_| |_|\__,_|\__, |\___|_| |___|_| |_|\__\___|_| \__,_|\___|\__|
* |___/
*/
// If the player right clicked on a non-liquid block with a boat in his hands, cancel the event.
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
final Player player = event.getPlayer();
if (player.getItemInHand().getType() != Material.BOAT) return;
if (event.getPlayer().hasPermission(Permissions.MOVING_BOATSANYWHERE)) return;
final org.bukkit.block.Block block = event.getClickedBlock();
final Material mat = block.getType();
if (mat == Material.WATER || mat == Material.STATIONARY_WATER) return;
final org.bukkit.block.Block relBlock = block.getRelative(event.getBlockFace());
final Material relMat = relBlock.getType();
if (relMat == Material.WATER || relMat == Material.STATIONARY_WATER) return;
event.setCancelled(true);
}
/**
* When a player moves, he will be checked for various suspicious behaviors.<br>
* (lowest priority)

View File

@ -93,6 +93,7 @@ public class Permissions {
public static final String BLOCKPLACE_AGAINST = BLOCKPLACE + ".against";
public static final String BLOCKPLACE_AGAINST_AIR = BLOCKPLACE_AGAINST + ".air";
public static final String BLOCKPLACE_AGAINST_LIQUIDS = BLOCKPLACE_AGAINST + ".liquids";
public static final String BLOCKPLACE_BOATSANYWHERE = BLOCKPLACE + ".boatsanywhere";
public static final String BLOCKPLACE_DIRECTION = BLOCKPLACE + ".direction";
public static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + ".fastplace";
public static final String BLOCKPLACE_NOSWING = BLOCKPLACE + ".noswing";
@ -166,7 +167,6 @@ public class Permissions {
* "8",P"
*/
public static final String MOVING = CHECKS + ".moving";
public static final String MOVING_BOATSANYWHERE = MOVING + ".boatsanywhere";
public static final String MOVING_CREATIVEFLY = MOVING + ".creativefly";
public static final String MOVING_MOREPACKETS = MOVING + ".morepackets";
public static final String MOVING_MOREPACKETSVEHICLE = MOVING + ".morepacketsvehicle";