use of com.elmakers.mine.bukkit.effect.builtin.EffectRing in project MagicPlugin by elBukkit.
the class LevitateSpell method thrust.
protected void thrust() {
if (thrustSpeed == 0)
return;
Player player = mage.getPlayer();
if (player == null)
return;
if (safetyLength > 0) {
mage.enableFallProtection(safetyLength, this);
}
if (mountEntity != null) {
Entity currentMount = player.getVehicle();
if (currentMount != mountEntity && (armorStand == null || currentMount != armorStand)) {
land();
return;
}
if (armorStand != null) {
Entity currentPassenger = armorStand.getPassenger();
if (currentPassenger != mountEntity) {
land();
return;
}
}
}
boolean isSneaking = mage.isPlayer() ? mage.getPlayer().isSneaking() : false;
if (!flight && isSneaking) {
land();
return;
}
boolean checkHeight = autoDeactivateHeight > 0 && isSneaking;
if (checkHeight) {
int height = 0;
Block block = player.getLocation().getBlock();
while (height < autoDeactivateHeight && block.getType() == Material.AIR) {
block = block.getRelative(BlockFace.DOWN);
height++;
}
if (height < autoDeactivateHeight) {
land();
return;
}
}
Location location = getLocation();
Vector mageDirection = getDirection().clone();
if (directionForceY != null) {
mageDirection.setY(directionForceY);
}
if (directionOffset != null) {
mageDirection.add(directionOffset);
}
boolean sneaking = player.isSneaking() || forceSneak > 0;
double move = sneakMoveDistance >= 0 && sneaking ? sneakMoveDistance : moveDistance;
if (direction == null || move <= 0 || grounded) {
direction = mageDirection;
} else {
double moveDistanceSquared = move * move;
double distanceSquared = direction.distanceSquared(mageDirection);
if (distanceSquared <= moveDistanceSquared) {
direction = mageDirection;
} else {
Vector targetDirection = mageDirection.subtract(direction).normalize().multiply(move);
direction.add(targetDirection);
}
}
grounded = false;
if (maxHeight > 0 && player.getLocation().getY() >= maxHeight) {
direction.setY(-1);
grounded = true;
} else if (maxHeightAboveGround > 0) {
Block block = player.getLocation().getBlock();
int height = 0;
while (height < maxHeightAboveGround && block.getType() == Material.AIR) {
block = block.getRelative(BlockFace.DOWN);
height++;
}
if (block.getType() == Material.AIR) {
direction.setY(-1);
grounded = true;
}
}
direction.normalize();
if (crashDistance > 0) {
Vector threshold = direction.clone().multiply(crashDistance);
if (checkForCrash(mage.getEyeLocation(), threshold)) {
crash();
return;
}
if (checkForCrash(mage.getLocation(), threshold)) {
crash();
return;
}
}
double boost = thrustSpeed;
if (mage.getPlayer().isSneaking() || forceSneak > 0) {
forceSneak--;
if (slowReduceBoostTicks > 0) {
mountBoostTicksRemaining = Math.max(0, mountBoostTicksRemaining - slowReduceBoostTicks);
updateMountHealth();
}
if (mountBoostTicksRemaining == 0) {
boost *= slowMultiplier;
}
}
if (mountBoostTicksRemaining > 0 && mountBoostTicks > 0) {
boost += (maxMountBoost * ((double) mountBoostTicksRemaining / mountBoostTicks));
--mountBoostTicksRemaining;
updateMountHealth();
} else if (boostTicksRemaining > 0) {
boost += castBoost;
--boostTicksRemaining;
}
direction.multiply(boost);
if (mountEntity != null) {
ArmorStand activeArmorStand = armorStand != null ? armorStand : (mountEntity instanceof ArmorStand ? (ArmorStand) mountEntity : null);
if (activeArmorStand != null) {
SafetyUtils.setVelocity(activeArmorStand, direction);
CompatibilityUtils.setYawPitch(activeArmorStand, location.getYaw() + (float) yawAmount, location.getPitch());
if (pitchAmount != 0) {
if (armorStandHead == null && useHelmet) {
activeArmorStand.setHeadPose(new EulerAngle(pitchAmount * location.getPitch() / 180 * Math.PI, 0, 0));
} else if (!useHelmet) {
EulerAngle armPose = activeArmorStand.getRightArmPose();
armPose = armPose.setY(pitchAmount * location.getPitch() / 180 * Math.PI);
armPose = armPose.setZ(rollAmount);
activeArmorStand.setRightArmPose(armPose);
}
}
} else {
SafetyUtils.setVelocity(mountEntity, direction);
}
} else {
SafetyUtils.setVelocity(player, direction);
}
if (effectParticle != null) {
if ((effectParticleCounter++ % effectParticleInterval) == 0) {
if (effectPlayer == null) {
effectPlayer = new EffectRing(controller.getPlugin());
effectPlayer.setParticleCount(2);
effectPlayer.setIterations(2);
effectPlayer.setRadius(2);
effectPlayer.setSize(5);
effectPlayer.setMaterial(location.getBlock().getRelative(BlockFace.DOWN));
}
effectPlayer.setParticleType(effectParticle);
effectPlayer.setParticleData(effectParticleData);
effectPlayer.setParticleCount(effectParticleCount);
effectPlayer.start(player.getEyeLocation(), null);
}
}
if (effectSound != null && controller.soundsEnabled()) {
if ((effectSoundCounter++ % effectSoundInterval) == 0) {
mage.getLocation().getWorld().playSound(location, effectSound, effectSoundVolume, effectSoundPitch);
}
}
}
use of com.elmakers.mine.bukkit.effect.builtin.EffectRing in project MagicPlugin by elBukkit.
the class Wand method updateEffects.
public void updateEffects(Mage mage) {
if (mage == null)
return;
Player player = mage.getPlayer();
if (player == null)
return;
// Update Bubble effects effects
if (effectBubbles && effectColor != null) {
Location potionEffectLocation = player.getLocation();
potionEffectLocation.setX(potionEffectLocation.getX() + random.nextDouble() - 0.5);
potionEffectLocation.setY(potionEffectLocation.getY() + random.nextDouble() * player.getEyeHeight());
potionEffectLocation.setZ(potionEffectLocation.getZ() + random.nextDouble() - 0.5);
ParticleEffect.SPELL_MOB.display(potionEffectLocation, effectColor.getColor(), 24);
}
Location location = mage.getLocation();
long now = System.currentTimeMillis();
boolean playEffects = !activeEffectsOnly || inventoryIsOpen || isInOffhand;
if (playEffects && effectParticle != null && effectParticleInterval > 0 && effectParticleCount > 0) {
boolean velocityCheck = true;
if (effectParticleMinVelocity > 0) {
double velocitySquared = effectParticleMinVelocity * effectParticleMinVelocity;
Vector velocity = mage.getVelocity().clone();
velocity.setY(0);
double speedSquared = velocity.lengthSquared();
velocityCheck = (speedSquared > velocitySquared);
}
if (velocityCheck && (lastParticleEffect == 0 || now > lastParticleEffect + effectParticleInterval)) {
lastParticleEffect = now;
Location effectLocation = player.getLocation();
Location eyeLocation = player.getEyeLocation();
effectLocation.setY(eyeLocation.getY() + effectParticleOffset);
if (effectPlayer == null) {
effectPlayer = new EffectRing(controller.getPlugin());
effectPlayer.setParticleCount(1);
effectPlayer.setIterations(1);
effectPlayer.setParticleOffset(0, 0, 0);
}
effectPlayer.setMaterial(location.getBlock().getRelative(BlockFace.DOWN));
if (effectParticleData == 0) {
effectPlayer.setColor(getEffectColor());
} else {
effectPlayer.setColor(null);
}
effectPlayer.setParticleType(effectParticle);
effectPlayer.setParticleData(effectParticleData);
effectPlayer.setSize(effectParticleCount);
effectPlayer.setRadius((float) effectParticleRadius);
effectPlayer.start(effectLocation, null);
}
}
if (castSpell != null && castInterval > 0) {
if (lastSpellCast == 0 || now > lastSpellCast + castInterval) {
boolean velocityCheck = true;
if (castMinVelocity > 0) {
double velocitySquared = castMinVelocity * castMinVelocity;
Vector velocity = mage.getVelocity();
if (castVelocityDirection != null) {
velocity = velocity.clone().multiply(castVelocityDirection);
// This is kind of a hack to make jump-detection work.
if (castVelocityDirection.getY() < 0) {
velocityCheck = velocity.getY() < 0;
} else {
velocityCheck = velocity.getY() > 0;
}
}
if (velocityCheck) {
double speedSquared = velocity.lengthSquared();
velocityCheck = (speedSquared > velocitySquared);
}
}
if (velocityCheck) {
lastSpellCast = now;
Spell spell = mage.getSpell(castSpell);
if (spell != null) {
if (castParameters == null) {
castParameters = new MemoryConfiguration();
}
castParameters.set("passive", true);
mage.setCostFree(true);
mage.setQuiet(true);
try {
spell.cast(castParameters);
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Error casting aura spell " + spell.getKey(), ex);
}
mage.setCostFree(false);
mage.setQuiet(false);
}
}
}
}
if (playEffects && effectSound != null && controller.soundsEnabled() && effectSoundInterval > 0) {
if (lastSoundEffect == 0 || now > lastSoundEffect + effectSoundInterval) {
lastSoundEffect = now;
effectSound.play(controller.getPlugin(), mage.getPlayer());
}
}
}
Aggregations