Clicked block in Main class

Discussion in 'Plugin Development' started by desup, Feb 9, 2012.

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

    desup

    Hello, another stupid question, ;) in my Player Listener, I have OnPlayerInteract event which gets clicked block, like this:
    Code:
    Block b = event.getClickedBlock();
    Then, in my main class i have OnCommand boolean, and there, i need to work with this block variable, but I dont know how to pass that variable from BlockListener to main class.

    Can you help me?
    Thank you!
     
  2. either make a public variable (or method) in the playerlistener or in the main class and save the playerlistener in a variable in the main class or pass the main class to the listener somewhere (e.g. in the constructor) depending on where you made the variable.
     
  3. Offline

    Njol

    If you want multiple players to use the command you're coding, you should use something like:
    Code:java
    1. static final HashMap<Player, Block> clickedBlocks = new HashMap<Player, Block>();
    where you store the last blocks clicked by each player using clickedBlocks.put(event.getPlayer(), event.getBlock()). You can then get the last block a player clicked on via clickedBlocks.get(player). You'll have to take into account that get() will return null if the player never clicked on a block since logging in.

    PS: If your plugins needs to store more player-related data, you should make a new PlayerInfo class, and make one single HashMap<Player, PlayerInfo> in your main class. PlayerInfo should contain the last clicked block, and any other data you want to store about the player.
     
  4. Offline

    desup

    Thank you Really much Njol ! :)
     
Thread Status:
Not open for further replies.

Share This Page