Search in sources :

Example 46 with BlockState

use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.

the class OreMonitor method processAlertsFromBlock.

/**
     * 
     * @param player
     * @param block
     */
public void processAlertsFromBlock(final Player player, final Block block) {
    if (!plugin.getConfig().getBoolean("prism.alerts.ores.enabled")) {
        return;
    }
    if (player == null || player.getGameMode() == null || player.getGameMode().equals(GameMode.CREATIVE)) {
        return;
    }
    if (block != null && isWatched(block) && !plugin.alertedBlocks.containsKey(block.getLocation())) {
        threshold = 1;
        // identify all ore blocks on same Y axis in x/z direction
        final ArrayList<Block> matchingBlocks = new ArrayList<Block>();
        final ArrayList<Block> foundores = findNeighborBlocks(block.getType(), block, matchingBlocks);
        if (!foundores.isEmpty()) {
            // Save the block
            final BlockState state = block.getState();
            // Set to air to get the light
            block.setType(Material.AIR);
            int light = block.getLightLevel();
            light = (light > 0 ? Math.round(((light) & 0xFF) * 100) / 15 : 0);
            // Restore the block
            block.setType(state.getType());
            final String count = foundores.size() + (foundores.size() >= threshold_max ? "+" : "");
            final String msg = getOreColor(block) + player.getName() + " found " + count + " " + getOreNiceName(block) + " " + light + "% light";
            /**
                 * Run the lookup itself in an async task so the lookup query
                 * isn't done on the main thread
                 */
            plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {

                @Override
                public void run() {
                    // check if block placed
                    boolean wasplaced = false;
                    // Build params
                    final QueryParameters params = new QueryParameters();
                    params.setWorld(player.getWorld().getName());
                    params.addSpecificBlockLocation(block.getLocation());
                    params.addActionType("block-place");
                    final ActionsQuery aq = new ActionsQuery(plugin);
                    final QueryResult results = aq.lookup(params, player);
                    if (!results.getActionResults().isEmpty()) {
                        wasplaced = true;
                    }
                    if (!wasplaced) {
                        // Alert staff
                        plugin.alertPlayers(null, TypeUtils.colorize(msg));
                        // Log to console
                        if (plugin.getConfig().getBoolean("prism.alerts.ores.log-to-console")) {
                            Prism.log(msg);
                        }
                        // Log to commands
                        List<String> commands = plugin.getConfig().getStringList("prism.alerts.ores.log-commands");
                        MiscUtils.dispatchAlert(msg, commands);
                    }
                }
            });
        }
    }
}
Also used : QueryResult(me.botsko.prism.actionlibs.QueryResult) BlockState(org.bukkit.block.BlockState) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) QueryParameters(me.botsko.prism.actionlibs.QueryParameters)

Example 47 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class BlockChest method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Chest) {
        Chest chest = (Chest) data;
        GlowBlock chestBlock = state.getBlock();
        BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
        Collection<BlockFace> attachedChests = searchChests(chestBlock);
        if (attachedChests.isEmpty()) {
            chest.setFacingDirection(normalFacing);
            state.setData(chest);
            return;
        } else if (attachedChests.size() > 1) {
            GlowServer.logger.warning("Chest placed near two other chests!");
            return;
        }
        BlockFace otherPart = attachedChests.iterator().next();
        GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
        if (getAttachedChest(otherPartBlock) != null) {
            GlowServer.logger.warning("Chest placed near already attached chest!");
            return;
        }
        BlockState otherPartState = otherPartBlock.getState();
        MaterialData otherPartData = otherPartState.getData();
        if (otherPartData instanceof Chest) {
            Chest otherChest = (Chest) otherPartData;
            BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
            chest.setFacingDirection(facing);
            state.setData(chest);
            otherChest.setFacingDirection(facing);
            otherPartState.setData(otherChest);
            otherPartState.update();
        } else {
            warnMaterialData(Chest.class, otherPartData);
        }
    } else {
        warnMaterialData(Chest.class, data);
    }
}
Also used : Chest(org.bukkit.material.Chest) GlowBlock(net.glowstone.block.GlowBlock) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Example 48 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class BlockChest method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    BlockState state = block.getState();
    if (state instanceof org.bukkit.block.Chest) {
        org.bukkit.block.Chest chest = (org.bukkit.block.Chest) state;
        player.openInventory(chest.getInventory());
        player.incrementStatistic(Statistic.CHEST_OPENED);
        return true;
    }
    GlowServer.logger.warning("Calling blockInteract on BlockChest, but BlockState is " + state);
    return false;
}
Also used : Chest(org.bukkit.material.Chest) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState)

Example 49 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class OreVein method generate.

