mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-18 18:01:17 +02:00
Make use of yaw/pitch correction (silent correction).
This commit is contained in:
parent
59054b402b
commit
db7b34e50c
@ -365,11 +365,17 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||||||
final Location to = event.getTo();
|
final Location to = event.getTo();
|
||||||
Location newTo = null;
|
Location newTo = null;
|
||||||
|
|
||||||
|
// Check problematic yaw/pitch values.
|
||||||
|
if (LocUtil.needsDirectionCorrection(from.getYaw(), from.getPitch())
|
||||||
|
|| LocUtil.needsDirectionCorrection(to.getYaw(), to.getPitch())) {
|
||||||
|
DataManager.getPlayerData(player).task.correctDirection();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Check illegal moves here anyway (!).
|
// TODO: Check illegal moves here anyway (!).
|
||||||
// TODO: Check if vehicle move logs correctly (fake).
|
// TODO: Check if vehicle move logs correctly (fake).
|
||||||
|
|
||||||
// Early return checks (no full processing).
|
// Early return checks (no full processing).
|
||||||
boolean earlyReturn = false;;
|
boolean earlyReturn = false;
|
||||||
if (player.isInsideVehicle()) {
|
if (player.isInsideVehicle()) {
|
||||||
// No full processing for players in vehicles.
|
// No full processing for players in vehicles.
|
||||||
newTo = onPlayerMoveVehicle(player, from, to, data);
|
newTo = onPlayerMoveVehicle(player, from, to, data);
|
||||||
@ -392,7 +398,14 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||||||
if (earlyReturn || newTo != null) {
|
if (earlyReturn || newTo != null) {
|
||||||
// TODO: Log "early return: " + tags.
|
// TODO: Log "early return: " + tags.
|
||||||
if (newTo != null) {
|
if (newTo != null) {
|
||||||
newTo = checkLookingDirection(from, to, newTo);
|
// Illegal Yaw/Pitch.
|
||||||
|
if (LocUtil.needsYawCorrection(newTo.getYaw())) {
|
||||||
|
newTo.setYaw(LocUtil.correctYaw(newTo.getYaw()));
|
||||||
|
}
|
||||||
|
if (LocUtil.needsPitchCorrection(newTo.getPitch())) {
|
||||||
|
newTo.setPitch(LocUtil.correctPitch(newTo.getPitch()));
|
||||||
|
}
|
||||||
|
// Set.
|
||||||
event.setTo(newTo);
|
event.setTo(newTo);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -589,12 +602,16 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Illegal Yaw/Pitch.
|
// Set-back handling.
|
||||||
// TODO: Extra check, to be able to trigger violations.
|
|
||||||
newTo = checkLookingDirection(from, to, newTo);
|
|
||||||
|
|
||||||
// Did one of the checks decide we need a new "to"-location?
|
|
||||||
if (newTo != null) {
|
if (newTo != null) {
|
||||||
|
// Illegal Yaw/Pitch.
|
||||||
|
if (LocUtil.needsYawCorrection(newTo.getYaw())) {
|
||||||
|
newTo.setYaw(LocUtil.correctYaw(newTo.getYaw()));
|
||||||
|
}
|
||||||
|
if (LocUtil.needsPitchCorrection(newTo.getPitch())) {
|
||||||
|
newTo.setPitch(LocUtil.correctPitch(newTo.getPitch()));
|
||||||
|
}
|
||||||
|
|
||||||
// Reset some data.
|
// Reset some data.
|
||||||
data.prepareSetBack(newTo);
|
data.prepareSetBack(newTo);
|
||||||
|
|
||||||
@ -623,60 +640,6 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||||||
parkedInfo.add(moveInfo);
|
parkedInfo.add(moveInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param from
|
|
||||||
* @param to
|
|
||||||
* @param newTo
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private final Location checkLookingDirection(final Location from, final Location to, final Location newTo) {
|
|
||||||
// TODO: Reduce signature, once decided.
|
|
||||||
final float yaw;
|
|
||||||
if (newTo == null) {
|
|
||||||
yaw = to.getYaw();
|
|
||||||
} else {
|
|
||||||
yaw = newTo.getYaw();
|
|
||||||
}
|
|
||||||
final float newYaw = safeYaw(yaw);
|
|
||||||
if (yaw != newYaw) {
|
|
||||||
// TODO: Trigger a violation ?
|
|
||||||
if (newTo != null) {
|
|
||||||
newTo.setYaw(newYaw);
|
|
||||||
return newTo;
|
|
||||||
} else {
|
|
||||||
return LocUtil.clone(to, newYaw, to.getPitch());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Return original newTo.
|
|
||||||
return newTo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe clamp "if necessary".
|
|
||||||
* @param val
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static final float safeYaw(float val) {
|
|
||||||
// Safety first.
|
|
||||||
if (val == Float.NaN || val > 100000f || val < -100000f) {
|
|
||||||
return 180f;
|
|
||||||
}
|
|
||||||
if (val >= 720f) {
|
|
||||||
while (val >= 360f) {
|
|
||||||
// TODO: Allow 360f explicitly?
|
|
||||||
val -= 360f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (val <= -360f) {
|
|
||||||
while (val < 0f) {
|
|
||||||
val += 360f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from player-move checking, if the player is inside of a vehicle.
|
* Called from player-move checking, if the player is inside of a vehicle.
|
||||||
* @param player
|
* @param player
|
||||||
@ -1302,22 +1265,9 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bad pitch/yaw.
|
// Bad pitch/yaw, just in case.
|
||||||
final Location newTo = checkLookingDirection(useLoc, useLoc, null);
|
if (LocUtil.needsDirectionCorrection(useLoc.getYaw(), useLoc.getPitch())) {
|
||||||
if (newTo != null) {
|
DataManager.getPlayerData(player).task.correctDirection();
|
||||||
// TODO: Make this kind of functionality part of PlayerTask (needs priority-handling, probably).
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
player.getLocation(useLoc);
|
|
||||||
final Location newTo = checkLookingDirection(useLoc, useLoc, null);
|
|
||||||
if (newTo != null) {
|
|
||||||
player.teleport(newTo);
|
|
||||||
}
|
|
||||||
// Cleanup.
|
|
||||||
useLoc.setWorld(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup.
|
// Cleanup.
|
||||||
|
@ -2,6 +2,8 @@ package fr.neatmonster.nocheatplus.players;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||||
|
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||||
import fr.neatmonster.nocheatplus.utilities.OnDemandTickListener;
|
import fr.neatmonster.nocheatplus.utilities.OnDemandTickListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,39 +13,55 @@ import fr.neatmonster.nocheatplus.utilities.OnDemandTickListener;
|
|||||||
*/
|
*/
|
||||||
public class PlayerTask extends OnDemandTickListener {
|
public class PlayerTask extends OnDemandTickListener {
|
||||||
|
|
||||||
|
// TODO: Consider overriding some logic, because it is used in the main thread only (context: isRegisterd + register).
|
||||||
|
|
||||||
public final String lcName;
|
public final String lcName;
|
||||||
|
|
||||||
protected boolean updateInventory = false;
|
protected boolean updateInventory = false;
|
||||||
|
|
||||||
|
protected boolean correctDirection = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param name Not demanded to be case sensitive.
|
* @param name Not demanded to be case sensitive.
|
||||||
*/
|
*/
|
||||||
public PlayerTask(final String name){
|
public PlayerTask(final String name) {
|
||||||
this.lcName = name.toLowerCase();
|
this.lcName = name.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public boolean delegateTick(final int tick, final long timeLast) {
|
public boolean delegateTick(final int tick, final long timeLast) {
|
||||||
final Player player = DataManager.getPlayer(lcName);
|
final Player player = DataManager.getPlayer(lcName);
|
||||||
if (player != null){
|
if (player != null) {
|
||||||
if (player.isOnline()){
|
if (player.isOnline()) {
|
||||||
if (updateInventory){
|
if (correctDirection) {
|
||||||
|
final MCAccess access = NoCheatPlus.getAPI().getMCAccess();
|
||||||
|
access.correctDirection(player);
|
||||||
|
}
|
||||||
|
if (updateInventory) {
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Reset values (players logging back in should be fine or handled differently).
|
||||||
updateInventory = false;
|
updateInventory = false;
|
||||||
}
|
correctDirection = false;
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateInventory(){
|
public void updateInventory() {
|
||||||
// TODO: Might not allow registering every tick.
|
// TODO: Might not allow registering every tick.
|
||||||
updateInventory = true;
|
updateInventory = true;
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void correctDirection() {
|
||||||
|
correctDirection = true;
|
||||||
|
register();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: updateHunger
|
// TODO: updateHunger
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user