use of org.bukkit.entity.ShulkerBullet in project MagicPlugin by elBukkit.
the class ProjectileAction method start.
@Override
public SpellResult start(CastContext context) {
MageController controller = context.getController();
Mage mage = context.getMage();
// Modify with wand power
// Turned some of this off for now
// int count = this.count * mage.getRadiusMultiplier();
// int speed = this.speed * damageMultiplier;
int size = (int) (mage.getRadiusMultiplier() * this.size);
double damageMultiplier = mage.getDamageMultiplier("projectile");
double damage = damageMultiplier * this.damage;
float radiusMultiplier = mage.getRadiusMultiplier();
float spread = this.spread;
if (radiusMultiplier > 1) {
spread = spread / radiusMultiplier;
}
Random random = context.getRandom();
Class<?> projectileType = CompatibilityLib.getCompatibilityUtils().getProjectileClass(projectileTypeName);
if (projectileType == null) {
controller.getLogger().warning("Bad projectile class: " + projectileTypeName);
return SpellResult.FAIL;
}
// Prepare parameters
Location location = sourceLocation.getLocation(context);
if (location == null) {
return SpellResult.LOCATION_REQUIRED;
}
Vector direction = location.getDirection();
if (startDistance > 0) {
location = location.clone().add(direction.clone().multiply(startDistance));
}
// Spawn projectiles
LivingEntity shootingEntity = context.getLivingEntity();
ProjectileSource source = null;
if (shootingEntity != null) {
source = shootingEntity;
}
mage.setLaunchingProjectile(true);
for (int i = 0; i < count; i++) {
try {
// Spawn a new projectile
Projectile projectile = CompatibilityLib.getCompatibilityUtils().spawnProjectile(projectileType, location, direction, source, speed, spread, i > 0 ? spread : 0, random);
if (projectile == null) {
return SpellResult.FAIL;
}
if (shootingEntity != null) {
projectile.setShooter(shootingEntity);
}
if (projectile instanceof ShulkerBullet) {
ShulkerBullet bullet = (ShulkerBullet) projectile;
bullet.setTarget(context.getTargetEntity());
}
if (projectile instanceof ThrownPotion && color != null && !color.isEmpty()) {
ThrownPotion potion = (ThrownPotion) projectile;
if (color.startsWith("#")) {
color = color.substring(1);
}
try {
Color potionColor = Color.fromRGB(Integer.parseInt(color, 16));
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
ItemMeta meta = itemStack.getItemMeta();
if (meta != null && meta instanceof PotionMeta) {
CompatibilityLib.getCompatibilityUtils().setColor((PotionMeta) meta, potionColor);
itemStack.setItemMeta(meta);
potion.setItem(itemStack);
}
} catch (Exception ex) {
context.getLogger().warning("Invalid potion color in Projectile action: " + color);
}
}
if (projectile instanceof Fireball) {
Fireball fireball = (Fireball) projectile;
fireball.setIsIncendiary(useFire);
fireball.setYield(size);
}
if (projectile instanceof Arrow) {
Arrow arrow = (Arrow) projectile;
if (useFire) {
arrow.setFireTicks(300);
}
if (damage > 0) {
CompatibilityLib.getCompatibilityUtils().setDamage(projectile, damage);
}
if (tickIncrease > 0) {
CompatibilityLib.getCompatibilityUtils().decreaseLifespan(projectile, tickIncrease);
}
}
if (pickupStatus != null && !pickupStatus.isEmpty()) {
CompatibilityLib.getCompatibilityUtils().setPickupStatus(projectile, pickupStatus);
}
if (!breakBlocks) {
CompatibilityLib.getEntityMetadataUtils().setBoolean(projectile, MagicMetaKeys.CANCEL_EXPLOSION_BLOCKS, true);
}
track(context, projectile);
} catch (Exception ex) {
ex.printStackTrace();
}
}
mage.setLaunchingProjectile(false);
return checkTracking(context);
}
use of org.bukkit.entity.ShulkerBullet in project Minigames by Derkades.
the class MeteorShower method spawnMeteor.
private void spawnMeteor() {
MeteorBounds bounds = this.map.getMeteorBounds();
float x = ThreadLocalRandom.current().nextFloat(bounds.minX(), bounds.maxX());
float y = ThreadLocalRandom.current().nextFloat(bounds.y() - 10, bounds.y() + 10);
float z = ThreadLocalRandom.current().nextFloat(bounds.minZ(), bounds.maxZ());
Location bulletLoc = new Location(this.map.getWorld(), x, y, z);
UUID uuid = this.map.getWorld().spawn(bulletLoc, ShulkerBullet.class).getUniqueId();
meteorTasks.add(new BukkitRunnable() {
Location loc = null;
public void run() {
Entity entity = map.getWorld().getEntity(uuid);
if (entity == null) {
if (loc != null) {
loc.getWorld().createExplosion(loc, 2.5f);
loc.getWorld().spawnParticle(Particle.LAVA, loc, 30, 1, 0, 1, 0);
if (ThreadLocalRandom.current().nextFloat() > 0.6) {
while (loc.getBlock().getType() == Material.AIR) {
loc.add(0, -1, 0);
if (y < 50) {
return;
}
}
createFire(loc);
loc.getBlock().setType(Material.LAVA);
}
}
this.cancel();
return;
}
ShulkerBullet bullet = (ShulkerBullet) entity;
loc = bullet.getLocation();
loc.getWorld().spawnParticle(Particle.FLAME, loc, 5, 0, 0.5, 0, 0);
loc.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, loc, 2, 0, .5, 0, 0);
}
}.runTaskTimer(Minigames.getInstance(), 1, 1));
long delay = 15 - Math.max(this.getSecondsLeft() / 10, 10);
this.meteorTasks.add(Scheduler.delay(delay, this::spawnMeteor));
}
Aggregations