use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.
the class DropSpell method drop.
protected void drop(Block block, MaterialSet dropTypes, Collection<ItemStack> drops, int maxRecursion, int rDepth) {
registerForUndo(block);
if (dropCount < 0 || drops.size() < dropCount) {
drops.addAll(block.getDrops());
} else if (falling) {
Location blockLocation = block.getLocation();
FallingBlock falling = block.getWorld().spawnFallingBlock(blockLocation, block.getType(), block.getData());
falling.setDropItem(false);
}
block.setType(Material.AIR);
if (rDepth < maxRecursion) {
tryDrop(block.getRelative(BlockFace.NORTH), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.SOUTH), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.EAST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.UP), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.DOWN), dropTypes, drops, maxRecursion, rDepth + 1);
if (diagonals) {
tryDrop(block.getRelative(BlockFace.NORTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.NORTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.SOUTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(block.getRelative(BlockFace.SOUTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
Block up = block.getRelative(BlockFace.UP);
tryDrop(up.getRelative(BlockFace.NORTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(up.getRelative(BlockFace.NORTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(up.getRelative(BlockFace.SOUTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(up.getRelative(BlockFace.SOUTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(up.getRelative(BlockFace.NORTH), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(up.getRelative(BlockFace.WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(up.getRelative(BlockFace.SOUTH), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(up.getRelative(BlockFace.EAST), dropTypes, drops, maxRecursion, rDepth + 1);
Block down = block.getRelative(BlockFace.DOWN);
tryDrop(down.getRelative(BlockFace.NORTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(down.getRelative(BlockFace.NORTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(down.getRelative(BlockFace.SOUTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(down.getRelative(BlockFace.SOUTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(down.getRelative(BlockFace.NORTH), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(down.getRelative(BlockFace.WEST), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(down.getRelative(BlockFace.SOUTH), dropTypes, drops, maxRecursion, rDepth + 1);
tryDrop(down.getRelative(BlockFace.EAST), dropTypes, drops, maxRecursion, rDepth + 1);
}
}
}
use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.
the class DropAction method perform.
@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
Block block = context.getTargetBlock();
if (!context.hasBreakPermission(block)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!context.isDestructible(block)) {
return SpellResult.NO_TARGET;
}
// Don't allow dropping temporary blocks
UndoList blockUndoList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(block.getLocation());
if (blockUndoList != null && blockUndoList.isScheduled()) {
return SpellResult.NO_TARGET;
}
if (dropCount < 0 || drops.size() < dropCount) {
drops.addAll(block.getDrops());
} else if (falling) {
Location blockLocation = block.getLocation();
FallingBlock falling = block.getWorld().spawnFallingBlock(blockLocation, block.getType(), block.getData());
falling.setDropItem(false);
}
block.setType(Material.AIR);
return SpellResult.CAST;
}
use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.
the class TossSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Location location = getLocation();
if (!hasBuildPermission(location.getBlock())) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
location.setY(location.getY() - 1);
MaterialBrush buildWith = getBrush();
buildWith.setTarget(location);
Material material = buildWith.getMaterial();
byte data = buildWith.getBlockData();
int tossCount = 1;
tossCount = parameters.getInt("count", tossCount);
tossCount = (int) (mage.getRadiusMultiplier() * tossCount);
float speed = 0.6f;
speed = (float) parameters.getDouble("speed", speed);
Vector direction = getDirection();
direction.normalize().multiply(speed);
Vector up = new Vector(0, 1, 0);
Vector perp = new Vector();
perp.copy(direction);
perp.crossProduct(up);
for (int i = 0; i < tossCount; i++) {
FallingBlock block = null;
location = getEyeLocation();
location.setX(location.getX() + perp.getX() * (Math.random() * tossCount / 4 - tossCount / 8));
location.setY(location.getY());
location.setZ(location.getZ() + perp.getZ() * (Math.random() * tossCount / 4 - tossCount / 8));
block = getWorld().spawnFallingBlock(location, material, data);
if (block == null) {
registerForUndo();
return SpellResult.FAIL;
}
registerForUndo(block);
block.setDropItem(false);
SafetyUtils.setVelocity(block, direction);
}
registerForUndo();
return SpellResult.CAST;
}
use of org.bukkit.entity.FallingBlock in project Ublisk by Derkades.
the class PlayerInteract method spellTest.
@EventHandler(priority = EventPriority.MONITOR)
public void spellTest(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.BLAZE_ROD) {
final Block block = event.getClickedBlock();
if (block.getType() == Material.COBBLESTONE) {
@SuppressWarnings("deprecation") FallingBlock fall = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
Vector velocity = fall.getVelocity();
velocity.setY(velocity.getY() + 1.0);
fall.setVelocity(velocity);
block.setType(Material.AIR);
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
public void run() {
Location loc = block.getLocation();
loc.setY(loc.getY() + 1);
ThrownPotion potion = (ThrownPotion) Var.WORLD.spawnEntity(loc, EntityType.SPLASH_POTION);
PotionEffect effect = new PotionEffect(PotionEffectType.HARM, 1, 2);
potion.getEffects().add(effect);
}
}, 2 * 20);
}
}
}
}
use of org.bukkit.entity.FallingBlock in project EliteMobs by MagmaGuy.
the class EliteExplosionEvent method visualExplosionEffect.
public void visualExplosionEffect(ElitePower elitePower) {
VisualExplosionEffectType visualExplosionEffectType;
if (elitePower == null)
visualExplosionEffectType = VisualExplosionEffectType.NORMAL;
else if (elitePower.getFileName().equals(new EnderDragonEmpoweredLightning().getFileName()))
visualExplosionEffectType = VisualExplosionEffectType.ASCEND;
else if (elitePower instanceof EnderDragonTornado) {
visualExplosionEffectType = VisualExplosionEffectType.HIGH_POWER;
} else
visualExplosionEffectType = VisualExplosionEffectType.NORMAL;
for (BlockState blockState : blockStates) {
FallingBlock fallingBlock = blockState.getBlock().getWorld().spawnFallingBlock(blockState.getLocation().add(new Vector(0, 0.2, 0)), blockState.getBlockData());
fallingBlock.setDropItem(false);
fallingBlock.setHurtEntities(true);
switch(visualExplosionEffectType) {
case ASCEND:
fallingBlock.setVelocity(fallingBlock.getLocation().clone().subtract(explosionSourceLocation).toVector().normalize().setY(1).normalize().multiply(ThreadLocalRandom.current().nextDouble()));
fallingBlock.setGravity(false);
fallingBlock.setGlowing(true);
break;
case HIGH_POWER:
fallingBlock.setVelocity(fallingBlock.getLocation().clone().subtract(explosionSourceLocation).toVector().normalize().setY(2).multiply(0.9));
break;
case NORMAL:
default:
fallingBlock.setVelocity(fallingBlock.getLocation().clone().subtract(explosionSourceLocation).toVector().normalize().setY(1).multiply(0.5));
}
new BukkitRunnable() {
@Override
public void run() {
if (fallingBlock.isValid())
fallingBlock.remove();
}
}.runTaskLater(MetadataHandler.PLUGIN, 20 * 4);
CrashFix.persistentTracker(fallingBlock);
fallingBlocks.add(fallingBlock);
}
}
Aggregations