Search in sources :

Example 56 with IPlayerData

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

the class InstantEat method check.

/**
 * Checks a player.
 *
 * @param player
 *            the player
 * @param level
 *            the level
 * @return true, if successful
 */
public boolean check(final Player player, final int level) {
    // Take time once.
    final long time = System.currentTimeMillis();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final InventoryData data = pData.getGenericInstance(InventoryData.class);
    boolean cancel = false;
    // Hunger level change seems to not be the result of eating.
    if (data.instantEatFood == null || level <= player.getFoodLevel())
        return false;
    // Rough estimation about how long it should take to eat
    final long expectedTimeWhenEatingFinished = Math.max(data.instantEatInteract, data.lastClickTime) + 700L;
    if (data.instantEatInteract > 0 && expectedTimeWhenEatingFinished < time) {
        // Acceptable, reduce VL to reward the player.
        data.instantEatVL *= 0.6D;
    } else if (data.instantEatInteract > time) {
    // Security test, if time ran backwards.
    } else {
        final double difference = (expectedTimeWhenEatingFinished - time) / 100D;
        // Player was too fast, increase their violation level.
        data.instantEatVL += difference;
        // Execute whatever actions are associated with this check and the violation level and find out if we should
        // cancel the event.
        final ViolationData vd = new ViolationData(this, player, data.instantEatVL, difference, pData.getGenericInstance(InventoryConfig.class).instantEatActions);
        if (data.instantEatFood != null) {
            vd.setParameter(ParameterName.FOOD, data.instantEatFood.toString());
        }
        cancel = executeActions(vd).willCancel();
    }
    data.instantEatInteract = 0;
    data.instantEatFood = null;
    return cancel;
}
Also used : IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 57 with IPlayerData

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

the class InventoryListener method onPlayerDropItem.

/**
 * We listen to DropItem events for the Drop check.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerDropItem(final PlayerDropItemEvent event) {
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    // Illegal enchantments hotfix check.
    final Item item = event.getItemDrop();
    if (item != null) {
        // No cancel here.
        Items.checkIllegalEnchantments(player, item.getItemStack(), pData);
    }
    // If the player died, all their items are dropped so ignore them.
    if (event.getPlayer().isDead())
        return;
    if (pData.isCheckActive(CheckType.INVENTORY_DROP, player)) {
        if (drop.check(player)) {
            // TODO: Is the following command still correct? If so, adapt actions.
            /*
                 * Cancelling drop events is not save (in certain circumstances
                 * items will disappear completely). So don't
                 */
            // do it and kick players instead by default.
            event.setCancelled(true);
        }
    }
}
Also used : Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 58 with IPlayerData

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

the class InventoryListener method onFoodLevelChange.

/**
 * We listen to FoodLevelChange events because Bukkit doesn't provide a PlayerFoodEating Event (or whatever it would
 * be called).
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onFoodLevelChange(final FoodLevelChangeEvent event) {
    // Only if a player ate food.
    if (event.getEntity() instanceof Player) {
        final Player player = (Player) event.getEntity();
        final IPlayerData pData = DataManager.getPlayerData(player);
        if (instantEat.isEnabled(player, pData) && instantEat.check(player, event.getFoodLevel())) {
            event.setCancelled(true);
        } else if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
            // Eat after death.
            event.setCancelled(true);
            counters.addPrimaryThread(idCancelDead, 1);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 59 with IPlayerData

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

the class FastConsume method onItemConsume.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onItemConsume(final PlayerItemConsumeEvent event) {
    final Player player = event.getPlayer();
    if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
        // Eat after death.
        event.setCancelled(true);
        counters.addPrimaryThread(idCancelDead, 1);
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    if (!pData.isCheckActive(type, player)) {
        return;
    }
    final InventoryData data = pData.getGenericInstance(InventoryData.class);
    final long time = System.currentTimeMillis();
    if (check(player, event.getItem(), time, data, pData)) {
        event.setCancelled(true);
        DataManager.getPlayerData(player).requestUpdateInventory();
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 60 with IPlayerData

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

the class DebugPlayerCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
    // TODO: Wild cards (all players)?
    // TODO: (Allow to specify OverrideType ?)
    // Note that MAYBE means to reset here, it's not the same as direct PlayerData API access.
    DebugEntry entry = new DebugEntry();
    for (int i = 2; i < args.length; i++) {
        String input = args[i];
        if (input.startsWith("?")) {
            entry = DebugEntry.parseEntry(input.substring(1));
            if (entry == null) {
                sender.sendMessage("Bad setup: " + input);
                // Can't continue.
                return true;
            } else {
                // Only update the entry.
                continue;
            }
        }
        final String name = input;
        final Player player;
        if (IdUtil.isValidMinecraftUserName(name)) {
            player = DataManager.getPlayer(name);
        } else {
            UUID id = IdUtil.UUIDFromStringSafe(input);
            if (id == null) {
                sender.sendMessage("Bad name or UUID: " + input);
                continue;
            } else {
                player = DataManager.getPlayer(id);
            }
        }
        if (player == null) {
            sender.sendMessage("Not online: " + name);
            continue;
        }
        // Execute for online player.
        final Collection<CheckType> checkTypes;
        if (entry.checkTypes.isEmpty()) {
            // CheckType.ALL
            checkTypes = Arrays.asList(CheckType.ALL);
        } else {
            checkTypes = entry.checkTypes;
        }
        final IPlayerData data = DataManager.getPlayerData(player);
        for (final CheckType checkType : checkTypes) {
            if (entry.active == AlmostBoolean.MAYBE) {
                data.resetDebug(checkType);
            } else {
                data.overrideDebug(checkType, entry.active, OverrideType.CUSTOM, true);
            }
        }
        sender.sendMessage("Set debug = " + entry.active + " for player " + player.getName() + " for checks: " + StringUtil.join(checkTypes, ","));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CheckType(fr.neatmonster.nocheatplus.checks.CheckType) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) UUID(java.util.UUID)

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