Skip to content

Commit 9614b06

Browse files
committed
fix getBukkitInstrument, other minor
1 parent 36d05cb commit 9614b06

File tree

6 files changed

+59
-46
lines changed

6 files changed

+59
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# NoteBlockAPI
22
[![](https://jitpack.io/v/koca2000/NoteBlockAPI.svg)](https://jitpack.io/#koca2000/NoteBlockAPI)
33

4-
For informations about this Spigot/Bukkit API go to https://www.spigotmc.org/resources/noteblockapi.19287/
4+
For information about this Spigot/Bukkit API, go to https://www.spigotmc.org/resources/noteblockapi.19287/

src/main/java/com/xxmicloxx/NoteBlockAPI/CustomInstrument.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class CustomInstrument {
1515
* Creates a CustomInstrument
1616
* @deprecated Unused parameters
1717
*/
18+
@Deprecated
1819
public CustomInstrument(byte index, String name, String soundFileName, byte pitch, byte press) {
1920
this.index = index;
2021
this.name = name;
@@ -73,8 +74,8 @@ public String getSoundFileName() {
7374
}
7475

7576
/**
76-
* Gets the Sound enum for this CustomInstrument
77-
* @return
77+
* Gets the org.bukkit.Sound enum for this CustomInstrument
78+
* @return org.bukkit.Sound enum
7879
*/
7980
public org.bukkit.Sound getSound() {
8081
return sound;

src/main/java/com/xxmicloxx/NoteBlockAPI/Instrument.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Various methods for working with instruments
55
* @deprecated Moved to InstrumentUtils
66
*/
7+
@Deprecated
78
public class Instrument {
89

910
/**
@@ -66,25 +67,30 @@ public static org.bukkit.Instrument getBukkitInstrument(byte instrument) {
6667
return org.bukkit.Instrument.SNARE_DRUM;
6768
case 4:
6869
return org.bukkit.Instrument.STICKS;
69-
case 5:
70-
return org.bukkit.Instrument.GUITAR;
71-
case 6:
72-
return org.bukkit.Instrument.FLUTE;
73-
case 7:
74-
return org.bukkit.Instrument.BELL;
75-
case 8:
76-
return org.bukkit.Instrument.CHIME;
77-
case 9:
78-
return org.bukkit.Instrument.XYLOPHONE;
79-
default:
70+
default: {
71+
if (CompatibilityUtils.isPost1_12()) {
72+
switch (instrument) {
73+
case 5:
74+
return org.bukkit.Instrument.GUITAR;
75+
case 6:
76+
return org.bukkit.Instrument.FLUTE;
77+
case 7:
78+
return org.bukkit.Instrument.BELL;
79+
case 8:
80+
return org.bukkit.Instrument.CHIME;
81+
case 9:
82+
return org.bukkit.Instrument.XYLOPHONE;
83+
}
84+
}
8085
return org.bukkit.Instrument.PIANO;
86+
}
8187
}
8288
}
8389

8490
/**
8591
* If true, the byte given represents a custom instrument
8692
* @param instrument
87-
* @return
93+
* @return whether the byte represents a custom instrument
8894
*/
8995
public static boolean isCustomInstrument(byte instrument) {
9096
if (CompatibilityUtils.isPost1_12()) {
@@ -102,7 +108,7 @@ public static boolean isCustomInstrument(byte instrument) {
102108
/**
103109
* Gets the first index in which a custom instrument
104110
* can be added to the existing list of instruments
105-
* @return instrument as a byte
111+
* @return index where an instrument can be added
106112
*/
107113
public static byte getCustomInstrumentFirstIndex() {
108114
if (CompatibilityUtils.isPost1_12()) {

src/main/java/com/xxmicloxx/NoteBlockAPI/InstrumentUtils.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,30 @@ public static org.bukkit.Instrument getBukkitInstrument(byte instrument) {
6565
return org.bukkit.Instrument.SNARE_DRUM;
6666
case 4:
6767
return org.bukkit.Instrument.STICKS;
68-
case 5:
69-
return org.bukkit.Instrument.GUITAR;
70-
case 6:
71-
return org.bukkit.Instrument.FLUTE;
72-
case 7:
73-
return org.bukkit.Instrument.BELL;
74-
case 8:
75-
return org.bukkit.Instrument.CHIME;
76-
case 9:
77-
return org.bukkit.Instrument.XYLOPHONE;
78-
default:
68+
default: {
69+
if (CompatibilityUtils.isPost1_12()) {
70+
switch (instrument) {
71+
case 5:
72+
return org.bukkit.Instrument.GUITAR;
73+
case 6:
74+
return org.bukkit.Instrument.FLUTE;
75+
case 7:
76+
return org.bukkit.Instrument.BELL;
77+
case 8:
78+
return org.bukkit.Instrument.CHIME;
79+
case 9:
80+
return org.bukkit.Instrument.XYLOPHONE;
81+
}
82+
}
7983
return org.bukkit.Instrument.PIANO;
84+
}
8085
}
8186
}
8287

8388
/**
8489
* If true, the byte given represents a custom instrument
8590
* @param instrument
86-
* @return
91+
* @return whether the byte represents a custom instrument
8792
*/
8893
public static boolean isCustomInstrument(byte instrument) {
8994
if (CompatibilityUtils.isPost1_12()) {
@@ -101,7 +106,7 @@ public static boolean isCustomInstrument(byte instrument) {
101106
/**
102107
* Gets the first index in which a custom instrument
103108
* can be added to the existing list of instruments
104-
* @return instrument as a byte
109+
* @return index where an instrument can be added
105110
*/
106111
public static byte getCustomInstrumentFirstIndex() {
107112
if (CompatibilityUtils.isPost1_12()) {

src/main/java/com/xxmicloxx/NoteBlockAPI/Layer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class Layer {
1818
* @return HashMap of notes with the tick they are played at
1919
* @Deprecated Method name is vague
2020
*/
21+
@Deprecated
2122
public HashMap<Integer, Note> getHashMap() {
2223
return getNotesAtTicks();
2324
}
@@ -26,6 +27,7 @@ public HashMap<Integer, Note> getHashMap() {
2627
* Sets the notes in the Layer with the tick they are created as a hash map
2728
* @Deprecated Method name is vague
2829
*/
30+
@Deprecated
2931
public void setHashMap(HashMap<Integer, Note> hashMap) {
3032
setNotesAtTicks(hashMap);
3133
}
@@ -40,7 +42,6 @@ public HashMap<Integer, Note> getNotesAtTicks() {
4042

4143
/**
4244
* Sets the notes in the Layer with the tick they are created as a hash map
43-
* @Deprecated Method name is vague
4445
*/
4546
public void setNotesAtTicks(HashMap<Integer, Note> notesAtTicks) {
4647
this.notesAtTicks = notesAtTicks;

src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,37 @@ private static Song parse(InputStream inputStream, File songFile) {
9999
}
100100
}
101101
for (int i = 0; i < songHeight; i++) {
102-
Layer l = layerHashMap.get(i);
102+
Layer layer = layerHashMap.get(i);
103103

104104
String name = readString(dataInputStream);
105105
byte volume = dataInputStream.readByte();
106-
if (l != null) {
107-
l.setName(name);
108-
l.setVolume(volume);
106+
if (layer != null) {
107+
layer.setName(name);
108+
layer.setVolume(volume);
109109
}
110110
}
111111
//count of custom instruments
112-
byte custom = dataInputStream.readByte();
113-
CustomInstrument[] customInstruments = new CustomInstrument[custom];
112+
byte customAmnt = dataInputStream.readByte();
113+
CustomInstrument[] customInstrumentsArray = new CustomInstrument[customAmnt];
114114

115-
for (int index = 0; index < custom; index++) {
116-
customInstruments[index] = new CustomInstrument((byte) index,
115+
for (int index = 0; index < customAmnt; index++) {
116+
customInstrumentsArray[index] = new CustomInstrument((byte) index,
117117
readString(dataInputStream), readString(dataInputStream));
118118
}
119119

120-
if (InstrumentUtils.isCustomInstrument((byte) (biggestInstrumentIndex - custom))){
121-
ArrayList<CustomInstrument> ci = CompatibilityUtils.get1_12Instruments();
122-
ci.addAll(Arrays.asList(customInstruments));
123-
customInstruments = ci.toArray(customInstruments);
120+
if (InstrumentUtils.isCustomInstrument((byte) (biggestInstrumentIndex - customAmnt))) {
121+
ArrayList<CustomInstrument> customInstruments = CompatibilityUtils.get1_12Instruments();
122+
customInstruments.addAll(Arrays.asList(customInstrumentsArray));
123+
customInstrumentsArray = customInstruments.toArray(customInstrumentsArray);
124124
}
125125

126126
return new Song(speed, layerHashMap, songHeight, length, title,
127-
author, description, songFile, customInstruments);
127+
author, description, songFile, customInstrumentsArray);
128128
} catch (FileNotFoundException e) {
129129
e.printStackTrace();
130-
} catch (EOFException e){
130+
} catch (EOFException e) {
131131
String file = "";
132-
if (songFile != null){
132+
if (songFile != null) {
133133
file = songFile.getName();
134134
}
135135
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Song is corrupted: " + file);
@@ -140,7 +140,7 @@ private static Song parse(InputStream inputStream, File songFile) {
140140
}
141141

142142
/**
143-
* Sets a note at a tick in a given
143+
* Sets a note at a tick in a song
144144
* @param layerIndex
145145
* @param ticks
146146
* @param instrument

0 commit comments

Comments
 (0)