use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class ProtocolLibComponent method onPlayerTeleport.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
if (!registeredPacketAdapters.isEmpty()) {
// TODO: Might move to MovingListener.
// TODO: Might still add cancelled UNKNOWN events. TEST IT
final Location to = event.getTo();
if (to == null) {
return;
}
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final NetData data = pData.getGenericInstance(NetData.class);
if (pData.isCheckActive(CheckType.NET_FLYINGFREQUENCY, player)) {
// Register expected location for comparison with outgoing packets.
data.teleportQueue.onTeleportEvent(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch());
}
data.clearFlyingQueue();
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class SoundDistance method onPacketSending.
@Override
public void onPacketSending(final PacketEvent event) {
final PacketContainer packetContainer = event.getPacket();
// Compare sound effect name.
if (!isSoundMonitored(packetContainer)) {
return;
}
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
if (!pData.isCheckActive(CheckType.NET_SOUNDDISTANCE, player)) {
return;
}
// Compare distance of player to the weather location.
final Location loc = player.getLocation(useLoc);
final StructureModifier<Integer> ints = packetContainer.getIntegers();
final double dSq = TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ());
// if (data.debug) {
// debug(player, "SoundDistance(" + soundName + "): " + StringUtil.fdec1.format(Math.sqrt(dSq)));
// }
final NetConfig cc = pData.getGenericInstance(NetConfig.class);
if (dSq > cc.soundDistanceSq) {
event.setCancelled(true);
counters.add(idSoundEffectCancel, 1);
}
useLoc.setWorld(null);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class BlockInteractListener method onPlayerInteract.
/**
* We listen to PlayerInteractEvent events for obvious reasons.
*
* @param event
* the event
*/
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onPlayerInteract(final PlayerInteractEvent event) {
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final BlockInteractData data = pData.getGenericInstance(BlockInteractData.class);
data.resetLastBlock();
// Early cancel for interact events with dead players and other.
final int cancelId;
if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
// TODO: Should be dead !?.
// Auto-soup after death.
/*
* TODO: Allow physical interact after death? Risks could be command
* blocks used etc.
*/
cancelId = idCancelDead;
} else if (!player.isOnline()) {
cancelId = idCancelOffline;
} else if (MovingUtil.hasScheduledPlayerSetBack(player)) {
// Might log.
// No counters yet, but do prevent.
cancelId = -1;
} else {
cancelId = Integer.MIN_VALUE;
}
if (cancelId != Integer.MIN_VALUE) {
event.setUseInteractedBlock(Result.DENY);
event.setUseItemInHand(Result.DENY);
event.setCancelled(true);
data.setPlayerInteractEventResolution(event);
if (cancelId >= 0) {
counters.addPrimaryThread(cancelId, 1);
}
return;
}
// TODO: Re-arrange for interact spamming. (With ProtocolLib something else is in place as well.)
final Action action = event.getAction();
final Block block = event.getClickedBlock();
final int previousLastTick = data.getLastTick();
// TODO: Last block setting: better on monitor !?.
boolean blockChecks = true;
if (block == null) {
data.resetLastBlock();
blockChecks = false;
} else {
data.setLastBlock(block, action);
}
final BlockFace face = event.getBlockFace();
final ItemStack stack;
switch(action) {
case RIGHT_CLICK_AIR:
// TODO: What else to adapt?
case LEFT_CLICK_AIR:
// TODO: What else to adapt?
case LEFT_CLICK_BLOCK:
stack = null;
break;
case RIGHT_CLICK_BLOCK:
stack = Bridge1_9.getUsedItem(player, event);
if (stack != null && stack.getType() == Material.ENDER_PEARL) {
checkEnderPearlRightClickBlock(player, block, face, event, previousLastTick, data, pData);
}
break;
default:
data.setPlayerInteractEventResolution(event);
return;
}
boolean cancelled = false;
if (event.isCancelled() && event.useInteractedBlock() != Result.ALLOW) {
if (event.useItemInHand() == Result.ALLOW) {
blockChecks = false;
// TODO: Some potential for plugin features...
} else {
// Can't do more than prevent all (could: set to prevent on highest, if desired).
data.setPlayerInteractEventResolution(event);
return;
}
}
final BlockInteractConfig cc = pData.getGenericInstance(BlockInteractConfig.class);
boolean preventUseItem = false;
final Location loc = player.getLocation(useLoc);
final FlyingQueueHandle flyingHandle = new FlyingQueueHandle(pData);
// Interaction speed.
if (!cancelled && speed.isEnabled(player, pData) && speed.check(player, data, cc)) {
cancelled = true;
preventUseItem = true;
}
if (blockChecks) {
final double eyeHeight = MovingUtil.getEyeHeight(player);
// First the reach check.
if (!cancelled && reach.isEnabled(player, pData) && reach.check(player, loc, eyeHeight, block, data, cc)) {
cancelled = true;
}
// Second the direction check
if (!cancelled && direction.isEnabled(player, pData) && direction.check(player, loc, eyeHeight, block, flyingHandle, data, cc, pData)) {
cancelled = true;
}
// Ray tracing for freecam use etc.
if (!cancelled && visible.isEnabled(player, pData) && visible.check(player, loc, eyeHeight, block, face, action, flyingHandle, data, cc, pData)) {
cancelled = true;
}
}
// If one of the checks requested to cancel the event, do so.
if (cancelled) {
onCancelInteract(player, block, face, event, previousLastTick, preventUseItem, data, cc, pData);
} else {
if (flyingHandle.isFlyingQueueFetched()) {
// TODO: Update flying queue removing failed entries? At least store index for subsequent checks.
final int flyingIndex = flyingHandle.getFirstIndexWithContentIfFetched();
final Integer cId;
if (flyingIndex == 0) {
cId = idInteractLookFlyingFirst;
} else {
cId = idInteractLookFlyingOther;
}
counters.add(cId, 1);
if (pData.isDebugActive(CheckType.BLOCKINTERACT)) {
// Log which entry was used.
logUsedFlyingPacket(player, flyingHandle, flyingIndex);
}
} else {
counters.addPrimaryThread(idInteractLookCurrent, 1);
}
}
// Set resolution here already:
data.setPlayerInteractEventResolution(event);
useLoc.setWorld(null);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class BlockPlaceListener method onPlayerInteract.
/**
* We listener to PlayerInteract events to prevent players from spamming the server with monster eggs.
*
* @param event
* the event
*/
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onPlayerInteract(final PlayerInteractEvent event) {
if (event.isCancelled()) {
// TODO: Might run checks if (event.useInteractedBlock()) ...
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
final Player player = event.getPlayer();
final ItemStack stack = Bridge1_9.getUsedItem(player, event);
if (stack == null) {
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final BlockPlaceConfig cc = pData.getGenericInstance(BlockPlaceConfig.class);
final Material type = stack.getType();
if (InventoryUtil.isBoat(type)) {
if (cc.preventBoatsAnywhere) {
// TODO: Alter config (activation, allow on top of ground).
// TODO: Version/plugin specific alteration for 'default'.
checkBoatsAnywhere(player, event, cc, pData);
}
} else if (type == Material.MONSTER_EGG) {
// Check blockplace.speed.
if (speed.isEnabled(player, pData) && speed.check(player, cc, pData)) {
// If the check was positive, cancel the event.
event.setCancelled(true);
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MunchHausen method checkFish.
public boolean checkFish(final Player player, final Entity caught, final State state) {
if (caught == null || !(caught instanceof Player))
return false;
final Player caughtPlayer = (Player) caught;
final IPlayerData pData = DataManager.getPlayerData(player);
final CombinedData data = pData.getGenericInstance(CombinedData.class);
if (player.equals(caughtPlayer)) {
data.munchHausenVL += 1.0;
if (executeActions(player, data.munchHausenVL, 1.0, pData.getGenericInstance(CombinedConfig.class).munchHausenActions).willCancel()) {
return true;
}
} else
data.munchHausenVL *= 0.96;
return false;
}
Aggregations