Player damage help?

Discussion in 'Spigot Plugin Help' started by AnujGR, May 5, 2015.

  1. I need to know if there's a way to get the entity last damaged by a player without using the EntityDamageByEntityEvent event. Anybody who can help me out a little?
  2. Why can't you use EntityDamageByEntityEvent?
  3. @VirtualByte

    Well, you see, the method under the @EventHandler annotation currently takes two events as its parameters. Apparently, these two events have to take place at the same time in order for the method to work. The two events are PlayerInteractEvent and EntityDamageByEntityEvent. The method is supposed to make it such that when a player right clicks the ground with a sword, a skeleton will spawn there and that skeleton will attack whomever the player last attacked.

    However, when I use two events in my method at the same time, then the two events have to happen at the same time for the method to actually run.

    To make the skeleton attack whomever the player last attacked, I tried this:

    Code (Text):

    Skeleton skele = (Skeleton) interactevent.getPlayer().getWorld().spawnEntity(interactevent.getClickedBlock().getLocation(), EntityType.SKELETON);
    skele.setTarget((LivingEntity) entitydamageevent.getEntity());
    There's nothing wrong with the syntax. I just can't use both events at once in a single method.
  4. Store who the player last damaged in a hashmap, then on PlayerInteractEvent, spawn the entity and set its target according to the value in the HashMap.
    • Agree Agree x 1
  5. That makes sense, but could I just use an ArrayList?
  6. No, you need to get what player hit what mob.