[experimental] Reset yawrate on teleports.

This commit is contained in:
asofold 2013-01-04 13:29:45 +01:00
parent 0f763782e0
commit 47faa014bf
2 changed files with 25 additions and 4 deletions

View File

@ -125,6 +125,23 @@ public class Combined {
}
return cancel;
}
/**
* Reset the yawrate data to yaw and time.
* @param player
* @param yaw
* @param time
* @param clear If to clear yaws.
*/
public static final void resetYawRate(final Player player, float yaw, final long time, final boolean clear){
if (yaw <= -360f) yaw = -((-yaw) % 360f);
else if (yaw >= 360f) yaw = yaw % 360f;
final CombinedData data = CombinedData.getData(player);
data.lastYaw = yaw;
data.lastYawTime = time; // TODO: One might set to some past-time to allow any move at first.
data.sumYaw = 0;
if (clear) data.yawFreq.clear(time);
}
/**
* Allow to pass a config flag if to check or only to feed.

View File

@ -663,17 +663,20 @@ public class MovingListener extends CheckListener{
// If it was a teleport initialized by NoCheatPlus, do it anyway even if another plugin said "no".
final Location to = event.getTo();
final Location ref;
if (teleported != null && teleported.equals(to)) {
// Teleport by NCP.
// Prevent cheaters getting rid of flying data (morepackets, other).
// TODO: even more strict enforcing ?
if (event.isCancelled()) {
event.setCancelled(false);
event.setTo(teleported);
event.setTo(teleported); // ?
event.setFrom(teleported);
ref = teleported;
}
else{
// Not cancelled but NCP teleport.
ref = to;
}
// TODO: This could be done on MONITOR.
data.onSetBack(teleported);
@ -682,14 +685,15 @@ public class MovingListener extends CheckListener{
// TODO: check if to do with cancelled teleports !
data.clearMorePacketsData();
data.clearFlyData();
data.resetPositions(event.isCancelled() ? event.getFrom() : to);
ref = event.isCancelled() ? event.getFrom() : to;
data.resetPositions(ref);
}
// Always drop data from fly checks, as it always loses its validity after teleports. Always!
// TODO: NoFall might be necessary to be checked here ?
data.teleported = null;
// Reset yawrate (experimental: might help preventing cascading improbable with rubberbanding).
Combined.resetYawRate(player, ref.getYaw(), System.currentTimeMillis(), true);
}
/**