diff --git a/src/main/java/Color_yr/ALLmusic/PlayMusic.java b/src/main/java/Color_yr/ALLmusic/PlayMusic.java index ecdb30cc..d3d87f72 100644 --- a/src/main/java/Color_yr/ALLmusic/PlayMusic.java +++ b/src/main/java/Color_yr/ALLmusic/PlayMusic.java @@ -22,13 +22,13 @@ public class PlayMusic { private static Integer warningTimes; public static int Mode = 0; public static int All_music = 0; - public static String Music_name; - + public static Map Vote = new HashMap(); + public static int Vote_time = 0; public static void PlayMusic_Start() { playgo.start(); } - public static int Music_Time(String music){ + public static int Music_Time(String music) { try { URL urlfile = new URL(music); URLConnection con = urlfile.openConnection(); @@ -38,8 +38,7 @@ public class PlayMusic { Header h = bt.readFrame(); int time = (int) h.total_ms(b); return time / 1000; - }catch (Exception e) - { + } catch (Exception e) { e.getMessage(); } return 0; @@ -76,19 +75,21 @@ public class PlayMusic { class playgo extends Thread { public static void music_list() { - if (PlayMusic.playlist.size() != 0) { + if (PlayMusic.playlist.size() == 1) { + String a = PlayMusic.playlist.get("1"); + PlayMusic.playlist.put("0", a); + PlayMusic.playlist.remove("1"); + } else if (PlayMusic.playlist.size() > 1) { int i = 0; for (; PlayMusic.playlist.size() - 1 > i; i++) { - String a = PlayMusic.playlist.get("" + (i + 1)); - ALLmusic_BC.log.info("处理队列" + "[" + (i + 1) + "]" + a); - PlayMusic.playlist.put("" + i, a); - ALLmusic_BC.log.info("到队列" + "[" + i + "]" + a); + String a = PlayMusic.playlist.get(String.valueOf(i + 1)); + PlayMusic.playlist.put(String.valueOf(i), a); } - PlayMusic.playlist.remove("" + (PlayMusic.playlist.size())); - ALLmusic_BC.log.info("删除队列" + (PlayMusic.playlist.size())); + PlayMusic.playlist.remove(String.valueOf(PlayMusic.All_music - 1)); } PlayMusic.All_music = PlayMusic.playlist.size(); } + public synchronized void run() { while (true) { if (PlayMusic.playlist.size() == 0) { @@ -101,27 +102,25 @@ class playgo extends Thread { String playsong = PlayMusic.playlist.get("0"); String song = PlayMusic.realURL("http://music.163.com/song/media/outer/url?id=" + playsong); int Music_time = PlayMusic.Music_Time(song); - ALLmusic_BC.log.info("音乐时长"+Music_time); ChannelListener.sendToBukkit("play", playsong); - ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2"+"正在播放歌曲"+playsong)); + ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2" + "正在播放歌曲" + playsong)); PlayMusic.playlist.remove("0"); - ALLmusic_BC.log.info("删除队列" + "[0]"); music_list(); try { - while(Music_time>0) - { + while (Music_time > 0) { Thread.sleep(1000); - Music_time -- ; - if(PlayMusic.Mode==1) - { - ChannelListener.sendToBukkit("stopALL", ""); - music_list(); - Music_time=0; - if(PlayMusic.All_music==0) - { - ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2"+"队列中无歌曲")); + Music_time--; + if(PlayMusic.Vote_time>0) { + PlayMusic.Vote_time--; + if (PlayMusic.Vote.size() >= ProxyServer.getInstance().getOnlineCount()) { + ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2" + "已切歌")); + ChannelListener.sendToBukkit("stopALL", ""); + Music_time = 0; + if (PlayMusic.All_music == 0) { + ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2" + "队列中无歌曲")); + } + PlayMusic.Mode = 0; } - PlayMusic.Mode=0; } } } catch (InterruptedException e) { diff --git a/src/main/java/Color_yr/ALLmusic/command.java b/src/main/java/Color_yr/ALLmusic/command.java index 7b14f3aa..31f50faf 100644 --- a/src/main/java/Color_yr/ALLmusic/command.java +++ b/src/main/java/Color_yr/ALLmusic/command.java @@ -1,6 +1,7 @@ package Color_yr.ALLmusic; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.plugin.Command; @@ -19,47 +20,57 @@ public class command extends Command { } public void execute(CommandSender sender, String[] args) { - if(args.length == 0) { + if (args.length == 0) { sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§c错误,请使用/music help 获取帮助")); return; - } - else if (args[0].equalsIgnoreCase("help")) { + } else if (args[0].equalsIgnoreCase("help")) { sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2帮助手册")); sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music play [音乐ID] 来点歌")); sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music stop 停止播放歌曲")); - sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music start 开始播放歌曲")); + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music now 查看歌曲队列")); sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music vote 投票切歌")); return; - } - else if (args[0].equalsIgnoreCase("play")) { - if(args.length < 1){ + } else if (args[0].equalsIgnoreCase("play")) { + if (args.length < 2) { sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§c错误,请输入歌曲ID")); return; - } - else { - if (isInteger(args[1])==true) { - PlayMusic.playlist.put(String.valueOf(PlayMusic.All_music),args[1]); - PlayMusic.All_music ++; - sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已发送" + args[1])); + } else { + if (isInteger(args[1]) == true) { + PlayMusic.playlist.put(String.valueOf(PlayMusic.All_music), args[1]); + PlayMusic.All_music++; + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已添加" + args[1])); } else sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§c错误,请输入歌曲数字ID")); return; } - } - else if(args[0].equalsIgnoreCase("stop")) { + } else if (args[0].equalsIgnoreCase("stop")) { ChannelListener.sendToBukkit("stop", sender.getName()); - sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已停止" + sender.getName()+"的音乐播放")); - }else if(args[0].equalsIgnoreCase("now")) - { - Iterator iterator = PlayMusic.playlist.keySet().iterator(); - while (iterator.hasNext()) - { - String key = iterator.next(); - sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2当前队列"+key+"->"+PlayMusic.playlist.get(key))); + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已停止" + sender.getName() + "的音乐播放")); + } else if (args[0].equalsIgnoreCase("now")) { + if (PlayMusic.playlist.size() == 0) { + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2队列中无歌曲")); + } + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2队列中有歌曲数:"+PlayMusic.playlist.size())); + Iterator iterator = PlayMusic.playlist.keySet().iterator(); + while (iterator.hasNext()) { + String key = iterator.next(); + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2当前队列" + key + "->" + PlayMusic.playlist.get(key))); + } + } else if (args[0].equalsIgnoreCase("vote")) { + if (PlayMusic.playlist.size() == 0) { + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2队列中无歌曲")); + } else if (PlayMusic.Vote_time == 0) { + PlayMusic.Vote_time = 10; + PlayMusic.Vote.put(sender.getName(), "true"); + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已发起切歌投票")); + ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2" + sender.getName()+ + "发起了切歌投票,10秒后结束,输入/music vote 同意切歌")); + } else if (PlayMusic.Vote_time > 0) { + if (PlayMusic.Vote.get(sender.getName()) != "true") { + PlayMusic.Vote.put(sender.getName(), "true"); + sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已同意切歌")); + } } - }else if(args[0].equalsIgnoreCase("next")) - { - PlayMusic.Mode=1; } } }