Best listener for this?

Discussion in 'Plugin Development' started by Phinary, Jul 13, 2012.

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

    Phinary

    Hey guys, so I coded a simple thing where when you stand on a certain block, it will launch you into the air. You can also place blocks on top of each other and get launched higher. To use this, I did a OnPlayerMove event for this where it basically checks whenever the player moves if that block is below them. I was wondering if there was a more optimized way to do this as I feel doing that check every single time a player moves could probably be very cpu intensive. Thanks
     
  2. Offline

    Bavestry

    I'm new to bukkit, what I would do is go to your imports and type import org.bukkit.event.player. then scroll through the options it gives you. ^^
     
  3. Offline

    r0306

    In a PlayerInteractEvent, check if the action is PHYSICAL and check if the block involved is your launching block.
     
  4. Offline

    pzxc

    PlayerMove is the correct event to use for this I think, but as stated it can be very resource intensive as it fires whenever they move the slightest bit, including turning. It can fire a couple dozen times a second per player, that adds up fast.

    If you have to do something like this, a good way to optimize is to return from the PlayerMove function early if they didn't change from one block to another.

    if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockY() == event.getTo().getBlockY() && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) return;

    Something like that. So any "movements" that don't change the block they're standing on don't execute any code after that statement, only a movement from one block to another continues in the function.
     
Thread Status:
Not open for further replies.

Share This Page