Solved Checking if player has hit another player within x seconds?

Discussion in 'Plugin Development' started by tlm920, Jul 25, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    tlm920

    How would I test for a player hitting another player within x amount of seconds.

    EXAMPLE: Player1 hits Player1 10 times in 1 second?
     
  2. Offline

    KarimAKL

    @tlm920 Use EntityDamageByEntityEvent, then check if both entities are players, if so, store it.
     
  3. Offline

    Kars

    Do as Karim says.

    You could use a multi dimensional map to store the player data.
    PHP:
    Map<PlayerMap<Playerdouble>> hitMap;
    The key for the top level map would be the victim. The key for the nested map would be the attacker. The value for the nested map would be the time at which the hit occured (System.getCurrentTimeMillis). You can then write your logic accordingly.

    Just make sure to have an asynchronous repeating task that removes entries from the map every so often, to prevent memory leaks.
     
  4. Offline

    KarimAKL

    @Kars
    1. You can't use 'double', you need to use 'Double'.
    2. System.currentTimeMillis returns a long, not a double.
    3. You should probably store the player's UUID instead.
    Just a few things i wanted to mention. :p
     
  5. Offline

    Kars

    @KarimAKL You're right i meant long. And storing UUID would be more effective. It is though only an idea of concept.
     
    KarimAKL likes this.
  6. Offline

    tlm920

    Thanks guys. Worked perfect!
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page