Search in sources :

Example 1 with TreeType

use of org.bukkit.TreeType in project Glowstone by GlowstoneMC.

the class BlockMushroom method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    TreeType type;
    if (mushroomType == Material.BROWN_MUSHROOM) {
        type = TreeType.BROWN_MUSHROOM;
    } else if (mushroomType == Material.RED_MUSHROOM) {
        type = TreeType.RED_MUSHROOM;
    } else {
        return;
    }
    Location loc = block.getLocation();
    BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
    if (GlowTree.newInstance(type, random, loc, blockStateDelegate).generate()) {
        List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
        StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, true, player, blockStates);
        EventFactory.callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            for (BlockState state : blockStates) {
                state.update(true);
            }
        }
    }
}
Also used : TreeType(org.bukkit.TreeType) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) ArrayList(java.util.ArrayList) StructureGrowEvent(org.bukkit.event.world.StructureGrowEvent) Location(org.bukkit.Location)

Example 2 with TreeType

use of org.bukkit.TreeType in project Glowstone by GlowstoneMC.

the class BlockSapling method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt(7) == 0) {
        int dataValue = block.getData();
        if ((dataValue & 8) == 0) {
            block.setData((byte) (dataValue | 8));
        } else {
            MaterialData data = block.getState().getData();
            if (data instanceof Sapling) {
                Sapling sapling = (Sapling) data;
                TreeType type = getTreeType(sapling.getSpecies());
                block.setType(Material.AIR);
                int saplingData = block.getData() & 0x7;
                if (!block.getWorld().generateTree(block.getLocation(), type)) {
                    block.setType(Material.SAPLING);
                    block.setData((byte) saplingData);
                }
            } else {
                warnMaterialData(Sapling.class, data);
            }
        }
    }
}
Also used : Sapling(org.bukkit.material.Sapling) TreeType(org.bukkit.TreeType) MaterialData(org.bukkit.material.MaterialData)

Example 3 with TreeType

use of org.bukkit.TreeType in project Essentials by drtshock.

the class Commandtree method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    TreeType tree = null;
    if (args.length < 1) {
        throw new NotEnoughArgumentsException();
    } else {
        for (TreeType type : TreeType.values()) {
            if (type.name().replace("_", "").equalsIgnoreCase(args[0])) {
                tree = type;
                break;
            }
        }
        if (args[0].equalsIgnoreCase("jungle")) {
            tree = TreeType.SMALL_JUNGLE;
        }
        if (tree == null) {
            throw new NotEnoughArgumentsException();
        }
    }
    final Location loc = LocationUtil.getTarget(user.getBase());
    final Location safeLocation = LocationUtil.getSafeDestination(loc);
    final boolean success = user.getWorld().generateTree(safeLocation, tree);
    if (success) {
        user.sendMessage(tl("treeSpawned"));
    } else {
        user.sendMessage(tl("treeFailure"));
    }
}
Also used : TreeType(org.bukkit.TreeType) Location(org.bukkit.Location)

Example 4 with TreeType

use of org.bukkit.TreeType in project Essentials by drtshock.

the class Commandbigtree method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    TreeType tree;
    if (args.length > 0 && args[0].equalsIgnoreCase("redwood")) {
        tree = TreeType.TALL_REDWOOD;
    } else if (args.length > 0 && args[0].equalsIgnoreCase("tree")) {
        tree = TreeType.BIG_TREE;
    } else if (args.length > 0 && args[0].equalsIgnoreCase("jungle")) {
        tree = TreeType.JUNGLE;
    } else {
        throw new NotEnoughArgumentsException();
    }
    final Location loc = LocationUtil.getTarget(user.getBase());
    final Location safeLocation = LocationUtil.getSafeDestination(loc);
    final boolean success = user.getWorld().generateTree(safeLocation, tree);
    if (success) {
        user.sendMessage(tl("bigTreeSuccess"));
    } else {
        throw new Exception(tl("bigTreeFailure"));
    }
}
Also used : TreeType(org.bukkit.TreeType) Location(org.bukkit.Location)

Example 5 with TreeType

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

the class PrismWorldEvents method onStructureGrow.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onStructureGrow(final StructureGrowEvent event) {
    String type = "tree-grow";
    final TreeType species = event.getSpecies();
    if (species != null && species.name().toLowerCase().contains("mushroom"))
        type = "mushroom-grow";
    if (!Prism.getIgnore().event(type, event.getWorld()))
        return;
    for (final BlockState block : event.getBlocks()) {
        if (me.botsko.elixr.BlockUtils.isGrowableStructure(block.getType())) {
            String player = "Environment";
            if (event.getPlayer() != null) {
                player = event.getPlayer().getName();
            }
            RecordingQueue.addToQueue(ActionFactory.createGrow(type, block, player));
        }
    }
}
Also used : TreeType(org.bukkit.TreeType) BlockState(org.bukkit.block.BlockState) EventHandler(org.bukkit.event.EventHandler)

Aggregations

TreeType (org.bukkit.TreeType)5 Location (org.bukkit.Location)3 BlockState (org.bukkit.block.BlockState)2 ArrayList (java.util.ArrayList)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 BlockStateDelegate (net.glowstone.util.BlockStateDelegate)1 EventHandler (org.bukkit.event.EventHandler)1 StructureGrowEvent (org.bukkit.event.world.StructureGrowEvent)1 MaterialData (org.bukkit.material.MaterialData)1 Sapling (org.bukkit.material.Sapling)1