Help with interact events

Discussion in 'Plugin Development' started by yustinv2, Mar 5, 2016.

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

    yustinv2

    Hello, im having some little problems with actions in the interact event, i wanna make that the user recieves a message when they do left then right and then left click like that, i have problems when i do left click because is repeated and it do 2 actions instead of 1 my code is this:

    public class Testing implements Listener {

    @EventHandler
    public void InteractEvent(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    Action action = e.getAction();

    if (p.getItemInHand().getType() == Material.PAPER){
    if (action.equals(Action.LEFT_CLICK_AIR) || action.equals(Action.LEFT_CLICK_BLOCK)){
    p.sendMessage(ChatColor.DARK_RED + "Test 1");}
    if (action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)){
    p.sendMessage(ChatColor.DARK_RED + "Test 2");}
    if (action.equals(Action.LEFT_CLICK_AIR) || action.equals(Action.LEFT_CLICK_BLOCK)){
    p.sendMessage(ChatColor.DARK_RED + "Test 3");}
    }

    }
    }

    So the problems is when i left click with a paper i recieve the message Test 1 what is the correct one and i recieve Test 3, how i could make to just run test1 in the first left click and then test2 in the second or third left click ?

    Im sorry if my english is so bad...
     
  2. Offline

    JetsinsuGZ

    Code:
    if (action.equals(Action.LEFT_CLICK_AIR) || action.equals(Action.LEFT_CLICK_BLOCK))
    Instead of using .equals, use == Action.LEFT_CLICK_AIR

    You could use an ArrayList to get the different message.
     
    Last edited: Mar 5, 2016
  3. Offline

    yustinv2

    how i could make an arraylist to send diferent messages ? i never tried it, btw i dont need it to send message, i will make it to combine diferents click to make diferents actions like if you do left click then right and then left you will fire a fireball,

    i alredy resolved it making just a 1 block, not necesary a arraylist btw Thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 5, 2016
Thread Status:
Not open for further replies.

Share This Page