1010import org .bukkit .entity .Player ;
1111
1212public class CompatibilityUtils {
13-
13+
1414 public static final String OBC_DIR = Bukkit .getServer ().getClass ().getPackage ().getName ();
15- public static final String NMS_DIR = OBC_DIR .replaceFirst ("org.bukkit.craftbukkit" , "net.minecraft.server" );
16-
17- public static Class <?> getMinecraftClass (String name ){
18- try {
19- return Class .forName (NMS_DIR + "." + name );
20- } catch (ClassNotFoundException e ) {
21- e .printStackTrace ();
22- return null ;
23- }
24- }
15+ public static final String NMS_DIR = OBC_DIR .replaceFirst ("org.bukkit.craftbukkit" , "net.minecraft.server" );
16+
17+ public static Class <?> getMinecraftClass (String name ) {
18+ try {
19+ return Class .forName (NMS_DIR + "." + name );
20+ } catch (ClassNotFoundException e ) {
21+ e .printStackTrace ();
22+ return null ;
23+ }
24+ }
2525
26- public static Class <?> getCraftBukkitClass (String name ){
27- try {
28- return Class .forName (OBC_DIR + "." + name );
29- } catch (ClassNotFoundException e ) {
30- e .printStackTrace ();
31- return null ;
32- }
33- }
34-
35- public static class NoteBlockCompatibility {
36- public static final int pre1_9 = 0 ;
37- public static final int pre1_12 = 1 ;
38- public static final int v1_12 = 2 ;
39- public static final int post1_12 = 3 ;
40- public static final int post1_13 = 4 ;
41- }
42-
43- protected static int getCompatibility (){
44- if (Bukkit .getVersion ().contains ("1.8" ) || Bukkit .getVersion ().contains ("1.7" )){
45- return NoteBlockCompatibility .pre1_9 ;
46- } else if (Bukkit .getVersion ().contains ("1.9" ) || Bukkit .getVersion ().contains ("1.10" ) || Bukkit .getVersion ().contains ("1.11" )){
47- return NoteBlockCompatibility .pre1_12 ;
48- } else if (Bukkit .getVersion ().contains ("1.12" )){
49- return NoteBlockCompatibility .v1_12 ;
50- } else {
51- return NoteBlockCompatibility .post1_13 ;
52- }
53- }
54-
55- protected static boolean isSoundCategoryCompatible (){
56- if (Bukkit .getVersion ().contains ("1.7" ) || Bukkit .getVersion ().contains ("1.8" ) || Bukkit .getVersion ().contains ("1.9" ) || Bukkit .getVersion ().contains ("1.10" )){
57- return false ;
58- } else {
59- return true ;
60- }
61- }
62-
63- protected static void playSound (Player p , Location location , String sound , SoundCategory category , float volume , float pitch ){
64- try {
65- if (isSoundCategoryCompatible ()){
66- Method m = Player .class .getMethod ("playSound" , Location .class , String .class , Class .forName ("org.bukkit.SoundCategory" ), float .class , float .class );
67- Class <? extends Enum > sc = (Class <? extends Enum >) Class .forName ("org.bukkit.SoundCategory" );
68- Enum <?> scenum = Enum .valueOf (sc , category .name ());
69- m .invoke (p , location , sound , scenum , volume , pitch );
70- } else {
71- Method m = Player .class .getMethod ("playSound" , Location .class , String .class , float .class , float .class );
72- m .invoke (p , location , sound , volume , pitch );
73- }
26+ public static Class <?> getCraftBukkitClass (String name ) {
27+ try {
28+ return Class .forName (OBC_DIR + "." + name );
29+ } catch (ClassNotFoundException e ) {
30+ e .printStackTrace ();
31+ return null ;
32+ }
33+ }
34+
35+ public static class NoteBlockCompatibility {
36+ public static final int pre1_9 = 0 ;
37+ public static final int pre1_12 = 1 ;
38+ public static final int v1_12 = 2 ;
39+ public static final int post1_12 = 3 ;
40+ public static final int post1_13 = 4 ;
41+ }
42+
43+ protected static int getCompatibility () {
44+ if (Bukkit .getVersion ().contains ("1.8" ) || Bukkit .getVersion ().contains ("1.7" )) {
45+ return NoteBlockCompatibility .pre1_9 ;
46+ } else if (Bukkit .getVersion ().contains ("1.9" )
47+ || Bukkit .getVersion ().contains ("1.10" )
48+ || Bukkit .getVersion ().contains ("1.11" )) {
49+ return NoteBlockCompatibility .pre1_12 ;
50+ } else if (Bukkit .getVersion ().contains ("1.12" )) {
51+ return NoteBlockCompatibility .v1_12 ;
52+ } else {
53+ return NoteBlockCompatibility .post1_13 ;
54+ }
55+ }
56+
57+ protected static boolean isSoundCategoryCompatible () {
58+ if (Bukkit .getVersion ().contains ("1.7" )
59+ || Bukkit .getVersion ().contains ("1.8" )
60+ || Bukkit .getVersion ().contains ("1.9" )
61+ || Bukkit .getVersion ().contains ("1.10" )) {
62+ return false ;
63+ } else {
64+ return true ;
65+ }
66+ }
67+
68+ protected static void playSound (Player player , Location location , String sound ,
69+ SoundCategory category , float volume , float pitch ) {
70+ try {
71+ if (isSoundCategoryCompatible ()) {
72+ Method method = Player .class .getMethod ("playSound" , Location .class , String .class ,
73+ Class .forName ("org.bukkit.SoundCategory" ), float .class , float .class );
74+ Class <? extends Enum > soundCategory =
75+ (Class <? extends Enum >) Class .forName ("org.bukkit.SoundCategory" );
76+ Enum <?> soundCategoryEnum = Enum .valueOf (soundCategory , category .name ());
77+ method .invoke (player , location , sound , soundCategoryEnum , volume , pitch );
78+ } else {
79+ Method method = Player .class .getMethod ("playSound" , Location .class ,
80+ String .class , float .class , float .class );
81+ method .invoke (player , location , sound , volume , pitch );
82+ }
7483 } catch (NoSuchMethodException e ) {
7584 e .printStackTrace ();
7685 } catch (SecurityException e ) {
@@ -84,20 +93,23 @@ protected static void playSound(Player p, Location location, String sound, Sound
8493 } catch (ClassNotFoundException e ) {
8594 e .printStackTrace ();
8695 }
87- }
96+ }
8897
89- public static void playSound (Player p , Location location , Sound sound , SoundCategory category , float volume , float pitch ) {
98+ public static void playSound (Player player , Location location , Sound sound ,
99+ SoundCategory category , float volume , float pitch ) {
90100 try {
91- if (isSoundCategoryCompatible ()){
92- Method m = Player .class .getMethod ("playSound" , Location .class , Sound .class , Class .forName ("org.bukkit.SoundCategory" ), float .class , float .class );
93- Class <? extends Enum > sc = (Class <? extends Enum >) Class .forName ("org.bukkit.SoundCategory" );
94- Enum <?> scenum = Enum .valueOf (sc , category .name ());
95- m .invoke (p , location , sound , scenum , volume , pitch );
101+ if (isSoundCategoryCompatible ()) {
102+ Method method = Player .class .getMethod ("playSound" , Location .class , Sound .class ,
103+ Class .forName ("org.bukkit.SoundCategory" ), float .class , float .class );
104+ Class <? extends Enum > soundCategory =
105+ (Class <? extends Enum >) Class .forName ("org.bukkit.SoundCategory" );
106+ Enum <?> soundCategoryEnum = Enum .valueOf (soundCategory , category .name ());
107+ method .invoke (player , location , sound , soundCategoryEnum , volume , pitch );
96108 } else {
97- Method m = Player .class .getMethod ("playSound" , Location .class , Sound .class , float .class , float .class );
98- m .invoke (p , location , sound , volume , pitch );
109+ Method method = Player .class .getMethod ("playSound" , Location .class ,
110+ Sound .class , float .class , float .class );
111+ method .invoke (player , location , sound , volume , pitch );
99112 }
100-
101113 } catch (NoSuchMethodException e ) {
102114 e .printStackTrace ();
103115 } catch (SecurityException e ) {
@@ -112,14 +124,15 @@ public static void playSound(Player p, Location location, Sound sound, SoundCate
112124 e .printStackTrace ();
113125 }
114126 }
115-
127+
116128 public static ArrayList <CustomInstrument > get1_12Instruments (){
117129 ArrayList <CustomInstrument > instruments = new ArrayList <>();
118- instruments .add (new CustomInstrument ((byte ) 0 , "Guitar" , "guitar.ogg" , ( byte ) 0 , ( byte ) 0 ));
119- instruments .add (new CustomInstrument ((byte ) 0 , "Flute" , "flute.ogg" , ( byte ) 0 , ( byte ) 0 ));
120- instruments .add (new CustomInstrument ((byte ) 0 , "Bell" , "bell.ogg" , ( byte ) 0 , ( byte ) 0 ));
121- instruments .add (new CustomInstrument ((byte ) 0 , "Chime" , "icechime.ogg" , ( byte ) 0 , ( byte ) 0 ));
122- instruments .add (new CustomInstrument ((byte ) 0 , "Xylophone" , "xylobone.ogg" , ( byte ) 0 , ( byte ) 0 ));
130+ instruments .add (new CustomInstrument ((byte ) 0 , "Guitar" , "guitar.ogg" ));
131+ instruments .add (new CustomInstrument ((byte ) 0 , "Flute" , "flute.ogg" ));
132+ instruments .add (new CustomInstrument ((byte ) 0 , "Bell" , "bell.ogg" ));
133+ instruments .add (new CustomInstrument ((byte ) 0 , "Chime" , "icechime.ogg" ));
134+ instruments .add (new CustomInstrument ((byte ) 0 , "Xylophone" , "xylobone.ogg" ));
123135 return instruments ;
124136 }
137+
125138}
0 commit comments