use of org.bukkit.entity.ThrownExpBottle in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method callExpBottleEvent.
public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {
ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity();
ExpBottleEvent event = new ExpBottleEvent(bottle, exp);
Bukkit.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.entity.ThrownExpBottle in project Magma-1.16.x by magmafoundation.
the class CraftBlockProjectileSource method launchProjectile.
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
// Copied from DispenserBlock.dispense()
ProxyBlockSource isourceblock = new ProxyBlockSource(dispenserBlock.getLevel().getMinecraftWorld(), dispenserBlock.getBlockPos());
// Copied from DispenseTaskProjectile
IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
net.minecraft.world.World world = dispenserBlock.getLevel();
net.minecraft.entity.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EnderPearlEntity(world, null);
launch.setPos(iposition.x(), iposition.y(), iposition.z());
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
if (LingeringPotion.class.isAssignableFrom(projectile)) {
launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else {
launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
} else if (AbstractArrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
} else if (SpectralArrow.class.isAssignableFrom(projectile)) {
launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
} else {
launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
}
((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
((AbstractArrowEntity) launch).projectileSource = this;
} else if (Fireball.class.isAssignableFrom(projectile)) {
double d0 = iposition.x() + (double) ((float) enumdirection.getStepX() * 0.3F);
double d1 = iposition.y() + (double) ((float) enumdirection.getStepY() * 0.3F);
double d2 = iposition.z() + (double) ((float) enumdirection.getStepZ() * 0.3F);
Random random = world.random;
double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepX();
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepY();
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepZ();
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new SmallFireballEntity(world, null, d0, d1, d2);
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = EntityType.WITHER_SKULL.create(world);
launch.setPos(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
} else {
launch = EntityType.FIREBALL.create(world);
launch.setPos(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
}
((DamagingProjectileEntity) launch).projectileSource = this;
}
Validate.notNull(launch, "Projectile not supported");
if (launch instanceof ProjectileEntity) {
if (launch instanceof ThrowableEntity) {
((ThrowableEntity) launch).projectileSource = this;
}
// Values from DispenseTaskProjectile
float a = 6.0F;
float b = 1.1F;
if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
// Values from respective DispenseTask classes
a *= 0.5F;
b *= 1.25F;
}
// Copied from DispenseTaskProjectile
((ProjectileEntity) launch).shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), b, a);
}
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addFreshEntity(launch);
return (T) launch.getBukkitEntity();
}
use of org.bukkit.entity.ThrownExpBottle in project WindSpigot by Wind-Development.
the class CraftBlockProjectileSource method launchProjectile.
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
// Copied from BlockDispenser.dispense()
SourceBlock isourceblock = new SourceBlock(dispenserBlock.getWorld(), dispenserBlock.getPosition());
// Copied from DispenseBehaviorProjectile
IPosition iposition = BlockDispenser.a(isourceblock);
EnumDirection enumdirection = BlockDispenser.b(isourceblock.f());
net.minecraft.server.World world = dispenserBlock.getWorld();
net.minecraft.server.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ());
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ());
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EntityEnderPearl(world, null);
launch.setPosition(iposition.getX(), iposition.getY(), iposition.getZ());
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ());
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
} else if (Arrow.class.isAssignableFrom(projectile)) {
launch = new EntityArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
((EntityArrow) launch).fromPlayer = 1;
((EntityArrow) launch).projectileSource = this;
} else if (Fireball.class.isAssignableFrom(projectile)) {
double d0 = iposition.getX() + enumdirection.getAdjacentX() * 0.3F;
double d1 = iposition.getY() + enumdirection.getAdjacentY() * 0.3F;
double d2 = iposition.getZ() + enumdirection.getAdjacentZ() * 0.3F;
Random random = world.random;
double d3 = random.nextGaussian() * 0.05D + enumdirection.getAdjacentX();
double d4 = random.nextGaussian() * 0.05D + enumdirection.getAdjacentY();
double d5 = random.nextGaussian() * 0.05D + enumdirection.getAdjacentZ();
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new EntitySmallFireball(world, d0, d1, d2, d3, d4, d5);
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = new EntityWitherSkull(world);
launch.setPosition(d0, d1, d2);
double d6 = MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((EntityFireball) launch).dirX = d3 / d6 * 0.1D;
((EntityFireball) launch).dirY = d4 / d6 * 0.1D;
((EntityFireball) launch).dirZ = d5 / d6 * 0.1D;
} else {
launch = new EntityLargeFireball(world);
launch.setPosition(d0, d1, d2);
double d6 = MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((EntityFireball) launch).dirX = d3 / d6 * 0.1D;
((EntityFireball) launch).dirY = d4 / d6 * 0.1D;
((EntityFireball) launch).dirZ = d5 / d6 * 0.1D;
}
((EntityFireball) launch).projectileSource = this;
}
Validate.notNull(launch, "Projectile not supported");
if (launch instanceof IProjectile) {
if (launch instanceof EntityProjectile) {
((EntityProjectile) launch).projectileSource = this;
}
// Values from DispenseBehaviorProjectile
float a = 6.0F;
float b = 1.1F;
if (launch instanceof EntityPotion || launch instanceof ThrownExpBottle) {
// Values from respective DispenseBehavior classes
a *= 0.5F;
b *= 1.25F;
}
// Copied from DispenseBehaviorProjectile
((IProjectile) launch).shoot(enumdirection.getAdjacentX(), enumdirection.getAdjacentY() + 0.1F, enumdirection.getAdjacentZ(), b, a);
}
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addEntity(launch);
return (T) launch.getBukkitEntity();
}
use of org.bukkit.entity.ThrownExpBottle in project Easterlyn by Easterlyn.
the class BottleExperience method onProjectileLaunch.
@EventHandler(ignoreCancelled = true)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
if (!(event.getEntity() instanceof ThrownExpBottle) || !(event.getEntity().getShooter() instanceof Player)) {
return;
}
RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynProvider == null) {
return;
}
User user = easterlynProvider.getProvider().getUserManager().getUser(((Player) event.getEntity().getShooter()).getUniqueId());
Object cooldown = user.getTemporaryStorage().get(keyBottleThrow);
if (cooldown instanceof Long && (Long) cooldown >= System.currentTimeMillis()) {
event.setCancelled(true);
}
}
use of org.bukkit.entity.ThrownExpBottle in project LoliServer by Loli-Server.
the class CraftBlockProjectileSource method launchProjectile.
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
// Copied from DispenserBlock.dispense()
ProxyBlockSource isourceblock = new ProxyBlockSource((ServerWorld) dispenserBlock.getLevel(), dispenserBlock.getBlockPos());
// Copied from DispenseTaskProjectile
IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
net.minecraft.world.World world = dispenserBlock.getLevel();
net.minecraft.entity.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EnderPearlEntity(world, null);
launch.setPos(iposition.x(), iposition.y(), iposition.z());
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
if (LingeringPotion.class.isAssignableFrom(projectile)) {
launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else {
launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
} else if (AbstractArrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
} else if (SpectralArrow.class.isAssignableFrom(projectile)) {
launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
} else {
launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
}
((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
((AbstractArrowEntity) launch).projectileSource = this;
} else if (Fireball.class.isAssignableFrom(projectile)) {
double d0 = iposition.x() + (double) ((float) enumdirection.getStepX() * 0.3F);
double d1 = iposition.y() + (double) ((float) enumdirection.getStepY() * 0.3F);
double d2 = iposition.z() + (double) ((float) enumdirection.getStepZ() * 0.3F);
Random random = world.random;
double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepX();
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepY();
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepZ();
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new SmallFireballEntity(world, null, d0, d1, d2);
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = EntityType.WITHER_SKULL.create(world);
launch.setPos(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
} else {
launch = EntityType.FIREBALL.create(world);
launch.setPos(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
}
((DamagingProjectileEntity) launch).projectileSource = this;
}
Validate.notNull(launch, "Projectile not supported");
if (launch instanceof ProjectileEntity) {
if (launch instanceof ThrowableEntity) {
((ThrowableEntity) launch).projectileSource = this;
}
// Values from DispenseTaskProjectile
float a = 6.0F;
float b = 1.1F;
if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
// Values from respective DispenseTask classes
a *= 0.5F;
b *= 1.25F;
}
// Copied from DispenseTaskProjectile
((ProjectileEntity) launch).shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), b, a);
}
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addFreshEntity(launch);
return (T) launch.getBukkitEntity();
}
Aggregations