Question about PlayerMoveEvent

Discussion in 'Plugin Development' started by ocomobock, Jul 17, 2015.

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

    ocomobock

    I have multiple PlayerMoveEvents being used that all check for different things. Would it be better to combine all of them into one event? I did /timings on and then /timings paste, and I found this under my plugin:
    Code:
    0.01% 0.03% 0.00 s 0.02 ms 0.4 0.1k Spellbook::youAlreadyHave(PlayerMoveEvent)
    
    0.01% 0.01% 0.00 s 0.00 ms 1.0 0.1k Task: Spellbook$20(interval 1)
    
    0.01% 0.02% 0.00 s 0.01 ms 0.4 0.1k Spellbook::snowshoes(PlayerMoveEvent)
    
    0.01% 0.01% 0.00 s 0.01 ms 0.4 0.1k Spellbook::speedup(PlayerMoveEvent)
    
    0.00% 0.01% 0.00 s 0.00 ms 0.4 0.1k Spellbook::pressurePlate(PlayerMoveEvent)
    
    0.00% 0.01% 0.00 s 0.00 ms 0.4 0.1k Spellbook::wallJump(PlayerMoveEvent)
    
    0.00% 0.01% 0.00 s 0.00 ms 0.4 0.1k Spellbook::rocketBoat(PlayerMoveEvent)
    
    0.00% 0.01% 0.00 s 0.00 ms 0.4 0.1k Spellbook::poseidon(PlayerMoveEvent)
    
    0.00% 0.01% 0.00 s 0.00 ms 0.4 0.1k Spellbook::cultivator(PlayerMoveEvent)
    
    0.00% 0.01% 0.00 s 0.00 ms 0.4 0.1k Spellbook::nether(PlayerMoveEvent)
    
    0.00% 0.01% 0.00 s 0.00 ms 0.4 0.1k Spellbook::glide(PlayerMoveEvent)
    
    My server has been really laggy with my plugin, and I'm not sure what to do. Would combining the events fix the lag?
     
  2. Offline

    adam753

    It would be better, but only a minor difference at best. Running lots of code every time any player moves is difficult (and not necessarily possible) to optimize. You should try to see if any of your events can be made reactive rather than using PlayerMoveEvent, because the latter really is a brute force approach to things.
     
  3. Offline

    Konato_K

    @ocomobock The best way to optimize the PlayerMoveEvent is to only run logic when the player changes block, this way you void doing all your fancy math every single movement.
     
  4. Offline

    ocomobock

    Could you explain how I would do this?
     
  5. Offline

    yupie_123

    @ocomobock
    Put this in the move event:
    Code:
    if(e.getFrom().getX() != e.getTo.getX() || e.getFrom().getZ() != e.getTo.getZ(){
      //Your code
    }
     
  6. Offline

    SuperOriginal

    @yupie_123 That wouldn't really help unless you floored the doubles or made them integers.

    0.0001 != 0.0002 so the slightest movement at all would trigger it anyways.
     
  7. Offline

    ocomobock

    Thanks, I used this code in all of my events, and combined all PlayerMoveEvents. It seems to be lagging less now.

    It doesn't trigger it when just looking around though, which could help.

    Although for some events, I'm unable to use that code, because it requires players to be looking around. It works for most though.
     
  8. Offline

    adam753

    You could avoid this using getBlockX() rather than getX() etc
     
  9. Offline

    SuperOriginal

    Indeed.
     
  10. Offline

    yupie_123

    Yes, sorry. I meant that ;) Was on my phone
     
Thread Status:
Not open for further replies.

Share This Page