@@ -24,12 +24,7 @@ public class CompatibilityUtils {
2424 * @return Class of given name
2525 */
2626 public static Class <?> getMinecraftClass (String name ) {
27- try {
28- return Class .forName (NMS_DIR + "." + name );
29- } catch (ClassNotFoundException e ) {
30- e .printStackTrace ();
31- return null ;
32- }
27+ return com .xxmicloxx .NoteBlockAPI .utils .CompatibilityUtils .getMinecraftClass (name );
3328 }
3429
3530 /**
@@ -38,23 +33,15 @@ public static Class<?> getMinecraftClass(String name) {
3833 * @return Class of given name
3934 */
4035 public static Class <?> getCraftBukkitClass (String name ) {
41- try {
42- return Class .forName (OBC_DIR + "." + name );
43- } catch (ClassNotFoundException e ) {
44- e .printStackTrace ();
45- return null ;
46- }
36+ return com .xxmicloxx .NoteBlockAPI .utils .CompatibilityUtils .getCraftBukkitClass (name );
4737 }
4838
4939 /**
5040 * Returns whether the version of Bukkit is or is after 1.12
5141 * @return version is after 1.12
5242 */
5343 public static boolean isPost1_12 () {
54- if (!isSoundCategoryCompatible () || Bukkit .getVersion ().contains ("1.11" )) {
55- return false ;
56- }
57- return true ;
44+ return com .xxmicloxx .NoteBlockAPI .utils .CompatibilityUtils .isPost1_12 ();
5845 }
5946
6047 /**
@@ -64,14 +51,7 @@ public static boolean isPost1_12() {
6451 * @return can use SoundCategory
6552 */
6653 protected static boolean isSoundCategoryCompatible () {
67- if (Bukkit .getVersion ().contains ("1.7" )
68- || Bukkit .getVersion ().contains ("1.8" )
69- || Bukkit .getVersion ().contains ("1.9" )
70- || Bukkit .getVersion ().contains ("1.10" )) {
71- return false ;
72- } else {
73- return true ;
74- }
54+ return com .xxmicloxx .NoteBlockAPI .utils .CompatibilityUtils .getServerVersion () >= 0.0111f ;
7555 }
7656
7757 /**
@@ -85,32 +65,7 @@ protected static boolean isSoundCategoryCompatible() {
8565 */
8666 public static void playSound (Player player , Location location , String sound ,
8767 SoundCategory category , float volume , float pitch ) {
88- try {
89- if (isSoundCategoryCompatible ()) {
90- Method method = Player .class .getMethod ("playSound" , Location .class , String .class ,
91- Class .forName ("org.bukkit.SoundCategory" ), float .class , float .class );
92- Class <? extends Enum > soundCategory =
93- (Class <? extends Enum >) Class .forName ("org.bukkit.SoundCategory" );
94- Enum <?> soundCategoryEnum = Enum .valueOf (soundCategory , category .name ());
95- method .invoke (player , location , sound , soundCategoryEnum , volume , pitch );
96- } else {
97- Method method = Player .class .getMethod ("playSound" , Location .class ,
98- String .class , float .class , float .class );
99- method .invoke (player , location , sound , volume , pitch );
100- }
101- } catch (NoSuchMethodException e ) {
102- e .printStackTrace ();
103- } catch (SecurityException e ) {
104- e .printStackTrace ();
105- } catch (IllegalAccessException e ) {
106- e .printStackTrace ();
107- } catch (IllegalArgumentException e ) {
108- e .printStackTrace ();
109- } catch (InvocationTargetException e ) {
110- e .printStackTrace ();
111- } catch (ClassNotFoundException e ) {
112- e .printStackTrace ();
113- }
68+ com .xxmicloxx .NoteBlockAPI .utils .CompatibilityUtils .playSound (player , location , sound , com .xxmicloxx .NoteBlockAPI .model .SoundCategory .valueOf (category .name ()), volume , pitch );
11469 }
11570
11671 /**
@@ -124,32 +79,7 @@ public static void playSound(Player player, Location location, String sound,
12479 */
12580 public static void playSound (Player player , Location location , Sound sound ,
12681 SoundCategory category , float volume , float pitch ) {
127- try {
128- if (isSoundCategoryCompatible ()) {
129- Method method = Player .class .getMethod ("playSound" , Location .class , Sound .class ,
130- Class .forName ("org.bukkit.SoundCategory" ), float .class , float .class );
131- Class <? extends Enum > soundCategory =
132- (Class <? extends Enum >) Class .forName ("org.bukkit.SoundCategory" );
133- Enum <?> soundCategoryEnum = Enum .valueOf (soundCategory , category .name ());
134- method .invoke (player , location , sound , soundCategoryEnum , volume , pitch );
135- } else {
136- Method method = Player .class .getMethod ("playSound" , Location .class ,
137- Sound .class , float .class , float .class );
138- method .invoke (player , location , sound , volume , pitch );
139- }
140- } catch (NoSuchMethodException e ) {
141- e .printStackTrace ();
142- } catch (SecurityException e ) {
143- e .printStackTrace ();
144- } catch (IllegalAccessException e ) {
145- e .printStackTrace ();
146- } catch (IllegalArgumentException e ) {
147- e .printStackTrace ();
148- } catch (InvocationTargetException e ) {
149- e .printStackTrace ();
150- } catch (ClassNotFoundException e ) {
151- e .printStackTrace ();
152- }
82+ com .xxmicloxx .NoteBlockAPI .utils .CompatibilityUtils .playSound (player , location , sound , com .xxmicloxx .NoteBlockAPI .model .SoundCategory .valueOf (category .name ()), volume , pitch );
15383 }
15484
15585 /**
0 commit comments