Does PlayerMoveEvent require a lot of performance?

Discussion in 'Plugin Development' started by SammurDev, Sep 12, 2017.

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

    SammurDev

    Well, I'm currently not sure, whether to use this event or not. I have really nice ideas to implement, but since this event is always called when a player moves, which happens all the time and depending on the playerbase, it can get very performance-heavy.(that is what I think)

    Do you guys think that it could consume much performance? I have not tested anything, as I am currently on my own RPG plugin, which involved alot of RPG-like features and I'm also on building the spawn, first city etc..

    But as for this issue, I have no idea. Logically, it would be as I think. But I might be wrong and would like to hear out some experienced devs regarding this matter.
     
  2. Offline

    travja

    I wouldn't use anything too complex and whatnot in PlayerMoveEvent as it runs basically all the time, but small things should be fine.
     
  3. Offline

    SammurDev

    What do you think about checking location each time the player moves? I mean, it should work when playing with like 20 players or less, but do you think it would cause lags when playing with >50?
     
  4. Offline

    Zombie_Striker

    @SammurDev
    PlayerMoveEvent is called whenever a player moves and whenever a player looks around. If you only need to get their location, use BukkitRunnables and get the player's location every couple of ticks.
     
  5. Offline

    SammurDev

    Well, this sounds like another option. But I'd really want to avoid using runnables for this matter. I need the location right on time and not like 2-3 seconds later.

    I'd like to run a server with Open PvP with PvP safezones. So, if the player enters a PvP zone, it should tell him right away, and not after 2-3 seconds and also the other way around - when they enter a PvP safezone.

    This would consume some performance as well, maybe not as much as the event, but still.

    Either I would have to use a runnable for each player and get their location, or use a for loop to get all players at once and also their location.

    But, as coding is all about writing and testing, this is gonna be nothing else. I will use the event for this and look if it consumes much performance. But thanks for replying anyways.
     
  6. Offline

    Zombie_Striker

    @SammurDev
    But it does not need to be 2-3 seconds later. You can narrow it down to once every tick (1/20th of a second) if you really need it, although you should not need to check more than twice a second (or every 10 ticks).

    As for performance, Unless you have hundreds of players on the server at the same time (in which case, you must have a good enough computer that performance is not be important to you), the lag should be not be noticeable.
     
  7. Offline

    travja

    If you're okay using WorldGuard on your server, WorldGuard has flags for entry/exit messages that you can add to your regions. Otherwise, I'd say a scheduler is probably the best way to go. You can do it in PlayerMoveEvent just fine though. The math is fairly simple as it's just checking differences in x, y, and z coordinates. Really up to you ;)
     
  8. Offline

    Caderape2

    @SammurDev If you wanna do it with the PlayerMoveEvent, Compare the block location e.getTo() and e.getFrom() for minimize the execution of your code. That should not be a problem for 20 or 50 players, if you don't have others plugin like worldguard or portals that use this event too.
     
  9. Offline

    SammurDev

    Wow, I didn't know that WG has this kind of feature. I never had a deep look into that plugin, only used it to cover regions from griefings. Thanks alot to you and the rest of you. I will take every advice under consideration.
     
Thread Status:
Not open for further replies.

Share This Page