Search in sources :

Example 11 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class VehicleChecks method onVehicleMove.

/**
 * When a vehicle moves, its player will be checked for various suspicious behaviors.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onVehicleMove(final VehicleMoveEvent event) {
    // Check data.
    final Vehicle vehicle = event.getVehicle();
    if (vehicle == null) {
        return;
    }
    // Mind that players could be riding horses inside of minecarts etc.
    if (vehicle.getVehicle() != null) {
        // Do ignore events for vehicles inside of other vehicles.
        return;
    }
    final Player player = passengerUtil.getFirstPlayerPassenger(vehicle);
    if (player == null) {
        return;
    }
    if (vehicle.isDead() || !vehicle.isValid()) {
        // TODO: Actually force dismount?
        onPlayerVehicleLeave(player, vehicle);
        return;
    }
    final EntityType vehicleType = vehicle.getType();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final MovingData data = pData.getGenericInstance(MovingData.class);
    final Location from = event.getFrom();
    final Location to = event.getTo();
    if (pData.isDebugActive(checkType)) {
        outputDebugVehicleMoveEvent(player, from, to);
    }
    if (from == null) {
        // TODO: (In case update doesn't, could fake it here.)
        return;
    } else if (from.equals(to)) {
    // Not possible by obc code.
    } else {
        if (!from.getWorld().equals(to.getWorld())) {
            // TODO: Data adjustments will be necessary with the envelope check.
            return;
        }
    // TODO: Check consistency with assumed/tracked past position, both for from and to. Do something based on result.
    }
    if (normalVehicles.contains(vehicleType)) {
        // Assume handled.
        return;
    } else {
    // Should not be possible, unless plugins somehow force this.
    // TODO: Log warning once / what?
    // TODO: Ignore or continue?
    }
    // Process as move.
    final boolean debug = pData.isDebugActive(checkType);
    if (debug) {
        debug(player, "VehicleMoveEvent: legacy handling, potential issue.");
    }
    // TODO: Actually here consistency with past position tracking should be tested.
    // TODO: Abstraction creation before calling checkVehicleMove, compare/align with onVehicleUpdate.
    checkVehicleMove(vehicle, vehicleType, from, to, player, false, data, pData, debug);
}
Also used : Vehicle(org.bukkit.entity.Vehicle) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) MovingData(fr.neatmonster.nocheatplus.checks.moving.MovingData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Location(org.bukkit.Location) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation) EventHandler(org.bukkit.event.EventHandler)

Example 12 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class InstantBow method check.

/**
 * Checks a player.
 *
 * @param player
 *            the player
 * @param force
 *            the force
 * @return true, if successful
 */
public boolean check(final Player player, final float force, final long now) {
    final IPlayerData pData = DataManager.getPlayerData(player);
    final InventoryData data = pData.getGenericInstance(InventoryData.class);
    final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
    boolean cancel = false;
    // Rough estimation of how long pulling the string should've taken.
    final long expectedPullDuration = (long) (maxTime - maxTime * (1f - force) * (1f - force)) - cc.instantBowDelay;
    // Time taken to pull the string.
    final long pullDuration;
    final boolean valid;
    if (cc.instantBowStrict) {
        // The interact time is invalid, if set to 0.
        valid = data.instantBowInteract != 0;
        pullDuration = valid ? (now - data.instantBowInteract) : 0L;
    } else {
        valid = true;
        pullDuration = now - data.instantBowShoot;
    }
    if (valid && (!cc.instantBowStrict || data.instantBowInteract > 0L) && pullDuration >= expectedPullDuration) {
        // The player was slow enough, reward them by lowering their violation level.
        data.instantBowVL *= 0.9D;
    } else if (valid && data.instantBowInteract > now) {
    // Security check if time ran backwards.
    // TODO: Maybe this can be removed, though TickTask does not reset at the exact moment.
    } else {
        // Account for server side lag.
        // (Do not apply correction to invalid pulling.)
        final long correctedPullduration = valid ? (pData.getCurrentWorldData().shouldAdjustToLag(type) ? (long) (TickTask.getLag(expectedPullDuration, true) * pullDuration) : pullDuration) : 0;
        if (correctedPullduration < expectedPullDuration) {
            // TODO: Consider: Allow one time but set yawrate penalty time ?
            final double difference = (expectedPullDuration - pullDuration) / 100D;
            // Player was too fast, increase their violation level.
            data.instantBowVL += difference;
            // Execute whatever actions are associated with this check and the
            // violation level and find out if we should cancel the event
            cancel = executeActions(player, data.instantBowVL, difference, cc.instantBowActions).willCancel();
        }
    }
    if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
        player.sendMessage(ChatColor.YELLOW + "NCP: " + ChatColor.GRAY + "Bow shot - force: " + force + ", " + (cc.instantBowStrict || pullDuration < 2 * expectedPullDuration ? ("pull time: " + pullDuration) : "") + "(" + expectedPullDuration + ")");
    }
    // Reset data here.
    data.instantBowInteract = 0;
    data.instantBowShoot = now;
    return cancel;
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 13 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class InventoryListener method onItemHeldChange.

