mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-20 11:42:50 +02:00
Abstracted death listeners to allow wider variety of projectiles.
This commit is contained in:
parent
a333a24c0a
commit
d9fdad0086
|
@ -58,10 +58,10 @@ public class DeathEventListener implements Listener {
|
|||
KillProcessor processor = null;
|
||||
if (killerEntity instanceof Player) {
|
||||
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
||||
} else if (killerEntity instanceof Wolf) {
|
||||
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
|
||||
} else if (killerEntity instanceof Arrow) {
|
||||
processor = handleArrowKill(time, dead, (Arrow) killerEntity);
|
||||
} else if (killerEntity instanceof Tameable) {
|
||||
processor = handlePetKill(time, dead, (Tameable) killerEntity);
|
||||
} else if (killerEntity instanceof Projectile) {
|
||||
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
|
||||
}
|
||||
if (processor != null) {
|
||||
Processing.submit(processor);
|
||||
|
@ -83,28 +83,32 @@ public class DeathEventListener implements Listener {
|
|||
return new KillProcessor(killer.getUniqueId(), time, dead, normalizeMaterialName(itemInHand));
|
||||
}
|
||||
|
||||
private KillProcessor handleWolfKill(long time, LivingEntity dead, Wolf wolf) {
|
||||
if (!wolf.isTamed()) {
|
||||
private KillProcessor handlePetKill(long time, LivingEntity dead, Tameable tameable) {
|
||||
if (!tameable.isTamed()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AnimalTamer owner = wolf.getOwner();
|
||||
AnimalTamer owner = tameable.getOwner();
|
||||
if (!(owner instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new KillProcessor(owner.getUniqueId(), time, dead, "Wolf");
|
||||
return new KillProcessor(owner.getUniqueId(), time, dead,
|
||||
new Format(tameable.getType().name()).capitalize().toString()
|
||||
);
|
||||
}
|
||||
|
||||
private KillProcessor handleArrowKill(long time, LivingEntity dead, Arrow arrow) {
|
||||
ProjectileSource source = arrow.getShooter();
|
||||
private KillProcessor handleProjectileKill(long time, LivingEntity dead, Projectile projectile) {
|
||||
ProjectileSource source = projectile.getShooter();
|
||||
if (!(source instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = (Player) source;
|
||||
|
||||
return new KillProcessor(player.getUniqueId(), time, dead, "Bow");
|
||||
return new KillProcessor(player.getUniqueId(), time, dead,
|
||||
new Format(projectile.getType().name()).capitalize().toString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.spongepowered.api.entity.Entity;
|
|||
import org.spongepowered.api.entity.living.Living;
|
||||
import org.spongepowered.api.entity.living.animal.Wolf;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.entity.projectile.arrow.Arrow;
|
||||
import org.spongepowered.api.entity.projectile.Projectile;
|
||||
import org.spongepowered.api.entity.projectile.source.ProjectileSource;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource;
|
||||
|
@ -59,8 +59,8 @@ public class SpongeDeathListener {
|
|||
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
||||
} else if (killerEntity instanceof Wolf) {
|
||||
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
|
||||
} else if (killerEntity instanceof Arrow) {
|
||||
processor = handleArrowKill(time, dead, (Arrow) killerEntity);
|
||||
} else if (killerEntity instanceof Projectile) {
|
||||
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
|
||||
}
|
||||
if (processor != null) {
|
||||
Processing.submit(processor);
|
||||
|
@ -95,15 +95,17 @@ public class SpongeDeathListener {
|
|||
).orElse(null);
|
||||
}
|
||||
|
||||
private SpongeKillProcessor handleArrowKill(long time, Living dead, Arrow arrow) {
|
||||
ProjectileSource source = arrow.getShooter();
|
||||
private SpongeKillProcessor handleProjectileKill(long time, Living dead, Projectile projectile) {
|
||||
ProjectileSource source = projectile.getShooter();
|
||||
if (!(source instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = (Player) source;
|
||||
|
||||
return new SpongeKillProcessor(player.getUniqueId(), time, getUUID(dead), "Bow");
|
||||
return new SpongeKillProcessor(player.getUniqueId(), time, getUUID(dead),
|
||||
new Format(projectile.getType().getName()).capitalize().toString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user