PlayerMoveEvent Conflict

Discussion in 'Plugin Development' started by simonsigge, Jan 4, 2014.

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

    simonsigge

    Hello!
    I've made a plugin that teleports players when the walk on redstoneblocks.
    However when I use the plugin on my server it conflicts with NoCheatPlus.
    It makes it so that when players teleport they will be teleported one block more down than the should. (y-1).

    I know the reason for this but I cant fix it. Anyone knows how?
    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent e){
    3. Player p = e.getPlayer();
    4. Block blox = e.getTo().add(0,1,0).getBlock();
    5. World w = p.getWorld();
    6. if(blox.getType() == Material.REDSTONE_BLOCK){
    7. p.sendMessage(ChatColor.GRAY+""+ChatColor.ITALIC+""+ChatColor.BOLD+"xPlayPvP ->"+ChatColor.BLUE+" Grattis! Du klarade MLGn! :)");
    8. p.teleport(new Location(w, 0.5D, 50D, 0.5D));
    9. p.getInventory().clear();
    10. }
    11. }
     
  2. Offline

    GusGold

    simonsigge

    I don't know what your problem is, but as a hint for performance in your plugin, trying checking if they have chnaged block, not just everytime they move.

    The client will send upto 20 move events per second, and if you are doing all that processing on each one, it is a waste of resources and could potentially be a cause of server lag. Add a check in to see if the player has changed block. I.e:
    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent e){
    3. If (e.getFrom().getBlockX() != e.getTo().getBlockY() || e.getFrom().getBlockY() != e.getTo().getBlockY() || e.getFrom().getBlockZ() != e.getTo().getBlockZ()){
    4. //Now do stuff here because the player has changed block, rather than just moving inside the same block
    5. }
    6. }
     
    HelpfulBeast likes this.
  3. Offline

    xTrollxDudex

    simonsigge
    Try
    PHP:
    Block blox e.getTo().clone().add(0,1,0).getBlock();
     
Thread Status:
Not open for further replies.

Share This Page