use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class VehicleChecks method onVehicleDestroyLowest.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onVehicleDestroyLowest(final VehicleDestroyEvent event) {
// Prevent destroying ones own vehicle.
final Entity attacker = event.getAttacker();
if (attacker instanceof Player && passengerUtil.isPassenger(attacker, event.getVehicle())) {
final Player player = (Player) attacker;
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
if (cc.vehiclePreventDestroyOwn) {
if (pData.isCheckActive(CheckType.MOVING_SURVIVALFLY, player) || pData.isCheckActive(CheckType.MOVING_CREATIVEFLY, player)) {
}
event.setCancelled(true);
// TODO: This message must be configurable.
player.sendMessage(ChatColor.DARK_RED + "Destroying your own vehicle is disabled.");
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class VehicleChecks method onVehicleUpdate.
/**
* This should always fire, prefer over VehicleMoveEvent, if possible.
*
* @param event
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVehicleUpdate(final VehicleUpdateEvent event) {
// TODO: VehicleUpdateEvent. How to track teleporting of the vehicle?
// TODO: Track just left vehicle/entity positions otherwise (on tick + vehicle update)?
// TODO: No problem: (?) update 'authorized state' if no player passenger.
final Vehicle vehicle = event.getVehicle();
final EntityType vehicleType = vehicle.getType();
if (!normalVehicles.contains(vehicleType)) {
// A little extra sweep to check for debug flags.
normalVehicles.add(vehicleType);
if (worldDataManager.getWorldData(vehicle.getWorld()).isDebugActive(checkType)) {
debug(null, "VehicleUpdateEvent fired for: " + vehicleType);
}
}
// TODO: Detect if a VehicleMove event will fire (not strictly possible without nms, depends on visibility of fields, possibly estimate instead?).
if (vehicle.getVehicle() != null) {
// Do ignore events for vehicles inside of other vehicles.
return;
}
final Player player = passengerUtil.getFirstPlayerPassenger(vehicle);
if (player == null || player.isDead()) {
return;
}
if (vehicle.isDead() || !vehicle.isValid()) {
// TODO: Actually force dismount?
onPlayerVehicleLeave(player, vehicle);
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
// final MovingConfig cc = MovingConfig.getConfig(player);
final boolean debug = pData.isDebugActive(checkType);
if (debug) {
final Location loc = vehicle.getLocation(useLoc1);
debug(player, "VehicleUpdateEvent: " + vehicleType + " " + loc);
useLoc1.setWorld(null);
}
onVehicleUpdate(vehicle, vehicleType, player, false, data, pData, debug);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class VehicleSetBackTask method run.
@Override
public void run() {
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
data.vehicleSetBackTaskId = -1;
try {
NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(PassengerUtil.class).teleportWithPassengers(vehicle, player, location, debug, passengers, true, pData);
} catch (Throwable t) {
StaticLog.logSevere(t);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingListener method checkFallDamageEvent.
private void checkFallDamageEvent(final Player player, final EntityDamageEvent event) {
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
if (player.isInsideVehicle()) {
// Ignore vehicles (noFallFallDistance will be inaccurate anyway).
data.clearNoFallData();
return;
}
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
final PlayerMoveInfo moveInfo = aux.usePlayerMoveInfo();
final double yOnGround = Math.max(cc.noFallyOnGround, cc.yOnGround);
final Location loc = player.getLocation(useLoc);
moveInfo.set(player, loc, null, yOnGround);
final PlayerLocation pLoc = moveInfo.from;
pLoc.collectBlockFlags(yOnGround);
if (event.isCancelled() || !MovingUtil.shouldCheckSurvivalFly(player, pLoc, data, cc, pData) || !noFall.isEnabled(player, pData)) {
data.clearNoFallData();
useLoc.setWorld(null);
aux.returnPlayerMoveInfo(moveInfo);
return;
}
final boolean debug = pData.isDebugActive(CheckType.MOVING_NOFALL);
boolean allowReset = true;
float fallDistance = player.getFallDistance();
final float yDiff = (float) (data.noFallMaxY - loc.getY());
// Raw damage.
final double damage = BridgeHealth.getRawDamage(event);
// TODO: Account for modifiers.
if (debug) {
debug(player, "Damage(FALL/PRE): " + damage + " / mc=" + player.getFallDistance() + " nf=" + data.noFallFallDistance + " yDiff=" + yDiff);
}
// NoFall bypass checks.
if (!data.noFallSkipAirCheck) {
// Cheat: let Minecraft gather and deal fall damage.
/*
* TODO: data.noFallSkipAirCheck is used to skip checking in
* general, thus move into that block or not?
*/
// TODO: Could consider skipping accumulated fall distance for NoFall in general as well.
final float dataDist = Math.max(yDiff, data.noFallFallDistance);
final double dataDamage = NoFall.getDamage(dataDist);
if (damage > dataDamage + 0.5 || dataDamage <= 0.0) {
// TODO: Also relate past y-distance(s) to the fall distance (mc).
// Hot fix: allow fall damage in lava.
/*
* TODO: Correctly model the half fall distance per in-lava move
* and taking fall damage in lava. Should have a block flag for
* this.
*/
final PlayerMoveData firstPastMove = data.playerMoves.getFirstPastMove();
if (pLoc.isOnGround() && pLoc.isInLava() && firstPastMove.toIsValid && firstPastMove.yDistance < 0.0) {
/*
* 1. Strictly someone could attempt to accumulate fall
* damage by help of fast place and pickup lava. 2. There
* are other cases not ending up in lava, but having a
* reduced fall distance (then bigger than nofall data).
*/
if (debug) {
debug(player, "NoFall/Damage: allow fall damage in lava (hotfix).");
}
} else if (noFallVL(player, "fakefall", data, cc)) {
// NOTE: Double violations are possible with the in-air check below.
// TODO: Differing sub checks, once cancel action...
player.setFallDistance(dataDist);
if (dataDamage <= 0.0) {
// Cancel the event.
event.setCancelled(true);
useLoc.setWorld(null);
aux.returnPlayerMoveInfo(moveInfo);
return;
} else {
// Adjust and continue.
if (debug) {
debug(player, "NoFall/Damage: override player fall distance and damage (" + fallDistance + " -> " + dataDist + ").");
}
fallDistance = dataDist;
BridgeHealth.setRawDamage(event, dataDamage);
}
}
}
// Cheat: set ground to true in-air.
// Be sure not to lose that block.
// TODO: What is this and why is it right here?
data.noFallFallDistance += 1.0;
// TODO: Account for liquid too?
if (!pLoc.isOnGround(1.0, 0.3, 0.1) && !pLoc.isResetCond() && !pLoc.isAboveLadder() && !pLoc.isAboveStairs()) {
// Likely: force damage in mid-air by setting on-ground to true.
if (noFallVL(player, "fakeground", data, cc) && data.hasSetBack()) {
// Cancel the event and restore fall distance.
// NoFall data will not be reset
allowReset = false;
}
} else {
// Legitimate damage: clear accounting data.
data.vDistAcc.clear();
// TODO: Why only reset in case of !data.noFallSkipAirCheck?
// TODO: Also reset other properties.
// TODO: Also reset in other cases (moved too quickly)?
}
}
aux.returnPlayerMoveInfo(moveInfo);
// Fall-back check (skip with jump amplifier).
final double maxD = data.jumpAmplifier > 0.0 ? NoFall.getDamage((float) NoFall.getApplicableFallHeight(player, loc.getY(), data)) : NoFall.getDamage(Math.max(yDiff, Math.max(data.noFallFallDistance, fallDistance))) + (allowReset ? 0.0 : Magic.FALL_DAMAGE_DIST);
if (maxD > damage) {
// TODO: respect dealDamage ?
BridgeHealth.setRawDamage(event, maxD);
if (debug) {
debug(player, "Adjust fall damage to: " + maxD);
}
}
if (allowReset) {
// Normal fall damage, reset data.
data.clearNoFallData();
if (debug) {
debug(player, "Reset NoFall data on fall damage.");
}
} else {
// (Do not cancel the event, otherwise: "moved too quickly exploit".)
if (cc.noFallViolationReset) {
data.clearNoFallData();
}
// Add player to hover checks.
if (cc.sfHoverCheck && data.sfHoverTicks < 0) {
data.sfHoverTicks = 0;
hoverTicks.add(player.getName());
}
}
// Entity fall-distance should be reset elsewhere.
// Cleanup.
useLoc.setWorld(null);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingListener method onCancelledMove.
/**
* Adjust data for a cancelled move. No teleport event will fire, but an
* outgoing position is sent. Note that event.getFrom() may be overridden by
* a plugin, which the server will ignore, but can lead to confusion.
*
* @param player
* @param from
* @param tick
* @param now
* @param mData
* @param data
*/
private void onCancelledMove(final Player player, final Location from, final int tick, final long now, final MovingData mData, final MovingConfig mCc, final CombinedData data, final IPlayerData pData) {
final boolean debug = pData.isDebugActive(checkType);
// Detect our own set back, choice of reference location.
if (mData.hasTeleported()) {
final Location ref = mData.getTeleported();
// Initiate further action depending on settings.
final PlayerSetBackMethod method = mCc.playerSetBackMethod;
if (method.shouldUpdateFrom()) {
// Attempt to do without a PlayerTeleportEvent as follow up.
// TODO: Doing this on MONITOR priority is problematic, despite optimal.
LocUtil.set(from, ref);
}
if (method.shouldSchedule()) {
// Schedule the teleport, because it might be faster than the next incoming packet.
final IPlayerData pd = DataManager.getPlayerData(player);
if (pd.isPlayerSetBackScheduled()) {
debug(player, "Teleport (set back) already scheduled to: " + ref);
} else if (debug) {
pd.requestPlayerSetBack();
if (debug) {
debug(player, "Schedule teleport (set back) to: " + ref);
}
}
}
// (Position adaption will happen with the teleport on tick, or with the next move.)
}
// Assume the implicit teleport to the from-location (no Bukkit event fires).
// Not reset frequency, but do set yaw.
Combined.resetYawRate(player, from.getYaw(), now, false, pData);
aux.resetPositionsAndMediumProperties(player, from, mData, mCc);
// TODO: Should probably leave this to the teleport event!
mData.resetTrace(player, from, tick, mcAccess.getHandle(), mCc);
// Expect a teleport to the from location (packet balance, no Bukkit event will fire).
if (pData.isCheckActive(CheckType.NET_FLYINGFREQUENCY, player)) {
// TODO: A summary method.
pData.getGenericInstance(NetData.class).teleportQueue.onTeleportEvent(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch());
}
}
Aggregations