Illuminatiiiiii
4/21/2019 - 5:41 PM

helll

package me.illuminatiproductions.spigotplugin;

import com.xxmicloxx.NoteBlockAPI.model.Song;
import com.xxmicloxx.NoteBlockAPI.utils.NBSDecoder;
import me.illuminatiproductions.spigotplugin.commands.RadioCommand;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.ArrayList;

public final class SpigotPlugin extends JavaPlugin {

    //List of all the songs
    public static ArrayList<Song> songs = new ArrayList<>();

    @Override
    public void onEnable() {
        // Plugin startup logic
        getCommand("radio").setExecutor(new RadioCommand());

        getServer().getPluginManager().registerEvents(new MenuHandler(), this);
    }

    public static void loadSongs(){ //Call this whenever u want to refresh the list of songs from the folder
        File music = new File(Bukkit.getServer().getPluginManager().getPlugin("SpigotPlugin").getDataFolder() + "/music/");
        File[] songsList = music.listFiles();
        int numOfSongs = songsList.length;
        System.out.println("Number of songs: " + numOfSongs);

        for (int i = 0;i < numOfSongs;i++){
            //Parse each song from the music folder and store each music file in the arraylist
            songs.add(NBSDecoder.parse(songsList[i]));
        }
    }



}
package me.illuminatiproductions.spigotplugin;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;

import static me.illuminatiproductions.spigotplugin.GUI.openTrackList;

public class MenuHandler implements Listener {

    @EventHandler
    public void onMenuClick(InventoryClickEvent e){
        Player player = (Player) e.getWhoClicked();

        //Menu List
        final String MAIN_MENU = "Radio";

        if (e.getClickedInventory().getTitle().equalsIgnoreCase(MAIN_MENU)){
            switch (e.getCurrentItem().getType()){
                case MUSIC_DISC_MELLOHI:
                    player.sendMessage("Opening Tracklist");
                    openTrackList(player);
                    break;
            }
        }
    }

}
package me.illuminatiproductions.spigotplugin;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class GUI {

    public static void openRadio(Player player){
        //GUI for the radio
        Inventory radioMenu = Bukkit.createInventory(player, 9, "Radio");
        ItemStack tracklist = new ItemStack(Material.MUSIC_DISC_MELLOHI);
        ItemStack random = new ItemStack(Material.COMPASS);

        radioMenu.addItem(tracklist);
        player.openInventory(radioMenu);
    }

    public static void openTrackList(Player player){
        Inventory trackList = Bukkit.createInventory(player, 45, "Tracklist");

        player.sendMessage("Opening Tracklist2");

        ItemStack[] songDisks = new ItemStack[SpigotPlugin.songs.size()];
        for (int i = 0;i < 45; i++){
            ItemStack disk = new ItemStack(Material.MUSIC_DISC_CHIRP, 1);
            ItemMeta disk_meta = disk.getItemMeta();
            disk_meta.setDisplayName(SpigotPlugin.songs.get(i).getTitle());
            disk.setItemMeta(disk_meta);
            songDisks[i] = disk;
        }

        player.sendMessage("Opening Tracklist3");

        trackList.setStorageContents(songDisks);
        player.openInventory(trackList);
    }

}
package me.illuminatiproductions.spigotplugin.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;


import static me.illuminatiproductions.spigotplugin.GUI.openRadio;

public class RadioCommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        if (sender instanceof Player){
            Player player = (Player) sender;

            openRadio(player);
        }


        return true;
    }
}