org.spongepowered.api.block.BlockTypes Java Examples

The following examples show how to use org.spongepowered.api.block.BlockTypes. 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: EconomyUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
private Consumer<CommandSource> createSellCancelConfirmed(CommandSource src, Claim claim, Sign sign) {
    return confirm -> {
        if (!claim.getEconomyData().isForSale()) {
            return;
        }
        Location<World> location = null;
        if (sign != null) {
            location = sign.getLocation();
        } else {
            final Sign saleSign = SignUtil.getSign(((GDClaim) claim).getWorld(), claim.getEconomyData().getSaleSignPosition());
            if (saleSign != null) {
                location = saleSign.getLocation();
            }
        }
        if (location != null && location.getBlockType() != BlockTypes.AIR) {
            location.setBlockType(BlockTypes.AIR);
            SignUtil.resetSellData(claim);
            claim.getData().save();
            GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().ECONOMY_CLAIM_SALE_CANCELLED);
        }
    };
}
 
Example #2
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private void coverSurfaceStone() {
    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            int y = this.highestY(x, z, true);
            BlockSnapshot block = snapshots[x][y][z];

            if (block.getState().getType() == BlockTypes.STONE || block.getState().getType() == BlockTypes.GRAVEL
                    || block.getState().getType() == BlockTypes.FARMLAND
                    || block.getState().getType() == BlockTypes.DIRT || block.getState().getType() == BlockTypes.SANDSTONE) {
                if (this.biome == BiomeTypes.DESERT || this.biome == BiomeTypes.DESERT_HILLS || this.biome == BiomeTypes.BEACH) {
                    this.snapshots[x][y][z] = this.snapshots[x][y][z].withState(BlockTypes.SAND.getDefaultState());
                } else {
                    this.snapshots[x][y][z] = this.snapshots[x][y][z].withState(BlockTypes.GRASS.getDefaultState());
                }
            }
        }
    }
}
 
Example #3
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private void removeHanging() {
    int miny = this.miny;
    if (miny < 1) {
        miny = 1;
    }

    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            for (int y = miny; y < snapshots[0].length - 1; y++) {
                BlockSnapshot block = snapshots[x][y][z];
                BlockSnapshot underBlock = snapshots[x][y - 1][z];

                if (underBlock.getState().getType() == BlockTypes.AIR || underBlock.getState().getType() == BlockTypes.WATER
                        || underBlock.getState().getType() == BlockTypes.LAVA || underBlock.getState().getType() == BlockTypes.LEAVES) {
                    if (this.notAllowedToHang.contains(block.getState().getType())) {
                        snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example #4
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private void removePlayerBlocks() {
    int miny = this.miny;
    if (miny < 1) {
        miny = 1;
    }

    // remove all player blocks
    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            for (int y = miny; y < snapshots[0].length - 1; y++) {
                BlockSnapshot block = snapshots[x][y][z];
                if (this.playerBlocks.contains(block.getState().getType())) {
                    snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState());
                }
            }
        }
    }
}
 
Example #5
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private void removeDumpedFluids() {
    if (this.seaLevel < 1) {
        return;
    }

    // remove any surface water or lava above sea level, presumed to be
    // placed by players
    // sometimes, this is naturally generated. but replacing it is very easy
    // with a bucket, so overall this is a good plan
    if (this.environment.equals(DimensionTypes.NETHER)) {
        return;
    }
    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            for (int y = this.seaLevel - 1; y < snapshots[0].length - 1; y++) {
                BlockSnapshot block = snapshots[x][y][z];
                if (block.getState().getType() == BlockTypes.WATER || block.getState().getType() == BlockTypes.LAVA ||
                        block.getState().getType() == BlockTypes.WATER || block.getState().getType() == BlockTypes.LAVA) {
                    snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState());
                }
            }
        }
    }
}
 
