doxa97
대표칭호 없음
doxa97 951212593122449fbdd52f302c595cf1
이해도 | 플러그인 |
---|---|
게임버전 (JE) | 버킷 |
@EventHandler public void AttackEvent(EntityDamageByEntityEvent event) { Player player = (Player) event.getDamager(); double ac = player.getAttackCooldown(); if (ac < 1.0) { event.setCancelled(true); player.sendMessage(ChatColor.DARK_AQUA+"[ Ercanel ]"+ChatColor.WHITE+"성급!"); } else { if (event.getDamager() instanceof Projectile) { Projectile p = (Projectile) event.getDamager(); if (p.getType() == EntityType.ARROW) { if (p.getShooter() != null && p.getShooter() instanceof Player && event.getEntity() instanceof Player) { PlayerDamageByPlayer(event, (Player) p.getShooter(), (Player) event.getEntity(), (int) event.getDamage(), "B"); } else if (p.getShooter() != null && p.getShooter() instanceof Player && !(event.getEntity() instanceof Player)) { EntityDamageByPlayer(event, (Player) p.getShooter(), (int) event.getDamage(), "B"); } else if (p.getShooter() != null && !(p.getShooter() instanceof Player) && event.getEntity() instanceof Player) { PlayerDamageByEntity(event, (Player) event.getEntity()); } } } else { if (event.getDamager() instanceof LivingEntity) { if (Objects.requireNonNull(event.getEntity().getLastDamageCause()).getCause().equals(EntityDamageEvent.DamageCause.MAGIC)) { if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) { PlayerDamageByPlayer(event, (Player) event.getDamager(), (Player) event.getEntity(), (int) event.getDamage(), "M"); } else if (event.getDamager() instanceof Player && !(event.getEntity() instanceof Player)) { EntityDamageByPlayer(event, (Player) event.getDamager(), (int) event.getDamage(), "M"); } else if (!(event.getDamager() instanceof Player) && event.getEntity() instanceof Player) { PlayerDamageByEntity(event, (Player) event.getEntity()); } } else if (event.getEntity().getLastDamageCause().getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK)){ if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) { PlayerDamageByPlayer(event, (Player) event.getDamager(), (Player) event.getEntity(), (int) event.getDamage(), "A"); } else if (event.getDamager() instanceof Player && !(event.getEntity() instanceof Player)) { EntityDamageByPlayer(event, (Player) event.getDamager(), (int) event.getDamage(), "A"); } else if (!(event.getDamager() instanceof Player) && event.getEntity() instanceof Player) { PlayerDamageByEntity(event, (Player) event.getEntity()); } } } } } }
위의 구문에서
if (Objects.requireNonNull(event.getEntity().getLastDamageCause()).getCause().equals(EntityDamageEvent.DamageCause.MAGIC))
이 부분에 지속적으로 NullPointerException 이 뜨는데 어떻게 해결할 수 있을까요?
sendMessage 로 DamageCause 를 확인해보았는데 NPE 가 뜰 때 마다 DamageCause 구문이 인식을 못하는 것 같네요 ㅠㅠ
doxa97
2022.02.10그냥 마인크래프트에서 생성되고 최초로 맞는 공격을 인식하지 못하는 것 같군요 ㅠㅠ