NoteBlockAPI-Sponge
Original Bukkit project: https://dev.bukkit.org/projects/noteblockapi
This is a Sponge port of xxmicloxx and michidk’s Noteblock API. This plugin allows developers to play .nbs files created in NoteblockStudio. (https://www.stuffbydavid.com/mcnbs)
Installing
Just add the plugin to the server’s mods folder.
Developing
Step 1. Libraries
To interface with NoteBlockAPI add the plugin to your projects libraries. The prefered method for this is using the Jitpack maven repository.
Maven example:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
...
<dependency>
<groupId>com.github.Sansko1337</groupId>
<artifactId>NoteBlockAPI-Sponge</artifactId>
<version>1.9.0-Sponge</version>
</dependency>
Gradle Example:
repositories {
maven { url 'https://jitpack.io' }
}
...
dependencies {
compile 'com.github.Sansko1337:NoteBlockAPI-Sponge:1.9.0-Sponge'
}
Step 2. Getting the Song
Load the song file using either of the following methods:
Song song1 = NBSDecoder.parse(new File("NeverGonnaGiveYouUp.nbs"));
Song song2 = NBSDecoder.parse(Files.newInputStream(Paths.get("Friday.nbs"));
Step 3. Playing the song
Create the SongPlayer. You can choose either of the SongPlayer implementations and add the User to it.
SongPlayer songPlayer = new RadioSongPlayer(song1, SoundCategories.RECORD);
songPlayer.addPlayer(player);
songPlayer.setAutoDestroy(true); //Destoy the songplayer if no one is listening to it.
Step 4. Start the party!
Start playing the song and let your players enjoy the music!
songPlayer.setPlaying(true);