Java Code Examples for org.spongepowered.api.block.BlockType#equals()

The following examples show how to use org.spongepowered.api.block.BlockType#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventUtil.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Reject certain events which can only be identified
 * by the change + cause signature.
 *
 * @param a BlockType original
 * @param b BlockType replacement
 * @param cause Cause chain from event
 * @return boolean If should be rejected
 */
public static boolean rejectBreakEventIdentity(BlockType a, BlockType b, Cause cause) {
    // Falling blocks
    if (a.equals(BlockTypes.GRAVEL) && b.equals(BlockTypes.AIR)) {
        return !cause.first(Player.class).isPresent();
    }

    // Interesting bugs...
    if (a.equals(BlockTypes.AIR) && b.equals(BlockTypes.AIR)) {
        return true;
    }

    return false;
}
 
Example 2
Source File: EventUtil.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Reject certain events which can only be identified
 * by the change + cause signature.
 *
 * @param a BlockType original
 * @param b BlockType replacement
 * @param cause Cause chain from event
 * @return boolean If should be rejected
 */
public static boolean rejectPlaceEventIdentity(BlockType a, BlockType b, Cause cause) {
    // Things that eat grass...
    if (a.equals(BlockTypes.GRASS) && b.equals(BlockTypes.DIRT)) {
        return cause.first(Living.class).isPresent();
    }

    // Grass-like "Grow" events
    if (a.equals(BlockTypes.DIRT) && b.equals(BlockTypes.GRASS)) {
        return cause.first(BlockSnapshot.class).isPresent();
    }

    // If no entity at fault, we don't care about placement that didn't affect anything
    if (!cause.first(Entity.class).isPresent()) {
        return (a.equals(BlockTypes.AIR));
    }

    // Natural flow/fire.
    // Note: This only allows tracking on the source block set by a player using
    // buckets, or items to set fires. Blocks broken by water, lava or fire are still logged as usual.
    // Full flow/fire tracking would be hard on the database and is generally unnecessary.
    if (!cause.first(Player.class).isPresent()) {
        return (a.equals(BlockTypes.AIR) && (b.equals(BlockTypes.FLOWING_LAVA) || b.equals(BlockTypes.FLOWING_WATER)) ||
        b.equals(BlockTypes.FIRE));
    }

    return false;
}
 
Example 3
Source File: WorldUtil.java    From Prism with MIT License 5 votes vote down vote up
public static int removeIllegalBlocks(Location<World> location, int radius) {
    final World world = location.getExtent();

    int xMin = location.getBlockX() - radius;
    int xMax = location.getBlockX() + radius;

    int zMin = location.getBlockZ() - radius;
    int zMax = location.getBlockZ() + radius;

    int yMin = location.getBlockY() - radius;
    int yMax = location.getBlockY() + radius;

    // Clamp Y basement
    if (yMin < 0) {
        yMin = 0;
    }

    // Clamp Y ceiling
    if (yMax >= world.getDimension().getBuildHeight()) {
        yMax = world.getDimension().getBuildHeight();
    }

    int changeCount = 0;
    for (int x = xMin; x <= xMax; x++) {
        for (int z = zMin; z <= zMax; z++) {
            for (int y = yMin; y <= yMax; y++) {
                BlockType existing = world.getBlock(x, y, z).getType();
                if (existing.equals(BlockTypes.FIRE) || existing.equals(BlockTypes.TNT)) {
                    world.setBlockType(x, y, z, BlockTypes.AIR);
                    changeCount++;
                }
            }
        }
    }

    return changeCount;
}
 
Example 4
Source File: BlockUtil.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Reject specific blocks from an applier because they're 99% going to do more harm.
 *
 * @param type BlockType
 * @return
 */
public static boolean rejectIllegalApplierBlock(BlockType type) {
    return (type.equals(BlockTypes.FIRE) ||
            type.equals(BlockTypes.TNT) ||
            type.equals(BlockTypes.LAVA) ||
            type.equals(BlockTypes.FLOWING_LAVA));
}
 
Example 5
Source File: BlockUtil.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Sponge's ChangeBlockEvent.Place covers a lot, but it also includes a lot
 * we don't want. So here we can setup checks to filter out block combinations.
 *
 * @param a BlockType original
 * @param b BlockType final
 * @return boolean True if combo should be rejected
 */
