Bukkit PlayerMoveEvent

Discussion in 'Plugin Development' started by MCKrypto14, Jun 22, 2016.

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

    MCKrypto14

    Hi! I'm making sort of an RPG plugin for my Bukkit server, and I'm using the PlayerMoveEvent to send titles to players for when they enter different areas.

    What I was wondering is if the PlayerMoveEvent was a bad idea to use. I realized it's called whenever a player's x/y/z/yaw/pitch changes. I also figured that if 200 players are on, and atleast half of them are moving, that's 100 different events to handle at once.

    Does anyone know if it's not as bad as I think, or maybe there is a more efficient alternative? Thanks in advance!

    -Krypto14
     
  2. Offline

    timtower Administrator Moderator

    Moved to plugin development.
     
  3. Offline

    MisterErwin

    @MCKrypto14 You could improve it by checking if the distance (use the distanceSquared method as it is far easier to compute) is greater than a specific value.

    Or do it in a Runnable, but then you have to make sure that you only check on recently moved players.

    But the most important thing (either way) would be your "area-detection" part.

    As when you have like 300 regions, you can't check against every region. Instead optimize that part (e.g. via trees (quadtrees) )
     
  4. Offline

    Zombie_Striker

    @MCKrypto14 @MisterErwin
    The best way you can do this is by either storing the center of a region, or the min/max values for a region. This is so you don't have to check all locations in a region. Every couple of ticks (use a Runnable), loop through all the players and check if their location is either in the min/max area or are close to the center of a region. If so, send the message and do something to make sure the player only receive the message once.
     
  5. Offline

    OTF Catastrophe

    I know this might not be helpful all to much because you're looking for help for YOUR plugin, but this plugin allows you to pop up titles when you enter a different region. Works good with Factions and depends on WorldGuard regions. Might be something to look into ^-^
     
Thread Status:
Not open for further replies.

Share This Page