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);
}
}
}
}
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);
}
}
}
}
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"));
}
}
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"));
}
}
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));
}
}
}
Aggregations