|
| 1 | +package com.xxmicloxx.NoteBlockAPI; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Collections; |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.Map; |
| 7 | +import java.util.UUID; |
| 8 | + |
| 9 | +import org.bstats.Metrics; |
| 10 | +import org.bukkit.Bukkit; |
| 11 | +import org.bukkit.entity.Player; |
| 12 | +import org.bukkit.plugin.java.JavaPlugin; |
| 13 | + |
| 14 | +import com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer; |
| 15 | + |
| 16 | +public class NoteBlockAPI extends JavaPlugin { |
| 17 | + |
| 18 | + public static NoteBlockAPI plugin; |
| 19 | + |
| 20 | + private Map<UUID, ArrayList<SongPlayer>> playingSongs = |
| 21 | + Collections.synchronizedMap(new HashMap<UUID, ArrayList<SongPlayer>>()); |
| 22 | + private Map<UUID, Byte> playerVolume = Collections.synchronizedMap(new HashMap<UUID, Byte>()); |
| 23 | + |
| 24 | + private boolean disabling = false; |
| 25 | + |
| 26 | + /** |
| 27 | + * Returns true if a Player is currently receiving a song |
| 28 | + * @param player |
| 29 | + * @return is receiving a song |
| 30 | + */ |
| 31 | + public static boolean isReceivingSong(Player player) { |
| 32 | + return ((plugin.playingSongs.get(player.getUniqueId()) != null) |
| 33 | + && (!plugin.playingSongs.get(player.getUniqueId()).isEmpty())); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Stops the song for a Player |
| 38 | + * @param player |
| 39 | + */ |
| 40 | + public static void stopPlaying(Player player) { |
| 41 | + if (plugin.playingSongs.get(player.getUniqueId()) == null) { |
| 42 | + return; |
| 43 | + } |
| 44 | + for (SongPlayer songPlayer : plugin.playingSongs.get(player.getUniqueId())) { |
| 45 | + songPlayer.removePlayer(player); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Sets the volume for a given Player |
| 51 | + * @param player |
| 52 | + * @param volume |
| 53 | + */ |
| 54 | + public static void setPlayerVolume(Player player, byte volume) { |
| 55 | + plugin.playerVolume.put(player.getUniqueId(), volume); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Gets the volume for a given Player |
| 60 | + * @param player |
| 61 | + * @return volume (byte) |
| 62 | + */ |
| 63 | + public static byte getPlayerVolume(Player player) { |
| 64 | + Byte byteObj = plugin.playerVolume.get(player.getUniqueId()); |
| 65 | + if (byteObj == null) { |
| 66 | + byteObj = 100; |
| 67 | + plugin.playerVolume.put(player.getUniqueId(), byteObj); |
| 68 | + } |
| 69 | + return byteObj; |
| 70 | + } |
| 71 | + |
| 72 | + public static ArrayList<SongPlayer> getSongPlayersByPlayer(Player player){ |
| 73 | + return plugin.playingSongs.get(player.getUniqueId()); |
| 74 | + } |
| 75 | + |
| 76 | + public static void setSongPlayersByPlayer(Player player, ArrayList<SongPlayer> songs){ |
| 77 | + plugin.playingSongs.put(player.getUniqueId(), songs); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public void onEnable() { |
| 82 | + plugin = this; |
| 83 | + new Metrics(this); |
| 84 | + new NoteBlockPlayerMain().onEnable(); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void onDisable() { |
| 89 | + disabling = true; |
| 90 | + Bukkit.getScheduler().cancelTasks(this); |
| 91 | + NoteBlockPlayerMain.plugin.onDisable(); |
| 92 | + } |
| 93 | + |
| 94 | + public void doSync(Runnable runnable) { |
| 95 | + getServer().getScheduler().runTask(this, runnable); |
| 96 | + } |
| 97 | + |
| 98 | + public void doAsync(Runnable runnable) { |
| 99 | + getServer().getScheduler().runTaskAsynchronously(this, runnable); |
| 100 | + } |
| 101 | + |
| 102 | + public boolean isDisabling() { |
| 103 | + return disabling; |
| 104 | + } |
| 105 | + |
| 106 | +} |
0 commit comments