mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-03 10:50:27 +02:00
Merge pull request #25 from Scetch/master
Prevent weather sound effect > 512 blocks away.
This commit is contained in:
commit
cdf79c854f
|
@ -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.");
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
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);
|
||||
|
||||
if (player.getLocation().distance(weatherLocation) > 512.0F) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user