mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-19 14:01:20 +01:00
Bleeding: Cancel damage for a while after turning a lot. (test commit)
This commit is contained in:
parent
1f07e303cd
commit
e7d536cd39
@ -44,9 +44,13 @@ public class CombinedData extends ACheckData {
|
||||
public double improbableVL = 0;
|
||||
public double speedVL = 0;
|
||||
|
||||
public final ActionFrequency improbableCount = new ActionFrequency(20, 3000);
|
||||
public float lastYaw;
|
||||
public long lastYawTime;
|
||||
public final ActionFrequency yawFreq = new ActionFrequency(4, 500);
|
||||
|
||||
public final ActionFrequency speedCount = new ActionFrequency(20, 3000);
|
||||
public long timeFreeze = 0;
|
||||
|
||||
public final ActionFrequency improbableCount = new ActionFrequency(20, 3000);
|
||||
|
||||
public CombinedData(final Player player){
|
||||
// final CombinedConfig cc = CombinedConfig.getConfig(player);
|
||||
|
@ -1,10 +1,10 @@
|
||||
package fr.neatmonster.nocheatplus.checks.combined;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -19,16 +19,23 @@ public class CombinedListener implements Listener {
|
||||
this.improbable = new Improbable();
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onPlayerToggleSneak(final PlayerToggleSneakEvent event){
|
||||
// Check also in case of cancelled events.
|
||||
if (Improbable.check(event.getPlayer(), 0.35f, System.currentTimeMillis())) event.setCancelled(true);
|
||||
}
|
||||
// @EventHandler(priority=EventPriority.LOW)
|
||||
// public void onPlayerToggleSneak(final PlayerToggleSneakEvent event){
|
||||
// // Check also in case of cancelled events.
|
||||
// if (Improbable.check(event.getPlayer(), 0.35f, System.currentTimeMillis())) event.setCancelled(true);
|
||||
// }
|
||||
//
|
||||
// @EventHandler(priority=EventPriority.LOW)
|
||||
// public void onPlayerToggleSprint(final PlayerToggleSprintEvent event){
|
||||
// // Check also in case of cancelled events.
|
||||
// if (Improbable.check(event.getPlayer(), 0.35f, System.currentTimeMillis())) event.setCancelled(true);
|
||||
// }
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onPlayerToggleSprint(final PlayerToggleSprintEvent event){
|
||||
// Check also in case of cancelled events.
|
||||
if (Improbable.check(event.getPlayer(), 0.35f, System.currentTimeMillis())) event.setCancelled(true);
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public final void onPlayerMove(final PlayerMoveEvent event){
|
||||
final Player player =event.getPlayer();
|
||||
// Just add the yaw to the list.
|
||||
Improbable.checkYaw(player, player.getLocation().getYaw(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
// (possibly other types of events, but these combine with fighting).
|
||||
|
@ -27,7 +27,10 @@ public class Improbable extends Check {
|
||||
return instance.checkImprobable(player, weight, now);
|
||||
}
|
||||
|
||||
|
||||
public static final boolean checkYaw(final Player player, final float yaw, final long now){
|
||||
return instance.checkLastYaw(player, yaw, now);
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Instance methods.
|
||||
///////////////////////////////////
|
||||
@ -64,5 +67,28 @@ public class Improbable extends Check {
|
||||
data.improbableVL *= 0.95;
|
||||
return cancel;
|
||||
}
|
||||
|
||||
private boolean checkLastYaw(Player player, float yaw, long now) {
|
||||
if (!isEnabled(player)) return false;
|
||||
final CombinedData data = CombinedData.getData(player);
|
||||
// final CombinedConfig cc = CombinedConfig.getConfig(player);
|
||||
final float yawDiff = (yaw - data.lastYaw) % 180;
|
||||
|
||||
|
||||
// final long elapsed = now - data.lastYawTime;
|
||||
boolean cancel = false;
|
||||
|
||||
if (now < data.timeFreeze) cancel = true;
|
||||
|
||||
final float dAbs = Math.abs(yawDiff);
|
||||
data.yawFreq.add(now, (float) dAbs); // *3f / ((float) (elapsed + 1)) );
|
||||
if (dAbs > 30) data.timeFreeze = now + (long) dAbs * 3;
|
||||
// System.out.println("yawDiff " + player.getName() + ": " + yawDiff + " (" + elapsed+ ") - " + data.yawFreq.getScore(1f));
|
||||
|
||||
// Set data to current state.
|
||||
data.lastYaw = yaw;
|
||||
data.lastYawTime = now;
|
||||
return cancel;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
|
||||
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
@ -105,15 +104,23 @@ public class FightListener implements Listener {
|
||||
if (selfHit.isEnabled(player) && selfHit.check(player, cbEntity, data, cc))
|
||||
cancelled = true;
|
||||
else{
|
||||
// Check if improbable
|
||||
if (Improbable.check(player, 2.0f, System.currentTimeMillis()))
|
||||
cancelled = true;
|
||||
CombinedData.getData((Player) cbEntity).improbableCount.add(System.currentTimeMillis(), -2.0f);
|
||||
// // Check if improbable
|
||||
// if (Improbable.check(player, 2.0f, System.currentTimeMillis()))
|
||||
// cancelled = true;
|
||||
// CombinedData.getData((Player) cbEntity).improbableCount.add(System.currentTimeMillis(), -2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
|
||||
// Improbable yaw:
|
||||
if (Improbable.checkYaw(player, player.getLocation().getYaw(), now)){
|
||||
cancelled = true;
|
||||
// System.out.println(player.getName() + " <- cancelled attack by yaw.");
|
||||
}
|
||||
|
||||
// Combined speed:
|
||||
if (Improbable.check(player, 1f, System.currentTimeMillis()))
|
||||
if (!cancelled && Improbable.check(player, 1f, now))
|
||||
cancelled = true;
|
||||
|
||||
// Get the attacked entity.
|
||||
|
Loading…
Reference in New Issue
Block a user