Shift click on player event?

Discussion in 'Plugin Development' started by Meatiex, Aug 5, 2013.

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

    Meatiex

    Is there a event for shift clicking on another player? or one like it?
    I would like to use that event to open a chest like thing that has the player's head and a map that you can click on that opens the player's inventory (player command /invsee player)

    any help? Thanks! ~Meatie
     
  2. Offline

    chasechocolate

    PlayerInteractEntityEvent, check if the player is sneaking.
     
  3. The best I can think if is "PlayerRightClickEntityEvent"
    You could check if the item in their hand is equal to air, and if the entity they right click is an instanceof a Player.
    And then create a new inventory with the right clicked entities contents and add their username to an arraylist. Then if they try to edit the inventory just cancel the event if the arraylist contains their username. :)
    EDIT: Damn Ninjas ;)
     
  4. Offline

    Meatiex

    Thanks, any idea how to get the target player's name?
    I just want it to make the player run a command(/invsee player)

    Code:java
    1. public void PlayerRightClickEntity(PlayerRightClickEntityEvent event) {
    2. event.getPlayer().performCommand("invsee " /*+ TargePlayer*/);
    3. }
     
    hintss likes this.
  5. Offline

    chasechocolate

    Meatiex check if event.getRightClicked() instanceof Player, then cast, then use target.getName().
     
  6. Offline

    Meatiex

    How do i define the event on the first line?
     
  7. Offline

    chasechocolate

    Meatiex if(event.getRightClicked() instanceof Player) and Player target = (Player) event.getRightClicked().
     
  8. Offline

    Meatiex

    It didn't work... Nothing happend

    Code:java
    1. public void PlayerRightClickEntity(PlayerInteractEntityEvent event) {
    2. if(event.getRightClicked() instanceof Player) {
    3. Player player = event.getPlayer();
    4. event.getRightClicked();
    5. event.getPlayer().performCommand("invsee " + player.getName());
    6. }
    7. }
     
  9. Offline

    chasechocolate

    Meatiex not on my computer, but:
    Player player = event.getPlayer();

    if(event.getRightClicked() instanceof Player){
    Player clicked = (Player) event.getRightClicked();
    //Perform command.
    }
     
  10. Offline

    Meatiex

    it didnt work...
    Code:java
    1. public void PlayerRightClickEntity(PlayerInteractEntityEvent event) {
    2. if(event.getRightClicked() instanceof Player){
    3. Player clicked = (Player) event.getRightClicked();
    4. event.getPlayer().performCommand("invsee " + clicked.getName());
    5. }
    6. }
     
  11. Offline

    fanaticmw2

    Are you using the @EventHandler annotation? Have you even registered the event?
     
  12. Offline

    chasechocolate

    Meatiex then you either didn't register your events or add the @EventHandler annotation.

    EDIT: Ninja'd by fanaticmw2
     
  13. Offline

    Meatiex

    Thanks! I forgot to import listener in main class :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  14. Offline

    AndyMcB1

    Is there a right click event?
     
  15. Offline

    Meatiex

    yes, this is right click event, i dono how to do shift right click.

    1. public void PlayerRightClickEntity(PlayerInteractEntityEvent event) {
     
  16. Offline

    AndyMcB1

    I mean just right click in general.. not a block or entity?
     
  17. Offline

    Meatiex

    public static final ClickType RIGHT() {
    I think...
    Check out the events here.
     
  18. Offline

    AndyMcB1

    Code:java
    1. @EventHandler
    2. public void PlayerInteractEvent(PlayerInteractEvent event) {
    3. event.getPlayer().sendMessage("Interact event!");
    4. if (event.getAction() == Action.LEFT_CLICK_AIR){
    5. event.getPlayer().sendMessage("Click!");
    6.  
    7.  
    8. }
    9. }


    This works when, well you left click AIR, however when I change it to RIGHT it doesn't work..
     
  19. Offline

    chasechocolate

    Action.RIGHT_CLICK_AIR or Action.RIGHT_CLICK_BLOCK.
     
  20. Offline

    AndyMcB1

    I tried RIGHT_CLICK_AIR

    Code:
     @EventHandler
        public void PlayerInteractEvent(PlayerInteractEvent event) {
            event.getPlayer().sendMessage("Interact event!");
            if (event.getAction() == Action.RIGHT_CLICK_AIR){
                event.getPlayer().sendMessage("Click!");
               
             
            }
        }
     
  21. Offline

    Plo124

    Make sure your hand is empty, I don't think right clicking a block in the air registers an event
     
  22. Offline

    ReggieMOL

    AndyMcB1
    Do not hold anything while clicking to the air, you can also test RIGHT_CLICK_BLOCK and same for left.
     
Thread Status:
Not open for further replies.

Share This Page