Skip to content

Commit 7c22d8f

Browse files
committed
Fixed NoteBlockSongPlayer in 1.12 and lower
1 parent 9c29827 commit 7c22d8f

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.xxmicloxx</groupId>
77
<artifactId>NoteBlockAPI</artifactId>
8-
<version>1.6.1.1-SNAPSHOT</version>
8+
<version>1.6.2-SNAPSHOT</version>
99
<name>NoteBlockAPI</name>
1010

1111
<properties>

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.xxmicloxx.NoteBlockAPI;
22

3+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
34
import org.bukkit.Bukkit;
4-
import org.bukkit.Material;
55
import org.bukkit.block.Block;
66
import org.bukkit.entity.Player;
77

8-
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
9-
108
/**
119
* @deprecated {@link com.xxmicloxx.NoteBlockAPI.songplayer.NoteBlockSongPlayer}
1210
*/
@@ -62,7 +60,7 @@ public void setNoteBlock(Block noteBlock) {
6260

6361
@Override
6462
public void playTick(Player player, int tick) {
65-
if (noteBlock.getType() != Material.NOTE_BLOCK) {
63+
if (noteBlock.getType() != com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils.getNoteBlockMaterial()) {
6664
return;
6765
}
6866
if (!player.getWorld().getName().equals(noteBlock.getWorld().getName())) {

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
package com.xxmicloxx.NoteBlockAPI.songplayer;
22

3-
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
4-
import org.bukkit.Bukkit;
5-
import org.bukkit.Location;
6-
import org.bukkit.Material;
7-
import org.bukkit.block.Block;
8-
import org.bukkit.entity.Player;
9-
103
import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI;
114
import com.xxmicloxx.NoteBlockAPI.SongPlayer;
125
import com.xxmicloxx.NoteBlockAPI.event.PlayerRangeStateChangeEvent;
13-
import com.xxmicloxx.NoteBlockAPI.model.Layer;
14-
import com.xxmicloxx.NoteBlockAPI.model.Note;
15-
import com.xxmicloxx.NoteBlockAPI.model.Playlist;
16-
import com.xxmicloxx.NoteBlockAPI.model.Song;
17-
import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
6+
import com.xxmicloxx.NoteBlockAPI.model.*;
7+
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
188
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
9+
import org.bukkit.Bukkit;
10+
import org.bukkit.Location;
11+
import org.bukkit.block.Block;
12+
import org.bukkit.entity.Player;
1913

2014
/**
2115
* SongPlayer created at a specified NoteBlock
@@ -78,7 +72,7 @@ public void setNoteBlock(Block noteBlock) {
7872

7973
@Override
8074
public void playTick(Player player, int tick) {
81-
if (noteBlock.getType() != Material.NOTE_BLOCK) {
75+
if (noteBlock.getType() != CompatibilityUtils.getNoteBlockMaterial()) {
8276
return;
8377
}
8478
if (!player.getWorld().getName().equals(noteBlock.getWorld().getName())) {
@@ -94,12 +88,16 @@ public void playTick(Player player, int tick) {
9488
if (note == null) {
9589
continue;
9690
}
91+
int key = note.getKey() - 33;
92+
93+
while (key < 0) key += 12;
94+
while (key > 24) key -= 12;
95+
9796
player.playNote(loc, InstrumentUtils.getBukkitInstrument(note.getInstrument()),
98-
new org.bukkit.Note(note.getKey() - 33));
97+
new org.bukkit.Note(key));
9998

10099
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
101100
* ((1F / 16F) * getDistance());
102-
float pitch = NoteUtils.getPitch(note);
103101

104102
channelMode.play(player, loc, song, layer, note, soundCategory, volume, !enable10Octave);
105103

src/main/java/com/xxmicloxx/NoteBlockAPI/utils/CompatibilityUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.bukkit.Bukkit;
99
import org.bukkit.Location;
10+
import org.bukkit.Material;
1011
import org.bukkit.Sound;
1112
import org.bukkit.entity.Player;
1213

@@ -290,4 +291,8 @@ public static float getServerVersion(){
290291
return serverVersion;
291292
}
292293

294+
public static Material getNoteBlockMaterial(){
295+
return Material.valueOf("NOTE_BLOCK");
296+
}
297+
293298
}

0 commit comments

Comments
 (0)