Solved Right click block + right click air ???

Discussion in 'Plugin Development' started by ThunderWaffeMC, Dec 31, 2012.

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

    ThunderWaffeMC

    Code:java
    1.  
    2. if (event.getAction() == Action.RIGHT_CLICK_AIR){
    3.  


    How can I make it so in my code you can either right click air OR right click a block for the event to work?

    Thanks in advance
     
  2. Offline

    chasechocolate

    Code:java
    1. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
    2. //code
    3. }
     
    ThunderWaffeMC likes this.
  3. Offline

    ThunderWaffeMC

    Okay but what is for RIGHT_CLICK player? I tried entity and player but it doesn't work?
     
  4. Offline

    pkt

    What do you mean...?
     
  5. Offline

    ThunderWaffeMC

    Well it has so when you right click a block or air it does the event, but how can I do it so when you right click a player?
     
  6. Offline

    pkt

    Oh idk.. try Action.PHYSICAL as I am unsure what it does because thebukkit javadoc description of it is: "Ass-pressure" lol
     
  7. Offline

    Jogy34

    That would be handeled in a PlayerInteractEntityEvent
     
  8. Offline

    ThunderWaffeMC

  9. Offline

    pkt

    Oh yea Jogy34 is right: use the PlayerInteractEntityEvent
    something like this:
    Code:
        @EventHandler
        public void onRightClickPlayer(PlayerInteractEntityEvent event) {
            Entity entity = event.getRightClicked();
         
            if (entity instanceof Player) {
                //code
            }
        }

    Though I am still curious what Action.PHYSICAL is....
     
  10. Offline

    ThunderWaffeMC

    pkt If I did that then my PlayerInteractEvent wouldn't work. Is there a way to combine both?

    public void onPlayerInteract(PlayerInteractEvent event) {
     
  11. Offline

    pkt

    Why would it not work? its 2 different events....
     
  12. Offline

    Jogy34

    Why wouldn't your PlayerInteractEvent work?
     
  13. Offline

    ThunderWaffeMC

    Well because I'm using the code:

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. Player player = event.getPlayer();
    5. if (player.hasPermission("swordbow.use")) {
    6. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
    7. if(event.getPlayer().getItemInHand().getType() == itemRequired) {
    8. player.launchProjectile(Arrow.class);
    9.  
     
  14. Offline

    pkt

    Right, but it would not make PlayerInteractEntityEvent not work...
     
  15. Offline

    ThunderWaffeMC

    Alright so I use this?

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. boolean onRightClickPlayer;PlayerInteractEntityEvent event1; {
    5. Entity entity = event1.getRightClicked();
    6. Player player = event1.getPlayer();
    7. if (player.hasPermission("swordbow.use")) {
    8. if(event1.getAction() == Action.RIGHT_CLICK_AIR || event1.getAction() == Action.RIGHT_CLICK_BLOCK){
    9. if(event1.getPlayer().getItemInHand().getType() == itemRequired) {
    10. player.launchProjectile(Arrow.class);
    11.  
     
  16. Offline

    pkt

    oh no, you would do this:
    Code:
        @EventHandler
        public void onRightClickPlayer(PlayerInteractEntityEvent event) {
            Player player = event.getPlayer();
            Entity entity = event.getRightClicked();
     
            if (entity instanceof Player) {
                if (player.hasPermission("swordbow.use")) {
                    if (event.getPlayer().getItemInHand().getType() == itemRequired) {
                        player.launchProjectile(Arrow.class);
                    }
                }
            }
        }
    (edit to your liking)
     
    ThunderWaffeMC likes this.
  17. Offline

    Jogy34

    ya what pkt said and also keep your onPlayerInteract() method how you had it
     
    ThunderWaffeMC likes this.
  18. Offline

    ThunderWaffeMC

    pkt I've edited heaps to make the errors go away and I've came up with the last 2 errors (same error just duplicated)

    Code:java
    1.  
    2. public void onRightClickPlayer(PlayerInteractEntityEvent event) {
    3. boolean onPlayerInteract(PlayerInteractEvent event1) { //where "(" and ")" is I get the error saying syntax error on token and I should change it to a ; but if I do then the getAction() wont work?
    4. Entity entity = event.getRightClicked();
    5. Player player = event.getPlayer();
    6. if (player.hasPermission("swordbow.use")) {
    7. if (entity instanceof Player) {
    8. if(event1.getAction() == Action.RIGHT_CLICK_AIR || event1.getAction() == Action.RIGHT_CLICK_BLOCK){
    9. if(event.getPlayer().getItemInHand().getType() == itemRequired) {
    10. player.launchProjectile(Arrow.class);
    11.  
     
  19. Offline

    Jogy34

    The PlayerInteractEvent and PlayerInteractEntityEvent are two completely separate methods
     
  20. Offline

    ThunderWaffeMC

    Oh alright, I'll check it out.
     
  21. Offline

    pkt

    Ohhh, you are trying to combine the 2 events(that boolean is not needed) try:
    Code:
        @EventHandler
        public void onPlayerClick(PlayerInteractEvent event1, PlayerInteractEntityEvent event2) {
            Player player = event1.getPlayer();
            Action action = event1.getAction();
            Entity entity = event2.getRightClicked();
    Player player2 = event2.getPlayer();
     
            if (player.hasPermission("swordbow.use")) {
                if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
                    if (event1.getPlayer().getItemInHand().getType() == itemRequired) {
                        player.launchProjectile(Arrow.class);
                    }
                }
            }
     
            if (entity instanceof Player) {
                if (player2.hasPermission("swordbow.use")) {
                    if (event2.getPlayer().getItemInHand().getType() == itemRequired) {
                        player2.launchProjectile(Arrow.class);
                    }
                }
            }
        }
     
  22. Offline

    Jogy34

    Can you combine 2 events like that?
     
  23. Offline

    pkt

    Idk... I was just guessing...

    EDIT: Just tested and no you cannot lol srry
     
  24. Offline

    ThunderWaffeMC

    Just tried right clicking a mob and it works. Thanks everyone.
     
  25. Offline

    kkkeeeddd

    I'll
    use
    Code:java
    1. @EventHandler
    2. public void onClick(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE) {
    5. e.setCancelled(true);
    6. p.sendMessage("Test");
    7. }
    8. }
     
Thread Status:
Not open for further replies.

Share This Page