44import java .lang .reflect .Method ;
55import java .util .ArrayList ;
66import java .util .HashMap ;
7+ import java .util .List ;
78
89import org .bukkit .Bukkit ;
910import org .bukkit .Location ;
@@ -26,6 +27,7 @@ public class CompatibilityUtils {
2627 private static HashMap <String , Method > playSoundMethod = new HashMap <>();
2728
2829 private static float serverVersion = -1 ;
30+ private static List <CustomInstrument > customInstrumentsForDefaultInstruments = null ;
2931
3032 /**
3133 * Gets NMS class from given name
@@ -225,13 +227,14 @@ public static ArrayList<CustomInstrument> get1_12Instruments(){
225227 }
226228
227229 /**
228- * Return list of instuments which were added in specified version
230+ * Return list of instruments which were added in specified version
229231 * @param serverVersion 1.12 = 0.0112f, 1.14 = 0.0114f,...
230- * @return list of custom instruments, if no instuments were added in specified version returns empty list
232+ * @return list of custom instruments, if no instruments were added in specified version returns empty list
231233 */
232234 public static ArrayList <CustomInstrument > getVersionCustomInstruments (float serverVersion ){
233235 ArrayList <CustomInstrument > instruments = new ArrayList <>();
234- if (serverVersion == 0.0112f ){
236+ float epsilon = 0.0001F ;
237+ if (Math .abs (serverVersion - 0.0112f ) < epsilon ){
235238 instruments .add (new CustomInstrument ((byte ) 0 , "Guitar" , "block.note_block.guitar.ogg" ));
236239 instruments .add (new CustomInstrument ((byte ) 0 , "Flute" , "block.note_block.flute.ogg" ));
237240 instruments .add (new CustomInstrument ((byte ) 0 , "Bell" , "block.note_block.bell.ogg" ));
@@ -240,7 +243,7 @@ public static ArrayList<CustomInstrument> getVersionCustomInstruments(float serv
240243 return instruments ;
241244 }
242245
243- if (serverVersion == 0.0114f ){
246+ if (Math . abs ( serverVersion - 0.0114f ) < epsilon ){
244247 instruments .add (new CustomInstrument ((byte ) 0 , "Iron Xylophone" , "block.note_block.iron_xylophone.ogg" ));
245248 instruments .add (new CustomInstrument ((byte ) 0 , "Cow Bell" , "block.note_block.cow_bell.ogg" ));
246249 instruments .add (new CustomInstrument ((byte ) 0 , "Didgeridoo" , "block.note_block.didgeridoo.ogg" ));
@@ -249,6 +252,14 @@ public static ArrayList<CustomInstrument> getVersionCustomInstruments(float serv
249252 instruments .add (new CustomInstrument ((byte ) 0 , "Pling" , "block.note_block.pling.ogg" ));
250253 return instruments ;
251254 }
255+
256+ if (Math .abs (serverVersion - 0.2601f ) < epsilon ){
257+ instruments .add (new CustomInstrument ((byte ) 0 , "Trumpet" , "block.note_block.trumpet.ogg" ));
258+ instruments .add (new CustomInstrument ((byte ) 0 , "Exposed Trumpet" , "block.note_block.trumpet_exposed.ogg" ));
259+ instruments .add (new CustomInstrument ((byte ) 0 , "Weathered Trumpet" , "block.note_block.trumpet_weathered.ogg" ));
260+ instruments .add (new CustomInstrument ((byte ) 0 , "Oxidized Trumpet" , "block.note_block.trumpet_oxidized.ogg" ));
261+ return instruments ;
262+ }
252263 return instruments ;
253264 }
254265
@@ -260,18 +271,20 @@ public static ArrayList<CustomInstrument> getVersionCustomInstruments(float serv
260271 public static ArrayList <CustomInstrument > getVersionCustomInstrumentsForSong (int firstCustomInstrumentIndex ){
261272 ArrayList <CustomInstrument > instruments = new ArrayList <>();
262273
263- if (getServerVersion () < 0.0112f ){
264- if (firstCustomInstrumentIndex == 10 ) {
265- instruments .addAll (getVersionCustomInstruments (0.0112f ));
266- } else if (firstCustomInstrumentIndex == 16 ){
267- instruments .addAll (getVersionCustomInstruments (0.0112f ));
268- instruments .addAll (getVersionCustomInstruments (0.0114f ));
269- }
270- } else if (getServerVersion () < 0.0114f ){
271- if (firstCustomInstrumentIndex == 16 ){
272- instruments .addAll (getVersionCustomInstruments (0.0114f ));
273- }
274- }
274+ if (customInstrumentsForDefaultInstruments == null ) {
275+ customInstrumentsForDefaultInstruments = new ArrayList <>();
276+ customInstrumentsForDefaultInstruments .addAll (getVersionCustomInstruments (0.0112f ));
277+ customInstrumentsForDefaultInstruments .addAll (getVersionCustomInstruments (0.0114f ));
278+ customInstrumentsForDefaultInstruments .addAll (getVersionCustomInstruments (0.2601f ));
279+ }
280+
281+ byte serverFirstCustomInstrumentIndex = InstrumentUtils .getCustomInstrumentFirstIndex ();
282+ for (int i = serverFirstCustomInstrumentIndex ; i < firstCustomInstrumentIndex ; i ++) {
283+ int customInstrumentIndex = i - 5 ;
284+ if (customInstrumentIndex < customInstrumentsForDefaultInstruments .size ()) {
285+ instruments .add (customInstrumentsForDefaultInstruments .get (customInstrumentIndex ));
286+ }
287+ }
275288
276289 return instruments ;
277290 }
0 commit comments