@EventHandler(priority = EventPriority.MONITOR)
public void onItemHeldChange(final PlayerItemHeldEvent event) {
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final InventoryData data = pData.getGenericInstance(InventoryData.class);
    if (pData.isDebugActive(checkType) && data.instantEatFood != null) {
        debug(player, "PlayerItemHeldEvent, reset fastconsume (legacy: instanteat).");
    }
    data.instantBowInteract = 0;
    data.instantEatInteract = 0;
    data.instantEatFood = null;
    // Illegal enchantments hotfix check.
    final PlayerInventory inv = player.getInventory();
    Items.checkIllegalEnchantments(player, inv.getItem(event.getNewSlot()), pData);
    Items.checkIllegalEnchantments(player, inv.getItem(event.getPreviousSlot()), pData);
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) PlayerInventory(org.bukkit.inventory.PlayerInventory) EventHandler(org.bukkit.event.EventHandler)

Example 14 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class InventoryListener method onPlayerInteract.

/**
 * We listen to PlayerInteract events for the InstantEat and InstantBow checks.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public final void onPlayerInteract(final PlayerInteractEvent event) {
    // Only interested in right-clicks while holding an item.
    if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final InventoryData data = pData.getGenericInstance(InventoryData.class);
    boolean resetAll = false;
    if (event.hasItem()) {
        final ItemStack item = event.getItem();
        final Material type = item.getType();
        // TODO: Cancelled / deny use item -> reset all?
        if (type == Material.BOW) {
            final long now = System.currentTimeMillis();
            // It was a bow, the player starts to pull the string, remember this time.
            data.instantBowInteract = (data.instantBowInteract > 0 && now - data.instantBowInteract < 800) ? Math.min(System.currentTimeMillis(), data.instantBowInteract) : System.currentTimeMillis();
        } else if (InventoryUtil.isConsumable(type)) {
            final long now = System.currentTimeMillis();
            // It was food, the player starts to eat some food, remember this time and the type of food.
            data.instantEatFood = type;
            data.instantEatInteract = (data.instantEatInteract > 0 && now - data.instantEatInteract < 800) ? Math.min(System.currentTimeMillis(), data.instantEatInteract) : System.currentTimeMillis();
            // Who's monitoring this indentation code?
            data.instantBowInteract = 0;
        } else
            resetAll = true;
        // Illegal enchantments hotfix check.
        if (Items.checkIllegalEnchantments(player, item, pData)) {
            event.setCancelled(true);
            counters.addPrimaryThread(idIllegalItem, 1);
        }
    } else {
        resetAll = true;
    }
    if (resetAll) {
        // Nothing that we are interested in, reset data.
        if (pData.isDebugActive(CheckType.INVENTORY_INSTANTEAT) && data.instantEatFood != null) {
            debug(player, "PlayerInteractEvent, reset fastconsume (legacy: instanteat).");
        }
        data.instantBowInteract = 0;
        data.instantEatInteract = 0;
        data.instantEatFood = null;
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 15 with IPlayerData

use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.

the class InventoryListener method onEntityShootBow.

/**
 * We listen to EntityShootBow events for the InstantBow check.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityShootBow(final EntityShootBowEvent event) {
    // Only if a player shot the arrow.
    if (event.getEntity() instanceof Player) {
        final Player player = (Player) event.getEntity();
        final IPlayerData pData = DataManager.getPlayerData(player);
        if (instantBow.isEnabled(player, pData)) {
            final long now = System.currentTimeMillis();
            final Location loc = player.getLocation(useLoc);
            if (Combined.checkYawRate(player, loc.getYaw(), now, loc.getWorld().getName(), pData)) {
                // No else if with this, could be cancelled due to other checks feeding, does not have actions.
                event.setCancelled(true);
            }
            final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
            // Still check instantBow, whatever yawrate says.
            if (instantBow.check(player, event.getForce(), now)) {
                // The check requested the event to be cancelled.
                event.setCancelled(true);
            } else if (cc.instantBowImprobableWeight > 0.0f) {
                if (cc.instantBowImprobableFeedOnly) {
                    Improbable.feed(player, cc.instantBowImprobableWeight, now);
                } else if (Improbable.check(player, cc.instantBowImprobableWeight, now, "inventory.instantbow", pData)) {
                    // Combined fighting speed (Else if: Matter of taste, preventing extreme cascading and actions spam).
                    event.setCancelled(true);
                }
            }
            useLoc.setWorld(null);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Location(org.bukkit.Location) 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