use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile in project MechanicsMain by WeaponMechanics.
the class ShootHandler method shoot.
/**
* Shoots using weapon.
* Does not use ammo nor check for it.
*/
public void shoot(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, Location shootLocation, boolean mainHand, boolean updateSpreadChange, boolean isMelee) {
Configuration config = getConfigurations();
LivingEntity livingEntity = entityWrapper.getEntity();
if (!isMelee) {
HandData handData = mainHand ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
handData.setLastShotTime(System.currentTimeMillis());
if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Delay_Between_Shots") && entityWrapper.getEntity().getType() == EntityType.PLAYER) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entityWrapper, weaponStack.getType(), config.getInt(weaponTitle + ".Shoot.Delay_Between_Shots") / 50);
}
}
Mechanics shootMechanics = config.getObject(weaponTitle + ".Shoot.Mechanics", Mechanics.class);
if (shootMechanics != null)
shootMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
if (entityWrapper instanceof PlayerWrapper) {
WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
if (weaponInfoDisplay != null)
weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainHand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND);
}
Projectile projectile = config.getObject(weaponTitle + ".Projectile", Projectile.class);
if (projectile == null || isMelee) {
// No projectile defined or was melee trigger
return;
}
Spread spread = config.getObject(weaponTitle + ".Shoot.Spread", Spread.class);
Recoil recoil = config.getObject(weaponTitle + ".Shoot.Recoil", Recoil.class);
double projectileSpeed = config.getDouble(weaponTitle + ".Shoot.Projectile_Speed");
for (int i = 0; i < config.getInt(weaponTitle + ".Shoot.Projectiles_Per_Shot"); ++i) {
// i == 0
// -> Only allow spread changing on first shot
Vector motion = spread != null ? spread.getNormalizedSpreadDirection(entityWrapper, mainHand, i == 0 && updateSpreadChange).multiply(projectileSpeed) : livingEntity.getLocation().getDirection().multiply(projectileSpeed);
if (recoil != null && i == 0 && livingEntity instanceof Player) {
recoil.start((Player) livingEntity, mainHand);
}
// Only create bullet first if WeaponShootEvent changes
WeaponProjectile bullet = projectile.create(livingEntity, shootLocation, motion, weaponStack, weaponTitle);
WeaponShootEvent shootEvent = new WeaponShootEvent(bullet);
Bukkit.getPluginManager().callEvent(shootEvent);
bullet = shootEvent.getProjectile();
// Shoot the given bullet
projectile.shoot(bullet, shootLocation);
}
}
use of me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile in project MechanicsMain by WeaponMechanics.
the class ShootCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
double speed = Double.parseDouble(args[0]) / 20;
double gravity = 0.05;
EntityType entityType = null;
if (args.length > 1) {
entityType = EntityType.valueOf(args[1].toUpperCase());
}
if (args.length > 2) {
gravity = Double.parseDouble(args[1]);
}
ProjectileSettings projectileSettings = new ProjectileSettings(entityType, null, gravity, false, -1, false, -1, 0.99, 0.96, 0.98, false, 600, -1);
Projectile projectile = new Projectile(projectileSettings, null, null, null, null);
projectile.shoot(player, player.getEyeLocation(), player.getLocation().getDirection().multiply(speed), null, null);
}
Aggregations