public static boolean rejectPlaceCombination(BlockType a, BlockType b) {
    return (
        // Just basic state changes
        a.equals(BlockTypes.LIT_FURNACE) || b.equals(BlockTypes.LIT_FURNACE) ||
        a.equals(BlockTypes.LIT_REDSTONE_LAMP) || b.equals(BlockTypes.LIT_REDSTONE_LAMP) ||
        a.equals(BlockTypes.LIT_REDSTONE_ORE) || b.equals(BlockTypes.LIT_REDSTONE_ORE) ||
        a.equals(BlockTypes.UNLIT_REDSTONE_TORCH) || b.equals(BlockTypes.UNLIT_REDSTONE_TORCH) ||
        (a.equals(BlockTypes.POWERED_REPEATER) && b.equals(BlockTypes.UNPOWERED_REPEATER)) ||
        (a.equals(BlockTypes.UNPOWERED_REPEATER) && b.equals(BlockTypes.POWERED_REPEATER)) ||
        (a.equals(BlockTypes.POWERED_COMPARATOR) && b.equals(BlockTypes.UNPOWERED_COMPARATOR)) ||
        (a.equals(BlockTypes.UNPOWERED_COMPARATOR) && b.equals(BlockTypes.POWERED_COMPARATOR)) ||

        // It's all water...
        (a.equals(BlockTypes.WATER) && b.equals(BlockTypes.FLOWING_WATER)) ||
        (a.equals(BlockTypes.FLOWING_WATER) && b.equals(BlockTypes.WATER)) ||

        // It's all lava....
        (a.equals(BlockTypes.LAVA) && b.equals(BlockTypes.FLOWING_LAVA)) ||
        (a.equals(BlockTypes.FLOWING_LAVA) && b.equals(BlockTypes.LAVA)) ||

        // Crap that fell into lava
        (a.equals(BlockTypes.LAVA) && b.equals(BlockTypes.GRAVEL)) ||
        (a.equals(BlockTypes.FLOWING_LAVA) && b.equals(BlockTypes.GRAVEL)) ||
        (a.equals(BlockTypes.LAVA) && b.equals(BlockTypes.SAND)) ||
        (a.equals(BlockTypes.FLOWING_LAVA) && b.equals(BlockTypes.SAND)) ||

        // It's fire (which didn't burn anything)
        (a.equals(BlockTypes.FIRE) && b.equals(BlockTypes.AIR)) ||

        // Piston
        a.equals(BlockTypes.PISTON_EXTENSION) || b.equals(BlockTypes.PISTON_EXTENSION) ||
        a.equals(BlockTypes.PISTON_HEAD) || b.equals(BlockTypes.PISTON_HEAD) ||

        // You can't place air
        b.equals(BlockTypes.AIR)
    );
}
 
Example 6
Source File: BlockUtil.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Sponge's ChangeBlockEvent.Break covers a lot, but it also includes a lot
 * we don't want. So here we can setup checks to filter out block combinations.
 *
 * @param a BlockType original
 * @param b BlockType final
 * @return boolean True if combo should be rejected
 */
public static boolean rejectBreakCombination(BlockType a, BlockType b) {
    return (
        // You can't break these...
        a.equals(BlockTypes.FIRE) ||
        a.equals(BlockTypes.AIR) ||

        // Note, see "natural flow" comment above.
        ((a.equals(BlockTypes.FLOWING_WATER) || a.equals(BlockTypes.FLOWING_LAVA)) && b.equals(BlockTypes.AIR)) ||

        // Piston
        a.equals(BlockTypes.PISTON_EXTENSION) || b.equals(BlockTypes.PISTON_EXTENSION) ||
        a.equals(BlockTypes.PISTON_HEAD) || b.equals(BlockTypes.PISTON_HEAD)
    );
}
 
Example 7
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handletp(CommandSource source, String rname, World world, Player play) {
    Region region = RedProtect.get().rm.getRegion(rname, world.getName());
    if (region == null) {
        RedProtect.get().lang.sendMessage(source, RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + rname);
        return;
    }

    if (play == null) {
        if (source instanceof Player && !RedProtect.get().ph.hasRegionPermMember((Player) source, "teleport", region)) {
            RedProtect.get().lang.sendMessage(source, "no.permission");
            return;
        }
    } else {
        if (!RedProtect.get().ph.hasPerm(source, "redprotect.command.admin.teleport")) {
            RedProtect.get().lang.sendMessage(source, "no.permission");
            return;
        }
    }

    Location<World> loc = null;
    if (region.getTPPoint() != null) {
        loc = new Location<>(world, region.getTPPoint().getBlockX() + 0.500, region.getTPPoint().getBlockY(), region.getTPPoint().getBlockZ() + 0.500);
    } else {
        int limit = world.getBlockMax().getY();
        if (world.getDimension().getType().equals(DimensionTypes.NETHER)) {
            limit = 124;
        }
        for (int i = limit; i > 0; i--) {
            BlockType mat = world.createSnapshot(region.getCenterX(), i, region.getCenterZ()).getState().getType();
            BlockType mat1 = world.createSnapshot(region.getCenterX(), i + 1, region.getCenterZ()).getState().getType();
            BlockType mat2 = world.createSnapshot(region.getCenterX(), i + 2, region.getCenterZ()).getState().getType();
            if (!mat.equals(BlockTypes.LAVA) && !mat.equals(BlockTypes.AIR) && mat1.equals(BlockTypes.AIR) && mat2.equals(BlockTypes.AIR)) {
                loc = new Location<>(world, region.getCenterX() + 0.500, i + 1, region.getCenterZ() + 0.500);
                break;
            }
        }
    }

    if (loc != null) {
        if (play != null) {
            play.setLocation(loc);
            RedProtect.get().lang.sendMessage(play, RedProtect.get().lang.get("cmdmanager.region.teleport") + " " + rname);
            RedProtect.get().lang.sendMessage(source, RedProtect.get().lang.get("cmdmanager.region.tpother") + " " + rname);
        } else if (source instanceof Player) {
            tpWait((Player) source, loc, rname);
        }
    }
}