use of fr.neatmonster.nocheatplus.worlds.IWorldData in project NoCheatPlus by NoCheatPlus.
the class HotFixFallingBlockPortalEnter method onEntityPortalEnter.
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityPortalEnter(EntityPortalEnterEvent event) {
final Entity entity = event.getEntity();
final Material mat;
if (entity instanceof FallingBlock) {
mat = ((FallingBlock) entity).getMaterial();
} else if (entity instanceof Item) {
// TODO: Not sure if needed.
if (((Item) entity).getItemStack().getType().hasGravity()) {
mat = ((Item) entity).getItemStack().getType();
} else {
mat = null;
}
} else {
mat = null;
}
if (mat != null) {
final Location loc = entity.getLocation(useLoc);
final World world = loc.getWorld();
final IWorldData worldData = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager().getWorldData(world);
if (worldData.getGenericInstance(InventoryConfig.class).hotFixFallingBlockEndPortalActive) {
final BlockCache blockCache = wrapBlockCache.getBlockCache();
blockCache.setAccess(world);
final boolean nearbyPortal = BlockProperties.collidesId(blockCache, loc.getX() - 2.0, loc.getY() - 2.0, loc.getZ() - 2.0, loc.getX() + 3.0, loc.getY() + 3.0, loc.getZ() + 3.0, Material.ENDER_PORTAL);
blockCache.cleanup();
if (nearbyPortal) {
// Likely spigot currently removes entities entering portals anyway (cross-world teleport issues).
// On remove: Looks like setDropItem(false) wouldn't suffice.
entity.remove();
// TODO: STATUS: should have another stream for violations/protection.
final String message = "[INVENTORY_HOTFIX] Remove falling block entering a portal near an end portal: " + mat + " at " + world.getName() + "/" + LocUtil.simpleFormatPosition(loc);
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().info(Streams.STATUS, message);
}
}
useLoc.setWorld(null);
}
}
use of fr.neatmonster.nocheatplus.worlds.IWorldData in project NoCheatPlus by NoCheatPlus.
the class MovingFlying method onFlyingPacket.
private void onFlyingPacket(final PacketEvent event) {
// TODO: Code review protocol plugin :p.
final boolean primaryThread = Bukkit.isPrimaryThread();
counters.add(idFlying, 1, primaryThread);
if (event.isAsync() == primaryThread) {
counters.add(ProtocolLibComponent.idInconsistentIsAsync, 1, primaryThread);
}
if (!primaryThread) {
// Count all asynchronous events extra.
counters.addSynchronized(idAsyncFlying, 1);
// TODO: Detect game phase for the player?
}
final long time = System.currentTimeMillis();
final Player player = event.getPlayer();
if (player == null) {
// TODO: Need config?
counters.add(ProtocolLibComponent.idNullPlayer, 1, primaryThread);
event.setCancelled(true);
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
// Always update last received time.
final NetData data = pData.getGenericInstance(NetData.class);
// Update without much of a contract.
data.lastKeepAliveTime = time;
// TODO: Leniency options too (packet order inversion). -> current: flyingQueue is fetched.
final IWorldData worldData = pData.getCurrentWorldDataSafe();
if (!worldData.isCheckActive(CheckType.NET_FLYINGFREQUENCY)) {
return;
}
final NetConfig cc = pData.getGenericInstance(NetConfig.class);
boolean cancel = false;
// Interpret the packet content.
final DataPacketFlying packetData = interpretPacket(event, time);
// Early return tests, if the packet can be interpreted.
boolean skipFlyingFrequency = false;
if (packetData != null) {
// Prevent processing packets with obviously malicious content.
if (isInvalidContent(packetData)) {
// TODO: extra actions: log and kick (cancel state is not evaluated)
event.setCancelled(true);
if (pData.isDebugActive(this.checkType)) {
debug(player, "Incoming packet, cancel due to malicious content: " + packetData.toString());
}
return;
}
switch(data.teleportQueue.processAck(packetData)) {
case WAITING:
{
if (pData.isDebugActive(this.checkType)) {
debug(player, "Incoming packet, still waiting for ACK on outgoing position.");
}
if (confirmTeleportType != null && cc.supersededFlyingCancelWaiting) {
// Don't add to the flying queue for now (assumed invalid).
final AckReference ackReference = data.teleportQueue.getLastAckReference();
if (ackReference.lastOutgoingId != Integer.MIN_VALUE && ackReference.lastOutgoingId != ackReference.maxConfirmedId) {
// Still waiting for a 'confirm teleport' packet. More or less safe to cancel this out.
/*
* TODO: The actual issue with this, apart from
* potential freezing, also concerns gameplay experience
* in case of minor set backs, which also could be
* caused by the server, e.g. with 'moved wrongly' or
* setting players outside of blocks. In this case the
* moves sent before teleport ack would still be valid
* after the teleport, because distances are small. The
* actual solution should still be to a) not have false
* positives b) somehow get rid all the
* position-correction teleporting the server does, for
* the cases a plugin can handle.
*/
// TODO: Timeout -> either skip cancel or schedule a set back (to last valid pos or other).
// TODO: Config?
cancel = true;
}
}
break;
}
case ACK:
{
// Skip processing ACK packets, no cancel.
skipFlyingFrequency = true;
if (pData.isDebugActive(this.checkType)) {
debug(player, "Incoming packet, interpret as ACK for outgoing position.");
}
}
default:
{
// Continue.
// TODO: Not the optimal position, perhaps.
data.addFlyingQueue(packetData);
}
}
// Add as valid packet (exclude invalid coordinates etc. for now).
validContent.add(packetData.getSimplifiedContentType());
}
// TODO: Consider using the NetStatic check.
if (!cancel && !skipFlyingFrequency && !pData.hasBypass(CheckType.NET_FLYINGFREQUENCY, player) && flyingFrequency.check(player, packetData, time, data, cc, pData)) {
cancel = true;
}
// Process cancel and debug log.
if (cancel) {
event.setCancelled(true);
}
if (pData.isDebugActive(this.checkType)) {
debug(player, (packetData == null ? "(Incompatible data)" : packetData.toString()) + (event.isCancelled() ? " CANCEL" : ""));
}
}
Aggregations