ProtocolLib: build vs. 4.0.2, reactivate SoundDistance.
This commit is contained in:
parent
8ae36791a9
commit
5ec8c2fe56
|
@ -24,7 +24,7 @@
|
|||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<version>1.9.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -36,7 +36,7 @@
|
|||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>3.6.4</version>
|
||||
<version>4.0.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -94,12 +94,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload, Joi
|
|||
// (Set lastKeepAlive if this or fight.godmode is enabled.)
|
||||
register("fr.neatmonster.nocheatplus.checks.net.protocollib.KeepAliveAdapter", plugin);
|
||||
}
|
||||
if (ServerVersion.compareMinecraftVersion("1.9") >= 0) {
|
||||
// Don't use this listener.
|
||||
// TODO: Add module for ProtocolLib 3.7 ?
|
||||
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().info(Streams.STATUS, "Disable SoundDistance due to incompatibilities.");
|
||||
}
|
||||
else if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) {
|
||||
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) {
|
||||
register("fr.neatmonster.nocheatplus.checks.net.protocollib.SoundDistance", plugin);
|
||||
}
|
||||
if (!registeredPacketAdapters.isEmpty()) {
|
||||
|
|
|
@ -14,11 +14,14 @@
|
|||
*/
|
||||
package fr.neatmonster.nocheatplus.checks.net.protocollib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
@ -31,6 +34,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
|||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.net.NetConfigCache;
|
||||
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
|
||||
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
||||
|
||||
public class SoundDistance extends BaseAdapter {
|
||||
|
@ -40,6 +44,10 @@ public class SoundDistance extends BaseAdapter {
|
|||
|
||||
/** Partly by debugging, partly from various sources, possibly including wrong spelling. */
|
||||
private static final Set<String> effectNames = new HashSet<String>(Arrays.asList(
|
||||
////////////
|
||||
// PRE 1.9
|
||||
////////////
|
||||
|
||||
// Weather
|
||||
"ambient.weather.thunder",
|
||||
// Wither
|
||||
|
@ -56,17 +64,81 @@ public class SoundDistance extends BaseAdapter {
|
|||
"mob.enderdragon.growl",
|
||||
"mob.enderdragon.hit",
|
||||
"mob.enderdragon.end",
|
||||
"game.neutral.die" // Enderdragon 1.8.7 (debug).
|
||||
"game.neutral.die", // Enderdragon 1.8.7 (debug).
|
||||
|
||||
//////////////////
|
||||
// 1.9 AND LATER
|
||||
//////////////////
|
||||
// Weather
|
||||
"ENTITY_LIGHTNING_IMPACT",
|
||||
"ENTITY_LIGHTNING_THUNDER",
|
||||
// Enderdragon
|
||||
"ENTITY_ENDERDRAGON_AMBIENT",
|
||||
"ENTITY_ENDERDRAGON_DEATH",
|
||||
"ENTITY_ENDERDRAGON_FIREBALL_EXPLODE",
|
||||
"ENTITY_ENDERDRAGON_FLAP",
|
||||
"ENTITY_ENDERDRAGON_GROWL",
|
||||
"ENTITY_ENDERDRAGON_HURT",
|
||||
"ENTITY_ENDERDRAGON_SHOOT",
|
||||
// Wither
|
||||
"ENTITY_WITHER_AMBIENT",
|
||||
"ENTITY_WITHER_BREAK_BLOCK",
|
||||
"ENTITY_WITHER_DEATH",
|
||||
"ENTITY_WITHER_HURT",
|
||||
"ENTITY_WITHER_SHOOT",
|
||||
"ENTITY_WITHER_SPAWN"
|
||||
|
||||
|
||||
));
|
||||
|
||||
private final Integer idSoundEffectCancel = counters.registerKey("packet.sound.cancel");
|
||||
private final NetConfigCache configs;
|
||||
private final Location useLoc = new Location(null, 0, 0, 0);
|
||||
/** Legacy check behavior. */
|
||||
private final boolean pre1_9;
|
||||
|
||||
public SoundDistance(Plugin plugin) {
|
||||
super(plugin, ListenerPriority.LOW, PacketType.Play.Server.NAMED_SOUND_EFFECT);
|
||||
this.configs = (NetConfigCache) CheckType.NET.getConfigFactory(); // TODO: DataManager.getConfig(NetConfigCache.class);
|
||||
this.checkType = CheckType.NET_SOUNDDISTANCE;
|
||||
pre1_9 = ServerVersion.compareMinecraftVersion("1.9") < 0;
|
||||
inflateEffectNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure both lower and upper case are contained.
|
||||
*/
|
||||
private void inflateEffectNames() {
|
||||
final List<String> names = new ArrayList<String>(effectNames);
|
||||
for (String name : names) {
|
||||
effectNames.add(name.toLowerCase());
|
||||
effectNames.add(name.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSoundMonitoredPre1_9(final PacketContainer packetContainer) {
|
||||
//debug(null, packetContainer.getStrings().read(0));
|
||||
return effectNames.contains(packetContainer.getStrings().read(0));
|
||||
}
|
||||
|
||||
private boolean isSoundMonitoredLatest(final PacketContainer packetContainer) {
|
||||
StructureModifier<Sound> sounds = packetContainer.getSoundEffects();
|
||||
for (final Sound sound : sounds.getValues()) {
|
||||
if (effectNames.contains(sound.name())) {
|
||||
//debug(null, "MONITOR SOUND: " + sound);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isSoundMonitored(final PacketContainer packetContainer) {
|
||||
if (pre1_9) {
|
||||
return isSoundMonitoredPre1_9(packetContainer);
|
||||
}
|
||||
else {
|
||||
return isSoundMonitoredLatest(packetContainer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -74,8 +146,7 @@ public class SoundDistance extends BaseAdapter {
|
|||
final PacketContainer packetContainer = event.getPacket();
|
||||
|
||||
// Compare sound effect name.
|
||||
final String soundName = packetContainer.getStrings().read(0);
|
||||
if (!effectNames.contains(soundName)) {
|
||||
if (!isSoundMonitored(packetContainer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue