Skip to content

Instantly share code, notes, and snippets.

@aadnk
Created January 18, 2014 19:56
Show Gist options
  • Select an option

  • Save aadnk/8495364 to your computer and use it in GitHub Desktop.

Select an option

Save aadnk/8495364 to your computer and use it in GitHub Desktop.
Updated version of HideChestOpeningMod
package com.comphenix.hidechest;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
public class HideChestOpeningMod extends JavaPlugin {
@Override
public void onEnable() {
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
manager.addPacketListener(new PacketAdapter(this,
PacketType.Play.Server.BLOCK_ACTION, PacketType.Play.Server.NAMED_SOUND_EFFECT) {
@Override
public void onPacketSending(PacketEvent event) {
PacketType type = event.getPacketType();
if (type == PacketType.Play.Server.BLOCK_ACTION) {
World world = event.getPlayer().getWorld();
StructureModifier<Integer> ints = event.getPacket().getSpecificModifier(int.class);
int blockX = ints.read(0);
int blockY = ints.read(1);
int blockZ = ints.read(2);
// See if this is is a chest animation
if (world.getBlockAt(blockX, blockY, blockZ).getType() == Material.CHEST) {
// Don't send the animation
event.setCancelled(true);
}
} else if (type == PacketType.Play.Server.NAMED_SOUND_EFFECT) {
String soundEffectName = event.getPacket().getSpecificModifier(String.class).read(0);
// Disable all "chest" sound effects
if (soundEffectName.contains("chest")) {
event.setCancelled(true);
}
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment