mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 01:12:47 +01:00
Prevent movement event to be spammed for moving less than a pixel.
This commit is contained in:
parent
78af4f97f9
commit
88dea6189a
1 changed files with 12 additions and 1 deletions
|
@ -56,6 +56,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||
private int lastY;
|
||||
private int lastZ;
|
||||
|
||||
private double lastPosX = Double.MIN_VALUE;
|
||||
private double lastPosY = Double.MIN_VALUE;
|
||||
private double lastPosZ = Double.MIN_VALUE;
|
||||
|
||||
// Store the last block right clicked and what type it was
|
||||
private CraftBlock lastRightClicked;
|
||||
private BlockFace lastRightClickedFace;
|
||||
|
@ -111,7 +115,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||
Player player = getPlayer();
|
||||
Location from = new Location(player.getWorld(), i, j, k, this.e.yaw, this.e.pitch);
|
||||
Location to = player.getLocation();
|
||||
if (!from.equals(to)) {
|
||||
|
||||
// Prevent 40 event-calls for less than a single pixel of movement >.>
|
||||
double delta = Math.pow( this.lastPosX - this.i, 2) + Math.pow( this.lastPosY - this.j, 2) + Math.pow( this.lastPosZ - this.k, 2);
|
||||
if (delta > 1f/256) {
|
||||
PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_MOVE, player, from, to);
|
||||
server.getPluginManager().callEvent(event);
|
||||
|
||||
|
@ -123,6 +130,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||
this.e.locZ = to.getZ();
|
||||
this.e.yaw = to.getYaw();
|
||||
this.e.pitch = to.getPitch();
|
||||
|
||||
this.lastPosX = this.e.locX;
|
||||
this.lastPosY = this.e.locY;
|
||||
this.lastPosZ = this.e.locZ;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
|
|
Loading…
Reference in a new issue