3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00

Prevent movement event to be spammed for moving less than a pixel.

Dieser Commit ist enthalten in:
Erik Broes 2011-02-25 22:40:06 +01:00
Ursprung 78af4f97f9
Commit 88dea6189a

Datei anzeigen

@ -56,6 +56,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
private int lastY; private int lastY;
private int lastZ; 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 // Store the last block right clicked and what type it was
private CraftBlock lastRightClicked; private CraftBlock lastRightClicked;
private BlockFace lastRightClickedFace; private BlockFace lastRightClickedFace;
@ -111,7 +115,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
Player player = getPlayer(); Player player = getPlayer();
Location from = new Location(player.getWorld(), i, j, k, this.e.yaw, this.e.pitch); Location from = new Location(player.getWorld(), i, j, k, this.e.yaw, this.e.pitch);
Location to = player.getLocation(); 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); PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_MOVE, player, from, to);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
@ -123,6 +130,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
this.e.locZ = to.getZ(); this.e.locZ = to.getZ();
this.e.yaw = to.getYaw(); this.e.yaw = to.getYaw();
this.e.pitch = to.getPitch(); this.e.pitch = to.getPitch();
this.lastPosX = this.e.locX;
this.lastPosY = this.e.locY;
this.lastPosZ = this.e.locZ;
} }
// CraftBukkit end // CraftBukkit end