Skip to content

Commit

Permalink
Added TNT kill crediting (#25) (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
cervinakuy committed May 24, 2020
1 parent d55c7d2 commit 949dd34
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/main/java/com/planetgallium/kitpvp/listener/DeathListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand All @@ -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);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/planetgallium/kitpvp/util/Toolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,5 +470,21 @@ public static List<String> colorizeList(List<String> 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;

}

}

0 comments on commit 949dd34

Please sign in to comment.