From a367c8f20c10cfeb758a1b23032f15223ce4fc69 Mon Sep 17 00:00:00 2001 From: Scetch Date: Tue, 15 Jul 2014 17:14:45 -0400 Subject: [PATCH 1/2] Prevent weather sound effect > 512 blocks away. --- .../net/protocollib/ProtocolLibComponent.java | 5 ++- .../net/protocollib/WeatherDistance.java | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java index b9269091..a3a88536 100644 --- a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java @@ -27,7 +27,10 @@ public class ProtocolLibComponent implements DisableListener{ LogUtil.logInfo("[NoCheatPlus] ProtocolLib seems to be available."); try { PacketAdapter adapter = new MoveFrequency(plugin); - protocolManager.addPacketListener(adapter); + PacketAdapter weatherAdapter = new WeatherDistance(plugin); + + protocolManager.addPacketListener(adapter); + protocolManager.addPacketListener(weatherAdapter); registeredPacketAdapters.add(adapter); } catch (Throwable t) { LogUtil.logWarning("[NoCheatPlus] Could not register some packet-level hook."); diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java new file mode 100644 index 00000000..14a33ba6 --- /dev/null +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java @@ -0,0 +1,38 @@ +package fr.neatmonster.nocheatplus.net.protocollib; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class WeatherDistance extends PacketAdapter { + + public WeatherDistance(Plugin plugin) { + super(plugin, PacketType.Play.Server.NAMED_SOUND_EFFECT); + } + + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packetContainer = event.getPacket(); + Player player = event.getPlayer(); + + String soundEffect = packetContainer.getStrings().read(0); + + if (!soundEffect.equals("ambient.weather.thunder")) + return; + + double locX = packetContainer.getIntegers().read(0) / 8; + double locY = packetContainer.getIntegers().read(1) / 8; + double locZ = packetContainer.getIntegers().read(2) / 8; + + Location weatherLocation = new Location(player.getWorld(), locX, locY, locZ); + Location location = player.getLocation().clone(); + + if (player.getLocation().distance(weatherLocation) > 512.0F) { + event.setCancelled(true); + } + } +} From 1e6d69b50f91ff5e1dcf5c34710b7f227d487f89 Mon Sep 17 00:00:00 2001 From: Scetch Date: Tue, 15 Jul 2014 17:17:49 -0400 Subject: [PATCH 2/2] Oops. This doesn't need to be there. --- .../neatmonster/nocheatplus/net/protocollib/WeatherDistance.java | 1 - 1 file changed, 1 deletion(-) diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java index 14a33ba6..8e2607c0 100644 --- a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/WeatherDistance.java @@ -29,7 +29,6 @@ public class WeatherDistance extends PacketAdapter { double locZ = packetContainer.getIntegers().read(2) / 8; Location weatherLocation = new Location(player.getWorld(), locX, locY, locZ); - Location location = player.getLocation().clone(); if (player.getLocation().distance(weatherLocation) > 512.0F) { event.setCancelled(true);