Skip to content

Commit b366f94

Browse files
committed
v1.1.7
Added support for custom instruments. Fixed 1.12 sounds. Added bStats.
1 parent f896d79 commit b366f94

File tree

10 files changed

+196
-23
lines changed

10 files changed

+196
-23
lines changed

pom.xml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
<groupId>com.xxmicloxx</groupId>
88
<artifactId>NoteBlockAPI</artifactId>
9-
<version>1.1.6</version>
9+
<version>1.1.7</version>
1010
<repositories>
1111
<repository>
1212
<id>spigot-repo</id>
1313
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
1414
</repository>
15+
<repository>
16+
<id>bstats-repo</id>
17+
<url>http://repo.bstats.org/content/repositories/releases/</url>
18+
</repository>
1519
</repositories>
1620
<dependencies>
1721
<dependency>
@@ -20,6 +24,11 @@
2024
<version>1.12-pre2-SNAPSHOT</version>
2125
<scope>provided</scope>
2226
</dependency>
27+
<dependency>
28+
<groupId>org.bstats</groupId>
29+
<artifactId>bstats-bukkit</artifactId>
30+
<version>1.1</version>
31+
</dependency>
2332
</dependencies>
2433
<distributionManagement>
2534
<repository>
@@ -44,6 +53,32 @@
4453
<target>1.7</target>
4554
</configuration>
4655
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-shade-plugin</artifactId>
59+
<version>2.3</version>
60+
<configuration>
61+
<artifactSet>
62+
<includes>
63+
<include>org.bstats:*</include>
64+
</includes>
65+
</artifactSet>
66+
<relocations>
67+
<relocation>
68+
<pattern>org.bstats</pattern>
69+
<shadedPattern>com.xxmicloxx.NoteBlockAPI</shadedPattern>
70+
</relocation>
71+
</relocations>
72+
</configuration>
73+
<executions>
74+
<execution>
75+
<phase>package</phase>
76+
<goals>
77+
<goal>shade</goal>
78+
</goals>
79+
</execution>
80+
</executions>
81+
</plugin>
4782
</plugins>
4883
</build>
4984
</project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.xxmicloxx.NoteBlockAPI;
2+
3+
import org.bukkit.Sound;
4+
5+
public class CustomInstrument {
6+
7+
private byte index;
8+
private String name;
9+
private String soundfile;
10+
private byte pitch;
11+
private byte press;
12+
private Sound sound;
13+
14+
public CustomInstrument(byte index, String name, String soundfile, byte pitch, byte press){
15+
this.index = index;
16+
this.name = name;
17+
this.soundfile = soundfile.replaceAll(".ogg", "");
18+
if (this.soundfile.equalsIgnoreCase("pling")){
19+
switch (NoteBlockPlayerMain.getCompatibility()){
20+
case NoteBlockPlayerMain.NoteBlockCompatibility.pre1_9:
21+
this.sound = Sound.valueOf("NOTE_PLING");
22+
break;
23+
case NoteBlockPlayerMain.NoteBlockCompatibility.pre1_12:
24+
case NoteBlockPlayerMain.NoteBlockCompatibility.post1_12:
25+
this.sound = Sound.valueOf("BLOCK_NOTE_PLING");
26+
break;
27+
}
28+
}
29+
this.pitch = pitch;
30+
this.press = press;
31+
}
32+
33+
public byte getIndex() {
34+
return index;
35+
}
36+
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public String getSoundfile() {
42+
return soundfile;
43+
}
44+
45+
public Sound getSound(){
46+
return sound;
47+
}
48+
}

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public static Sound getInstrument(byte instrument) {
3939
if (NoteBlockPlayerMain.getCompatibility() == NoteBlockCompatibility.post1_12){
4040
switch (instrument) {
4141
case 5:
42-
return Sound.valueOf("BLOCK_NOTE_FLUTE");
42+
return Sound.valueOf("BLOCK_NOTE_GUITAR");
4343
case 6:
44-
return Sound.valueOf("BLOCK_NOTE_BELL");
44+
return Sound.valueOf("BLOCK_NOTE_FLUTE");
4545
case 7:
46-
return Sound.valueOf("BLOCK_NOTE_GUITAR");
46+
return Sound.valueOf("BLOCK_NOTE_BELL");
4747
case 8:
4848
return Sound.valueOf("BLOCK_NOTE_CHIME");
4949
case 9:
@@ -72,4 +72,26 @@ public static org.bukkit.Instrument getBukkitInstrument(byte instrument) {
7272
return org.bukkit.Instrument.PIANO;
7373
}
7474
}
75+
76+
public static boolean isCustomInstrument(byte instrument){
77+
if (NoteBlockPlayerMain.getCompatibility() != NoteBlockCompatibility.post1_12){
78+
if (instrument > 4){
79+
return true;
80+
}
81+
return false;
82+
} else {
83+
if (instrument > 9){
84+
return true;
85+
}
86+
return false;
87+
}
88+
}
89+
90+
public static byte getCustomInstrumentFirstIndex(){
91+
if (NoteBlockPlayerMain.getCompatibility() != NoteBlockCompatibility.post1_12){
92+
return 5;
93+
} else {
94+
return 10;
95+
}
96+
}
7597
}

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

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

3-
import java.io.*;
3+
import java.io.DataInputStream;
4+
import java.io.File;
5+
import java.io.FileInputStream;
6+
import java.io.FileNotFoundException;
7+
import java.io.IOException;
8+
import java.io.InputStream;
49
import java.util.HashMap;
510

611
public class NBSDecoder {
@@ -60,12 +65,22 @@ private static Song parse(InputStream inputStream, File decodeFile) {
6065
}
6166
for (int i = 0; i < songHeight; i++) {
6267
Layer l = layerHashMap.get(i);
68+
69+
String name = readString(dis);
70+
byte volume = dis.readByte();
6371
if (l != null) {
64-
l.setName(readString(dis));
65-
l.setVolume(dis.readByte());
72+
l.setName(name);
73+
l.setVolume(volume);
6674
}
6775
}
68-
return new Song(speed, layerHashMap, songHeight, length, title, author, description, decodeFile);
76+
//count of custom instruments
77+
byte custom = dis.readByte();
78+
CustomInstrument[] customInstruments = new CustomInstrument[custom];
79+
80+
for (int i = 0; i < custom; i++) {
81+
customInstruments[i] = new CustomInstrument((byte)i, readString(dis), readString(dis), dis.readByte(), dis.readByte());
82+
}
83+
return new Song(speed, layerHashMap, songHeight, length, title, author, description, decodeFile, customInstruments);
6984
} catch (FileNotFoundException e) {
7085
e.printStackTrace();
7186
} catch (IOException e) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashMap;
66
import java.util.Map;
77

8+
import org.bstats.Metrics;
89
import org.bukkit.Bukkit;
910
import org.bukkit.entity.Player;
1011
import org.bukkit.plugin.java.JavaPlugin;
@@ -47,6 +48,7 @@ public static byte getPlayerVolume(Player p) {
4748
@Override
4849
public void onEnable() {
4950
plugin = this;
51+
new Metrics(this);
5052
}
5153

5254
@Override

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,27 @@ public void playTick(Player p, int tick) {
3939
}
4040
p.playNote(noteBlock.getLocation(), Instrument.getBukkitInstrument(note.getInstrument()),
4141
new org.bukkit.Note(note.getKey() - 33));
42-
p.playSound(noteBlock.getLocation(),
42+
43+
if (Instrument.isCustomInstrument(note.getInstrument())){
44+
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
45+
p.playSound(noteBlock.getLocation(),
46+
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
47+
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
48+
NotePitch.getPitch(note.getKey() - 33));
49+
}else {
50+
p.playSound(noteBlock.getLocation(),
51+
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSoundfile(),
52+
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
53+
NotePitch.getPitch(note.getKey() - 33));
54+
}
55+
56+
}else {
57+
p.playSound(noteBlock.getLocation(),
4358
Instrument.getInstrument(note.getInstrument()),
4459
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4560
NotePitch.getPitch(note.getKey() - 33));
61+
}
62+
4663
if (isPlayerInRange(p)){
4764
if (!this.playerList.get(p.getName())){
4865
playerList.put(p.getName(), true);

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,27 @@ public void playTick(Player p, int tick) {
3434
if (note == null) {
3535
continue;
3636
}
37-
p.playSound(targetLocation,
37+
38+
if (Instrument.isCustomInstrument(note.getInstrument())){
39+
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
40+
p.playSound(targetLocation,
41+
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
42+
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
43+
NotePitch.getPitch(note.getKey() - 33));
44+
}else {
45+
p.playSound(targetLocation,
46+
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSoundfile(),
47+
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
48+
NotePitch.getPitch(note.getKey() - 33));
49+
}
50+
51+
}else {
52+
p.playSound(targetLocation,
3853
Instrument.getInstrument(note.getInstrument()),
3954
((l.getVolume() * (int) volume * (int) playerVolume) / 1000000f) * ((1f/16f) * distance),
4055
NotePitch.getPitch(note.getKey() - 33));
56+
}
57+
4158
if (isPlayerInRange(p)){
4259
if (!this.playerList.get(p.getName())){
4360
playerList.put(p.getName(), true);

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@ public void playTick(Player p, int tick) {
1717
if (note == null) {
1818
continue;
1919
}
20-
p.playSound(p.getEyeLocation(),
20+
if (Instrument.isCustomInstrument(note.getInstrument())){
21+
if (song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound() != null){
22+
p.playSound(p.getEyeLocation(),
23+
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSound(),
24+
(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
25+
NotePitch.getPitch(note.getKey() - 33));
26+
}else {
27+
p.playSound(p.getEyeLocation(),
28+
song.getCustomInstruments()[note.getInstrument() - Instrument.getCustomInstrumentFirstIndex()].getSoundfile(),
29+
(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
30+
NotePitch.getPitch(note.getKey() - 33));
31+
}
32+
33+
}else {
34+
p.playSound(p.getEyeLocation(),
2135
Instrument.getInstrument(note.getInstrument()),
2236
(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
2337
NotePitch.getPitch(note.getKey() - 33));
38+
}
2439
}
2540
}
2641
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@ public class Song {
1414
private String description;
1515
private float speed;
1616
private float delay;
17+
private CustomInstrument[] customInstrument;
1718

1819
public Song(Song other) {
19-
this.speed = other.getSpeed();
20-
delay = 20 / speed;
21-
this.layerHashMap = other.getLayerHashMap();
22-
this.songHeight = other.getSongHeight();
23-
this.length = other.getLength();
24-
this.title = other.getTitle();
25-
this.author = other.getAuthor();
26-
this.description = other.getDescription();
27-
this.path = other.getPath();
20+
this(other.getSpeed(), other.getLayerHashMap(), other.getSongHeight(), other.getLength(), other.getTitle(), other.getAuthor(), other.getDescription(), other.getPath());
2821
}
29-
22+
3023
public Song(float speed, HashMap<Integer, Layer> layerHashMap,
3124
short songHeight, final short length, String title, String author,
3225
String description, File path) {
33-
this.speed = speed;
26+
this(speed, layerHashMap, songHeight, length, title, author, description, path, new CustomInstrument[0]);
27+
}
28+
29+
public Song(float speed, HashMap<Integer, Layer> layerHashMap, short songHeight, final short length, String title, String author, String description, File path, CustomInstrument[] customInstrument) {
30+
this.speed = speed;
3431
delay = 20 / speed;
3532
this.layerHashMap = layerHashMap;
3633
this.songHeight = songHeight;
@@ -39,6 +36,7 @@ public Song(float speed, HashMap<Integer, Layer> layerHashMap,
3936
this.author = author;
4037
this.description = description;
4138
this.path = path;
39+
this.customInstrument = customInstrument;
4240
}
4341

4442
public HashMap<Integer, Layer> getLayerHashMap() {
@@ -76,4 +74,8 @@ public float getSpeed() {
7674
public float getDelay() {
7775
return delay;
7876
}
77+
78+
public CustomInstrument[] getCustomInstruments(){
79+
return customInstrument;
80+
}
7981
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: NoteBlockAPI
22

33
main: com.xxmicloxx.NoteBlockAPI.NoteBlockPlayerMain
4-
version: 1.1.6
4+
version: 1.1.7
55

66
description: a developer interface to play nbs-files ingame
77
authors: [xxmicloxx, michidk, koca2000, Luck]

0 commit comments

Comments
 (0)