diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index b793aa58..4463608e 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -660,9 +660,22 @@ public class MovingData extends ACheckData implements IRemoveSubCheckData { public void clearPlayerMorePacketsData() { morePacketsSetback = null; + final long now = System.currentTimeMillis(); + morePacketsFreq.clear(now); + morePacketsBurstFreq.clear(now); // TODO: Also reset other data ? } + /** + * Reduce the morepackets frequency counters by the given amount, capped at + * a minimum of 0. + * + * @param amount + */ + public void reducePlayerMorePacketsData(final float amount) { + CheckUtils.reduce(System.currentTimeMillis(), amount, morePacketsFreq, morePacketsBurstFreq); + } + public void clearVehicleMorePacketsData() { vehicleMorePacketsLastTime = 0; vehicleMorePacketsBuffer = vehicleMorePacketsBufferDefault; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 5ccd4e4c..8641b629 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -1792,6 +1792,9 @@ public class MovingListener extends CheckListener implements TickListener, IRemo if (data.isTeleportedPosition(to)) { // Set back. confirmSetBack(player, true, data, cc); + // Reset some more data. + // TODO: Some more? + data.reducePlayerMorePacketsData(1); // Log. if (data.debug) { debugTeleportMessage(player, event, "(set back)", to); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java index 939cd978..5b14c3c5 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java @@ -36,6 +36,7 @@ import fr.neatmonster.nocheatplus.hooks.APIUtils; import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; import fr.neatmonster.nocheatplus.logging.StaticLog; import fr.neatmonster.nocheatplus.logging.Streams; +import fr.neatmonster.nocheatplus.utilities.ds.count.ActionFrequency; // TODO: Auto-generated Javadoc /** @@ -260,4 +261,36 @@ public class CheckUtils { return NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Random.class); } + /** + * Update and then reduce all given ActionFrequency instances by the given + * amount, capped at a maximum of 0 for the resulting first bucket score. + * + * @param amount + * The amount to subtract. + * @param freqs + */ + public static void reduce(final long time, final float amount, final ActionFrequency... freqs) { + for (int i = 0; i < freqs.length; i++) { + final ActionFrequency freq = freqs[i]; + freq.update(time); + freq.setBucket(0, Math.max(0f, freq.bucketScore(0) - amount)); + } + } + + /** + * Update and then reduce all given ActionFrequency instances by the given + * amount, without capping the result. + * + * @param amount + * The amount to subtract. + * @param freqs + */ + public static void subtract(final long time, final float amount, final ActionFrequency... freqs) { + for (int i = 0; i < freqs.length; i++) { + final ActionFrequency freq = freqs[i]; + freq.update(time); + freq.setBucket(0, freq.bucketScore(0) - amount); + } + } + }