protected void processProjectiles(ProjectileDistanceTracker tracker, PlayerDeath death) {
    if (death.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) {
      EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) death.getEvent();
      Projectile projectile = (Projectile) event.getDamager();
      if (projectile.getShooter() instanceof Entity) {
        Entity shooter = (Entity) projectile.getShooter();
        double distance = projectile.getLocation().distance(tracker.getLaunchLocation(projectile));

        death.setKiller(shooter);
        death.setMisc("(" + (int) Math.round(distance) + " blocks)");
      }
    }
  }
Example #2
0
  @Override
  public void onEnable() {
    // basic operation listeners
    this.registerEvents(new LifetimeListener());
    this.registerEvents(new WorldListener(Trackers.getManager()));

    EntityDamageEventListener damageEventListener = new EntityDamageEventListener();
    damageEventListener.register(this);

    // initialize timer
    this.tickTimer = new TickTimer(this);
    this.tickTimer.start();

    // tracker setup
    TrackerManager tm = Trackers.getManager();

    ExplosiveTracker explosiveTracker = new SimpleExplosiveTracker();
    SimpleGravityKillTracker gravityKillTracker =
        new SimpleGravityKillTracker(this, this.tickTimer);

    explosiveTracker.enable();
    gravityKillTracker.enable();

    this.registerEvents(new ExplosiveListener(explosiveTracker));
    this.registerEvents(new GravityListener(this, gravityKillTracker, this.tickTimer));

    tm.setTracker(ExplosiveTracker.class, explosiveTracker);
    tm.setTracker(SimpleGravityKillTracker.class, gravityKillTracker);

    DispenserTracker dispenserTracker = new SimpleDispenserTracker();
    dispenserTracker.enable();

    this.registerEvents(new DispenserListener(dispenserTracker));
    tm.setTracker(DispenserTracker.class, dispenserTracker);

    ProjectileDistanceTracker projectileDistanceTracker = new SimpleProjectileDistanceTracker();
    projectileDistanceTracker.enable();

    this.registerEvents(new ProjectileDistanceListener(projectileDistanceTracker));
    tm.setTracker(ProjectileDistanceTracker.class, projectileDistanceTracker);

    OwnedMobTracker ownedMobTracker = new SimpleOwnedMobTracker();
    ownedMobTracker.enable();

    this.registerEvents(new OwnedMobListener(ownedMobTracker));
    tm.setTracker(OwnedMobTracker.class, ownedMobTracker);

    AnvilTracker anvilTracker = new SimpleAnvilTracker();
    anvilTracker.enable();

    this.registerEvents(new AnvilListener(anvilTracker));
    tm.setTracker(AnvilTracker.class, anvilTracker);

    // register damage resolvers
    DamageResolverManager drm = DamageResolvers.getManager();

    drm.register(new BlockDamageResolver());
    drm.register(new FallDamageResolver());
    drm.register(new LavaDamageResolver());
    drm.register(new MeleeDamageResolver());
    drm.register(new ProjectileDamageResolver(projectileDistanceTracker));
    drm.register(new TNTDamageResolver(explosiveTracker, dispenserTracker));
    drm.register(new VoidDamageResolver());
    drm.register(new GravityDamageResolver(gravityKillTracker, this.tickTimer));
    drm.register(
        new DispensedProjectileDamageResolver(projectileDistanceTracker, dispenserTracker));
    drm.register(new OwnedMobDamageResolver(ownedMobTracker));
    drm.register(new AnvilDamageResolver(anvilTracker));

    // debug
    // this.registerEvents(new DebugListener());
  }