mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-12 06:48: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;
|
KillProcessor processor = null;
|
||||||
if (killerEntity instanceof Player) {
|
if (killerEntity instanceof Player) {
|
||||||
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
||||||
} else if (killerEntity instanceof Wolf) {
|
} else if (killerEntity instanceof Tameable) {
|
||||||
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
|
processor = handlePetKill(time, dead, (Tameable) killerEntity);
|
||||||
} else if (killerEntity instanceof Arrow) {
|
} else if (killerEntity instanceof Projectile) {
|
||||||
processor = handleArrowKill(time, dead, (Arrow) killerEntity);
|
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
|
||||||
}
|
}
|
||||||
if (processor != null) {
|
if (processor != null) {
|
||||||
Processing.submit(processor);
|
Processing.submit(processor);
|
||||||
@ -83,28 +83,32 @@ public class DeathEventListener implements Listener {
|
|||||||
return new KillProcessor(killer.getUniqueId(), time, dead, normalizeMaterialName(itemInHand));
|
return new KillProcessor(killer.getUniqueId(), time, dead, normalizeMaterialName(itemInHand));
|
||||||
}
|
}
|
||||||
|
|
||||||
private KillProcessor handleWolfKill(long time, LivingEntity dead, Wolf wolf) {
|
private KillProcessor handlePetKill(long time, LivingEntity dead, Tameable tameable) {
|
||||||
if (!wolf.isTamed()) {
|
if (!tameable.isTamed()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimalTamer owner = wolf.getOwner();
|
AnimalTamer owner = tameable.getOwner();
|
||||||
if (!(owner instanceof Player)) {
|
if (!(owner instanceof Player)) {
|
||||||
return null;
|
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) {
|
private KillProcessor handleProjectileKill(long time, LivingEntity dead, Projectile projectile) {
|
||||||
ProjectileSource source = arrow.getShooter();
|
ProjectileSource source = projectile.getShooter();
|
||||||
if (!(source instanceof Player)) {
|
if (!(source instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) source;
|
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.Living;
|
||||||
import org.spongepowered.api.entity.living.animal.Wolf;
|
import org.spongepowered.api.entity.living.animal.Wolf;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
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.entity.projectile.source.ProjectileSource;
|
||||||
import org.spongepowered.api.event.Listener;
|
import org.spongepowered.api.event.Listener;
|
||||||
import org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource;
|
import org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource;
|
||||||
@ -59,8 +59,8 @@ public class SpongeDeathListener {
|
|||||||
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
||||||
} else if (killerEntity instanceof Wolf) {
|
} else if (killerEntity instanceof Wolf) {
|
||||||
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
|
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
|
||||||
} else if (killerEntity instanceof Arrow) {
|
} else if (killerEntity instanceof Projectile) {
|
||||||
processor = handleArrowKill(time, dead, (Arrow) killerEntity);
|
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
|
||||||
}
|
}
|
||||||
if (processor != null) {
|
if (processor != null) {
|
||||||
Processing.submit(processor);
|
Processing.submit(processor);
|
||||||
@ -95,15 +95,17 @@ public class SpongeDeathListener {
|
|||||||
).orElse(null);
|
).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SpongeKillProcessor handleArrowKill(long time, Living dead, Arrow arrow) {
|
private SpongeKillProcessor handleProjectileKill(long time, Living dead, Projectile projectile) {
|
||||||
ProjectileSource source = arrow.getShooter();
|
ProjectileSource source = projectile.getShooter();
|
||||||
if (!(source instanceof Player)) {
|
if (!(source instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) source;
|
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