Files
src
Code
7 3,536
src/main/java/net/byebye/astralrpg/artefatos/itens/AzurionPA.java
package net.byebye.astralrpg.artefatos.itens;
import net.byebye.astralrpg.artefatos.ArtifactManager;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;
import java.util.*;
public class AzurionPA implements Listener {
private final JavaPlugin plugin;
// Mapas para armazenar a habilidade atual de cada jogador
private final HashMap<UUID, Integer> currentSkill = new HashMap<>();
// Mapas de cooldown para cada habilidade
private final HashMap<UUID, Long> hadoWaveTurboCooldowns = new HashMap<>();
private final HashMap<UUID, Long> swiftStrikeCooldowns = new HashMap<>();
private final HashMap<UUID, Long> sacrificioCooldowns = new HashMap<>();
private final HashMap<UUID, UUID> sacrificioTargets = new HashMap<>();
private final HashMap<UUID, BukkitRunnable> sacrificioTasks = new HashMap<>();
// Tempo de cooldown para cada habilidade (em milissegundos)
private final long HADO_WAVE_TURBO_COOLDOWN = 40000; // 40 segundos
private final long SWIFT_STRIKE_COOLDOWN = 25000; // 25 segundos
private final long SACRIFICIO_COOLDOWN = 60000; // 60 segundos
private final int TOTAL_SKILLS = 3;
private final String[] SKILL_NAMES = {
"§c§l⚡ Hadō no Tsubasa Turbo ⚡",
"§e§lGolpe Relâmpago",
"§4§lSacrifício Final"
};
public AzurionPA(JavaPlugin plugin) {
this.plugin = plugin;
startProjectileDetector();
}
private void startProjectileDetector() {
// Verifica projéteis próximos a jogadores segurando a Azurion
new BukkitRunnable() {
@Override
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (isHoldingAzurion(player)) {
// Busca projéteis em um raio de 5 blocos
Collection<Entity> nearbyEntities = player.getNearbyEntities(5, 5, 5);
for (Entity entity : nearbyEntities) {
if (entity instanceof Projectile) {
Projectile projectile = (Projectile) entity;
// Verifica se o projétil está vindo em direção ao jogador
if (isProjectileComingTowards(projectile, player)) {
interceptProjectile(projectile, player);
}
}
}
}
}
}
}.runTaskTimer(plugin, 2L, 2L); // Verifica a cada 2 ticks (0.1 segundos)
}
private boolean isProjectileComingTowards(Projectile projectile, Player player) {
// Calcula a direção do projétil em relação ao jogador
Vector projectileVelocity = projectile.getVelocity();
Vector toPlayer = player.getLocation().toVector().subtract(projectile.getLocation().toVector());
// Normaliza os vetores
projectileVelocity.normalize();
toPlayer.normalize();
// Calcula o produto escalar (se for positivo, está vindo em direção ao jogador)
double dotProduct = projectileVelocity.dot(toPlayer);
return dotProduct > 0.5; // Considera apenas projéteis vindo diretamente para o jogador
}
private void interceptProjectile(Projectile projectile, Player player) {
// Obtém a localização do projétil
Location projectileLoc = projectile.getLocation();
// Obtém a espada Azurion da mão do jogador
ItemStack swordItem;
// Verifica em qual mão está a espada
boolean isMainHand = false;
if (isAzurion(player.getInventory().getItemInMainHand())) {
swordItem = player.getInventory().getItemInMainHand().clone();
isMainHand = true;
} else if (isAzurion(player.getInventory().getItemInOffHand())) {
swordItem = player.getInventory().getItemInOffHand().clone();
} else {
swordItem = null;
// Se não encontrar a espada (caso estranho), usa efeitos padrão
createDefaultInterceptEffect(projectile, player);
return;
}
// Som inicial de arremesso
player.getWorld().playSound(
player.getLocation(),
Sound.ENTITY_ARROW_SHOOT,
0.7f,
1.2f
);
// Cria o item que vai representar a Azurion arremessada
Item sword = player.getWorld().dropItem(player.getEyeLocation(), swordItem);
// Configurações para evitar bugs de coleta
sword.setPickupDelay(Integer.MAX_VALUE);
sword.setUnlimitedLifetime(true);
sword.setInvulnerable(true);
sword.setPersistent(true);
sword.setGravity(false);
sword.setTicksLived(1);
sword.setRotation(90, 90);
// Velocidade em direção ao projétil
Vector toProjectile = projectileLoc.toVector().subtract(player.getEyeLocation().toVector()).normalize();
sword.setVelocity(toProjectile.multiply(2.0)); // Velocidade alta para parecer rápido
// Tarefa para monitorar a espada e criar efeitos
final boolean finalIsMainHand = isMainHand;
new BukkitRunnable() {
private int ticks = 0;
private boolean intercepted = false;
private boolean returning = false;
@Override
public void run() {
ticks++;
// Se passou muito tempo ou a espada sumiu, cancela e restaura a espada
if (!sword.isValid() || ticks > 100) {
sword.remove();
this.cancel();
return;
}
// Efeito de rastro da espada
player.getWorld().spawnParticle(
Particle.SOUL_FIRE_FLAME,
sword.getLocation(),
3, 0.1, 0.1, 0.1, 0.01
);
// Fase de interceptação - espada indo em direção ao projétil
if (!intercepted) {
// Verifica se a espada está próxima do projétil
if (sword.getLocation().distance(projectileLoc) < 2.0 || ticks > 20) {
intercepted = true;
returning = true;
// Efeito de interceptação
player.getWorld().spawnParticle(
Particle.SWEEP_ATTACK,
projectileLoc,
5, 0.3, 0.3, 0.3, 0.01
);
player.getWorld().spawnParticle(
Particle.FLASH,
projectileLoc,
2, 0.1, 0.1, 0.1, 0
);
// Som do impacto
player.getWorld().playSound(
projectileLoc,
Sound.ENTITY_PLAYER_ATTACK_SWEEP,
1.0f, 1.5f
);