diff --git a/src/main/java/com/planetgallium/kitpvp/listener/DeathListener.java b/src/main/java/com/planetgallium/kitpvp/listener/DeathListener.java index 66c32bd6..8fcadd31 100644 --- a/src/main/java/com/planetgallium/kitpvp/listener/DeathListener.java +++ b/src/main/java/com/planetgallium/kitpvp/listener/DeathListener.java @@ -168,6 +168,18 @@ private void setDeathMessage(Player victim, PlayerDeathEvent e) { broadcast(victim.getWorld(), Config.getS("Death.Messages.Player").replace("%victim%", victim.getName()).replace("%killer%", killerName)); creditWithKill(victim, getPlayer(victim, killerName)); + } else if ((cause == DamageCause.BLOCK_EXPLOSION || cause == DamageCause.ENTITY_EXPLOSION) && getExplodedEntity(victim.getLastDamageCause()).getType() == EntityType.PRIMED_TNT) { + + String bomberName = getExplodedEntity(victim.getLastDamageCause()).getCustomName(); + + if (bomberName != null) { + + Player killer = Toolkit.getPlayer(victim.getWorld(), bomberName); + broadcast(victim.getWorld(), Config.getS("Death.Messages.Player").replace("%victim%", victim.getName()).replace("%killer%", bomberName)); + creditWithKill(victim, killer); + + } + } else if (cause == DamageCause.VOID) { broadcast(victim.getWorld(), Config.getS("Death.Messages.Void").replace("%victim%", victim.getName())); @@ -183,7 +195,7 @@ private void setDeathMessage(Player victim, PlayerDeathEvent e) { } else if (cause == DamageCause.BLOCK_EXPLOSION || cause == DamageCause.ENTITY_EXPLOSION) { broadcast(victim.getWorld(), Config.getS("Death.Messages.Explosion").replace("%victim%", victim.getName())); - + } else { broadcast(victim.getWorld(), Config.getS("Death.Messages.Unknown").replace("%victim%", victim.getName())); @@ -203,31 +215,43 @@ private Entity getShooter(EntityDamageEvent e) { } + private Entity getExplodedEntity(EntityDamageEvent e) { + + EntityDamageByEntityEvent blownUpEvent = (EntityDamageByEntityEvent) e; + + return blownUpEvent.getDamager(); + + } + private void creditWithKill(Player victim, Player killer) { - if (!victim.getName().equals(killer.getName())) { + if (victim != null && killer != null) { - arena.getStats().addKill(killer.getUniqueId()); - arena.getLevels().addExperience(killer, resources.getLevels().getInt("Levels.General.Experience.Kill")); + if (!victim.getName().equals(killer.getName())) { - Toolkit.runKillCommands(victim, killer); + arena.getStats().addKill(killer.getUniqueId()); + arena.getLevels().addExperience(killer, resources.getLevels().getInt("Levels.General.Experience.Kill")); - if (resources.getScoreboard().getBoolean("Scoreboard.General.Enabled")) { + Toolkit.runKillCommands(victim, killer); - new BukkitRunnable() { + if (resources.getScoreboard().getBoolean("Scoreboard.General.Enabled")) { - @Override - public void run() { + new BukkitRunnable() { - if (killer instanceof Player) { + @Override + public void run() { - arena.updateScoreboards(killer, false); + if (killer instanceof Player) { + + arena.updateScoreboards(killer, false); + + } } - } + }.runTaskLater(Game.getInstance(), 20L); - }.runTaskLater(Game.getInstance(), 20L); + } } diff --git a/src/main/java/com/planetgallium/kitpvp/listener/ItemListener.java b/src/main/java/com/planetgallium/kitpvp/listener/ItemListener.java index 1a0e9956..3354d0c7 100644 --- a/src/main/java/com/planetgallium/kitpvp/listener/ItemListener.java +++ b/src/main/java/com/planetgallium/kitpvp/listener/ItemListener.java @@ -107,6 +107,7 @@ public void onInteract(PlayerInteractEvent e) { Entity entity = p.getWorld().spawn(handLocation, TNTPrimed.class); entity.setVelocity(direction.multiply(1.5)); + entity.setCustomName(p.getName()); useAbilityItem(p, p, item, "none"); diff --git a/src/main/java/com/planetgallium/kitpvp/util/Toolkit.java b/src/main/java/com/planetgallium/kitpvp/util/Toolkit.java index 79544098..0ac4decc 100644 --- a/src/main/java/com/planetgallium/kitpvp/util/Toolkit.java +++ b/src/main/java/com/planetgallium/kitpvp/util/Toolkit.java @@ -470,5 +470,21 @@ public static List colorizeList(List list) { return newList; } + + public static Player getPlayer(World world, String name) { + + for (Player player : world.getPlayers()) { + + if (player.getName().equals(name)) { + + return player; + + } + + } + + return null; + + } }