use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class Gutenberg method onEditBook.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEditBook(final PlayerEditBookEvent event) {
final Player player = event.getPlayer();
if (!isEnabled(player)) {
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
final BookMeta newMeta = event.getNewBookMeta();
final int pages = newMeta.getPageCount();
if (pages <= 50) {
// Legitimate.
return;
}
// Violation.
final int vl = pages - 50;
if (executeActions(player, vl, vl, cc.gutenbergActions).willCancel()) {
event.setCancelled(true);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class KeepAliveAdapter method onPacketReceiving.
@Override
public void onPacketReceiving(final PacketEvent event) {
final long time = System.currentTimeMillis();
final Player player = event.getPlayer();
if (player == null) {
counters.add(ProtocolLibComponent.idNullPlayer, 1);
event.setCancelled(true);
return;
}
// Always update last received time.
final IPlayerData pData = DataManager.getPlayerData(player);
final NetData data = pData.getGenericInstance(NetData.class);
data.lastKeepAliveTime = time;
final NetConfig cc = pData.getGenericInstance(NetConfig.class);
// TODO: Better integration with god-mode check / trigger reset ndt.
if (frequencyCheck.isEnabled(player, pData) && frequencyCheck.check(player, time, data, cc, pData)) {
event.setCancelled(true);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingFlying method processConfirmTeleport.
private void processConfirmTeleport(final PacketEvent event) {
final PacketContainer packet = event.getPacket();
final StructureModifier<Integer> integers = packet.getIntegers();
if (integers.size() != 1) {
noConfirmTeleportPacket();
return;
}
// TODO: Cross check legacy types (if they even had an integer).
Integer teleportId = integers.read(0);
if (teleportId == null) {
// TODO: Not sure ...
return;
}
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final NetData data = pData.getGenericInstance(NetData.class);
final AlmostBoolean matched = data.teleportQueue.processAck(teleportId);
if (matched.decideOptimistically()) {
ActionFrequency.subtract(System.currentTimeMillis(), 1, data.flyingFrequencyAll);
}
if (pData.isDebugActive(this.checkType)) {
// TODO: FlyingFrequency / NET_MOVING? + check others who depend
debug(player, "Confirm teleport packet" + (matched.decideOptimistically() ? (" (matched=" + matched + ")") : "") + ": " + teleportId);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class UseEntityAdapter method onPacketReceiving.
@Override
public void onPacketReceiving(final PacketEvent event) {
final long time = System.currentTimeMillis();
final Player player = event.getPlayer();
if (player == null) {
// TODO: Warn once?
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final NetData data = pData.getGenericInstance(NetData.class);
// Always set last received time.
data.lastKeepAliveTime = time;
// Quick return, if no checks are active.
if (!pData.isCheckActive(CheckType.NET_ATTACKFREQUENCY, player)) {
return;
}
final PacketContainer packet = event.getPacket();
// MIGHT: use entity, use block both on packet level?
boolean isAttack = false;
boolean packetInterpreted = false;
if (legacySet != null) {
// Attempt to extract legacy information.
final int flags = getAction_legacy(packet);
if ((flags & INTERPRETED) != 0) {
packetInterpreted = true;
if ((flags & ATTACK) != 0) {
isAttack = true;
}
}
}
if (!packetInterpreted) {
// Handle as if latest.
final StructureModifier<EntityUseAction> actions;
actions = packet.getEntityUseActions();
if (actions.size() == 1 && actions.read(0) == EntityUseAction.ATTACK) {
isAttack = true;
packetInterpreted = true;
}
}
if (!packetInterpreted) {
// TODO: Log warning once, if the packet could not be interpreted.
return;
}
// Run checks.
boolean cancel = false;
// AttackFrequency
if (isAttack) {
final NetConfig cc = pData.getGenericInstance(NetConfig.class);
if (attackFrequency.isEnabled(player, pData) && attackFrequency.check(player, time, data, cc, pData)) {
cancel = true;
}
}
if (cancel) {
event.setCancelled(true);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class BlockInteractListener method onPlayerInteractMonitor.
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onPlayerInteractMonitor(final PlayerInteractEvent event) {
// Set event resolution.
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final BlockInteractData data = pData.getGenericInstance(BlockInteractData.class);
data.setPlayerInteractEventResolution(event);
// }
if ((event.getAction() == Action.RIGHT_CLICK_AIR) && event.isCancelled() && event.useItemInHand() != Result.DENY) {
final ItemStack stack = Bridge1_9.getUsedItem(player, event);
if (stack != null && BridgeMisc.maybeElytraBoost(player, stack.getType())) {
final int power = BridgeMisc.getFireworksPower(stack);
final MovingData mData = pData.getGenericInstance(MovingData.class);
final int ticks = Math.max((1 + power) * 20, 30);
mData.fireworksBoostDuration = ticks;
// Expiration tick: not general latency, rather a minimum margin for sudden congestion.
mData.fireworksBoostTickExpire = TickTask.getTick() + ticks;
// TODO: Implement using it in CreativeFly.
if (pData.isDebugActive(CheckType.MOVING)) {
debug(player, "Elytra boost (power " + power + "): " + stack);
}
}
}
}
Aggregations