From 42df4d87953ea06d25c2fb127909dfecae35be8a Mon Sep 17 00:00:00 2001 From: kaboom <58372747+kaboombot@users.noreply.github.com> Date: Fri, 31 Mar 2023 22:08:11 +0300 Subject: [PATCH] Machine Gun: Avoid exception in Folia Not a great solution, but it will do for now. --- .../modules/weapons/WeaponArmageddon.java | 2 +- .../modules/weapons/WeaponMachineGun.java | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponArmageddon.java b/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponArmageddon.java index c786bfd..eaa8452 100644 --- a/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponArmageddon.java +++ b/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponArmageddon.java @@ -88,7 +88,7 @@ public final class WeaponArmageddon implements Listener { if ((collidedWith.getType() == EntityType.PLAYER && projectile.getShooter() instanceof Player && ((Player) projectile.getShooter()).getUniqueId().equals( - collidedWith.getUniqueId())) { + collidedWith.getUniqueId())) || collidedWith.getType() == EntityType.FIREBALL) { event.setCancelled(true); } diff --git a/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponMachineGun.java b/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponMachineGun.java index 38f94c1..703af25 100644 --- a/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponMachineGun.java +++ b/src/main/java/pw/kaboom/weapons/modules/weapons/WeaponMachineGun.java @@ -116,21 +116,22 @@ public final class WeaponMachineGun implements Listener { final World world = player.getWorld(); final Vector velocity = eyeLocation.getDirection().multiply(12); - final Arrow arrow = player.launchProjectile(Arrow.class); + world.getChunkAtAsync(eyeLocation).thenAccept(chunk -> { + final Arrow arrow = player.launchProjectile(Arrow.class); + final float volume = 1.0F; + final float pitch = 63.0F; - arrow.customName(Component.text("WeaponMachineGunBullet")); - arrow.setShooter(player); - arrow.setVelocity(velocity); + arrow.customName(Component.text("WeaponMachineGunBullet")); + arrow.setShooter(player); + arrow.setVelocity(velocity); - final float volume = 1.0F; - final float pitch = 63.0F; - - world.playSound( - eyeLocation, - Sound.ENTITY_GENERIC_EXPLODE, - volume, - pitch - ); + world.playSound( + eyeLocation, + Sound.ENTITY_GENERIC_EXPLODE, + volume, + pitch + ); + }); numFiredBullets++; machineGunActive.put(playerUUID, numFiredBullets);