Skip to content

Commit 9fc7db0

Browse files
committed
Set default SoundCategory to MASTER and allow to change the default on a per-instance basis.
1 parent 4b1e13e commit 9fc7db0

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public NoteBlockSongPlayer(Song song) {
1414
super(song);
1515
}
1616

17+
public NoteBlockSongPlayer(Song song, SoundCategory soundCategory) {
18+
super(song, soundCategory);
19+
}
20+
1721
public Block getNoteBlock() {
1822
return noteBlock;
1923
}
@@ -45,7 +49,7 @@ public void playTick(Player p, int tick) {
4549
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
4650
p.playSound(noteBlock.getLocation(),
4751
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
48-
SoundCategory.MUSIC,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
52+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4953
NotePitch.getPitch(note.getKey() - 33));
5054
}else {
5155
p.playSound(noteBlock.getLocation(),
@@ -57,7 +61,7 @@ public void playTick(Player p, int tick) {
5761
}else {
5862
p.playSound(noteBlock.getLocation(),
5963
Instrument.getInstrument(note.getInstrument()),
60-
SoundCategory.MUSIC,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
64+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
6165
NotePitch.getPitch(note.getKey() - 33));
6266
}
6367

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public PositionSongPlayer(Song song) {
1414
super(song);
1515
}
1616

17+
public PositionSongPlayer(Song song, SoundCategory soundCategory) {
18+
super(song, soundCategory);
19+
}
20+
1721
public Location getTargetLocation() {
1822
return targetLocation;
1923
}
@@ -40,19 +44,19 @@ public void playTick(Player p, int tick) {
4044
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
4145
p.playSound(targetLocation,
4246
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
43-
SoundCategory.MUSIC,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
47+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4448
NotePitch.getPitch(note.getKey() - 33));
4549
}else {
4650
p.playSound(targetLocation,
4751
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSoundfile(),
48-
SoundCategory.MUSIC,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
52+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4953
NotePitch.getPitch(note.getKey() - 33));
5054
}
5155

5256
}else {
5357
p.playSound(targetLocation,
5458
Instrument.getInstrument(note.getInstrument()),
55-
SoundCategory.MUSIC,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
59+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
5660
NotePitch.getPitch(note.getKey() - 33));
5761
}
5862

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public RadioSongPlayer(Song song) {
99
super(song);
1010
}
1111

12+
public RadioSongPlayer(Song song, SoundCategory soundCategory) {
13+
super(song, soundCategory);
14+
}
15+
1216
@Override
1317
public void playTick(Player p, int tick) {
1418
byte playerVolume = NoteBlockPlayerMain.getPlayerVolume(p);
@@ -22,19 +26,19 @@ public void playTick(Player p, int tick) {
2226
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
2327
p.playSound(p.getEyeLocation(),
2428
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
25-
SoundCategory.MUSIC,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
29+
this.soundCategory,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
2630
NotePitch.getPitch(note.getKey() - 33));
2731
}else {
2832
p.playSound(p.getEyeLocation(),
2933
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSoundfile(),
30-
SoundCategory.MUSIC,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
34+
this.soundCategory,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
3135
NotePitch.getPitch(note.getKey() - 33));
3236
}
3337

3438
}else {
3539
p.playSound(p.getEyeLocation(),
3640
Instrument.getInstrument(note.getInstrument()),
37-
SoundCategory.MUSIC,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
41+
this.soundCategory,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
3842
NotePitch.getPitch(note.getKey() - 33));
3943
}
4044
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.concurrent.locks.ReentrantLock;
1010

1111
import org.bukkit.Bukkit;
12+
import org.bukkit.SoundCategory;
1213
import org.bukkit.entity.Player;
1314

1415
public abstract class SongPlayer {
@@ -28,9 +29,15 @@ public abstract class SongPlayer {
2829
protected FadeType fadeType = FadeType.FADE_LINEAR;
2930
private final Lock lock = new ReentrantLock();
3031
protected NoteBlockPlayerMain plugin;
32+
protected SoundCategory soundCategory;
3133

3234
public SongPlayer(Song song) {
35+
this(song, SoundCategory.MASTER);
36+
}
37+
38+
public SongPlayer(Song song, SoundCategory soundCategory) {
3339
this.song = song;
40+
this.soundCategory = soundCategory;
3441
plugin = NoteBlockPlayerMain.plugin;
3542
start();
3643
}
@@ -258,4 +265,12 @@ public void setVolume(byte volume) {
258265
public Song getSong() {
259266
return song;
260267
}
268+
269+
public SoundCategory getCategory() {
270+
return soundCategory;
271+
}
272+
273+
public void setCategory(SoundCategory soundCategory) {
274+
this.soundCategory = soundCategory;
275+
}
261276
}

0 commit comments

Comments
 (0)