Skip to content

Instantly share code, notes, and snippets.

@aadnk
Created July 19, 2013 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadnk/6042716 to your computer and use it in GitHub Desktop.
Save aadnk/6042716 to your computer and use it in GitHub Desktop.
Silence a player's walking.
package com.comphenix.example;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
public class SilentWalkers extends JavaPlugin {
@Override
public void onEnable() {
ProtocolLibrary.getProtocolManager().addPacketListener(
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.NAMED_SOUND_EFFECT) {
@Override
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
World world = event.getPlayer().getWorld();
String soundName = packet.getStrings().read(0);
double x = (packet.getIntegers().read(0) / 8.0);
double y = (packet.getIntegers().read(1) / 8.0);
double z = (packet.getIntegers().read(2) / 8.0);
Location loc = new Location(world, x, y, z);
if (soundName.startsWith("step.")) {
Player closest = null;
double bestDistance = Double.MAX_VALUE;
// Find the player closest to the sound
for (Player player : world.getPlayers()) {
double distance = player.getLocation().distance(loc);
if (distance < bestDistance) {
bestDistance = distance;
closest = player;
}
}
System.out.println("Cancelled " + soundName + " caused by " + closest);
event.setCancelled(true);
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment