mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-27 18:01:33 +01:00
[ProtocolLib] Add several missing sounds to block. Count cancellation.
This commit is contained in:
parent
0d7d179853
commit
ab88b98704
@ -1,12 +1,15 @@
|
||||
package fr.neatmonster.nocheatplus.checks.net.protocollib;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
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.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
@ -16,27 +19,33 @@ import fr.neatmonster.nocheatplus.checks.net.NetConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.net.NetConfigCache;
|
||||
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
||||
|
||||
public class SoundDistance extends PacketAdapter {
|
||||
public class SoundDistance extends BaseAdapter {
|
||||
|
||||
// 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.
|
||||
|
||||
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;
|
||||
}
|
||||
/** Partly by debugging, partly from various sources, possibly including wrong spelling. */
|
||||
private static final Set<String> effectNames = new HashSet<String>(Arrays.asList(
|
||||
// Weather
|
||||
"ambient.weather.thunder",
|
||||
// Wither
|
||||
"wither-spawn-sound-radius",
|
||||
"mob.wither.spawn",
|
||||
"mob.wither.shoot",
|
||||
"mob.wither.idle",
|
||||
"mob.wither.hurt",
|
||||
"mob.wither.death",
|
||||
// Enderdragon
|
||||
"dragon-death-sound-radius",
|
||||
"mob.enderdragon.wings",
|
||||
"mob.enderdragon.grow",
|
||||
"mob.enderdragon.growl",
|
||||
"mob.enderdragon.hit",
|
||||
"mob.enderdragon.end",
|
||||
"game.neutral.die" // Enderdragon 1.8.7 (debug).
|
||||
));
|
||||
|
||||
private final Integer idSoundEffectCancel = counters.registerKey("packet.sound.cancel");
|
||||
private final NetConfigCache configs;
|
||||
private final Location useLoc = new Location(null, 0, 0, 0);
|
||||
|
||||
@ -50,7 +59,8 @@ public class SoundDistance extends PacketAdapter {
|
||||
final PacketContainer packetContainer = event.getPacket();
|
||||
|
||||
// Compare sound effect name.
|
||||
if (!contains(packetContainer.getStrings().read(0))) {
|
||||
final String soundName = packetContainer.getStrings().read(0);
|
||||
if (!effectNames.contains(soundName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -60,11 +70,16 @@ public class SoundDistance extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
final Location loc = player.getLocation(useLoc);
|
||||
// Compare distance of player to the weather location.
|
||||
final Location loc = player.getLocation(useLoc);
|
||||
final StructureModifier<Integer> ints = packetContainer.getIntegers();
|
||||
if (TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ()) > cc.soundDistanceSq) {
|
||||
final double dSq = TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ());
|
||||
// if (cc.debug) {
|
||||
// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " SoundDistance(" + soundName + "): " + StringUtil.fdec1.format(Math.sqrt(dSq)));
|
||||
// }
|
||||
if (dSq > cc.soundDistanceSq) {
|
||||
event.setCancelled(true);
|
||||
counters.add(idSoundEffectCancel, 1);
|
||||
}
|
||||
useLoc.setWorld(null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user