Created
August 11, 2013 04:34
-
-
Save aadnk/6203394 to your computer and use it in GitHub Desktop.
Suppress pressure plate sounds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.comphenix.example; | |
| import java.util.logging.Filter; | |
| import java.util.logging.LogRecord; | |
| import org.bukkit.Bukkit; | |
| import org.bukkit.Location; | |
| import org.bukkit.Material; | |
| import org.bukkit.World; | |
| import org.bukkit.plugin.java.JavaPlugin; | |
| import org.bukkit.event.Listener; | |
| 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.PacketEvent; | |
| public class PressurePlate extends JavaPlugin implements Listener { | |
| @Override | |
| public void onEnable() { | |
| ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.NAMED_SOUND_EFFECT) { | |
| @Override | |
| public void onPacketSending(PacketEvent event) { | |
| // Add AbstractPacket and Packet3ENamedSoundEffect from PacketWrapper for this to work | |
| Packet3ENamedSoundEffect packet = new Packet3ENamedSoundEffect(event.getPacket()); | |
| World world = event.getPlayer().getWorld(); | |
| // Look in BlockBasePressurePlate for these constants | |
| int x = (int) Math.round(packet.getEffectPositionX() - 0.5); | |
| int y = (int) Math.round(packet.getEffectPositionY() - 0.1); | |
| int z = (int) Math.round(packet.getEffectPositionZ() - 0.5); | |
| int blockId = world.getBlockTypeIdAt(x, y, z); | |
| if (isPressurePlate(blockId)) { | |
| if ("random.click".equals(packet.getSoundName())) { | |
| event.setCancelled(true); | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| private boolean isPressurePlate(int id) { | |
| return id == Material.STONE_PLATE.getId() || | |
| id == Material.WOOD_PLATE.getId() || | |
| id == Material.GOLD_PLATE.getId() || | |
| id == Material.IRON_PLATE.getId(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment