2019-12-17 15:12:51 +00:00
|
|
|
package pw.kaboom.weapons.modules.weapons;
|
2019-09-19 15:33:22 +00:00
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.Fireball;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.Projectile;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
2023-03-31 18:32:51 +00:00
|
|
|
import org.bukkit.event.entity.ProjectileHitEvent;
|
2019-09-19 15:33:22 +00:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2022-11-04 22:10:41 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.format.TextDecoration;
|
|
|
|
|
2019-12-17 15:12:51 +00:00
|
|
|
public final class WeaponArmageddon implements Listener {
|
2022-11-04 22:10:41 +00:00
|
|
|
public static void leftClick(final Material item, final Component name,
|
2022-05-20 02:05:54 +00:00
|
|
|
final PlayerInteractEvent event) {
|
2022-11-04 22:10:41 +00:00
|
|
|
if (item == Material.FIRE_CHARGE && Component.text("Armageddon")
|
|
|
|
.decoration(TextDecoration.ITALIC, false).equals(name)) {
|
2022-05-20 01:44:37 +00:00
|
|
|
final Player player = event.getPlayer();
|
|
|
|
final World world = player.getWorld();
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-05-20 01:44:37 +00:00
|
|
|
final int min = -12;
|
|
|
|
final int max = 12;
|
|
|
|
final int iteratorSpacing = 4;
|
2019-12-17 15:12:51 +00:00
|
|
|
|
2022-05-20 01:44:37 +00:00
|
|
|
for (int i = min; i <= max; i += iteratorSpacing) {
|
|
|
|
final Location eyeLocation = player.getEyeLocation();
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-05-20 01:44:37 +00:00
|
|
|
final double x = i * Math.cos(Math.toRadians(eyeLocation.getYaw()));
|
|
|
|
final double z = i * Math.sin(Math.toRadians(eyeLocation.getYaw()));
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-05-20 01:44:37 +00:00
|
|
|
final Vector velocity = eyeLocation.getDirection().multiply(12);
|
|
|
|
final int yield = 5;
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-05-20 01:44:37 +00:00
|
|
|
final Fireball fireball = (Fireball) world.spawnEntity(
|
|
|
|
eyeLocation.add(x, 0, z),
|
|
|
|
EntityType.FIREBALL
|
|
|
|
);
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-11-04 22:10:41 +00:00
|
|
|
fireball.customName(Component.text("WeaponArmegaddonCharge"));
|
2022-05-20 01:44:37 +00:00
|
|
|
fireball.setDirection(velocity);
|
|
|
|
fireball.setShooter(player);
|
|
|
|
fireball.setYield(yield);
|
|
|
|
}
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-05-20 01:44:37 +00:00
|
|
|
final Location eyeLocation = player.getEyeLocation();
|
|
|
|
final float volume = 0.9F;
|
|
|
|
final float pitch = 1.5F;
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-05-20 01:44:37 +00:00
|
|
|
world.playSound(
|
|
|
|
eyeLocation,
|
|
|
|
Sound.ENTITY_GHAST_SHOOT,
|
|
|
|
volume,
|
|
|
|
pitch
|
|
|
|
);
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 15:33:22 +00:00
|
|
|
|
2022-05-20 02:05:54 +00:00
|
|
|
/* Make shooter invulnerable to weapon projectiles, and prevent charges from
|
|
|
|
colliding with each other */
|
2022-05-20 01:44:37 +00:00
|
|
|
@EventHandler
|
2023-03-31 18:32:51 +00:00
|
|
|
private void onProjectileHit(final ProjectileHitEvent event) {
|
|
|
|
if (event.getEntityType() != EntityType.FIREBALL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Projectile projectile = event.getEntity();
|
|
|
|
|
|
|
|
if (!Component.text("WeaponArmegaddonCharge").equals(projectile.customName())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Entity collidedWith = event.getHitEntity();
|
|
|
|
|
|
|
|
if (collidedWith == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((collidedWith.getType() == EntityType.PLAYER
|
|
|
|
&& projectile.getShooter() instanceof Player
|
|
|
|
&& ((Player) projectile.getShooter()).getUniqueId().equals(
|
2023-03-31 19:08:11 +00:00
|
|
|
collidedWith.getUniqueId()))
|
2023-03-31 18:32:51 +00:00
|
|
|
|| collidedWith.getType() == EntityType.FIREBALL) {
|
|
|
|
event.setCancelled(true);
|
2022-05-20 01:44:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-19 15:33:22 +00:00
|
|
|
}
|