Search in sources :

Example 46 with IPlayerData

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);
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 47 with IPlayerData

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);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)

Example 48 with IPlayerData

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);
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) CombinedData(fr.neatmonster.nocheatplus.checks.combined.CombinedData) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 49 with IPlayerData

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);
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 50 with IPlayerData

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);
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Aggregations

IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)74 Player (org.bukkit.entity.Player)55 EventHandler (org.bukkit.event.EventHandler)40 Location (org.bukkit.Location)22 PlayerLocation (fr.neatmonster.nocheatplus.utilities.location.PlayerLocation)12 Entity (org.bukkit.entity.Entity)8 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)7 NetData (fr.neatmonster.nocheatplus.checks.net.NetData)7 ItemStack (org.bukkit.inventory.ItemStack)7 PlayerMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)6 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)5 NetConfig (fr.neatmonster.nocheatplus.checks.net.NetConfig)5 Material (org.bukkit.Material)5 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)4 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)4 Block (org.bukkit.block.Block)4 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 FlyingQueueHandle (fr.neatmonster.nocheatplus.checks.net.FlyingQueueHandle)3 EntityType (org.bukkit.entity.EntityType)3 BlockInteractData (fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractData)2