Do debug log for block break and place and dig/place packets.

Dig/place is only logged if a debug flag is set in the config, it won't
activate with on-the-fly per player debug logging.
This commit is contained in:
asofold 2015-10-03 00:19:45 +02:00
parent 49c08c453a
commit 7bcae640e9
4 changed files with 143 additions and 97 deletions

View File

@ -0,0 +1,30 @@
package fr.neatmonster.nocheatplus.checks.net.protocollib;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketEvent;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.logging.Streams;
public class DebugAdapter extends BaseAdapter {
public DebugAdapter(Plugin plugin) {
super(plugin, ListenerPriority.LOW, new PacketType[] {
PacketType.Play.Client.BLOCK_PLACE,
PacketType.Play.Client.BLOCK_DIG,
});
}
@Override
public void onPacketReceiving(PacketEvent event) {
final Player player = event.getPlayer();
if (dataFactory.getData(player).debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " packet: " + event.getPacketType());
}
}
}

View File

@ -40,7 +40,10 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
private void register(Plugin plugin) {
StaticLog.logInfo("Adding packet level hooks for ProtocolLib (MC " + ProtocolLibrary.getProtocolManager().getMinecraftVersion().getVersion() + ")...");
// Register Classes having a constructor with Plugin as argument.
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET + ConfPaths.SUB_DEBUG) || ConfigManager.isTrueForAnyConfig(ConfPaths.CHECKS_DEBUG) ) {
// (Debug logging. Only activates if debug is set for checks or checks.net, not on the fly.)
register("fr.neatmonster.nocheatplus.checks.net.protocollib.DebugAdapter", plugin);
}
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) {
// (Also sets lastKeepAliveTime, if enabled.)
register("fr.neatmonster.nocheatplus.checks.net.protocollib.FlyingFrequency", plugin);

View File

@ -21,6 +21,7 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.inventory.Items;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.stats.Counters;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
@ -145,7 +146,11 @@ public class BlockBreakListener extends CheckListener {
}
else{
// Invalidate last damage position:
// data.clickedX = Integer.MAX_VALUE;
// data.clickedX = Integer.MAX_VALUE;
// Debug log (only if not cancelled, to avoid spam).
if (data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " block break(" + block.getType() + "): " + block.getX() + ", " + block.getY() + ", " + block.getZ());
}
}
if (isInstaBreak.decideOptimistically()) {
@ -157,7 +162,7 @@ public class BlockBreakListener extends CheckListener {
// Adjust data.
data.fastBreakBreakTime = now;
// data.fastBreakfirstDamage = now;
// data.fastBreakfirstDamage = now;
isInstaBreak = AlmostBoolean.NO;
}
@ -172,7 +177,7 @@ public class BlockBreakListener extends CheckListener {
priority = EventPriority.MONITOR)
public void onPlayerAnimation(final PlayerAnimationEvent event) {
// Just set a flag to true when the arm was swung.
// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "Animation");
// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "Animation");
BlockBreakData.getData(event.getPlayer()).noSwingArmSwung = true;
}
@ -186,7 +191,7 @@ public class BlockBreakListener extends CheckListener {
@EventHandler(
ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onPlayerInteract(final PlayerInteractEvent event) {
// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "Interact("+event.isCancelled()+"): " + event.getClickedBlock());
// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "Interact("+event.isCancelled()+"): " + event.getClickedBlock());
// The following is to set the "first damage time" for a block.
// Return if it is not left clicking a block.
@ -224,12 +229,12 @@ public class BlockBreakListener extends CheckListener {
final long now = System.currentTimeMillis();
final BlockBreakData data = BlockBreakData.getData(player);
// if (event.isCancelled()){
// // Reset the time, to avoid certain kinds of cheating. => WHICH ?
// data.fastBreakfirstDamage = now;
// data.clickedX = Integer.MAX_VALUE; // Should be enough to reset that one.
// return;
// }
// if (event.isCancelled()){
// // Reset the time, to avoid certain kinds of cheating. => WHICH ?
// data.fastBreakfirstDamage = now;
// data.clickedX = Integer.MAX_VALUE; // Should be enough to reset that one.
// return;
// }
// Do not care about null blocks.
if (block == null) {

View File

@ -24,6 +24,7 @@ import fr.neatmonster.nocheatplus.checks.combined.CombinedConfig;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.stats.Counters;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
@ -101,8 +102,10 @@ public class BlockPlaceListener extends CheckListener {
final Block block = event.getBlockPlaced();
final Block blockAgainst = event.getBlockAgainst();
// Skip any null blocks.
if (block == null || blockAgainst == null)
if (block == null || blockAgainst == null) {
return;
}
// TODO: What if same block?
// TODO: Revise material use (not block.get... ?)
//final Material mat = block.getType();
@ -154,6 +157,11 @@ public class BlockPlaceListener extends CheckListener {
// If one of the checks requested to cancel the event, do so.
if (cancelled) {
event.setCancelled(cancelled);
} else {
// Debug log (only if not cancelled, to avoid spam).
if (data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " block place(" + placedMat + "): " + block.getX() + ", " + block.getY() + ", " + block.getZ());
}
}
// Cleanup
// Reminder(currently unused): useLoc.setWorld(null);