Example #6
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private int highestY(int x, int z, boolean ignoreLeaves) {
    int y;
    for (y = snapshots[0].length - 1; y > 0; y--) {
        BlockSnapshot block = this.snapshots[x][y][z];
        if (block.getState().getType() != BlockTypes.AIR &&
                !(ignoreLeaves && block.getState().getType() == BlockTypes.SNOW) &&
                !(ignoreLeaves && block.getState().getType() == BlockTypes.LEAVES) &&
                !(block.getState().getType() == BlockTypes.WATER) &&
                !(block.getState().getType() == BlockTypes.FLOWING_WATER) &&
                !(block.getState().getType() == BlockTypes.LAVA) &&
                !(block.getState().getType() == BlockTypes.FLOWING_LAVA)) {
            return y;
        }
    }

    return y;
}
 
Example #7
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(ChangeBlockEvent.Break e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event");

    BlockState sourceState = locatable.getBlockState();

    if (sourceState.getType() == BlockTypes.FIRE) {
        BlockSnapshot b = e.getTransactions().get(0).getOriginal();
        boolean fireDamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).fire_block_damage;
        if (!fireDamage && b.getState().getType() != BlockTypes.FIRE) {
            Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
            if (r == null) {
                RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to break from FIRE!");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #8
Source File: RestoreNatureProcessingTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private void removePlayerLeaves() {
    if (this.seaLevel < 1) {
        return;
    }

    for (int x = 1; x < snapshots.length - 1; x++) {
        for (int z = 1; z < snapshots[0][0].length - 1; z++) {
            for (int y = this.seaLevel - 1; y < snapshots[0].length; y++) {
                // note: see minecraft wiki data values for leaves
                BlockSnapshot block = snapshots[x][y][z];
                if (block.getState().getType() == BlockTypes.LEAVES && (BlockUtils.getBlockStateMeta(block.getState()) & 0x4) != 0) {
                    snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState());
                }
            }
        }
    }
}
 
Example #9
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l;

    RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event");

    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }

    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());
    if (r != null) {
        ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p);
        if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
            event.setCancelled(true);
        }
    }
}
 
Example #10
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(ChangeBlockEvent.Place e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onFireSpread event!");

    BlockState sourceState = locatable.getBlockState();

    if (e.getTransactions().get(0).getFinal().getState().getType().equals(BlockTypes.FIRE) &&
            (sourceState.getType() == BlockTypes.FIRE || sourceState.getType() == BlockTypes.LAVA || sourceState.getType() == BlockTypes.FLOWING_LAVA)) {
        boolean fireDamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).fire_spread;
        if (!fireDamage) {
            Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get(), this.getClass().getName());
            if (r == null) {
                RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to PLACE FIRE!");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #11
Source File: ExtinguishCommand.java    From Prism with MIT License 6 votes vote down vote up
public static CommandSpec getCommand() {
    return CommandSpec.builder()
        .permission("prism.extinguish")
        .arguments(GenericArguments.integer(Text.of("radius")))
        .executor((source, args) -> {
            if (!(source instanceof Player)) {
                throw new CommandException(Format.error("You must be a player to use this command."));
            }

            int radius = args.<Integer>getOne("radius").get();
            int changes = WorldUtil.removeAroundFromLocation(
                BlockTypes.FIRE, ((Player) source).getLocation(), radius);

            source.sendMessage(Format.message(String.format("Removed %d matches within %d blocks", changes, radius)));

            return CommandResult.success();
        })
        .build();
}
 
Example #12
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event");

    BlockState sourceState = locatable.getBlockState();

    //liquid check
    MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
    if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
        e.getLocations().forEach(loc -> {
            Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());
            if (r == null) {
                boolean flow = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.liquid_flow;
                boolean allowWater = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.water_flow;
                boolean allowLava = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.lava_flow;

                if (!flow)
                    e.setCancelled(true);
                if (!allowWater && (loc.getBlockType() == BlockTypes.WATER || loc.getBlockType() == BlockTypes.FLOWING_WATER))
                    e.setCancelled(true);
                if (!allowLava && (loc.getBlockType() == BlockTypes.LAVA || loc.getBlockType() == BlockTypes.FLOWING_LAVA))
                    e.setCancelled(true);
            }
        });
    }
}
 
