SHARE
TWEET

SoundPlayerUtils

Ytnoos Mar 4th, 2019 153 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.bukkit.Sound;
  2. import org.bukkit.block.Block;
  3. import org.bukkit.craftbukkit.v1_8_R3.CraftSound;
  4. import org.bukkit.craftbukkit.v1_8_R3.block.CraftBlock;
  5.  
  6. import java.lang.reflect.Field;
  7. import java.lang.reflect.Method;
  8.  
  9. public class SoundPlayerUtils {
  10.  
  11.     public static void playBlockSound(Block block) {
  12.         try {
  13.             for (Sound sound : Sound.values()) {
  14.                 Field f = CraftSound.class.getDeclaredField("sounds");
  15.                 f.setAccessible(true);
  16.  
  17.                 String[] sounds = (String[]) f.get(null);
  18.                 Method getBlock = CraftBlock.class.getDeclaredMethod("getNMSBlock");
  19.                 getBlock.setAccessible(true);
  20.                 Object nmsBlockObject = getBlock.invoke(block);
  21.  
  22.                 if (((net.minecraft.server.v1_8_R3.Block) nmsBlockObject).stepSound.getBreakSound().equals(sounds[sound.ordinal()])) {
  23.                     block.getWorld().playSound(block.getLocation(), sound, 1, 1);
  24.                 }
  25.             }
  26.         } catch (Exception ignored) {
  27.         }
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top