Skip to content

Commit 63eda75

Browse files
authored
Merge pull request #2 from Selim042/master
Play all music in the music sound category.
2 parents 94a1460 + 9fc7db0 commit 63eda75

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bukkit.Bukkit;
44
import org.bukkit.Material;
5+
import org.bukkit.SoundCategory;
56
import org.bukkit.block.Block;
67
import org.bukkit.entity.Player;
78

@@ -13,6 +14,10 @@ public NoteBlockSongPlayer(Song song) {
1314
super(song);
1415
}
1516

17+
public NoteBlockSongPlayer(Song song, SoundCategory soundCategory) {
18+
super(song, soundCategory);
19+
}
20+
1621
public Block getNoteBlock() {
1722
return noteBlock;
1823
}
@@ -44,7 +49,7 @@ public void playTick(Player p, int tick) {
4449
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
4550
p.playSound(noteBlock.getLocation(),
4651
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
47-
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
52+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4853
NotePitch.getPitch(note.getKey() - 33));
4954
}else {
5055
p.playSound(noteBlock.getLocation(),
@@ -56,7 +61,7 @@ public void playTick(Player p, int tick) {
5661
}else {
5762
p.playSound(noteBlock.getLocation(),
5863
Instrument.getInstrument(note.getInstrument()),
59-
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
64+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
6065
NotePitch.getPitch(note.getKey() - 33));
6166
}
6267

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bukkit.Bukkit;
44
import org.bukkit.Location;
5+
import org.bukkit.SoundCategory;
56
import org.bukkit.entity.Player;
67

78
public class PositionSongPlayer extends SongPlayer {
@@ -13,6 +14,10 @@ public PositionSongPlayer(Song song) {
1314
super(song);
1415
}
1516

17+
public PositionSongPlayer(Song song, SoundCategory soundCategory) {
18+
super(song, soundCategory);
19+
}
20+
1621
public Location getTargetLocation() {
1722
return targetLocation;
1823
}
@@ -39,19 +44,19 @@ public void playTick(Player p, int tick) {
3944
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
4045
p.playSound(targetLocation,
4146
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
42-
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
47+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4348
NotePitch.getPitch(note.getKey() - 33));
4449
}else {
4550
p.playSound(targetLocation,
4651
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSoundfile(),
47-
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
52+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4853
NotePitch.getPitch(note.getKey() - 33));
4954
}
5055

5156
}else {
5257
p.playSound(targetLocation,
5358
Instrument.getInstrument(note.getInstrument()),
54-
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
59+
this.soundCategory,((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
5560
NotePitch.getPitch(note.getKey() - 33));
5661
}
5762

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.xxmicloxx.NoteBlockAPI;
22

3+
import org.bukkit.SoundCategory;
34
import org.bukkit.entity.Player;
45

56
public class RadioSongPlayer extends SongPlayer {
@@ -8,6 +9,10 @@ public RadioSongPlayer(Song song) {
89
super(song);
910
}
1011

12+
public RadioSongPlayer(Song song, SoundCategory soundCategory) {
13+
super(song, soundCategory);
14+
}
15+
1116
@Override
1217
public void playTick(Player p, int tick) {
1318
byte playerVolume = NoteBlockPlayerMain.getPlayerVolume(p);
@@ -21,19 +26,19 @@ public void playTick(Player p, int tick) {
2126
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
2227
p.playSound(p.getEyeLocation(),
2328
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
24-
(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
29+
this.soundCategory,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
2530
NotePitch.getPitch(note.getKey() - 33));
2631
}else {
2732
p.playSound(p.getEyeLocation(),
2833
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSoundfile(),
29-
(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
34+
this.soundCategory,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
3035
NotePitch.getPitch(note.getKey() - 33));
3136
}
3237

3338
}else {
3439
p.playSound(p.getEyeLocation(),
3540
Instrument.getInstrument(note.getInstrument()),
36-
(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
41+
this.soundCategory,(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
3742
NotePitch.getPitch(note.getKey() - 33));
3843
}
3944
}

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)