use of fr.neatmonster.nocheatplus.checks.moving.MovingConfig in project NoCheatPlus by NoCheatPlus.
the class MovingUtil method processStoredSetBack.
/**
* @param player
* @param debugMessagePrefix
* @return True, if the teleport has been successful.
*/
public static boolean processStoredSetBack(final Player player, final String debugMessagePrefix, final IPlayerData pData) {
final MovingData data = pData.getGenericInstance(MovingData.class);
final boolean debug = pData.isDebugActive(CheckType.MOVING);
if (!data.hasTeleported()) {
if (debug) {
CheckUtils.debug(player, CheckType.MOVING, debugMessagePrefix + "No stored location available.");
}
return false;
}
// (teleported is set.).
final Location loc = player.getLocation(useLoc);
if (data.isTeleportedPosition(loc)) {
// Skip redundant teleport.
if (debug) {
CheckUtils.debug(player, CheckType.MOVING, debugMessagePrefix + "Skip teleport, player is there, already.");
}
// Not necessary to keep.
data.resetTeleported();
useLoc.setWorld(null);
return false;
}
useLoc.setWorld(null);
// (player is somewhere else.)
// Post-1.9 packet level workaround.
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
// TODO: Consider to skip checking for packet level, if not available (plus optimize access).
// TODO: Consider a config flag, so this can be turned off (set back method).
final PlayerSetBackMethod method = cc.playerSetBackMethod;
if (!method.shouldNoRisk() && (method.shouldCancel() || method.shouldSetTo()) && method.shouldUpdateFrom()) {
/*
* Another leniency option: Skip, if we have already received an ACK
* for this position on packet level - typically the next move would
* confirm the set-back, but a redundant teleport would freeze the
* player for a slightly longer time. This could happen with the set
* back being at the coordinates the player had just been at, but
* between set back and on-tick there has been a micro move (not
* firing a PlayerMoveEvent) - similarly observed on a local test
* server once, HOWEVER there the micro move had been a look-only
* packet, not explaining why the position of the player wasn't
* reflecting the outgoing position. So here remains the uncertainty
* concerning the question if a (silent) Minecraft entity teleport
* always follows a cancelled PlayerMoveEvent (!), and a thinkable
* potential for abuse.
*/
// (CANCEL + UPDATE_FROM mean a certain teleport to the set back, still could be repeated tp.)
// TODO: Better method, full sync reference?
final CountableLocation cl = pData.getGenericInstance(NetData.class).teleportQueue.getLastAck();
if (data.isTeleportedPosition(cl)) {
if (debug) {
CheckUtils.debug(player, CheckType.MOVING, debugMessagePrefix + "Skip teleport, having received an ACK for the teleport on packet level. Player is at: " + LocUtil.simpleFormat(loc));
}
// Keep teleported in data. Subject to debug logs and/or discussion.
return false;
}
}
// (No ACK received yet.)
// Attempt to teleport.
final Location teleported = data.getTeleported();
// (Data resetting is done during PlayerTeleportEvent handling.)
if (player.teleport(teleported, BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION)) {
return true;
} else {
if (debug) {
CheckUtils.debug(player, CheckType.MOVING, "Player set back on tick: Teleport failed.");
}
return false;
}
}
use of fr.neatmonster.nocheatplus.checks.moving.MovingConfig in project NoCheatPlus by NoCheatPlus.
the class VehicleChecks method dataOnVehicleEnter.
/**
* Adjust data with given last non player vehicle.
*
* @param player
* @param vehicle
*/
private void dataOnVehicleEnter(final Player player, final Entity vehicle, final MovingData data, final IPlayerData pData) {
// Adjust data.
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
data.joinOrRespawn = false;
data.removeAllVelocity();
// Event should have a vehicle, in case check this last.
final Location vLoc = vehicle.getLocation(useLoc1);
data.vehicleConsistency = MoveConsistency.getConsistency(vLoc, null, player.getLocation(useLoc2));
if (data.isVehicleSetBack) {
/*
* Currently checking for consistency is done in
* TeleportUtil.teleport, so we skip that here: if
* (data.vehicleSetBacks.getFirstValidEntry(vLoc) == null) {
*/
} else {
data.vehicleSetBacks.resetAll(vLoc);
}
aux.resetVehiclePositions(vehicle, vLoc, data, cc);
if (pData.isDebugActive(checkType)) {
debug(player, "Vehicle enter: " + vehicle.getType() + " , player: " + useLoc2 + " c=" + data.vehicleConsistency);
}
useLoc1.setWorld(null);
useLoc2.setWorld(null);
// TODO: more resetting, visible check (visible -> interact entity) ?
}
use of fr.neatmonster.nocheatplus.checks.moving.MovingConfig in project NoCheatPlus by NoCheatPlus.
the class VehicleChecks method onPlayerVehicleLeave.
/**
* Call on leaving or just having left a vehicle.
* @param player
* @param vehicle May be null in case of "not possible to determine".
*/
private void onPlayerVehicleLeave(final Player player, final Entity vehicle) {
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
final boolean debug = pData.isDebugActive(checkType);
data.wasInVehicle = false;
data.joinOrRespawn = false;
// if (data.vehicleSetBackTaskId != -1) {
// // Await set back.
// // TODO: might still set ordinary set backs ?
// return;
// }
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
// TODO: Loc can be inconsistent, determine which to use !
final Location pLoc = player.getLocation(useLoc1);
// The location to use as set back.
Location loc = pLoc;
// final Entity vehicle = player.getVehicle();
if (vehicle != null) {
final Location vLoc = vehicle.getLocation(useLoc2);
// Workaround for some entities/animals that don't fire VehicleMoveEventS.
if (!normalVehicles.contains(vehicle.getType()) || cc.noFallVehicleReset) {
// Might allow one time cheat.
data.noFallSkipAirCheck = true;
data.clearNoFallData();
}
// Check consistency with vehicle location.
if (MoveConsistency.getConsistency(vLoc, null, pLoc) == MoveConsistency.INCONSISTENT) {
// TODO: Consider teleporting the player (...)
// TODO: What with the case of vehicle moved to another world !?
//
loc = vLoc;
if (data.vehicleConsistency != MoveConsistency.INCONSISTENT) {
// TODO: This may need re-setting on player move -> vehicle move.
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
if (lastMove.toIsValid) {
final Location oldLoc = new Location(pLoc.getWorld(), lastMove.to.getX(), lastMove.to.getY(), lastMove.to.getZ());
if (MoveConsistency.getConsistency(oldLoc, null, pLoc) != MoveConsistency.INCONSISTENT) {
loc = oldLoc;
}
}
}
}
if (debug) {
debug(player, "Vehicle leave: " + vehicle.getType() + "@" + pLoc.distance(vLoc));
}
}
// Adjust loc if in liquid (meant for boats !?).
if (BlockProperties.isLiquid(loc.getBlock().getType())) {
loc.setY(Location.locToBlock(loc.getY()) + 1.25);
}
if (debug) {
debug(player, "Vehicle leave: " + pLoc.toString() + (pLoc.equals(loc) ? "" : " / player at: " + pLoc.toString()));
}
aux.resetPositionsAndMediumProperties(player, loc, data, cc);
data.setSetBack(loc);
// Give some freedom to allow the "exiting move".
data.removeAllVelocity();
// TODO: Use-once entries usually are intended to allow one offset, but not jumping/flying on.
data.addHorizontalVelocity(new AccountEntry(0.9, 1, 1));
// TODO: Typical margin?
data.addVerticalVelocity(new SimpleEntry(0.6, 1));
useLoc1.setWorld(null);
useLoc2.setWorld(null);
}
use of fr.neatmonster.nocheatplus.checks.moving.MovingConfig in project NoCheatPlus by NoCheatPlus.
the class VehicleChecks method onPlayerMoveVehicle.
/**
* Called from player-move checking, if the player is inside of a vehicle.
* @param player
* @param from
* @param to
* @param data
*/
public Location onPlayerMoveVehicle(final Player player, final Location from, final Location to, final MovingData data, final IPlayerData pData) {
// Workaround for pigs and other (1.5.x and before)!
// Note that with 1.6 not even PlayerMove fires for horses and pigs.
// (isInsideVehicle is the faster check without object creation, do re-check though, if it changes to only check for Vehicle instances.)
final Entity vehicle = passengerUtil.getLastNonPlayerVehicle(player);
if (pData.isDebugActive(checkType)) {
debug(player, "onPlayerMoveVehicle: vehicle: " + vehicle);
}
data.wasInVehicle = true;
data.sfHoverTicks = -1;
data.removeAllVelocity();
data.sfLowJump = false;
// TODO: What with processingEvents.remove(player.getName());
if (vehicle == null || vehicle.isDead() || !vehicle.isValid()) {
// TODO: Note special case, if ever players can move with dead vehicles for a while.
// TODO: Actually force dismount?
onPlayerVehicleLeave(player, vehicle);
return null;
} else {
// (Auto detection of missing events, might fire one time too many per plugin run.)
final EntityType vehicleType = vehicle.getType();
if (!normalVehicles.contains(vehicleType)) {
// Treat like VehicleUpdateEvent.
onVehicleUpdate(vehicle, vehicleType, player, true, data, pData, pData.isDebugActive(checkType));
return null;
} else {
final Location vLoc = vehicle.getLocation();
data.vehicleConsistency = MoveConsistency.getConsistency(from, to, vLoc);
// TODO: Consider TeleportUtil.forceMount or similar.
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
if (data.vehicleConsistency == MoveConsistency.INCONSISTENT) {
if (cc.vehicleEnforceLocation) {
// TODO: Permission + bypass check(s) !
return vLoc;
} else {
return null;
}
} else {
// (Skip chunk loading here.)
aux.resetPositionsAndMediumProperties(player, vLoc, data, cc);
return null;
}
}
}
}
use of fr.neatmonster.nocheatplus.checks.moving.MovingConfig in project NoCheatPlus by NoCheatPlus.
the class ChatListener method onPlayerCommandPreprocess.
/**
* We listen to PlayerCommandPreprocess events because commands can be used for spamming too.
*
* @param event
* the event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final Player player = event.getPlayer();
// Tell TickTask to update cached permissions.
final IPlayerData pData = DataManager.getPlayerData(player);
final ChatConfig cc = pData.getGenericInstance(ChatConfig.class);
// Checks that replace parts of the message (color).
if (color.isEnabled(player, pData)) {
event.setMessage(color.check(player, event.getMessage(), true));
}
// Left-trim is necessary because the server accepts leading spaces with commands.
final String message = event.getMessage();
final String lcMessage = StringUtil.leftTrim(message).toLowerCase();
// TODO: Remove bukkit: etc.
final String[] split = lcMessage.split(" ", 2);
final String alias = split[0].substring(1);
final Command command = CommandUtil.getCommand(alias);
// Could as well use an array and allow null on input of SimpleCharPrefixTree.
final List<String> messageVars = new ArrayList<String>();
messageVars.add(lcMessage);
// Message to run chat checks on.
String checkMessage = message;
if (command != null) {
messageVars.add("/" + command.getLabel().toLowerCase() + (split.length > 1 ? (" " + split[1]) : ""));
}
if (alias.indexOf(":") != -1) {
final int index = message.indexOf(":") + 1;
if (index < message.length()) {
checkMessage = message.substring(index);
messageVars.add(checkMessage.toLowerCase());
}
}
// Prevent commands from being used by players (e.g. /op /deop /reload).
if (cc.consoleOnlyCheck && consoleOnlyCommands.hasAnyPrefixWords(messageVars)) {
if (command == null || command.testPermission(player)) {
player.sendMessage(cc.consoleOnlyMessage);
}
event.setCancelled(true);
return;
}
// Handle as chat or command.
if (chatCommands.hasAnyPrefixWords(messageVars)) {
// TODO: Cut off the command ?.
if (textChecks(player, checkMessage, cc, pData, true, false)) {
event.setCancelled(true);
}
} else if (!commandExclusions.hasAnyPrefixWords(messageVars)) {
// Treat as command.
if (commands.isEnabled(player, pData) && commands.check(player, checkMessage, cc, pData, captcha)) {
event.setCancelled(true);
} else {
// TODO: Consider always checking these?
// Note that this checks for prefixes, not prefix words.
final MovingConfig mcc = pData.getGenericInstance(MovingConfig.class);
if (mcc.passableUntrackedCommandCheck && mcc.passableUntrackedCommandPrefixes.hasAnyPrefix(messageVars)) {
if (checkUntrackedLocation(player, message, mcc, pData)) {
event.setCancelled(true);
}
}
}
}
}
Aggregations