public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    float angle = random.nextFloat() * (float) Math.PI;
    double dx1 = sourceX + Math.sin(angle) * amount / 8.0F;
    double dx2 = sourceX - Math.sin(angle) * amount / 8.0F;
    double dz1 = sourceZ + Math.cos(angle) * amount / 8.0F;
    double dz2 = sourceZ - Math.cos(angle) * amount / 8.0F;
    double dy1 = sourceY + random.nextInt(3) - 2;
    double dy2 = sourceY + random.nextInt(3) - 2;
    for (int i = 0; i < amount; i++) {
        double originX = dx1 + (dx2 - dx1) * i / amount;
        double originY = dy1 + (dy2 - dy1) * i / amount;
        double originZ = dz1 + (dz2 - dz1) * i / amount;
        double q = random.nextDouble() * amount / 16.0D;
        double hRadius = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
        double vRadius = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
        for (int x = (int) (originX - hRadius); x <= (int) (originX - hRadius); x++) {
            double pX = (x + 0.5D - originX) / hRadius;
            pX *= pX;
            if (pX < 1) {
                for (int y = (int) (originY - vRadius); y <= (int) (originY + vRadius); y++) {
                    double pY = (y + 0.5D - originY) / vRadius;
                    pY *= pY;
                    if (pX + pY < 1) {
                        for (int z = (int) (originZ - hRadius); z <= (int) (originZ + hRadius); z++) {
                            double pZ = (z + 0.5D - originZ) / hRadius;
                            pZ *= pZ;
                            if (pX + pY + pZ < 1 && world.getBlockAt(x, y, z).getType() == targetType) {
                                BlockState state = world.getBlockAt(x, y, z).getState();
                                state.setType(type);
                                state.setData(data);
                                state.update(true);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState)

Example 50 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class StoneBoulder method generate.

public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    boolean groundReached = false;
    while (!groundReached && sourceY > 3) {
        Block block = world.getBlockAt(sourceX, sourceY - 1, sourceZ);
        if (!block.isEmpty()) {
            for (Material mat : GROUND_TYPES) {
                if (mat == block.getType()) {
                    groundReached = true;
                    sourceY++;
                    break;
                }
            }
        }
        sourceY--;
    }
    if (groundReached && world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()) {
        for (int i = 0; i < 3; i++) {
            int radiusX = random.nextInt(2);
            int radiusZ = random.nextInt(2);
            int radiusY = random.nextInt(2);
            float f = (radiusX + radiusZ + radiusY) * 0.333F + 0.5F;
            for (int x = -radiusX; x <= radiusX; x++) {
                for (int z = -radiusZ; z <= radiusZ; z++) {
                    for (int y = -radiusY; y <= radiusY; y++) {
                        if (x * x + z * z + y * y <= f * f) {
                            BlockState state = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z).getState();
                            Block blockAbove = state.getBlock().getRelative(BlockFace.UP);
                            for (Material mat : PLANT_TYPES) {
                                if (blockAbove.getType() == mat) {
                                    if (mat == Material.DOUBLE_PLANT && blockAbove.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAbove.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
                                        blockAbove.getRelative(BlockFace.UP).setType(Material.AIR);
                                    }
                                    blockAbove.setType(Material.AIR);
                                    break;
                                }
                            }
                            state.setType(Material.MOSSY_COBBLESTONE);
                            state.setData(new MaterialData(Material.MOSSY_COBBLESTONE));
                            state.update(true);
                        }
                    }
                }
            }
            sourceX += random.nextInt(4) - 1;
            sourceZ += random.nextInt(4) - 1;
            sourceY -= random.nextInt(2);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) DoublePlant(org.bukkit.material.DoublePlant)

Aggregations

BlockState (org.bukkit.block.BlockState)62 Block (org.bukkit.block.Block)27 EventHandler (org.bukkit.event.EventHandler)16 Location (org.bukkit.Location)12 MaterialData (org.bukkit.material.MaterialData)12 BlockFace (org.bukkit.block.BlockFace)8 Material (org.bukkit.Material)7 World (org.bukkit.World)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 ItemStack (org.bukkit.inventory.ItemStack)5 BlockStateChange (me.botsko.prism.events.BlockStateChange)4 GlowBlockState (net.glowstone.block.GlowBlockState)4 CreatureSpawner (org.bukkit.block.CreatureSpawner)4 Sign (org.bukkit.block.Sign)4 Vector (org.bukkit.util.Vector)4 GlowBlock (net.glowstone.block.GlowBlock)3 TreeType (org.bukkit.TreeType)3 InventoryHolder (org.bukkit.inventory.InventoryHolder)3 HashMap (java.util.HashMap)2