use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class InventoryListener method onInventoryClick.
/**
* We listen to InventoryClick events for the FastClick check.
*
* @param event
* the event
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onInventoryClick(final InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) {
return;
}
final long now = System.currentTimeMillis();
final HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player)) {
return;
}
final Player player = (Player) entity;
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
final int slot = event.getSlot();
if (pData.isDebugActive(checkType)) {
outputDebugInventoryClick(player, slot, event, data);
}
if (slot == InventoryView.OUTSIDE || slot < 0) {
data.lastClickTime = now;
return;
}
final ItemStack cursor = event.getCursor();
final ItemStack clicked = event.getCurrentItem();
boolean cancel = false;
// Illegal enchantment checks.
try {
if (!cancel && Items.checkIllegalEnchantments(player, clicked, pData)) {
cancel = true;
counters.addPrimaryThread(idIllegalItem, 1);
}
}// Hotfix (CB)
catch (final ArrayIndexOutOfBoundsException e) {
}
try {
if (!cancel && Items.checkIllegalEnchantments(player, cursor, pData)) {
cancel = true;
counters.addPrimaryThread(idIllegalItem, 1);
}
}// Hotfix (CB)
catch (final ArrayIndexOutOfBoundsException e) {
}
// Fast inventory manipulation check.
if (fastClick.isEnabled(player, pData)) {
final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
if (player.getGameMode() != GameMode.CREATIVE || !cc.fastClickSpareCreative) {
if (fastClick.check(player, now, event.getView(), slot, cursor, clicked, event.isShiftClick(), data, cc, pData)) {
// The check requested the event to be cancelled.
cancel = true;
}
// Feed the improbable.
Improbable.feed(player, 0.7f, System.currentTimeMillis());
}
}
data.lastClickTime = now;
if (cancel) {
event.setCancelled(true);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class Open method check.
/**
* This check contains the isEnabled checking (!). Inventory is closed if set in the config.
* @param player
* @return If cancelling some event is opportune (open inventory and cancel flag set).
*/
public boolean check(final Player player) {
if (// TODO: POC: Item duplication with teleporting NPCS, having their inventory open.
exeSet.getHandle().isRegardedAsNpc(player) || !isEnabled(player) || !InventoryUtil.hasInventoryOpen(player)) {
return false;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
if (cc.openClose) {
final UUID id = player.getUniqueId();
if (this.nestedPlayer == null || !id.equals(this.nestedPlayer)) {
// (The second condition represents an error, but we don't handle alternating things just yet.)
this.nestedPlayer = id;
player.closeInventory();
this.nestedPlayer = null;
}
}
return cc.openCancelOther;
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class FightListener method onEntityDamage.
/**
* We listen to EntityDamage events for obvious reasons.
*
* @param event
* the event
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityDamage(final EntityDamageEvent event) {
final Entity damaged = event.getEntity();
final Player damagedPlayer = damaged instanceof Player ? (Player) damaged : null;
final FightData damagedData;
final boolean damagedIsDead = damaged.isDead();
final boolean damagedIsFake = !crossPlugin.getHandle().isNativeEntity(damaged);
IPenaltyList penaltyList = null;
if (damagedPlayer != null) {
final IPlayerData damagedPData = DataManager.getPlayerData(damagedPlayer);
damagedData = damagedPData.getGenericInstance(FightData.class);
if (!damagedIsDead) {
// (Do not test the savage.)
if (damagedPData.isCheckActive(CheckType.FIGHT_GODMODE, damagedPlayer)) {
if (penaltyList == null) {
penaltyList = new DefaultPenaltyList();
}
if (godMode.check(damagedPlayer, damagedIsFake, BridgeHealth.getRawDamage(event), damagedData, damagedPData)) {
// It requested to "cancel" the players invulnerability, so set their noDamageTicks to 0.
damagedPlayer.setNoDamageTicks(0);
}
}
// Adjust buffer for fast heal checks.
if (BridgeHealth.getHealth(damagedPlayer) >= BridgeHealth.getMaxHealth(damagedPlayer)) {
// TODO: Might use the same FightData instance for GodMode.
if (damagedData.fastHealBuffer < 0) {
// Reduce negative buffer with each full health.
damagedData.fastHealBuffer /= 2;
}
// Set reference time.
damagedData.fastHealRefTime = System.currentTimeMillis();
}
// TODO: TEST: Check unused velocity for the damaged player. (Needs more efficient pre condition checks.)
}
if (damagedPData.isDebugActive(checkType)) {
// TODO: Pass result to further checks for reference?
UnusedVelocity.checkUnusedVelocity(damagedPlayer, CheckType.FIGHT, damagedPData);
}
} else {
damagedData = null;
}
// Attacking entities.
if (event instanceof EntityDamageByEntityEvent) {
if (penaltyList == null) {
penaltyList = new DefaultPenaltyList();
}
onEntityDamageByEntity(damaged, damagedPlayer, damagedIsDead, damagedIsFake, damagedData, (EntityDamageByEntityEvent) event, penaltyList);
}
if (penaltyList != null && !penaltyList.isEmpty()) {
if (penaltyList.hasGenericPenalties()) {
penaltyList.applyAllApplicableGenericPenalties(event);
}
if (penaltyList.hasNonGenericPenalties()) {
penaltyList.applyNonGenericPenalties(event);
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class CombinedListener method onPlayerJoin.
/**
* We listen to this event to prevent players from leaving while falling, so from avoiding fall damages.
*
* @param event
* the event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(final PlayerJoinEvent event) {
// TODO: EventPriority
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final CombinedData data = pData.getGenericInstance(CombinedData.class);
final CombinedConfig cc = pData.getGenericInstance(CombinedConfig.class);
if (cc.invulnerableCheck && (cc.invulnerableTriggerAlways || cc.invulnerableTriggerFallDistance && player.getFallDistance() > 0)) {
// TODO: maybe make a heuristic for small fall distances with ground under feet (prevents future abuse with jumping) ?
final int invulnerableTicks = mcAccess.getHandle().getInvulnerableTicks(player);
if (invulnerableTicks == Integer.MAX_VALUE) {
// TODO: Maybe log a warning.
} else {
final int ticks = cc.invulnerableInitialTicksJoin >= 0 ? cc.invulnerableInitialTicksJoin : invulnerableTicks;
data.invulnerableTick = TickTask.getTick() + ticks;
mcAccess.getHandle().setInvulnerableTicks(player, 0);
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class CombinedListener method onEntityDamage.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
final Entity entity = event.getEntity();
if (!(entity instanceof Player))
return;
final Player player = (Player) entity;
final IPlayerData pData = DataManager.getPlayerData(player);
final CombinedConfig cc = pData.getGenericInstance(CombinedConfig.class);
if (!cc.invulnerableCheck)
return;
final DamageCause cause = event.getCause();
// Ignored causes.
if (cc.invulnerableIgnore.contains(cause))
return;
// Modified invulnerable ticks.
Integer modifier = cc.invulnerableModifiers.get(cause);
if (modifier == null)
modifier = cc.invulnerableModifierDefault;
final CombinedData data = pData.getGenericInstance(CombinedData.class);
// TODO: account for tick task reset ? [it should not though, due to data resetting too, but API would allow it]
if (TickTask.getTick() >= data.invulnerableTick + modifier.intValue())
return;
// Still invulnerable.
event.setCancelled(true);
counters.addPrimaryThread(idFakeInvulnerable, 1);
}
Aggregations