Example #13
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onIceForm(ChangeBlockEvent e) {
    if (e.getTransactions().isEmpty()) return;

    Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getFinal().getLocation().get(), this.getClass().getName());

    if (r == null && (e.getTransactions().get(0).getOriginal().getState().getType().equals(BlockTypes.ICE) ||
            e.getTransactions().get(0).getOriginal().getState().getType().equals(BlockTypes.FROSTED_ICE))) {
        if (e.getCause().containsType(Player.class)) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(e.getTransactions().get(0).getFinal().getLocation().get().getExtent().getName()).iceform_by.player) {
                e.setCancelled(true);
            }
        } else if (!RedProtect.get().config.globalFlagsRoot().worlds.get(e.getTransactions().get(0).getFinal().getLocation().get().getExtent().getName()).iceform_by.entity) {
            e.setCancelled(true);
        }
    }
}
 
Example #14
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGeneric(ChangeBlockEvent.Break e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event");

    LocatableBlock locatable = e.getCause().first(LocatableBlock.class).orElse(null);
    if (locatable != null) {
        BlockState sourceState = locatable.getBlockState();

        //liquid check
        MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
        if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
            boolean allowdamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.flow_damage;

            Region r = RedProtect.get().rm.getTopRegion(locatable.getLocation(), this.getClass().getName());
            if (r == null && !allowdamage && locatable.getLocation().getBlockType() != BlockTypes.AIR) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example #15
Source File: BlockUtil.java    From Prism with MIT License 6 votes vote down vote up
/**
 * Get a list of all LIQUID block types.
 *
 * @return List<BlockType>
 */
public static List<BlockType> getLiquidBlockTypes() {
    List<BlockType> liquids = new ArrayList<>();

    Collection<BlockType> types = Sponge.getRegistry().getAllOf(BlockType.class);
    for (BlockType type : types) {
        Optional<MatterProperty> property = type.getProperty(MatterProperty.class);
        if (property.isPresent() && Objects.equals(property.get().getValue(), Matter.LIQUID)) {
            liquids.add(type);
        }
    }

    // @todo Sponge has not yet implemented the MatterProperties...
    liquids.add(BlockTypes.LAVA);
    liquids.add(BlockTypes.FLOWING_LAVA);
    liquids.add(BlockTypes.WATER);
    liquids.add(BlockTypes.FLOWING_WATER);

    return liquids;
}
 
Example #16
Source File: FireListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.EARLY, beforeModifications = true)
public void onFire(ChangeBlockEvent event)
{
	if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	event
	.getTransactions()
	.stream()
	.filter(trans -> trans.getFinal().getState().getType() == BlockTypes.FIRE)
	.filter(trans -> {
		Optional<Location<World>> optLoc = trans.getFinal().getLocation();
		if (!optLoc.isPresent())
			return false;
		return !DataHandler.getFlag("fire", optLoc.get());
	})
	.forEach(trans -> trans.setValid(false));
}
 
Example #17
Source File: InteractPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onInteract(InteractBlockEvent event, @First Player player)
{
	if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (player.hasPermission("nations.admin.bypass.perm.interact"))
	{
		return;
	}
	Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
	if (optItem.isPresent() && (ConfigHandler.isWhitelisted("use", optItem.get().getItem().getId()) || optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE) && ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true)))
		return;
	event.getTargetBlock().getLocation().ifPresent(loc -> {
		if (!DataHandler.getPerm("interact", player.getUniqueId(), loc))
		{
			event.setCancelled(true);
			if (loc.getBlockType() != BlockTypes.STANDING_SIGN && loc.getBlockType() != BlockTypes.WALL_SIGN)
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT));
		}
	});
}
 
Example #18
Source File: PlayerInteractListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockInteract(final InteractBlockEvent event, @Root final Player player)
{
    //If AIR or NONE then return
    if (event.getTargetBlock() == BlockSnapshot.NONE || event.getTargetBlock().getState().getType() == BlockTypes.AIR)
        return;

    final Optional<Location<World>> optionalLocation = event.getTargetBlock().getLocation();
    if (!optionalLocation.isPresent())
        return;

    final Location<World> blockLocation = optionalLocation.get();

    final ProtectionResult protectionResult = super.getPlugin().getProtectionManager().canInteractWithBlock(blockLocation, player, true);
    if (!protectionResult.hasAccess())
    {
        event.setCancelled(true);
        return;
    }
    else
    {
        if(event instanceof InteractBlockEvent.Secondary && protectionResult.isEagleFeather())
            removeEagleFeather(player);
    }
}
 
