Klasse PlayerMouseButtonEvent


public final class PlayerMouseButtonEvent extends PlayerEvent
Called when a player presses or releases a mouse button. To receive this event, make sure to enable mouse input for the player first (see Player.setListenForMouseInput(boolean))
Example: Listen for mouse button input
1@EventMethod
2public void onPlayerSpawn(PlayerSpawnEvent event){
3 Player player = event.getPlayer();
4
5 //Important: Set listen for mouse input true, otherwise the PlayerMouseButtonEvent will not be triggered
6 player.setListenForMouseInput(true);
7}
8
9@EventMethod
10public void onMouseButton(PlayerMouseButtonEvent event){
11 //We only want to process mouse presses (ignore button releases)
12 if(event.isPressed()){
13 //Check if right mouse button was pressed
14 if(event.getButton() == MouseButton.Right){
15 //Do something
16 }
17 }
18}
Siehe auch:
  • Methodendetails

    • getButton

      public MouseButton getButton()
      Gets the mouse button that is actuated.
      Gibt zurück:
      the mouse button.
      Siehe auch:
    • isPressed

      public boolean isPressed()
      Gets whether the mouse button was pressed or released.
      Gibt zurück:
      true if the mouse button was pressed, false if it was released.