Search in sources :

Example 91 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method applyConfig.

/**
 * API access to read extra properties from files.
 *
 * @param config
 *            the config
 * @param pathPrefix
 *            the path prefix
 */
public static void applyConfig(final RawConfigFile config, final String pathPrefix) {
    // Breaking time overrides for specific side conditions.
    ConfigurationSection section = config.getConfigurationSection(pathPrefix + ConfPaths.SUB_BREAKINGTIME);
    for (final String input : section.getKeys(false)) {
        try {
            BlockProperties.setBreakingTimeOverride(new BlockBreakKey().fromString(input.trim()), section.getLong(input));
        } catch (Exception e) {
            StaticLog.logWarning("Bad breaking time override (" + pathPrefix + ConfPaths.SUB_BREAKINGTIME + "): " + input);
            StaticLog.logWarning(e);
        }
    }
    // Allow instant breaking.
    for (final String input : config.getStringList(pathPrefix + ConfPaths.SUB_ALLOWINSTANTBREAK)) {
        final Material id = RawConfigFile.parseMaterial(input);
        if (id == null) {
            StaticLog.logWarning("Bad block id (" + pathPrefix + ConfPaths.SUB_ALLOWINSTANTBREAK + "): " + input);
        } else {
            setBlockProps(id, instantType);
        }
    }
    // Override block flags.
    section = config.getConfigurationSection(pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS);
    if (section != null) {
        final Map<String, Object> entries = section.getValues(false);
        boolean hasErrors = false;
        for (final Entry<String, Object> entry : entries.entrySet()) {
            final String key = entry.getKey();
            final Material id = RawConfigFile.parseMaterial(key);
            if (id == null) {
                StaticLog.logWarning("Bad block id (" + pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS + "): " + key);
                continue;
            }
            final Object obj = entry.getValue();
            if (!(obj instanceof String)) {
                StaticLog.logWarning("Bad flags at " + pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS + " for key: " + key);
                hasErrors = true;
                continue;
            }
            final Collection<String> split = StringUtil.split((String) obj, ' ', ',', '/', '|', '+', ';', '\t');
            long flags = 0;
            boolean error = false;
            for (String input : split) {
                input = input.trim();
                if (input.isEmpty()) {
                    continue;
                } else if (input.equalsIgnoreCase("default")) {
                    flags |= getBlockFlags(id);
                    continue;
                }
                try {
                    flags |= parseFlag(input);
                } catch (InputMismatchException e) {
                    StaticLog.logWarning("Bad flag at " + pathPrefix + ConfPaths.SUB_OVERRIDEFLAGS + " for key " + key + " (skip setting flags for this block): " + input);
                    error = true;
                    hasErrors = true;
                    break;
                }
            }
            if (error) {
                continue;
            }
            setBlockFlags(id, flags);
        }
        if (hasErrors) {
            StaticLog.logInfo("Overriding block-flags was not entirely successful, all available flags: \n" + StringUtil.join(flagNameMap.values(), "|"));
        }
    }
}
Also used : Material(org.bukkit.Material) InputMismatchException(java.util.InputMismatchException) InputMismatchException(java.util.InputMismatchException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 92 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method isPassableWorkaround.

/**
 * Requires the hit-box of the block is hit (...): this checks for special
 * blocks properties such as glass panes and similar.<br>
 * Ray-tracing version for passable-workarounds.
 *
 * @param access
 *            the access
 * @param bx
 *            Block-coordinates.
 * @param by
 *            the by
 * @param bz
 *            the bz
 * @param fx
 *            Offset from block-coordinates in [0..1].
 * @param fy
 *            the fy
 * @param fz
 *            the fz
 * @param node
 *            The IBlockCacheNode instance for the given block coordinates.
 * @param dX
 *            Total ray distance for coordinated (see dT).
 * @param dY
 *            the d y
 * @param dZ
 *            the d z
 * @param dT
 *            Time to cover from given position in [0..1], relating to dX,
 *            dY, dZ.
 * @return true, if is passable workaround
 */
public static final boolean isPassableWorkaround(final BlockCache access, final int bx, final int by, final int bz, final double fx, final double fy, final double fz, final IBlockCacheNode node, final double dX, final double dY, final double dZ, final double dT) {
    // Note: Since this is only called if the bounding box collides, out-of-bounds checks should not be necessary.
    // TODO: Add a flag if a workaround exists (!), might store the type of workaround extra (generic!), or extra flags.
    final Material id = node.getType();
    final long flags = getBlockFlags(id);
    if ((flags & F_STAIRS) != 0) {
        if ((access.getData(bx, by, bz) & 0x4) != 0) {
            if (Math.max(fy, fy + dY * dT) < 0.5) {
                return true;
            }
        } else {
            // what with >= 1?
            if (Math.min(fy, fy + dY * dT) >= 0.5) {
                return true;
            }
        }
    } else if (id == Material.SOUL_SAND) {
        if (Math.min(fy, fy + dY * dT) >= 0.875) {
            // 0.125
            return true;
        }
    } else if ((flags & F_PASSABLE_X4) != 0 && (access.getData(bx, by, bz) & 0x4) != 0) {
        // (Allow checking further entries.)
        return true;
    } else if ((flags & F_THICK_FENCE) != 0) {
        if (!collidesFence(fx, fz, dX, dZ, dT, 0.125)) {
            return true;
        }
    } else if ((flags & F_THIN_FENCE) != 0) {
        if (!collidesFence(fx, fz, dX, dZ, dT, 0.05)) {
            return true;
        }
    } else if (id == Material.CAKE_BLOCK) {
        if (Math.min(fy, fy + dY * dT) >= 0.4375) {
            // 0.0625 = 0.125 / 2
            return true;
        }
    } else if (id == Material.CAULDRON) {
        if (Math.min(fy, fy + dY * dT) >= 0.3125) {
            // TODO: Maybe this is too exact...
            return isInsideCenter(fx, fz, dX, dZ, dT, 0.125);
        }
    } else if (id == Material.CACTUS) {
        if (Math.min(fy, fy + dY * dT) >= 0.9375) {
            return true;
        }
        return !collidesCenter(fx, fz, dX, dZ, dT, 0.0625);
    } else if (id == Material.PISTON_EXTENSION) {
        if (Math.min(fy, fy + dY * dT) >= 0.625) {
            return true;
        }
    } else if ((flags & F_GROUND_HEIGHT) != 0 && getGroundMinHeight(access, bx, by, bz, node, flags) <= Math.min(fy, fy + dY * dT)) {
        return true;
    }
    // Nothing found.
    return false;
}
Also used : Material(org.bukkit.Material)

Example 93 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method shouldLiquidBelowBeFullHeight.

// TODO: Consider for convenience ?
// /**
// * Determine if the liquid block below has full height or not (provided it
// * is max. level).
// *
// * @param access
// *            the access
// * @param x
// *            Coordinates of the block above the liquid block in question.
// * @param y
// *            the y
// * @param z
// *            the z
// * @return true, if successful
// */
// public static boolean shouldLiquidBelowBeFullHeight(final BlockCache access, final int x, final int y, final int z) {
// return shouldLiquidBelowBeFullHeight(access, x, y, z, null);
// }
/**
 * Determine if the liquid block below has full height or not (provided it
 * is max. level).
 *
 * @param access
 * @param x
 *            Coordinates of the block above the liquid block in question.
 * @param y
 * @param z
 * @param node
 *            The IBlockCacheNode instance for the given coordinates, may be null.
 * @return
 */
public static boolean shouldLiquidBelowBeFullHeight(final BlockCache access, final int x, final int y, final int z, IBlockCacheNode node) {
    if (node == null) {
        node = access.getOrCreateBlockCacheNode(x, y, z, false);
    }
    final Material id = node.getType();
    if (isLiquid(id)) {
        return true;
    }
    if (!isSolid(id)) {
        return false;
    }
    final double[] bounds = getCorrectedBounds(access, x, y, z, node);
    // TODO: Fences ~ test.
    return bounds == null ? true : (bounds[1] == 0.0);
}
Also used : Material(org.bukkit.Material)

Example 94 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method dumpBlocks.

/**
 * Dump blocks.
 *
 * @param all
 *            the all
 */
public static void dumpBlocks(boolean all) {
    final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
    List<String> missing = new LinkedList<String>();
    List<String> allBlocks = new LinkedList<String>();
    if (all) {
        allBlocks.add("Dump block properties for fastbreak check:");
        allBlocks.add("--- Present entries -------------------------------");
    }
    List<String> tags = new ArrayList<String>();
    for (Material temp : Material.values()) {
        String mat;
        try {
            if (!temp.isBlock()) {
                continue;
            }
            mat = temp.toString();
        } catch (Exception e) {
            mat = "?";
        }
        tags.clear();
        addFlagNames(getBlockFlags(temp), tags);
        String tagsJoined = tags.isEmpty() ? "" : " / " + StringUtil.join(tags, "+");
        if (blocks.get(temp) == null) {
            if (mat.equals("?")) {
                continue;
            }
            missing.add("* MISSING (" + mat + tagsJoined + ") ");
        } else {
            if (all) {
                allBlocks.add(": (" + mat + tagsJoined + ") " + getBlockProps(temp).toString());
            }
        }
    }
    if (all) {
        logManager.info(Streams.DEFAULT_FILE, StringUtil.join(allBlocks, "\n"));
    }
    if (!missing.isEmpty()) {
        missing.add(0, "--- Missing entries -------------------------------");
        missing.add(0, "The block breaking data is incomplete, default to allow instant breaking:");
        logManager.warning(Streams.INIT, StringUtil.join(missing, "\n"));
    }
}
Also used : ArrayList(java.util.ArrayList) Material(org.bukkit.Material) LogManager(fr.neatmonster.nocheatplus.logging.LogManager) LinkedList(java.util.LinkedList) InputMismatchException(java.util.InputMismatchException)

Example 95 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method isPassable.

/**
 * Test if a position can be passed through (collidesBlock + passable test,
 * no fences yet).<br>
 * NOTE: This is experimental.
 *
 * @param access
 *            the access
 * @param x
 *            the x
 * @param y
 *            the y
 * @param z
 *            the z
 * @param node
 *            The IBlockCacheNode instance for the given block coordinates.
 *            Not null.
 * @param nodeAbove
 *            The IBlockCacheNode instance above the given block
 *            coordinates. May be null.
 * @return true, if is passable
 */
public static final boolean isPassable(final BlockCache access, final double x, final double y, final double z, final IBlockCacheNode node, final IBlockCacheNode nodeAbove) {
    final Material id = node.getType();
    // Simple exclusion check first.
    if (isPassable(id)) {
        return true;
    }
    // Check if the position is inside of a bounding box.
    // TODO: Consider to pass these as arguments too.
    final int bx = Location.locToBlock(x);
    final int by = Location.locToBlock(y);
    final int bz = Location.locToBlock(z);
    if (node.hasNonNullBounds() == AlmostBoolean.NO || !collidesBlock(access, x, y, z, x, y, z, bx, by, bz, node, nodeAbove, getBlockFlags(id))) {
        return true;
    }
    final double fx = x - bx;
    final double fy = y - by;
    final double fz = z - bz;
    // Check workarounds (blocks with bigger collision box but passable on some spots).
    if (!isPassableWorkaround(access, bx, by, bz, fx, fy, fz, node, 0, 0, 0, 0)) {
        // Not passable.
        return false;
    }
    return true;
}
Also used : Material(org.bukkit.Material)

Aggregations

Material (org.bukkit.Material)427 ItemStack (org.bukkit.inventory.ItemStack)99 Block (org.bukkit.block.Block)87 EventHandler (org.bukkit.event.EventHandler)51 ArrayList (java.util.ArrayList)46 Player (org.bukkit.entity.Player)44 Location (org.bukkit.Location)42 Vector (org.bukkit.util.Vector)27 EntityType (org.bukkit.entity.EntityType)26 GlowBlock (net.glowstone.block.GlowBlock)24 Test (org.junit.Test)24 BlockFace (org.bukkit.block.BlockFace)23 Entity (org.bukkit.entity.Entity)22 MaterialData (org.bukkit.material.MaterialData)22 World (org.bukkit.World)20 HashMap (java.util.HashMap)19 IOException (java.io.IOException)17 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)16 File (java.io.File)15 HashSet (java.util.HashSet)13