use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingListener method onPlayerChangedWorld.
/**
* Just for security, if a player switches between worlds, reset the fly and more packets checks data, because it is
* definitely invalid now.
*
* @param event
* the event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
// Maybe this helps with people teleporting through Multiverse portals having problems?
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
data.clearMostMovingCheckData();
// TODO: Might omit this if neither check is activated.
final Location loc = player.getLocation(useLoc);
data.setSetBack(loc);
if (cc.loadChunksOnWorldChange) {
MovingUtil.ensureChunksLoaded(player, loc, "world change", data, cc, pData);
}
aux.resetPositionsAndMediumProperties(player, loc, data, cc);
data.resetTrace(player, loc, TickTask.getTick(), mcAccess.getHandle(), cc);
if (cc.enforceLocation) {
// Just in case.
playersEnforce.add(player.getName());
}
useLoc.setWorld(null);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingListener method checkOnTickHover.
/**
* Check for hovering.<br>
* NOTE: Makes use of useLoc, without resetting it.
*/
private void checkOnTickHover() {
// Pessimistic.
final List<String> rem = new ArrayList<String>(hoverTicks.size());
final PlayerMoveInfo info = aux.usePlayerMoveInfo();
for (final String playerName : hoverTicks) {
// TODO: put players into the set (+- one tick would not matter ?)
// TODO: might add an online flag to data !
final Player player = DataManager.getPlayerExact(playerName);
if (player == null || !player.isOnline()) {
rem.add(playerName);
continue;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
if (player.isDead() || player.isSleeping() || player.isInsideVehicle()) {
data.sfHoverTicks = -1;
// (Removed below.)
}
if (data.sfHoverTicks < 0) {
data.sfHoverLoginTicks = 0;
rem.add(playerName);
continue;
} else if (data.sfHoverLoginTicks > 0) {
// Additional "grace period".
data.sfHoverLoginTicks--;
continue;
}
final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
// Check if enabled at all.
if (!cc.sfHoverCheck) {
rem.add(playerName);
data.sfHoverTicks = -1;
continue;
}
// Increase ticks here.
data.sfHoverTicks += hoverTicksStep;
if (data.sfHoverTicks < cc.sfHoverTicks) {
// Don't do the heavier checking here, let moving checks reset these.
continue;
}
if (checkHover(player, data, cc, pData, info)) {
rem.add(playerName);
}
}
hoverTicks.removeAll(rem);
aux.returnPlayerMoveInfo(info);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingListener method onPlayerMoveMonitor.
/**
* Monitor level PlayerMoveEvent. Uses useLoc.
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onPlayerMoveMonitor(final PlayerMoveEvent event) {
// TODO: Use stored move data to verify if from/to have changed (thus a teleport will result, possibly a minor issue due to the teleport).
final long now = System.currentTimeMillis();
final Player player = event.getPlayer();
// TODO: Consider to store event.getFrom() from LOWEST priority in processingEvents.
if (processingEvents.remove(player.getName()) == null) {
// TODO: vehicles, cancelled, ...
return;
}
if (player.isDead() || player.isSleeping()) {
return;
}
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
// Feed combined check.
final CombinedData data = pData.getGenericInstance(CombinedData.class);
// TODO: Move to MovingData ?
data.lastMoveTime = now;
final Location from = event.getFrom();
// Feed yawrate and reset moving data positions if necessary.
final MovingData mData = pData.getGenericInstance(MovingData.class);
final int tick = TickTask.getTick();
final MovingConfig mCc = pData.getGenericInstance(MovingConfig.class);
if (!event.isCancelled()) {
final Location pLoc = player.getLocation(useLoc);
onMoveMonitorNotCancelled(player, TrigUtil.isSamePosAndLook(pLoc, from) ? from : pLoc, event.getTo(), now, tick, data, mData, mCc, pData);
useLoc.setWorld(null);
} else {
onCancelledMove(player, from, tick, now, mData, mCc, data, pData);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingListener method onPlayerDeath.
/**
* Clear fly data on death.
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(final PlayerDeathEvent event) {
final Player player = event.getEntity();
final IPlayerData pData = DataManager.getPlayerData(player);
final MovingData data = pData.getGenericInstance(MovingData.class);
// final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
data.clearMostMovingCheckData();
// TODO: Monitor this change (!).
data.setSetBack(player.getLocation(useLoc));
if (pData.isDebugActive(checkType)) {
// Log location.
debug(player, "Death: " + player.getLocation(useLoc));
}
useLoc.setWorld(null);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class FightListener method onEntityRegainHealthLow.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityRegainHealthLow(final EntityRegainHealthEvent event) {
final Entity entity = event.getEntity();
if (!(entity instanceof Player)) {
return;
}
final Player player = (Player) entity;
if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
// Heal after death.
// TODO: Problematic. At least skip CUSTOM.
event.setCancelled(true);
counters.addPrimaryThread(idCancelDead, 1);
return;
}
if (event.getRegainReason() != RegainReason.SATIATED) {
return;
}
// TODO: EATING reason / peaceful difficulty / regen potion - byCaptain SpigotMC
final IPlayerData pData = DataManager.getPlayerData(player);
if (pData.isCheckActive(CheckType.FIGHT_FASTHEAL, player) && fastHeal.check(player, pData)) {
// TODO: Can clients force events with 0-re-gain ?
event.setCancelled(true);
}
}
Aggregations