Solved How to detect if a player togglesneak 2 times

Discussion in 'Plugin Development' started by bennie3211, Dec 1, 2014.

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

    bennie3211

    Hello Bukkit,

    I've a question, I'm trying to detect if a player toggles 2 times in sneak modes. But I'm what the best way is to do this. What I'm trying to make is that when a player walks, then sneaks, stop sneaking and then sneaks again (and hold the sneak key) it activates something.

    Thnx
     
  2. Offline

    jusjus112

    bennie3211
    Just make a hashmap and when the player sneaks, add +1 to his name!
    And when it reached 2, activate something!
     
  3. Offline

    mythbusterma

    bennie3211 jusjus112

    Alternatively, add Metadata to your player and a timestamp. That way you can actually check how long between presses.
     
    bennie3211 and jusjus112 like this.
  4. Offline

    bennie3211

    mythbusterma Hmhmm didn't think of that xD I think I wil do that. Thnx!
     
  5. Offline

    Fozie

    Remember to delete the metadata/hashmap record after awhile or they will stack causing memory leak in time.
     
  6. Offline

    mythbusterma

    Fozie

    You don't have to delete the metadata entry, it will be cleaned up when the player logs out.
     
    bennie3211 likes this.
  7. Offline

    Fozie


    Oh i didnt know that :p
     
    bennie3211 likes this.
Thread Status:
Not open for further replies.

Share This Page