Solved Custom Sounds

Discussion in 'Plugin Development' started by Bammerbom, May 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Bammerbom

    First of all I KNOW THIS POSSIBLE
    In vanilla this is the playsoundcommand.

    But how to do this by code?

    I know a player has to have a resourcepack for this.
     
  2. Offline

    TGRHavoc

    Jhtzb
    Code:java
    1. World.playSound(Location, Sound, Volume, Pitch);
     
  3. Offline

    Bammerbom

    TGRHavoc This is only for MC sounds. How to do it for custom ones.
     
  4. Offline

    TGRHavoc

    Jhtzb
    Don't think that's possible. Click me for original thread.
     
  5. Offline

    JuicyDev

    If you want to play custom sounds from a custom resource pack, then try looking at the NMS code. Just follow through the methods until you find then NMS method. If possible try using reflection to invoke the method. If you need help with the reflection just ask, but only after first taking a look :).
     
    Jhtzb likes this.
  6. Offline

    Bammerbom

    TGRHavoc JuicyDev
    I found this: (CraftPlayer.class)
    Code:java
    1.  
    2. public void playSound(Location loc, String sound, float volume, float pitch)
    3. {
    4. if ((loc == null) || (sound == null) || (getHandle().playerConnection == null)) return;
    5.  
    6. double x = loc.getBlockX() + 0.5D;
    7. double y = loc.getBlockY() + 0.5D;
    8. double z = loc.getBlockZ() + 0.5D;
    9.  
    10. PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(sound, x, y, z, volume, pitch);
    11. getHandle().playerConnection.sendPacket(packet);
    12. }

    You can trigger it by:
    Code:
    playSound(Location, Sound(String), volume, pitch);
    Easy way:
    Code:java
    1. Player p;
    2. CraftPlayer pl = (CraftPlayer) p;
    3. pl.playSound(loc, sound, volume, pitch);

    And I found this for the standard sound locations (CraftSound.class)
    Code:java
    1. set(Sound.AMBIENCE_CAVE, "ambient.cave.cave");
    2. set(Sound.AMBIENCE_RAIN, "ambient.weather.rain");
    3. set(Sound.AMBIENCE_THUNDER, "ambient.weather.thunder");
    4.  
    5. set(Sound.HURT_FLESH, "game.neutral.hurt");
    6. set(Sound.FALL_BIG, "game.neutral.hurt.fall.big");
    7. set(Sound.FALL_SMALL, "game.neutral.hurt.fall.small");
    8.  
    9. set(Sound.DIG_WOOL, "dig.cloth");
    10. set(Sound.DIG_GRASS, "dig.grass");
    11. set(Sound.DIG_GRAVEL, "dig.gravel");
    12. set(Sound.DIG_SAND, "dig.sand");
    13. set(Sound.DIG_SNOW, "dig.snow");
    14. set(Sound.DIG_STONE, "dig.stone");
    15. set(Sound.DIG_WOOD, "dig.wood");
    16.  
    17. set(Sound.FIRE, "fire.fire");
    18. set(Sound.FIRE_IGNITE, "fire.ignite");
    19.  
    20. set(Sound.FIREWORK_BLAST, "fireworks.blast");
    21. set(Sound.FIREWORK_BLAST2, "fireworks.blast_far");
    22. set(Sound.FIREWORK_LARGE_BLAST, "fireworks.largeBlast");
    23. set(Sound.FIREWORK_LARGE_BLAST2, "fireworks.largeBlast_far");
    24. set(Sound.FIREWORK_TWINKLE, "fireworks.twinkle");
    25. set(Sound.FIREWORK_TWINKLE2, "fireworks.twinkle_far");
    26. set(Sound.FIREWORK_LAUNCH, "fireworks.launch");
    27.  
    28. set(Sound.SPLASH2, "game.neutral.swim.splash");
    29. set(Sound.SWIM, "game.neutral.swim");
    30. set(Sound.WATER, "liquid.water");
    31. set(Sound.LAVA, "liquid.lava");
    32. set(Sound.LAVA_POP, "liquid.lavapop");
    33.  
    34. set(Sound.MINECART_BASE, "minecart.base");
    35. set(Sound.MINECART_INSIDE, "minecart.inside");
    36.  
    37. set(Sound.BAT_DEATH, "mob.bat.death");
    38. set(Sound.BAT_HURT, "mob.bat.hurt");
    39. set(Sound.BAT_IDLE, "mob.bat.idle");
    40. set(Sound.BAT_LOOP, "mob.bat.loop");
    41. set(Sound.BAT_TAKEOFF, "mob.bat.takeoff");
    42. set(Sound.BLAZE_BREATH, "mob.blaze.breathe");
    43. set(Sound.BLAZE_DEATH, "mob.blaze.death");
    44. set(Sound.BLAZE_HIT, "mob.blaze.hit");
    45. set(Sound.CAT_HISS, "mob.cat.hiss");
    46. set(Sound.CAT_HIT, "mob.cat.hitt");
    47. set(Sound.CAT_MEOW, "mob.cat.meow");
    48. set(Sound.CAT_PURR, "mob.cat.purr");
    49. set(Sound.CAT_PURREOW, "mob.cat.purreow");
    50. set(Sound.CHICKEN_IDLE, "mob.chicken.say");
    51. set(Sound.CHICKEN_HURT, "mob.chicken.hurt");
    52. set(Sound.CHICKEN_EGG_POP, "mob.chicken.plop");
    53. set(Sound.CHICKEN_WALK, "mob.chicken.step");
    54. set(Sound.COW_HURT, "mob.cow.hurt");
    55. set(Sound.COW_IDLE, "mob.cow.say");
    56. set(Sound.COW_WALK, "mob.cow.step");
    57. set(Sound.CREEPER_DEATH, "mob.creeper.death");
    58. set(Sound.CREEPER_HISS, "mob.creeper.say");
    59. set(Sound.ENDERDRAGON_DEATH, "mob.enderdragon.end");
    60. set(Sound.ENDERDRAGON_GROWL, "mob.enderdragon.growl");
    61. set(Sound.ENDERDRAGON_HIT, "mob.enderdragon.hit");
    62. set(Sound.ENDERDRAGON_WINGS, "mob.enderdragon.wings");
    63. set(Sound.ENDERMAN_DEATH, "mob.endermen.death");
    64. set(Sound.ENDERMAN_HIT, "mob.endermen.hit");
    65. set(Sound.ENDERMAN_IDLE, "mob.endermen.idle");
    66. set(Sound.ENDERMAN_TELEPORT, "mob.endermen.portal");
    67. set(Sound.ENDERMAN_SCREAM, "mob.endermen.scream");
    68. set(Sound.ENDERMAN_STARE, "mob.endermen.stare");
    69. set(Sound.GHAST_SCREAM2, "mob.ghast.affectionate_scream");
    70. set(Sound.GHAST_CHARGE, "mob.ghast.charge");
    71. set(Sound.GHAST_DEATH, "mob.ghast.death");
    72. set(Sound.GHAST_FIREBALL, "mob.ghast.fireball");
    73. set(Sound.GHAST_MOAN, "mob.ghast.moan");
    74. set(Sound.GHAST_SCREAM, "mob.ghast.scream");
    75. set(Sound.HORSE_ANGRY, "mob.horse.angry");
    76. set(Sound.HORSE_ARMOR, "mob.horse.armor");
    77. set(Sound.HORSE_BREATHE, "mob.horse.breathe");
    78. set(Sound.HORSE_DEATH, "mob.horse.death");
    79. set(Sound.HORSE_GALLOP, "mob.horse.gallop");
    80. set(Sound.HORSE_HIT, "mob.horse.hit");
    81. set(Sound.HORSE_IDLE, "mob.horse.idle");
    82. set(Sound.HORSE_JUMP, "mob.horse.jump");
    83. set(Sound.HORSE_LAND, "mob.horse.land");
    84. set(Sound.HORSE_SADDLE, "mob.horse.leather");
    85. set(Sound.HORSE_SOFT, "mob.horse.soft");
    86. set(Sound.HORSE_WOOD, "mob.horse.wood");
    87. set(Sound.DONKEY_ANGRY, "mob.horse.donkey.angry");
    88. set(Sound.DONKEY_DEATH, "mob.horse.donkey.death");
    89. set(Sound.DONKEY_HIT, "mob.horse.donkey.hit");
    90. set(Sound.DONKEY_IDLE, "mob.horse.donkey.idle");
    91. set(Sound.HORSE_SKELETON_DEATH, "mob.horse.skeleton.death");
    92. set(Sound.HORSE_SKELETON_HIT, "mob.horse.skeleton.hit");
    93. set(Sound.HORSE_SKELETON_IDLE, "mob.horse.skeleton.idle");
    94. set(Sound.HORSE_ZOMBIE_DEATH, "mob.horse.zombie.death");
    95. set(Sound.HORSE_ZOMBIE_HIT, "mob.horse.zombie.hit");
    96. set(Sound.HORSE_ZOMBIE_IDLE, "mob.horse.zombie.idle");
    97. set(Sound.IRONGOLEM_DEATH, "mob.irongolem.death");
    98. set(Sound.IRONGOLEM_HIT, "mob.irongolem.hit");
    99. set(Sound.IRONGOLEM_THROW, "mob.irongolem.throw");
    100. set(Sound.IRONGOLEM_WALK, "mob.irongolem.walk");
    101. set(Sound.MAGMACUBE_WALK, "mob.magmacube.small");
    102. set(Sound.MAGMACUBE_WALK2, "mob.magmacube.big");
    103. set(Sound.MAGMACUBE_JUMP, "mob.magmacube.jump");
    104. set(Sound.PIG_IDLE, "mob.pig.say");
    105. set(Sound.PIG_DEATH, "mob.pig.death");
    106. set(Sound.PIG_WALK, "mob.pig.step");
    107. set(Sound.SHEEP_IDLE, "mob.sheep.say");
    108. set(Sound.SHEEP_SHEAR, "mob.sheep.shear");
    109. set(Sound.SHEEP_WALK, "mob.sheep.step");
    110. set(Sound.SILVERFISH_HIT, "mob.silverfish.hit");
    111. set(Sound.SILVERFISH_KILL, "mob.silverfish.kill");
    112. set(Sound.SILVERFISH_IDLE, "mob.silverfish.say");
    113. set(Sound.SILVERFISH_WALK, "mob.silverfish.step");
    114. set(Sound.SKELETON_IDLE, "mob.skeleton.say");
    115. set(Sound.SKELETON_DEATH, "mob.skeleton.death");
    116. set(Sound.SKELETON_HURT, "mob.skeleton.hurt");
    117. set(Sound.SKELETON_WALK, "mob.skeleton.step");
    118. set(Sound.SLIME_ATTACK, "mob.slime.attack");
    119. set(Sound.SLIME_WALK, "mob.slime.small");
    120. set(Sound.SLIME_WALK2, "mob.slime.big");
    121. set(Sound.SPIDER_IDLE, "mob.spider.say");
    122. set(Sound.SPIDER_DEATH, "mob.spider.death");
    123. set(Sound.SPIDER_WALK, "mob.spider.step");
    124. set(Sound.VILLAGER_DEATH, "mob.villager.death");
    125. set(Sound.VILLAGER_HAGGLE, "mob.villager.haggle");
    126. set(Sound.VILLAGER_HIT, "mob.villager.hit");
    127. set(Sound.VILLAGER_IDLE, "mob.villager.idle");
    128. set(Sound.VILLAGER_NO, "mob.villager.no");
    129. set(Sound.VILLAGER_YES, "mob.villager.yes");
    130. set(Sound.WITHER_DEATH, "mob.wither.death");
    131. set(Sound.WITHER_HURT, "mob.wither.hurt");
    132. set(Sound.WITHER_IDLE, "mob.wither.idle");
    133. set(Sound.WITHER_SHOOT, "mob.wither.shoot");
    134. set(Sound.WITHER_SPAWN, "mob.wither.spawn");
    135. set(Sound.WOLF_BARK, "mob.wolf.bark");
    136. set(Sound.WOLF_DEATH, "mob.wolf.death");
    137. set(Sound.WOLF_GROWL, "mob.wolf.growl");
    138. set(Sound.WOLF_HOWL, "mob.wolf.howl");
    139. set(Sound.WOLF_HURT, "mob.wolf.hurt");
    140. set(Sound.WOLF_PANT, "mob.wolf.panting");
    141. set(Sound.WOLF_SHAKE, "mob.wolf.shake");
    142. set(Sound.WOLF_WALK, "mob.wolf.step");
    143. set(Sound.WOLF_WHINE, "mob.wolf.whine");
    144. set(Sound.ZOMBIE_METAL, "mob.zombie.metal");
    145. set(Sound.ZOMBIE_WOOD, "mob.zombie.wood");
    146. set(Sound.ZOMBIE_WOODBREAK, "mob.zombie.woodbreak");
    147. set(Sound.ZOMBIE_IDLE, "mob.zombie.say");
    148. set(Sound.ZOMBIE_DEATH, "mob.zombie.death");
    149. set(Sound.ZOMBIE_HURT, "mob.zombie.hurt");
    150. set(Sound.ZOMBIE_INFECT, "mob.zombie.infect");
    151. set(Sound.ZOMBIE_UNFECT, "mob.zombie.unfect");
    152. set(Sound.ZOMBIE_REMEDY, "mob.zombie.remedy");
    153. set(Sound.ZOMBIE_WALK, "mob.zombie.step");
    154. set(Sound.ZOMBIE_PIG_IDLE, "mob.zombiepig.zpig");
    155. set(Sound.ZOMBIE_PIG_ANGRY, "mob.zombiepig.zpigangry");
    156. set(Sound.ZOMBIE_PIG_DEATH, "mob.zombiepig.zpigdeath");
    157. set(Sound.ZOMBIE_PIG_HURT, "mob.zombiepig.zpighurt");
    158.  
    159. set(Sound.NOTE_BASS_GUITAR, "note.bassattack");
    160. set(Sound.NOTE_SNARE_DRUM, "note.snare");
    161. set(Sound.NOTE_PLING, "note.pling");
    162. set(Sound.NOTE_BASS, "note.bass");
    163. set(Sound.NOTE_PIANO, "note.harp");
    164. set(Sound.NOTE_BASS_DRUM, "note.bd");
    165. set(Sound.NOTE_STICKS, "note.hat");
    166.  
    167. set(Sound.PORTAL, "portal.portal");
    168. set(Sound.PORTAL_TRAVEL, "portal.travel");
    169. set(Sound.PORTAL_TRIGGER, "portal.trigger");
    170.  
    171. set(Sound.ANVIL_BREAK, "random.anvil_break");
    172. set(Sound.ANVIL_LAND, "random.anvil_land");
    173. set(Sound.ANVIL_USE, "random.anvil_use");
    174. set(Sound.SHOOT_ARROW, "random.bow");
    175. set(Sound.ARROW_HIT, "random.bowhit");
    176. set(Sound.ITEM_BREAK, "random.break");
    177. set(Sound.BURP, "random.burp");
    178. set(Sound.CHEST_CLOSE, "random.chestclosed");
    179. set(Sound.CHEST_OPEN, "random.chestopen");
    180. set(Sound.CLICK, "random.click");
    181. set(Sound.DOOR_CLOSE, "random.door_close");
    182. set(Sound.DOOR_OPEN, "random.door_open");
    183. set(Sound.DRINK, "random.drink");
    184. set(Sound.EAT, "random.eat");
    185. set(Sound.EXPLODE, "random.explode");
    186. set(Sound.FIZZ, "random.fizz");
    187. set(Sound.FUSE, "creeper.primed");
    188. set(Sound.GLASS, "dig.glass");
    189. set(Sound.LEVEL_UP, "random.levelup");
    190. set(Sound.ORB_PICKUP, "random.orb");
    191. set(Sound.ITEM_PICKUP, "random.pop");
    192. set(Sound.SPLASH, "random.splash");
    193. set(Sound.SUCCESSFUL_HIT, "random.successful_hit");
    194. set(Sound.WOOD_CLICK, "random.wood_click");
    195.  
    196. set(Sound.STEP_WOOL, "step.cloth");
    197. set(Sound.STEP_GRASS, "step.grass");
    198. set(Sound.STEP_GRAVEL, "step.gravel");
    199. set(Sound.STEP_LADDER, "step.ladder");
    200. set(Sound.STEP_SAND, "step.sand");
    201. set(Sound.STEP_SNOW, "step.snow");
    202. set(Sound.STEP_STONE, "step.stone");
    203. set(Sound.STEP_WOOD, "step.wood");
    204.  
    205. set(Sound.PISTON_EXTEND, "tile.piston.out");
    206. set(Sound.PISTON_RETRACT, "tile.piston.in");


    TGRHavoc JuicyDev
    Can you help me by making this in reflection:
    Easy way:
    Code:java
    1. Player p;
    2. CraftPlayer pl = (CraftPlayer) p;
    3. pl.playSound(loc, sound, volume, pitch);


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. Offline

    TGRHavoc

    Jhtzb
    Wouldn't sound be "path.to.custom.sound". Or something like that.
     
  8. Offline

    Bammerbom

    TGRHavoc the "sound" is what I commented in post above like dig.snow, so the "sound" is a string

    Can someone make this code reflection for me:
    Code:java
    1. Player p;
    2. CraftPlayer pl = (CraftPlayer) p;
    3. pl.playSound(Location loc, String sound, Float volume, Float pitch);


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  9. Offline

    JuicyDev

    It's more complicated than that. Gimme a sec and I'll write one up.

    Code:java
    1. package juicydev.juicycore.util;
    2.  
    3. import java.lang.reflect.Constructor;
    4. import java.lang.reflect.Field;
    5. import java.lang.reflect.Method;
    6. import java.util.HashMap;
    7. import java.util.Map;
    8.  
    9. import juicydev.example.util.SoundPlayer.ReflectionUtil.PackageType;
    10. import juicydev.example.util.SoundPlayer.ReflectionUtil.SubPackageType;
    11.  
    12. import org.bukkit.Bukkit;
    13. import org.bukkit.Location;
    14. import org.bukkit.entity.Player;
    15.  
    16. public class SoundPlayer {
    17. private static Class<?> obc_CraftPlayer;
    18. private static Class<?> nms_EntityPlayer;
    19. private static Class<?> nms_packetPlayOutNamedSoundEffect;
    20. private static Constructor<?> con_packetPlayOutNamedSoundEffect;
    21. private static Method m_craftPlayer_getHandle;
    22. private static Method m_sendPacket;
    23. private static Field f_entityPlayer_playerConnection;
    24. private static final String packetName = "PacketPlayOutNamedSoundEffect";
    25.  
    26. static {
    27. try {
    28. nms_packetPlayOutNamedSoundEffect = ReflectionUtil.getClass(
    29. packetName, PackageType.MINECRAFT_SERVER);
    30. con_packetPlayOutNamedSoundEffect = ReflectionUtil.getConstructor(
    31. nms_packetPlayOutNamedSoundEffect, String.class,
    32. double.class, double.class, double.class, float.class,
    33. float.class);
    34. obc_CraftPlayer = ReflectionUtil.getClass("CraftPlayer",
    35. SubPackageType.ENTITY);
    36. nms_EntityPlayer = ReflectionUtil.getClass("EntityPlayer",
    37. PackageType.MINECRAFT_SERVER);
    38. m_craftPlayer_getHandle = ReflectionUtil.getMethod(obc_CraftPlayer,
    39. "getHandle");
    40. f_entityPlayer_playerConnection = ReflectionUtil.getField(
    41. nms_EntityPlayer, "playerConnection");
    42. m_sendPacket = ReflectionUtil.getMethod(
    43. f_entityPlayer_playerConnection.getType(), "sendPacket",
    44. ReflectionUtil.getClass("Packet",
    45. PackageType.MINECRAFT_SERVER));
    46. } catch (Exception e) {
    47. e.printStackTrace();
    48. }
    49. }
    50.  
    51. public void playSound(Player player, String soundName, Location loc,
    52. float volume, float pitch) {
    53. try {
    54. double x = loc.getBlockX() + 0.5;
    55. double y = loc.getBlockY() + 0.5;
    56. double z = loc.getBlockZ() + 0.5;
    57.  
    58. Object craftPlayer = obc_CraftPlayer.cast(player);
    59. Object entityPlayer = m_craftPlayer_getHandle.invoke(craftPlayer);
    60. Object packetPlayOutNamedSoundEffect = con_packetPlayOutNamedSoundEffect
    61. .newInstance(soundName, x, y, z, volume, pitch);
    62. m_sendPacket.invoke(
    63. f_entityPlayer_playerConnection.get(entityPlayer),
    64. packetPlayOutNamedSoundEffect);
    65. } catch (Exception e) {
    66. e.printStackTrace();
    67. }
    68. }
    69.  
    70. public static class ReflectionUtil {
    71.  
    72. public static Class<?> getClass(String name, PackageType type)
    73. throws Exception {
    74. return Class.forName(type + "." + name);
    75. }
    76.  
    77. public static Class<?> getClass(String name, SubPackageType type)
    78. throws Exception {
    79. return Class.forName(type + "." + name);
    80. }
    81.  
    82. public static Constructor<?> getConstructor(Class<?> clazz,
    83. Class<?>... parameterTypes) {
    84. Class<?>[] p = DataType.convertToPrimitive(parameterTypes);
    85. for (Constructor<?> c : clazz.getConstructors())
    86. if (DataType.equalsArray(
    87. DataType.convertToPrimitive(c.getParameterTypes()), p))
    88. return c;
    89. return null;
    90. }
    91.  
    92. public static Method getMethod(Class<?> clazz, String name,
    93. Class<?>... parameterTypes) {
    94. Class<?>[] p = DataType.convertToPrimitive(parameterTypes);
    95. for (Method m : clazz.getMethods())
    96. if (m.getName().equals(name)
    97. && DataType.equalsArray(DataType.convertToPrimitive(m
    98. .getParameterTypes()), p))
    99. return m;
    100. return null;
    101. }
    102.  
    103. public static Field getField(Class<?> clazz, String name)
    104. throws Exception {
    105. Field f = clazz.getField(name);
    106. f.setAccessible(true);
    107. return f;
    108. }
    109.  
    110. public enum DataType {
    111. BYTE(byte.class, Byte.class), SHORT(short.class, Short.class), INTEGER(
    112. int.class, Integer.class), LONG(long.class, Long.class), CHARACTER(
    113. char.class, Character.class), FLOAT(float.class,
    114. Float.class), DOUBLE(double.class, Double.class), BOOLEAN(
    115. boolean.class, Boolean.class);
    116.  
    117. private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>();
    118. private final Class<?> primitive;
    119. private final Class<?> reference;
    120.  
    121. static {
    122. for (DataType t : values()) {
    123. CLASS_MAP.put(t.primitive, t);
    124. CLASS_MAP.put(t.reference, t);
    125. }
    126. }
    127.  
    128. private DataType(Class<?> primitive, Class<?> reference) {
    129. this.primitive = primitive;
    130. this.reference = reference;
    131. }
    132.  
    133. public Class<?> getPrimitive() {
    134. return this.primitive;
    135. }
    136.  
    137. public Class<?> getReference() {
    138. return this.reference;
    139. }
    140.  
    141. public static DataType fromClass(Class<?> c) {
    142. return CLASS_MAP.get(c);
    143. }
    144.  
    145. public static Class<?> getPrimitive(Class<?> c) {
    146. DataType t = fromClass(c);
    147. return t == null ? c : t.getPrimitive();
    148. }
    149.  
    150. public static Class<?> getReference(Class<?> c) {
    151. DataType t = fromClass(c);
    152. return t == null ? c : t.getReference();
    153. }
    154.  
    155. public static Class<?>[] convertToPrimitive(Class<?>[] classes) {
    156. int length = classes == null ? 0 : classes.length;
    157. Class<?>[] types = new Class<?>[length];
    158. for (int i = 0; i < length; i++)
    159. types[i] = getPrimitive(classes[i]);
    160. return types;
    161. }
    162.  
    163. public static Class<?>[] convertToPrimitive(Object[] objects) {
    164. int length = objects == null ? 0 : objects.length;
    165. Class<?>[] types = new Class<?>[length];
    166. for (int i = 0; i < length; i++)
    167. types[i] = getPrimitive(objects[i].getClass());
    168. return types;
    169. }
    170.  
    171. public static boolean equalsArray(Class<?>[] a1, Class<?>[] a2) {
    172. if (a1 == null || a2 == null || a1.length != a2.length)
    173. return false;
    174. for (int i = 0; i < a1.length; i++)
    175. if (!a1[i].equals(a2[i]) && !a1[i].isAssignableFrom(a2[i]))
    176. return false;
    177. return true;
    178. }
    179. }
    180.  
    181. public enum PackageType {
    182. MINECRAFT_SERVER("net.minecraft.server."
    183. + Bukkit.getServer().getClass().getPackage().getName()
    184. .substring(23)), CRAFTBUKKIT(Bukkit.getServer()
    185. .getClass().getPackage().getName());
    186.  
    187. private final String name;
    188.  
    189. private PackageType(String name) {
    190. this.name = name;
    191. }
    192.  
    193. public String getName() {
    194. return this.name;
    195. }
    196.  
    197. @Override
    198. public String toString() {
    199. return name;
    200. }
    201. }
    202.  
    203. public enum SubPackageType {
    204. BLOCK, CHUNKIO, COMMAND, CONVERSATIONS, ENCHANTMENS, ENTITY, EVENT, GENERATOR, HELP, INVENTORY, MAP, METADATA, POTION, PROJECTILES, SCHEDULER, SCOREBOARD, UPDATER, UTIL;
    205.  
    206. private final String name;
    207.  
    208. private SubPackageType() {
    209. name = PackageType.CRAFTBUKKIT + "." + name().toLowerCase();
    210. }
    211.  
    212. public String getName() {
    213. return this.name;
    214. }
    215.  
    216. @Override
    217. public String toString() {
    218. return name;
    219. }
    220. }
    221. }
    222. }
    223. [/i][/i][/i][/i][/i][/i][/i][/i]


    OCD set in after the forums unformatted the code xD

    That should work, but if not you should set up a version checker and just update the version every update, so as to stop bad stuff happening.

    BTW this uses reflection to invoke the NMS method and send a PacketPlayOutNamedSound packet to the player.

    Also, this could be condensed down a lot, I just grabbed some methods from a reflection util class in one of my plugins.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
    Jhtzb likes this.
  10. Offline

    Bammerbom

    JuicyDev Really thank you <3 I will love you forever haha.

    Thread solved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page