mirror of
https://github.com/kaboomserver/weapons.git
synced 2025-02-05 14:13:52 +00:00
Fix machine gun bug
This commit is contained in:
parent
d7e59d5dc3
commit
671ac2798e
1 changed files with 45 additions and 37 deletions
|
@ -7,11 +7,12 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.entity.TippedArrow;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||||
|
@ -38,47 +39,39 @@ public final class WeaponMachineGun implements Listener {
|
||||||
machineGunActive.add(playerUUID);
|
machineGunActive.add(playerUUID);
|
||||||
final int maxBulletCount = 20;
|
final int maxBulletCount = 20;
|
||||||
|
|
||||||
for (int i = 0; i < maxBulletCount; i++) {
|
new BukkitRunnable() {
|
||||||
new BukkitRunnable() {
|
private int i;
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final Player player = event.getPlayer();
|
|
||||||
final Location eyeLocation = player.getEyeLocation();
|
|
||||||
final World world = player.getWorld();
|
|
||||||
final Vector velocity = eyeLocation.getDirection().multiply(12);
|
|
||||||
|
|
||||||
final TippedArrow arrow = player.launchProjectile(TippedArrow.class);
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
final Location eyeLocation = player.getEyeLocation();
|
||||||
|
final World world = player.getWorld();
|
||||||
|
final Vector velocity = eyeLocation.getDirection().multiply(12);
|
||||||
|
|
||||||
final int duration = 90000;
|
final Arrow arrow = player.launchProjectile(Arrow.class);
|
||||||
final int amplifier = 3;
|
|
||||||
final boolean ambient = true;
|
|
||||||
final boolean particles = false;
|
|
||||||
|
|
||||||
final PotionEffect harm = new PotionEffect(
|
arrow.setCustomName("WeaponMachineGunBullet");
|
||||||
PotionEffectType.HARM,
|
arrow.setShooter(player);
|
||||||
duration,
|
arrow.setVelocity(velocity);
|
||||||
amplifier,
|
|
||||||
ambient,
|
|
||||||
particles
|
|
||||||
);
|
|
||||||
|
|
||||||
arrow.setCustomName("WeaponMachineGunBullet");
|
final float volume = 1.0F;
|
||||||
arrow.addCustomEffect(harm, true);
|
final float pitch = 63.0F;
|
||||||
arrow.setShooter(player);
|
|
||||||
arrow.setVelocity(velocity);
|
|
||||||
|
|
||||||
final float volume = 1.0F;
|
world.playSound(
|
||||||
final float pitch = 63.0F;
|
eyeLocation,
|
||||||
|
Sound.ENTITY_GENERIC_EXPLODE,
|
||||||
|
volume,
|
||||||
|
pitch
|
||||||
|
);
|
||||||
|
|
||||||
world.playSound(
|
i++;
|
||||||
eyeLocation,
|
|
||||||
Sound.ENTITY_GENERIC_EXPLODE,
|
if (i >= maxBulletCount) {
|
||||||
volume,
|
this.cancel();
|
||||||
pitch
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}.runTask(JavaPlugin.getPlugin(Main.class));
|
}
|
||||||
}
|
}.runTaskTimer(JavaPlugin.getPlugin(Main.class), 0, 1);
|
||||||
|
|
||||||
machineGunActive.remove(playerUUID);
|
machineGunActive.remove(playerUUID);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +82,7 @@ public final class WeaponMachineGun implements Listener {
|
||||||
/* Make shooter invulnerable to weapon projectiles */
|
/* Make shooter invulnerable to weapon projectiles */
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onProjectileCollide(final ProjectileCollideEvent event) {
|
private void onProjectileCollide(final ProjectileCollideEvent event) {
|
||||||
if (event.getEntityType() == EntityType.TIPPED_ARROW) {
|
if (event.getEntityType() == EntityType.ARROW) {
|
||||||
final Projectile projectile = event.getEntity();
|
final Projectile projectile = event.getEntity();
|
||||||
|
|
||||||
if ("WeaponMachineGunBullet".equals(projectile.getCustomName())) {
|
if ("WeaponMachineGunBullet".equals(projectile.getCustomName())) {
|
||||||
|
@ -99,6 +92,21 @@ public final class WeaponMachineGun implements Listener {
|
||||||
&& projectile.getShooter() instanceof Player
|
&& projectile.getShooter() instanceof Player
|
||||||
&& ((Player) projectile.getShooter()).getUniqueId().equals(collidedWith.getUniqueId())) {
|
&& ((Player) projectile.getShooter()).getUniqueId().equals(collidedWith.getUniqueId())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
} else if (collidedWith instanceof LivingEntity) {
|
||||||
|
final int duration = 90000;
|
||||||
|
final int amplifier = 3;
|
||||||
|
final boolean ambient = true;
|
||||||
|
final boolean particles = false;
|
||||||
|
|
||||||
|
final PotionEffect harm = new PotionEffect(
|
||||||
|
PotionEffectType.HARM,
|
||||||
|
duration,
|
||||||
|
amplifier,
|
||||||
|
ambient,
|
||||||
|
particles
|
||||||
|
);
|
||||||
|
|
||||||
|
((LivingEntity) collidedWith).addPotionEffect(harm, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +114,7 @@ public final class WeaponMachineGun implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onProjectileHit(final ProjectileHitEvent event) {
|
private void onProjectileHit(final ProjectileHitEvent event) {
|
||||||
if (event.getEntityType() == EntityType.TIPPED_ARROW) {
|
if (event.getEntityType() == EntityType.ARROW) {
|
||||||
final Projectile projectile = event.getEntity();
|
final Projectile projectile = event.getEntity();
|
||||||
|
|
||||||
if ("WeaponMachineGunBullet".equals(projectile.getCustomName())) {
|
if ("WeaponMachineGunBullet".equals(projectile.getCustomName())) {
|
||||||
|
|
Loading…
Reference in a new issue