mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-26 06:14:42 +02:00
Fix boatsanywhere not recognizing other than oak boats.
Other: * Add and use BlockProperties.isWater.
This commit is contained in:
parent
8b02a7ce4c
commit
ddc0436e43
|
@ -48,6 +48,7 @@ import fr.neatmonster.nocheatplus.compat.Bridge1_9;
|
|||
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
|
||||
import fr.neatmonster.nocheatplus.permissions.Permissions;
|
||||
import fr.neatmonster.nocheatplus.stats.Counters;
|
||||
import fr.neatmonster.nocheatplus.utilities.InventoryUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
|
||||
|
@ -331,7 +332,7 @@ public class BlockPlaceListener extends CheckListener {
|
|||
|
||||
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);
|
||||
final Material type = stack.getType();
|
||||
if (type == Material.BOAT) {
|
||||
if (InventoryUtil.isBoat(type)) {
|
||||
if (cc.preventBoatsAnywhere) {
|
||||
checkBoatsAnywhere(player, event);
|
||||
}
|
||||
|
@ -351,7 +352,7 @@ public class BlockPlaceListener extends CheckListener {
|
|||
final Material mat = block.getType();
|
||||
|
||||
// TODO: allow lava ?
|
||||
if (mat == Material.WATER || mat == Material.STATIONARY_WATER) {
|
||||
if (BlockProperties.isWater(mat)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -359,7 +360,7 @@ public class BlockPlaceListener extends CheckListener {
|
|||
final Material relMat = relBlock.getType();
|
||||
|
||||
// TODO: Placing inside of water, but not "against" ?
|
||||
if (relMat == Material.WATER || relMat == Material.STATIONARY_WATER) {
|
||||
if (BlockProperties.isWater(relMat)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,11 @@
|
|||
*/
|
||||
package fr.neatmonster.nocheatplus.utilities;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
@ -32,6 +37,50 @@ import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
|
|||
*/
|
||||
public class InventoryUtil {
|
||||
|
||||
// TODO: Better location for the boat/item stuff than InventoryUtil.
|
||||
private static final Set<Material> boats = new HashSet<Material>();
|
||||
|
||||
static {
|
||||
boats.add(Material.BOAT);
|
||||
boats.addAll(collectItemsByPrefix("BOAT_")); // Oops: prefix.
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect non-block items by suffix of their Material name (case insensitive).
|
||||
* @param suffix
|
||||
* @return
|
||||
*/
|
||||
public static List<Material> collectItemsBySuffix(String suffix) {
|
||||
suffix = suffix.toLowerCase();
|
||||
final List<Material> res = new LinkedList<Material>();
|
||||
for (final Material mat : Material.values()) {
|
||||
if (!mat.isBlock() && mat.name().toLowerCase().endsWith(suffix)) {
|
||||
res.add(mat);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect non-block items by suffix of their Material name (case insensitive).
|
||||
* @param prefix
|
||||
* @return
|
||||
*/
|
||||
public static List<Material> collectItemsByPrefix(String prefix) {
|
||||
prefix = prefix.toLowerCase();
|
||||
final List<Material> res = new LinkedList<Material>();
|
||||
for (final Material mat : Material.values()) {
|
||||
if (!mat.isBlock() && mat.name().toLowerCase().startsWith(prefix)) {
|
||||
res.add(mat);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static boolean isBoat(final Material mat) {
|
||||
return boats.contains(mat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not account for special slots like armor.
|
||||
*
|
||||
|
|
|
@ -623,7 +623,7 @@ public class BlockProperties {
|
|||
public static final long F_MIN_HEIGHT16_1 = 0x80000000; // TODO: Lily pad min height of MC versions?
|
||||
|
||||
// TODO: Convenience constants combining all height / minheight flags.
|
||||
|
||||
|
||||
// TODO: When flags are out, switch to per-block classes :p.
|
||||
|
||||
// Special case activation flags.
|
||||
|
@ -2100,6 +2100,25 @@ public class BlockProperties {
|
|||
return (blockFlags[id] & F_LIQUID) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for water type of blocks.
|
||||
*
|
||||
* @param blockType
|
||||
* @return
|
||||
*/
|
||||
public static final boolean isWater(final Material blockType) {
|
||||
return isWater(getId(blockType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for water type of blocks.
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static final boolean isWater(final int id) {
|
||||
return (blockFlags[id] & F_WATER) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is ice.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user