Example #19
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockStartBurn(IgniteEntityEvent e) {

    Entity b = e.getTargetEntity();
    Cause ignit = e.getCause();

    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockIgniteEvent event.");

    Region r = RedProtect.get().rm.getTopRegion(b.getLocation(), this.getClass().getName());
    if (r != null && !r.canFire()) {
        if (ignit.first(Player.class).isPresent()) {
            Player p = ignit.first(Player.class).get();
            if (!r.canBuild(p)) {
                RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace");
                e.setCancelled(true);
                return;
            }
        } else {
            e.setCancelled(true);
            return;
        }

        if (ignit.first(BlockSnapshot.class).isPresent() && (ignit.first(BlockSnapshot.class).get().getState().getType().equals(BlockTypes.FIRE) || ignit.first(BlockSnapshot.class).get().getState().getType().getName().contains("lava"))) {
            e.setCancelled(true);
            return;
        }
        if (ignit.first(Lightning.class).isPresent() || ignit.first(Explosion.class).isPresent() || ignit.first(Fireball.class).isPresent()) {
            e.setCancelled(true);
        }
    }
}
 
Example #20
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 #21
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 #22
Source File: WorldUtil.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Remove a specific block from a given radius around a region.
 *
 * @param type BlockType to remove.
 * @param location Location center
 * @param radius Integer radius around location
 * @return integer Count of removals
 */
public static int removeAroundFromLocation(BlockType type, 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++) {
                if (world.getBlock(x, y, z).getType().equals(type)) {
                    world.setBlockType(x, y, z, BlockTypes.AIR);
                    changeCount++;
                }
            }
        }
    }

    return changeCount;
}
 
Example #23
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 #24
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 #25
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 #26
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public Transform<World> DenyEnterPlayer(World wFrom, Transform<World> from, Transform<World> to, Region r, boolean checkSec) {
    Location<World> setFrom = from.getLocation();
    for (int i = 0; i < r.getArea() + 10; i++) {
        Region r1 = RedProtect.get().rm.getTopRegion(wFrom.getName(), setFrom.getBlockX() + i, setFrom.getBlockY(), setFrom.getBlockZ(), RedProtectUtil.class.getName());
        Region r2 = RedProtect.get().rm.getTopRegion(wFrom.getName(), setFrom.getBlockX() - i, setFrom.getBlockY(), setFrom.getBlockZ(), RedProtectUtil.class.getName());
        Region r3 = RedProtect.get().rm.getTopRegion(wFrom.getName(), setFrom.getBlockX(), setFrom.getBlockY(), setFrom.getBlockZ() + i, RedProtectUtil.class.getName());
        Region r4 = RedProtect.get().rm.getTopRegion(wFrom.getName(), setFrom.getBlockX(), setFrom.getBlockY(), setFrom.getBlockZ() - i, RedProtectUtil.class.getName());
        Region r5 = RedProtect.get().rm.getTopRegion(wFrom.getName(), setFrom.getBlockX() + i, setFrom.getBlockY(), setFrom.getBlockZ() + i, RedProtectUtil.class.getName());
        Region r6 = RedProtect.get().rm.getTopRegion(wFrom.getName(), setFrom.getBlockX() - i, setFrom.getBlockY(), setFrom.getBlockZ() - i, RedProtectUtil.class.getName());
        if (r1 != r) {
            to = new Transform<>(setFrom.add(+i, 0, 0)).setRotation(from.getRotation());
            break;
        }
        if (r2 != r) {
            to = new Transform<>(setFrom.add(-i, 0, 0)).setRotation(from.getRotation());
            break;
        }
        if (r3 != r) {
            to = new Transform<>(setFrom.add(0, 0, +i)).setRotation(from.getRotation());
            break;
        }
        if (r4 != r) {
            to = new Transform<>(setFrom.add(0, 0, -i)).setRotation(from.getRotation());
            break;
        }
        if (r5 != r) {
            to = new Transform<>(setFrom.add(+i, 0, +i)).setRotation(from.getRotation());
            break;
        }
        if (r6 != r) {
            to = new Transform<>(setFrom.add(-i, 0, -i)).setRotation(from.getRotation());
            break;
        }
    }
    if (checkSec && !isSecure(to.getLocation())) {
        RedProtect.get().getVersionHelper().setBlock(to.getLocation().getBlockRelative(Direction.DOWN), BlockTypes.GRASS.getDefaultState());
    }
    return to;
}
 
