public EntityFallingBlockData(FallingBlock fallingBlock) { byte data = NMSUtils.getBlockData(fallingBlock); material = new com.elmakers.mine.bukkit.block.MaterialAndData(fallingBlock.getMaterial(), data); fallingBlock.setDropItem(dropItems); fallingBlock.setHurtEntities(hurtEntities); }
/** * Gets the lower-cased name of a given Entity<br> * - Items will get the name 'item' with the item type appended to it<br> * - Falling blocks will get the name 'falling' with the block type appended to it * * @param entity to get the name of * @return Entity name */ public static String getName(Entity entity) { if (entity == null) { return ""; } else if (entity instanceof Item) { Material mat = ((Item) entity).getItemStack().getType(); if (mat == null || mat == Material.AIR) { return "item"; } else { return "item" + mat.toString().toLowerCase(Locale.ENGLISH); } } else if (entity instanceof FallingBlock) { Material mat = ((FallingBlock) entity).getMaterial(); if (mat == null || mat == Material.AIR) { return "fallingblock"; } else { return "falling" + mat.toString().toLowerCase(Locale.ENGLISH); } } else { return getName(entity.getType()); } }
@EventHandler public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); if (entity instanceof FallingBlock) { if (event.getTo() == Material.AIR) { // Block is falling, register it controller.registerFallingBlock(entity, event.getBlock()); } else { // Block is landing, convert it UndoList blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity); if (blockList != null) { com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext(); if (context != null && !context.hasBuildPermission(entity.getLocation().getBlock())) { event.setCancelled(true); } else { Block block = event.getBlock(); blockList.convert(entity, block); if (!blockList.getApplyPhysics()) { FallingBlock falling = (FallingBlock)entity; DeprecatedUtils.setTypeAndData(block, falling.getMaterial(), NMSUtils.getBlockData(falling), false); event.setCancelled(true); } } } } } }
ItemStack itemStack = new ItemStack(entity.getMaterial(), 1, entity.getBlockData()); Item item = block.getWorld().dropItem(entity.getLocation(), itemStack); item.setVelocity(new Vector());
final Material mat; if (entity instanceof FallingBlock) { mat = ((FallingBlock) entity).getMaterial();