mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-15 03:51:20 +01:00
Packet checks adjustments and renaming.
* More appropriate names. SoundDistance * Plus wither plus dragon. * Horizontal distance.
This commit is contained in:
parent
288950edd4
commit
7b6305de78
@ -24,7 +24,7 @@ import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
||||
* @author dev1mc
|
||||
*
|
||||
*/
|
||||
public class MoveFrequency extends PacketAdapter implements Listener, JoinLeaveListener {
|
||||
public class FlyingFrequency extends PacketAdapter implements Listener, JoinLeaveListener {
|
||||
|
||||
// TODO: Configuration.
|
||||
// TODO: Optimized options (receive only, other?).
|
||||
@ -32,7 +32,7 @@ public class MoveFrequency extends PacketAdapter implements Listener, JoinLeaveL
|
||||
|
||||
private Map<String, ActionFrequency> freqMap = new LinkedHashMap<String, ActionFrequency>();
|
||||
|
||||
public MoveFrequency(Plugin plugin) {
|
||||
public FlyingFrequency(Plugin plugin) {
|
||||
// PacketPlayInFlying[3, legacy: 10]
|
||||
super(plugin, PacketType.Play.Client.FLYING); // TODO: How does POS and POS_LOOK relate/translate?
|
||||
}
|
@ -28,8 +28,8 @@ public class ProtocolLibComponent implements DisableListener{
|
||||
LogUtil.logInfo("[NoCheatPlus] ProtocolLib seems to be available.");
|
||||
// Classes having a constructor with Plugin as argument.
|
||||
List<Class<? extends PacketAdapter>> adapterClasses = Arrays.asList(
|
||||
MoveFrequency.class,
|
||||
WeatherDistance.class
|
||||
FlyingFrequency.class,
|
||||
SoundDistance.class
|
||||
);
|
||||
// TODO: Configurability.
|
||||
for (Class<? extends PacketAdapter> clazz : adapterClasses) {
|
||||
|
@ -12,15 +12,31 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
||||
|
||||
public class WeatherDistance extends PacketAdapter {
|
||||
public class SoundDistance extends PacketAdapter {
|
||||
|
||||
// TODO: Will not be effective with 512 radius, if they add the patch by @Amranth.
|
||||
// TODO: For lower distances more packets might need to be intercepted.
|
||||
|
||||
/** Maximum distance for thunder effects (squared). */
|
||||
private static final double distSq = 512.0 * 512.0; // TODO: Maybe configurable.
|
||||
|
||||
private static final String[] effectNames = new String[] { // Prefix tree?
|
||||
"ambient.weather.thunder",
|
||||
"wither-spawn-sound-radius",
|
||||
"dragon-death-sound-radius"
|
||||
// other ?
|
||||
};
|
||||
|
||||
private static final boolean contains(final String ref) {
|
||||
for (int i = 0; i < effectNames.length; i++) {
|
||||
if (effectNames[i].equals(ref)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public WeatherDistance(Plugin plugin) {
|
||||
public SoundDistance(Plugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.NAMED_SOUND_EFFECT);
|
||||
}
|
||||
|
||||
@ -30,8 +46,7 @@ public class WeatherDistance extends PacketAdapter {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// Compare sound effect name.
|
||||
// TODO: wither-spawn-sound-radius, dragon-death-sound-radius, other ?
|
||||
if (!packetContainer.getStrings().read(0).equals("ambient.weather.thunder")) {
|
||||
if (!contains(packetContainer.getStrings().read(0))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -39,7 +54,7 @@ public class WeatherDistance extends PacketAdapter {
|
||||
|
||||
// Compare distance of player to the weather location.
|
||||
final StructureModifier<Integer> ints = packetContainer.getIntegers();
|
||||
if (TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(1) / 8, ints.read(2) / 8, loc.getX(), loc.getY(), loc.getZ()) > distSq) {
|
||||
if (TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ()) > distSq) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -280,6 +280,12 @@ public class TrigUtil {
|
||||
final double dz = Math.abs(z1 - z2);
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
|
||||
public static final double distanceSquared(final double x1, final double z1, final double x2, final double z2) {
|
||||
final double dx = Math.abs(x1 - x2);
|
||||
final double dz = Math.abs(z1 - z2);
|
||||
return dx * dx + dz * dz;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2D-distance in x-z plane.
|
||||
|
Loading…
Reference in New Issue
Block a user