Shift double click itemlist?

Discussion in 'Plugin Development' started by thechrisanator, Dec 23, 2019.

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

    thechrisanator

    Is it possible to get an InventoryClickEvent and see all items that will be shift double clicked? or will I have to check and count them all myself?
     
  2. Offline

    KarimAKL

    @thechrisanator You could check if the item was shift-clicked, then add it to a collection.
    I'd do something like this:
    Code:Java
    1. private final Set<UUID> clicked = new HashSet<>();
    2.  
    3. @EventHandler
    4. private void onClick(InventoryClickEvent event) {
    5. Player player = (Player) event.getWhoClicked();
    6. UUID uuid = player.getUniqueId();
    7.  
    8. if (clicked.contains(uuid)) {
    9. // Do your stuff
    10. clicked.remove(uuid);
    11. }
    12.  
    13. // If you want to only count left clicks
    14. if (event.getClick() == ClickType.SHIFT_LEFT) {
    15. // Player left clicked while holding shift
    16. clicked.add(uuid);
    17. }
    18.  
    19. // If you want to only count right clicks
    20. if (event.getClick() == ClickType.SHIFT_RIGHT) {
    21. // Player right clicked while holding shift
    22. clicked.add(uuid);
    23. }
    24.  
    25. // If you want to count both left and right clicks
    26. if (event.getClick().isShiftClick()) {
    27. // Player left or right clicked while holding shift
    28. clicked.add(uuid);
    29. }
    30. }
     
  3. @KarimAKL Note that this doesn't work so well in creative mode because event.getClick() will then always return CREATIVE.
     
  4. Offline

    KarimAKL

    @knokko Huh, that seems like a weird decision.

    I'm guessing something like this should work for getting only left or right clicks:
    Code:Java
    1. if (event.getClick().isShiftClick() && event.getClick().isLeftClick()) {
    2. // Left click while holding shift
    3. }
    4.  
    5. if (event.getClick().isShiftClick() && event.getClick().isRightClick()) {
    6. // Right click while holding shift
    7. }

    Btw, i'd recommend removing the UUID from the list when the player leaves the server.
     
  5. Offline

    Sw_aG

    @thechrisanator you can try to make a scheduler which will remove the player from a variable after 10 ticks or so since the initial click.

    - Make the scheduler remove the player from a list or score or anything that you can check "if".
    - Make the first click change the variable for the player.

    So if 10 ticks (half a second, or what you prefer) passed since the first click, it'll remove the variable (reset).
     
Thread Status:
Not open for further replies.

Share This Page