Example #27
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST)
public void onInteractLeft(InteractBlockEvent.Primary event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l;

    RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Primary event");

    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - Is InteractBlockEvent.Primary event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }

    ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p);

    String claimmode = RedProtect.get().config.getWorldClaimType(p.getWorld().getName());
    if (event instanceof InteractBlockEvent.Primary.MainHand && itemInHand.getId().equalsIgnoreCase(RedProtect.get().config.configRoot().wands.adminWandID) && ((claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.claim"))) {
        if (!RedProtect.get().getUtil().canBuildNear(p, l)) {
            event.setCancelled(true);
            return;
        }
        RedProtect.get().firstLocationSelections.put(p, l);
        p.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("playerlistener.wand1") + RedProtect.get().lang.get("general.color") + " (&e" + l.getBlockX() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockY() + RedProtect.get().lang.get("general.color") + ", &e" + l.getBlockZ() + RedProtect.get().lang.get("general.color") + ")."));
        event.setCancelled(true);

        //show preview border
        previewSelection(p);
    }
}
 
Example #28
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 #29
Source File: DoorManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public static void ChangeDoor(BlockSnapshot b, Region r) {
    if ((!r.flagExists("smart-door") && !RedProtect.get().config.configRoot().flags.get("smart-door")) || !r.getFlagBool("smart-door")) {
        return;
    }

    Location<World> loc = b.getLocation().get();
    World w = loc.getExtent();

    if (isDoor(b)) {
        boolean iron = b.getState().getType() == BlockTypes.IRON_DOOR;
        if (iron) {
            changeDoorState(b);
            if (getDoorState(b)) {
                w.playSound(SoundTypes.BLOCK_IRON_DOOR_OPEN, loc.getPosition(), 1);
            } else {
                w.playSound(SoundTypes.BLOCK_IRON_DOOR_CLOSE, loc.getPosition(), 1);
            }
        }

        if (loc.getRelative(Direction.DOWN).getBlock().getType() == b.getState().getType() && loc.get(Keys.PORTION_TYPE).get() == PortionTypes.TOP) {
            loc = loc.getRelative(Direction.DOWN);
        }

        //check side block if is door
        BlockSnapshot[] block = new BlockSnapshot[4];
        block[0] = loc.getRelative(Direction.EAST).createSnapshot();
        block[1] = loc.getRelative(Direction.WEST).createSnapshot();
        block[2] = loc.getRelative(Direction.NORTH).createSnapshot();
        block[3] = loc.getRelative(Direction.SOUTH).createSnapshot();

        for (BlockSnapshot b2 : block) {
            if (b.getState().getType() == b2.getState().getType()) {
                changeDoorState(b2);
                break;
            }
        }
    }
}
 
Example #30
Source File: EconomyManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public static long getRegionValue(Region r) {
    long regionCost = 0;
    World w = RedProtect.get().getServer().getWorld(r.getWorld()).get();
    int maxX = r.getMaxMbrX();
    int minX = r.getMinMbrX();
    int maxZ = r.getMaxMbrZ();
    int minZ = r.getMinMbrZ();
    for (int x = minX; x < maxX; x++) {
        for (int y = 0; y < 256; y++) {
            for (int z = minZ; z < maxZ; z++) {

                BlockSnapshot b = w.createSnapshot(x, y, z);
                if (b.getState().getType().equals(BlockTypes.AIR)) {
                    continue;
                }

                if (b.getLocation().get().getTileEntity().isPresent()) {
                    TileEntity invTile = b.getLocation().get().getTileEntity().get();
                    if (invTile instanceof TileEntityInventory) {
                        TileEntityInventory<?> inv = (TileEntityInventory<?>) invTile;
                        regionCost += getInvValue(inv.slots());
                    }
                } else {
                    regionCost += RedProtect.get().config.ecoRoot().items.values.get(b.getState().getType().getName());
                }
            }
        }
    }
    r.setValue(regionCost);
    return regionCost;
}