Load songs from update folder
This commit is contained in:
parent
ed3bea8e85
commit
2afbe23a7c
@ -1,6 +1,10 @@
|
||||
package mineplex.hub;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
@ -171,8 +175,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
// Christmas Songs
|
||||
private Random _random = new Random();
|
||||
private int _lastSong = 0;
|
||||
private final String[] _songNames = {"JingleBells.nbs", "TheFirstNoel.nbs", "Hark.nbs", "DeckTheHalls.nbs", "Joy.nbs", "MerryChristmas.nbs"};
|
||||
private final NoteSong[] _songs;
|
||||
// private final String[] _songNames = {"JingleBells.nbs", "TheFirstNoel.nbs", "Hark.nbs", "DeckTheHalls.nbs", "Joy.nbs", "MerryChristmas.nbs"};
|
||||
private final ArrayList<NoteSong> _songs;
|
||||
|
||||
public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, GiveawayManager giveawayManager)
|
||||
{
|
||||
@ -241,15 +245,28 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
// NotificationManager notificationManager = new NotificationManager(plugin, clientManager, donationManager);
|
||||
// new MailManager(_plugin, notificationManager);
|
||||
|
||||
_songs = new NoteSong[_songNames.length];
|
||||
_songs = new ArrayList<NoteSong>();
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < _songNames.length; i++)
|
||||
|
||||
File songsFolder = new File("../../update/songs/");
|
||||
if (songsFolder.exists())
|
||||
{
|
||||
String name = "songs/" + _songNames[i];
|
||||
NoteSong song = NBSReader.loadSong(name);
|
||||
_songs[i] = song;
|
||||
System.out.println("Loaded Song: " + name);
|
||||
File[] files = songsFolder.listFiles();
|
||||
|
||||
for (File file : files)
|
||||
{
|
||||
if (file.getName().endsWith(".nbs"))
|
||||
{
|
||||
System.out.println("Loading Song " + file.getPath());
|
||||
NoteSong song = NBSReader.loadSong(new DataInputStream(new FileInputStream(file)));
|
||||
if (song != null)
|
||||
{
|
||||
_songs.add(song);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
@ -266,8 +283,11 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
|
||||
private void playNextSong()
|
||||
{
|
||||
int index = (_lastSong + _random.nextInt(_songs.length - 1)) % _songs.length;
|
||||
NoteSong song = _songs[index];
|
||||
if (_songs.isEmpty())
|
||||
return;
|
||||
|
||||
int index = (_lastSong + _random.nextInt(_songs.size() - 1)) % _songs.size();
|
||||
NoteSong song = _songs.get(index);
|
||||
if (song != null)
|
||||
{
|
||||
new NotePlayer(_plugin, song, new INoteVerifier()
|
||||
|
Loading…
Reference in New Issue
Block a user