Merge pull request #25 from Scetch/master

Prevent weather sound effect > 512 blocks away.
This commit is contained in:
asofold 2014-07-15 23:32:21 +02:00
commit cdf79c854f
2 changed files with 41 additions and 1 deletions

View File

@ -27,7 +27,10 @@ public class ProtocolLibComponent implements DisableListener{
LogUtil.logInfo("[NoCheatPlus] ProtocolLib seems to be available."); LogUtil.logInfo("[NoCheatPlus] ProtocolLib seems to be available.");
try { try {
PacketAdapter adapter = new MoveFrequency(plugin); PacketAdapter adapter = new MoveFrequency(plugin);
PacketAdapter weatherAdapter = new WeatherDistance(plugin);
protocolManager.addPacketListener(adapter); protocolManager.addPacketListener(adapter);
protocolManager.addPacketListener(weatherAdapter);
registeredPacketAdapters.add(adapter); registeredPacketAdapters.add(adapter);
} catch (Throwable t) { } catch (Throwable t) {
LogUtil.logWarning("[NoCheatPlus] Could not register some packet-level hook."); LogUtil.logWarning("[NoCheatPlus] Could not register some packet-level hook.");

View File

@ -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);
}
}
}