diff --git a/build.gradle b/build.gradle index a1c0a6a0..7804279c 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ repositories { } dependencies { - compile 'net.md-5:bungeecord-api:1.13-SNAPSHOT' + compile 'net.md-5:bungeecord-api:1.14-SNAPSHOT' } publishing { diff --git a/src/main/java/Color_yr/ALLmusic/ALLmusic_BC.java b/src/main/java/Color_yr/ALLmusic/ALLmusic_BC.java index a01f8c93..cc088064 100644 --- a/src/main/java/Color_yr/ALLmusic/ALLmusic_BC.java +++ b/src/main/java/Color_yr/ALLmusic/ALLmusic_BC.java @@ -10,6 +10,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.util.Collection; +import java.util.Map; import java.util.logging.Logger; import static Color_yr.ALLmusic.PlayMusic.PlayMusic_Start; @@ -23,22 +25,31 @@ public class ALLmusic_BC extends Plugin { public static String Music_Api1 = null; public static Configuration config; - private static File FileName; + public static File FileName; + public static Configuration Banconfig; public static File BanFileName; public static Logger log = ProxyServer.getInstance().getLogger(); - public static void loadconfig() { + public void loadconfig() { ProxyServer.getInstance().getLogger().info("§d[ALLmusic]§e当前插件版本为:" + Version + ",你的配置文件版本为:" + config.getString("Version")); Maxlist = config.getInt("Maxlist", 10); min_vote = config.getInt("min_vote", 3); Music_Api1 = config.getString("Music_Api1", "http://music.163.com/song/media/outer/url?id="); + + Configuration a = config.getSection("nomusic"); + Collection b = a.getKeys(); + for (String c : b) { + boolean d = a.getBoolean(c, false); + PlayMusic.stop.put(c, d); + log.info("玩家:" + c + "的点歌状态:" + !d); + } } - public static void reloadConfig() { + private void reloadConfig() { try { config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(FileName); Banconfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(BanFileName); @@ -48,10 +59,6 @@ public class ALLmusic_BC extends Plugin { } } - public static Configuration getConfig() { - return config; - } - public void setConfig() { FileName = new File(getDataFolder(), "config.yml"); BanFileName = new File(getDataFolder(), "banlist.yml"); @@ -77,13 +84,13 @@ public class ALLmusic_BC extends Plugin { } catch (IOException e) { log.warning("§d[ALLmusic]§c日志文件错误:" + e); } + reloadConfig(); } @Override public void onEnable() { log.info("§d[ALLmusic]§e正在启动,感谢使用,本插件交流群:571239090"); setConfig(); - reloadConfig(); PlayMusic_Start(); ProxyServer.getInstance().getPluginManager().registerCommand(this, new command()); log.info("§d[ALLmusic]§e已启动-" + Version); diff --git a/src/main/java/Color_yr/ALLmusic/PlayMusic.java b/src/main/java/Color_yr/ALLmusic/PlayMusic.java index e78a33cc..304401d5 100644 --- a/src/main/java/Color_yr/ALLmusic/PlayMusic.java +++ b/src/main/java/Color_yr/ALLmusic/PlayMusic.java @@ -4,9 +4,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.security.AlgorithmConstraints; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; +import java.util.*; import java.io.BufferedInputStream; import java.io.IOException; @@ -19,18 +17,18 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.Map; - public class PlayMusic { - public static Map playlist = new HashMap(); - public static Map Vote = new HashMap(); - public static Map stop = new HashMap(); + + public static Map playlist = new HashMap(); + public static List Vote = new ArrayList(); + public static Map stop = new HashMap(); public static int Vote_time = 0; public static int All_music = 0; public static int Music_time = 0; + public static String now_music; - static Thread playgo = new playgo(); + private static Thread playgo = new playgo(); public static void PlayMusic_Start() { playgo.start(); @@ -42,22 +40,22 @@ public class PlayMusic { while (iterator.hasNext()) { ProxiedPlayer players = iterator.next(); if (stop.size() != 0) { - if (stop.get(players.getDisplayName()).equals("true") == false) + if (!stop.get(players.getName()).booleanValue()) players.sendData("AudioBuffer", data.getBytes()); } else players.sendData("AudioBuffer", data.getBytes()); } } - public static void SendToOnePlayer(String data, String Player) - { + + public static void SendToOnePlayer(String data, String Player) { try { ProxiedPlayer players = ProxyServer.getInstance().getPlayer(Player); players.sendData("AudioBuffer", data.getBytes()); - }catch(Exception e) - { + } catch (Exception e) { } } + public static int Music_Time(String music) { try { URL urlfile = new URL(music); @@ -100,38 +98,40 @@ public class PlayMusic { } class playgo extends Thread { + public static void music_list() { + String a; if (PlayMusic.playlist.size() == 1) { - String a = PlayMusic.playlist.get("1"); - PlayMusic.playlist.put("0", a); - PlayMusic.playlist.remove("1"); + 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(String.valueOf(i + 1)); - PlayMusic.playlist.put(String.valueOf(i), a); + for (int i = 0; PlayMusic.playlist.size() - 1 > i; i++) { + a = PlayMusic.playlist.get(i + 1); + PlayMusic.playlist.put(i, a); } - PlayMusic.playlist.remove(String.valueOf(PlayMusic.All_music - 1)); + PlayMusic.playlist.remove(PlayMusic.All_music - 1); } PlayMusic.All_music = PlayMusic.playlist.size(); } + @Override public synchronized void run() { while (true) { if (PlayMusic.playlist.size() == 0) { try { - Thread.sleep(3000); + Thread.sleep(1000); } catch (InterruptedException e) { e.getMessage(); } } else { - String playsong = PlayMusic.playlist.get("0"); - String song = PlayMusic.realURL(ALLmusic_BC.Music_Api1 + playsong); + PlayMusic.now_music = PlayMusic.playlist.get(0); + String song = PlayMusic.realURL(ALLmusic_BC.Music_Api1 + PlayMusic.now_music); if (song != null) { PlayMusic.Music_time = PlayMusic.Music_Time(song); - ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "正在播放歌曲" + playsong)); + ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "正在播放歌曲" + PlayMusic.now_music)); PlayMusic.SendToPlayer("[Net]" + song); - PlayMusic.playlist.remove("0"); + PlayMusic.playlist.remove(0); music_list(); try { while (PlayMusic.Music_time > 0) { @@ -148,6 +148,7 @@ class playgo extends Thread { ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "队列中无歌曲")); } PlayMusic.Vote_time = 0; + PlayMusic.now_music = null; } } } @@ -155,8 +156,9 @@ class playgo extends Thread { e.getMessage(); } } else { - ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "无效歌曲歌曲" + playsong)); - PlayMusic.playlist.remove("0"); + ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "无效歌曲歌曲" + PlayMusic.now_music)); + PlayMusic.playlist.remove(0); + PlayMusic.now_music = null; music_list(); } } diff --git a/src/main/java/Color_yr/ALLmusic/command.java b/src/main/java/Color_yr/ALLmusic/command.java index 040ccd90..edefc9ea 100644 --- a/src/main/java/Color_yr/ALLmusic/command.java +++ b/src/main/java/Color_yr/ALLmusic/command.java @@ -4,10 +4,11 @@ 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; -import net.md_5.bungee.api.scheduler.GroupedThreadFactory; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; -import java.lang.reflect.Proxy; import java.util.Iterator; +import java.util.Map; import java.util.regex.Pattern; public class command extends Command { @@ -31,39 +32,33 @@ public class command extends Command { } public void add_music(CommandSender sender, String[] args) { - ; + String music_id; - if (args[0].indexOf("http") == 0) { + if (args[0].indexOf("id=") == 0) { if (args[0].indexOf("&user") != -1) music_id = get_string(args[0], "id=", "&user"); else music_id = get_string(args[0], "id=", null); } else music_id = args[0]; - ALLmusic_BC.log.info(music_id); if (isInteger(music_id)) { if (PlayMusic.playlist.size() == ALLmusic_BC.Maxlist) { sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,队列已满")); return; } else if (ALLmusic_BC.Banconfig.getBoolean(music_id, false) == true) { sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,这首歌被禁点了")); - return; } else if (PlayMusic.playlist.containsValue(music_id)) { sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,这首歌已经在队列了")); - return; + } else { + PlayMusic.playlist.put(PlayMusic.All_music, music_id); + PlayMusic.All_music++; + sender.sendMessage(new TextComponent("§d[ALLmusic]§c点歌" + music_id + "成功")); + ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + sender.getName() + + "点歌" + music_id)); + logs logs = new logs(); + logs.log_write("玩家:" + sender.getName() + " 点歌:" + music_id); } - if (PlayMusic.stop.size() != 0) { - if (PlayMusic.stop.get(sender.getName()).equals("true") == true) { - PlayMusic.stop.put(sender.getName(), "false"); - } - } - PlayMusic.playlist.put(String.valueOf(PlayMusic.All_music), music_id); - PlayMusic.All_music++; - sender.sendMessage(new TextComponent("§d[ALLmusic]§c点歌" + music_id + "成功")); - ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + sender.getName() + - "点歌" + music_id)); - logs logs = new logs(); - logs.log_write("玩家:" + sender.getName() + " 点歌:" + music_id); + PlayMusic.stop.put(sender.getName(), false); } else sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,请输入歌曲数字ID")); } @@ -76,52 +71,63 @@ public class command extends Command { sender.sendMessage(new TextComponent("§d[ALLmusic]§2帮助手册")); sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music [音乐ID] 来点歌")); sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music stop 停止播放歌曲")); - sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music now 查看歌曲队列")); + sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music list 查看歌曲队列")); sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music vote 投票切歌")); sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music nomusic 不再参与点歌")); return; } else if (args[0].equalsIgnoreCase("stop")) { PlayMusic.SendToOnePlayer("[Stop]", sender.getName()); sender.sendMessage(new TextComponent("§d[ALLmusic]§2已停止" + sender.getName() + "的音乐播放")); - } else if (args[0].equalsIgnoreCase("now")) { + } else if (args[0].equalsIgnoreCase("list")) { + if (PlayMusic.now_music == null) { + sender.sendMessage(new TextComponent("§d[ALLmusic]§2无正在播放的歌曲")); + } else { + sender.sendMessage(new TextComponent("§d[ALLmusic]§2正在播放:" + PlayMusic.now_music)); + } if (PlayMusic.playlist.size() == 0) { sender.sendMessage(new TextComponent("§d[ALLmusic]§2队列中无歌曲")); - } - sender.sendMessage(new TextComponent("§d[ALLmusic]§2队列中有歌曲数:" + PlayMusic.playlist.size())); - Iterator iterator = PlayMusic.playlist.keySet().iterator(); - while (iterator.hasNext()) { - String key = iterator.next(); - sender.sendMessage(new TextComponent("§d[ALLmusic]§2当前队列" + key + "->" + PlayMusic.playlist.get(key))); + } else { + sender.sendMessage(new TextComponent("§d[ALLmusic]§2队列中有歌曲数:" + PlayMusic.playlist.size())); + for (Map.Entry music : PlayMusic.playlist.entrySet()) { + sender.sendMessage(new TextComponent("§d[ALLmusic]§2当前队列" + music.getKey() + "->" + music.getValue())); + } } } else if (args[0].equalsIgnoreCase("vote")) { if (PlayMusic.playlist.size() == 0) { sender.sendMessage(new TextComponent("§d[ALLmusic]§2队列中无歌曲")); } else if (PlayMusic.Vote_time == 0) { - PlayMusic.Vote_time = 10; + PlayMusic.Vote_time = 30; PlayMusic.Vote.clear(); - PlayMusic.Vote.put(sender.getName(), "true"); + PlayMusic.Vote.add(sender.getName()); sender.sendMessage(new TextComponent("§d[ALLmusic]§2已发起切歌投票")); ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + sender.getName() + - "发起了切歌投票,10秒后结束,输入/music vote 同意切歌。")); + "发起了切歌投票,30秒后结束,输入/music vote 同意切歌。")); } else if (PlayMusic.Vote_time > 0) { - if (PlayMusic.Vote.get(sender.getName()) != "true") { - PlayMusic.Vote_time = 10; - PlayMusic.Vote.put(sender.getName(), "true"); + if (!PlayMusic.Vote.contains(sender.getName())) { + PlayMusic.Vote.add(sender.getName()); ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + sender.getName() + "同意切歌,共有" + PlayMusic.Vote.size() + "名玩家同意切歌。")); } } } else if (args[0].equalsIgnoreCase("reload")) { - ALLmusic_BC.reloadConfig(); + ALLmusic_BC music = new ALLmusic_BC(); + music.loadconfig(); sender.sendMessage(new TextComponent("§d[ALLmusic]§2已重读配置文件")); } else if (args[0].equalsIgnoreCase("next") && sender.hasPermission("ALLmusic.admin")) { PlayMusic.Music_time = 1; PlayMusic.SendToPlayer("[Stop]"); - sender.sendMessage(new TextComponent("§d[ALLmusic]§2已切歌")); + sender.sendMessage(new TextComponent("§d[ALLmusic]§2已强制切歌")); } else if (args[0].equalsIgnoreCase("nomusic")) { - PlayMusic.stop.put(sender.getName(), "true"); + PlayMusic.stop.put(sender.getName(), true); PlayMusic.SendToOnePlayer("[Stop]", sender.getName()); sender.sendMessage(new TextComponent("§d[ALLmusic]§2你不会再收到点歌了!想要再次参与点歌就点一首歌吧!")); + ALLmusic_BC.config.set("nomusic", PlayMusic.stop); + try { + ConfigurationProvider.getProvider(YamlConfiguration.class).save(ALLmusic_BC.config, ALLmusic_BC.FileName); + } catch (Exception e) { + logs log = new logs(); + log.log_write(e.getMessage()); + } } else add_music(sender, args); } diff --git a/src/main/java/Color_yr/ALLmusic/logs.java b/src/main/java/Color_yr/ALLmusic/logs.java index fabc2234..358a4a70 100644 --- a/src/main/java/Color_yr/ALLmusic/logs.java +++ b/src/main/java/Color_yr/ALLmusic/logs.java @@ -10,11 +10,6 @@ import java.util.Date; public class logs { public static File file; - public static Boolean Socket_log = false; - public static Boolean Group_log = false; - public static Boolean Send_log = false; - public static Boolean Error_log = false; - public void log_write(String text) { FileWriter fw = null; try { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 90911cc7..712ea532 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,5 +4,8 @@ Maxlist: 10 Music_Api1: http://music.163.com/song/media/outer/url?id= #最小投票人数 min_vote: 3 +#不参与点歌的人 +nomusic: + Color_yr: true #配置文件版本号 Version: 1.0.0 \ No newline at end of file