use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class FightListener method onEntityDamageByEntity.
/**
* (Not an event listener method: call from EntityDamageEvent handler at
* EventPriority.LOWEST.)
*
* @param damagedPlayer
* @param damagedIsDead
* @param damagedData
* @param event
*/
private void onEntityDamageByEntity(final Entity damaged, final Player damagedPlayer, final boolean damagedIsDead, final boolean damagedIsFake, final FightData damagedData, final EntityDamageByEntityEvent event, final IPenaltyList penaltyList) {
final Entity damager = event.getDamager();
final int tick = TickTask.getTick();
if (damagedPlayer != null && !damagedIsDead) {
// TODO: check once more when to set this (!) in terms of order.
damagedData.damageTakenByEntityTick = tick;
// TODO: Remove workaround anyway, if the issue only exists on a minor CB version.
if (BridgeEnchant.hasThorns(damagedPlayer)) {
// Remember the id of the attacker to allow counter damage.
damagedData.thornsId = damager.getEntityId();
} else {
damagedData.thornsId = Integer.MIN_VALUE;
}
}
final DamageCause damageCause = event.getCause();
final Player player = damager instanceof Player ? (Player) damager : null;
Player attacker = player;
// TODO: deobfuscate.
if (damager instanceof TNTPrimed) {
final Entity source = ((TNTPrimed) damager).getSource();
if (source instanceof Player) {
attacker = (Player) source;
}
}
final FightData attackerData;
final IPlayerData attackerPData = attacker == null ? null : DataManager.getPlayerData(attacker);
if (attacker != null) {
attackerData = attackerPData.getGenericInstance(FightData.class);
// TODO: TEST: Check unused velocity for the attacker. (Needs more efficient pre condition checks.)
if (attackerPData.isDebugActive(checkType)) {
// TODO: Pass result to further checks for reference?
// TODO: attackerData.debug flag.
// TODO: Fake players likely have unused velocity, just clear unused?
UnusedVelocity.checkUnusedVelocity(attacker, CheckType.FIGHT, attackerPData);
}
// Workaround for subsequent melee damage eventsfor explosions. TODO: Legacy or not, need a KB.
if (damageCause == DamageCause.BLOCK_EXPLOSION || damageCause == DamageCause.ENTITY_EXPLOSION) {
// NOTE: Pigs don't have data.
attackerData.lastExplosionEntityId = damaged.getEntityId();
attackerData.lastExplosionDamageTick = tick;
return;
}
} else {
attackerData = null;
}
if (player != null) {
// Actual fight checks.
if (damageCause == DamageCause.ENTITY_ATTACK) {
// TODO: Might/should skip the damage comparison, though checking on lowest priority.
if (damaged.getEntityId() == attackerData.lastExplosionEntityId && tick == attackerData.lastExplosionDamageTick) {
attackerData.lastExplosionDamageTick = -1;
attackerData.lastExplosionEntityId = Integer.MAX_VALUE;
} else // Prevent attacking if a set back is scheduled.
if (MovingUtil.hasScheduledPlayerSetBack(player)) {
if (attackerPData.isDebugActive(checkType)) {
// Use fight data flag for efficiency.
debug(attacker, "Prevent melee attack, due to a scheduled set back.");
}
event.setCancelled(true);
} else // Ordinary melee damage handling.
if (handleNormalDamage(player, !crossPlugin.getHandle().isNativePlayer(player), damaged, damagedIsFake, BridgeHealth.getOriginalDamage(event), BridgeHealth.getFinalDamage(event), tick, attackerData, attackerPData, penaltyList)) {
event.setCancelled(true);
}
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class FightListener method onItemHeld.
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onItemHeld(final PlayerItemHeldEvent event) {
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final long penalty = pData.getGenericInstance(FightConfig.class).toolChangeAttackPenalty;
if (penalty > 0) {
pData.getGenericInstance(FightData.class).attackPenalty.applyPenalty(penalty);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class FightListener method onEntityDamageMonitor.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityDamageMonitor(final EntityDamageEvent event) {
final Entity damaged = event.getEntity();
if (damaged instanceof Player) {
final Player damagedPlayer = (Player) damaged;
final IPlayerData damagedPData = DataManager.getPlayerData(damagedPlayer);
final FightData damagedData = damagedPData.getGenericInstance(FightData.class);
final int ndt = damagedPlayer.getNoDamageTicks();
if (damagedData.lastDamageTick == TickTask.getTick() && damagedData.lastNoDamageTicks != ndt) {
// Plugin compatibility thing.
damagedData.lastNoDamageTicks = ndt;
}
// Knock-back calculation (1.8: events only fire if they would count by ndt).
switch(event.getCause()) {
case ENTITY_ATTACK:
if (event instanceof EntityDamageByEntityEvent) {
final Entity entity = ((EntityDamageByEntityEvent) event).getDamager();
if ((entity instanceof Player) && !damagedPlayer.isInsideVehicle() && damagedPData.getGenericInstance(FightConfig.class).knockBackVelocityPvP) {
// TODO: Use the velocity event that is sent anyway and replace x/z if 0 (queue max. values).
applyKnockBack((Player) entity, damagedPlayer, damagedData, damagedPData);
}
}
default:
break;
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class ModUtil method motdOnJoin.
/**
* Send block codes to the player according to allowed or disallowed client-mods or client-mod features.
* @param player
*/
public static void motdOnJoin(final Player player) {
final ConfigFile config = ConfigManager.getConfigFile();
if (!config.getBoolean(ConfPaths.PROTECT_CLIENTS_MOTD_ACTIVE)) {
// No message is to be sent.
return;
}
// TODO: Somebody test this all !
// TODO: add feature to check world specific (!).
// Check if we allow all the client mods.
final boolean allowAll = config.getBoolean(ConfPaths.PROTECT_CLIENTS_MOTD_ALLOWALL);
String message = "";
final IPlayerData data = DataManager.getPlayerData(player);
for (int i = 0; i < motdS.length; i++) {
message = motdS[i].onPlayerJoin(message, player, data, allowAll);
}
if (!message.isEmpty()) {
player.sendMessage(message);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class Drop method check.
/**
* Checks a player.
*
* @param player
* the player
* @return true, if successful
*/
public boolean check(final Player player) {
// Take time once.
final long time = System.currentTimeMillis();
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
boolean cancel = false;
// Has the configured time passed? If so, reset the counter.
if (data.dropLastTime + cc.dropTimeFrame <= time) {
data.dropLastTime = time;
data.dropCount = 0;
data.dropVL = 0D;
} else // Security check, if the system time changes.
if (data.dropLastTime > time)
data.dropLastTime = Integer.MIN_VALUE;
data.dropCount++;
// The player dropped more than they should.
if (data.dropCount > cc.dropLimit) {
// Set their violation level.
data.dropVL = data.dropCount - cc.dropLimit;
// 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.dropVL, data.dropCount - cc.dropLimit, cc.dropActions).willCancel();
}
return cancel;
}
Aggregations