Checking if a player keeps right click pressed, and if so, how long

Discussion in 'Plugin Development' started by negative_codezZ, Jul 19, 2014.

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

    negative_codezZ

    Hello, for this minigame I am developing, there is a part where I have to make it so that every second a player right clicks something more, it increments an integer. I was thinking on how to do this, and thought maybe having a HashMap with a String (Player name) and a Long (Current time milliseconds). Then, every time, I could check if the hashmap contains the player name, and then if so, checking if the current time milliseconds - the one saved in the hashmap is greater than the amount of milliseconds between every PlayerInteractEvent. Pretty much, my question is, how many milliseconds are there between every PlayerInteractEvent (Or how many milliseconds is a tick)? The code that will be used:

    Code:java
    1. HashMap<String, Long> lastInteract = new HashMap<>();
    2. HashMap<String, Integer> playerIntegers = new HashMap<>();
    3.  
    4. if(lastInteract.containsKey(player.getName())) {
    5. if((System.currentTimeMillis() - lastInteract.get(player.getName())) > intervalInMillisecondsBetweenEveryPlayerInteractEvent) {
    6. lastInteract.remove(player.getName());
    7. } else {
    8. if(playerIntegers.containsKey(player.getName())) {
    9. playerIntegers.put(player.getName(), (playerIntegers.get(player.getName()) + 1));
    10. } else {
    11. playerIntegers.put(player.getName(), 1);
    12. }
    13. }
    14. } else {
    15. lastInteract.put(player.getName(), System.currentTimeMillis());
    16. }
    17. }


    Thanks in advance.
     
  2. Offline

    dsouzamatt

    negative_codezZ There are 20 ticks in a second I believe, which means that each is 50ms.
     
  3. Offline

    fireblast709

    negative_codezZ how are you planning to ensure the right mouse button is held?
     
  4. Offline

    negative_codezZ

    Well, the way I'm doing in the code.


    Thanks.
     
  5. Offline

    fireblast709

    negative_codezZ more like, the only way I know is by using isBlocking() with a sword
     
  6. Offline

    negative_codezZ

    That only works with a sword though. I need it with a bow. And I am pretty sure my method works, haven't tested yet though.
     
Thread Status:
Not open for further replies.

Share This Page