use of fr.neatmonster.nocheatplus.components.location.SimplePositionWithLook in project NoCheatPlus by NoCheatPlus.
the class MovingListener method onPlayerTeleportMonitor.
/**
* MONITOR: Adjust data to what happened.
*
* @param event
*/
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onPlayerTeleportMonitor(final PlayerTeleportEvent event) {
// Evaluate result and adjust data.
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
// Invalidate first-move thing.
// TODO: Might conflict with 'moved wrongly' on join.
data.joinOrRespawn = false;
// Special cases.
final Location to = event.getTo();
if (event.isCancelled()) {
onPlayerTeleportMonitorCancelled(player, event, to, data, pData);
return;
} else if (to == null) {
// Weird event.
onPlayerTeleportMonitorNullTarget(player, event, to, data, pData);
return;
}
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
// Detect our own player set backs.
if (data.hasTeleported() && onPlayerTeleportMonitorHasTeleported(player, event, to, data, cc, pData)) {
return;
}
// Skip extra data adjustments during special teleport, e.g. vehicle set back.
boolean skipExtras = false;
// Detect our own vehicle set backs (...).
if (data.isVehicleSetBack) {
// Uncertain if this is vehicle leave or vehicle enter.
if (event.getCause() != BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION) {
// TODO: Unexpected, what now?
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, CheckType.MOVING_VEHICLE) + "Unexpected teleport cause on vehicle set back: " + event.getCause());
}
// TODO: Consider to verify, if this is somewhere near the vehicle as expected (might need storing more data for a set back).
skipExtras = true;
}
// Normal teleport
final double fallDistance = data.noFallFallDistance;
// final LiftOffEnvelope oldEnv = data.liftOffEnvelope; // Remember for workarounds.
data.clearFlyData();
data.clearPlayerMorePacketsData();
data.setSetBack(to);
// Important against concurrent modification exception.
data.sfHoverTicks = -1;
if (cc.loadChunksOnTeleport) {
MovingUtil.ensureChunksLoaded(player, to, "teleport", data, cc, pData);
}
aux.resetPositionsAndMediumProperties(player, to, data, cc);
// TODO: Decide to remove the LiftOffEnvelope thing completely.
// if (TrigUtil.maxDistance(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ()) <= 12.0) {
// // TODO: Might happen with bigger distances (mainly ender pearl thrown at others).
// // Keep old lift-off envelope.
// data.liftOffEnvelope = oldEnv;
// }
// Reset stuff.
// TODO: Not sure.
Combined.resetYawRate(player, to.getYaw(), System.currentTimeMillis(), true, pData);
data.resetTeleported();
if (!skipExtras) {
// TODO: Detect transition from valid flying that needs resetting the fall distance.
if (event.getCause() == TeleportCause.UNKNOWN) {
// Always keep fall damage.
player.setFallDistance((float) fallDistance);
data.noFallFallDistance = (float) fallDistance;
} else if (fallDistance > 1.0 && fallDistance - player.getFallDistance() > 0.0) {
// Reset fall distance if set so in the config.
if (!cc.noFallTpReset) {
// (Set fall distance if set to not reset.)
player.setFallDistance((float) fallDistance);
data.noFallFallDistance = (float) fallDistance;
} else if (fallDistance >= Magic.FALL_DAMAGE_DIST) {
data.noFallSkipAirCheck = true;
}
}
if (event.getCause() == TeleportCause.ENDER_PEARL) {
// Prevent NoFall violations for ender-pearls.
data.noFallSkipAirCheck = true;
}
}
// Cross world teleportation issues with the end.
final Location from = event.getFrom();
if (from != null && // Currently only related to this.
event.getCause() == TeleportCause.END_PORTAL && !from.getWorld().getName().equals(to.getWorld().getName())) {
// Less java, though.
// Remember the position teleported from.
data.crossWorldFrom = new SimplePositionWithLook(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch());
} else {
// Reset last cross world position.
data.crossWorldFrom = null;
}
// Log.
if (pData.isDebugActive(checkType)) {
debugTeleportMessage(player, event, "(normal)", to);
}
}
Aggregations