From c80f0e575260b7ea9023f4079f02064a94e41462 Mon Sep 17 00:00:00 2001 From: Coloryr <402067010@qq.com> Date: Fri, 16 Aug 2024 18:49:30 +0800 Subject: [PATCH] =?UTF-8?q?up=20=E4=BF=AE=E6=AD=A3=E5=88=87=E6=AD=8C?= =?UTF-8?q?=E5=92=8C=E7=82=B9=E6=AD=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/AllMusic.java | 72 +--------------- core/command/CommandPush.java | 40 ++++----- core/command/CommandVote.java | 21 +++-- core/music/play/PlayMusic.java | 144 +++++++++++++++++++++++++++++-- core/music/play/PlayRuntime.java | 52 +++++------ version | 2 +- 6 files changed, 189 insertions(+), 142 deletions(-) diff --git a/core/AllMusic.java b/core/AllMusic.java index dd3b3d6..bfe47d4 100644 --- a/core/AllMusic.java +++ b/core/AllMusic.java @@ -36,7 +36,7 @@ public class AllMusic { /** * 插件版本号 */ - public static final String version = "3.2.0"; + public static final String version = "3.2.1"; /** * 配置文件版本号 */ @@ -50,14 +50,6 @@ public class AllMusic { * 玩家名 结果 */ private static final Map searchSave = new HashMap<>(); - /** - * 切歌投票的玩家 - */ - private static final Set votePlayer = new HashSet<>(); - /** - * 插歌投票的玩家 - */ - private static final Set pushPlayer = new HashSet<>(); /** * 正在播放的玩家 */ @@ -221,65 +213,6 @@ public static void removeSearch(String player) { searchSave.remove(player); } - /** - * 添加投票的玩家 - * - * @param player 用户名 - */ - public static void addVote(String player) { - player = player.toLowerCase(); - votePlayer.add(player); - } - - /** - * 添加投票的玩家 - * - * @param player 用户名 - */ - public static void addPush(String player) { - player = player.toLowerCase(); - pushPlayer.add(player); - } - - /** - * 获取投票数量 - * - * @return 数量 - */ - public static int getVoteCount() { - return votePlayer.size(); - } - - /** - * 清空投票 - */ - public static void clearVote() { - votePlayer.clear(); - } - - /** - * 清空插歌 - */ - public static void clearPush() { - pushPlayer.clear(); - } - - /** - * 是否已经投票了 - * - * @param player 用户名 - * @return 结果 - */ - public static boolean containVote(String player) { - player = player.toLowerCase(); - return votePlayer.contains(player); - } - - public static boolean containPush(String player) { - player = player.toLowerCase(); - return pushPlayer.contains(player); - } - /** * 添加正在播放的玩家 * @@ -375,7 +308,8 @@ public static void start() { */ public static void stop() { try { - clearVote(); + PlayMusic.clearVote(); + PlayMusic.clearPush(); Logs.stop(); side.sendStop(); MusicSearch.stop(); diff --git a/core/command/CommandPush.java b/core/command/CommandPush.java index 665cdc2..800314e 100644 --- a/core/command/CommandPush.java +++ b/core/command/CommandPush.java @@ -20,42 +20,40 @@ public void ex(Object sender, String name, String[] args) { if (PlayMusic.getListSize() == 0 && PlayMusic.getIdleListSize() == 0) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.emptyPlay); } - SongInfoObj id = null; + SongInfoObj music = null; if (args.length == 1) { - id = PlayMusic.findPlayerMusic(name); - if (id == null) { + music = PlayMusic.findPlayerMusic(name); + if (music == null) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.noId); return; } SongInfoObj id1 = PlayMusic.findMusicIndex(1); - if (id1 != null && id1.getID().equalsIgnoreCase(id.getID())) { + if (id1 != null && id1.getID().equalsIgnoreCase(music.getID())) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.pushErr); return; } } else if (args.length == 2) { if (args[1].equalsIgnoreCase("cancel")) { - if (!PlayMusic.pushSender.equalsIgnoreCase(name)) { + if (!name.equalsIgnoreCase(PlayMusic.getPushSender())) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.err1); return; } - if (PlayMusic.pushTime <= 0) { + if (PlayMusic.getPushTime() <= 0) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.err2); return; } - PlayMusic.pushTime = -1; - AllMusic.clearPush(); + PlayMusic.clearPush(); AllMusic.side.bq(AllMusic.getMessage().push.cancel); - PlayMusic.pushSender = null; return; } else { try { int index = Integer.parseInt(args[1]); - id = PlayMusic.findMusicIndex(index); + music = PlayMusic.findMusicIndex(index); } catch (Exception e) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.noId); return; } - if (id == null) { + if (music == null) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.noId1.replace(PAL.index, args[1])); return; } @@ -64,32 +62,30 @@ public void ex(Object sender, String name, String[] args) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error); return; } - if (PlayMusic.pushTime <= 0) { - if (id == null) { + if (PlayMusic.getPushTime() <= 0) { + if (music == null) { return; } - PlayMusic.pushTime = AllMusic.getConfig().voteTime; - PlayMusic.push = id; - AllMusic.addPush(name); + PlayMusic.startPush(name, music); AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.doVote); String data = AllMusic.getMessage().push.bq; AllMusic.side.bq(data .replace(PAL.player, name) .replace(PAL.time, String.valueOf(AllMusic.getConfig().voteTime)) - .replace(PAL.musicName, id.getName()) - .replace(PAL.musicAuthor, id.getAuthor())); + .replace(PAL.musicName, music.getName()) + .replace(PAL.musicAuthor, music.getAuthor())); AllMusic.side.bqRun(AllMusic.getMessage().push.bq1, AllMusic.getMessage().push.bq2, "/music push"); } else { - if (id != null) { + if (music != null) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.err3); return; } - if (!AllMusic.containPush(name)) { - AllMusic.addPush(name); + if (!PlayMusic.containPush(name)) { + PlayMusic.addPush(name); AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.agree); String data = AllMusic.getMessage().push.bqAgree; data = data.replace(PAL.player, name) - .replace(PAL.count, "" + AllMusic.getVoteCount()); + .replace(PAL.count, String.valueOf(PlayMusic.getVoteCount())); AllMusic.side.bq(data); } else { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.arAgree); diff --git a/core/command/CommandVote.java b/core/command/CommandVote.java index 9f06eff..325ad0c 100644 --- a/core/command/CommandVote.java +++ b/core/command/CommandVote.java @@ -13,19 +13,19 @@ public void ex(Object sender, String name, String[] args) { return; } else if (PlayMusic.getListSize() == 0 && PlayMusic.getIdleListSize() == 0) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.emptyPlay); + } else if (PlayMusic.nowPlayMusic == null) { + AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.emptyPlayingMusic); } else if (args.length == 2) { if (args[1].equalsIgnoreCase("cancel")) { - if (!PlayMusic.voteSender.equalsIgnoreCase(name)) { + if (!name.equalsIgnoreCase(PlayMusic.getVoteSender())) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().vote.err1); return; - } else if (PlayMusic.voteTime <= 0) { + } else if (PlayMusic.getVoteTime() <= 0) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().vote.err2); return; } AllMusic.side.bq(AllMusic.getMessage().vote.cancel); - PlayMusic.voteTime = -1; - AllMusic.clearVote(); - PlayMusic.voteSender = null; + PlayMusic.clearVote(); } else { AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error); } @@ -33,21 +33,20 @@ public void ex(Object sender, String name, String[] args) { } else if (args.length > 2) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error); return; - } else if (PlayMusic.voteTime <= 0) { - PlayMusic.voteTime = AllMusic.getConfig().voteTime; - AllMusic.addVote(name); + } else if (PlayMusic.getVoteTime() <= 0) { + PlayMusic.startVote(name); AllMusic.side.sendMessage(sender, AllMusic.getMessage().vote.doVote); String data = AllMusic.getMessage().vote.bq; AllMusic.side.bq(data.replace(PAL.player, name) .replace(PAL.time, String.valueOf(AllMusic.getConfig().voteTime))); AllMusic.side.bqRun(AllMusic.getMessage().vote.bq1, AllMusic.getMessage().vote.bq2, "/music vote"); } else { - if (!AllMusic.containVote(name)) { - AllMusic.addVote(name); + if (!PlayMusic.containVote(name)) { + PlayMusic.addVote(name); AllMusic.side.sendMessage(sender, AllMusic.getMessage().vote.agree); String data = AllMusic.getMessage().vote.bqAgree; data = data.replace(PAL.player, name) - .replace(PAL.count, "" + AllMusic.getVoteCount()); + .replace(PAL.count, String.valueOf(PlayMusic.getVoteCount())); AllMusic.side.bq(data); } else { AllMusic.side.sendMessage(sender, AllMusic.getMessage().vote.arAgree); diff --git a/core/music/play/PlayMusic.java b/core/music/play/PlayMusic.java index 023ef03..29a41d0 100644 --- a/core/music/play/PlayMusic.java +++ b/core/music/play/PlayMusic.java @@ -28,12 +28,33 @@ public class PlayMusic { private static final List playIdleList = new ArrayList<>(); private static final Queue deep = new PriorityQueue<>(); /** - * 投票时间 + * 切歌投票时间 */ - public static int voteTime = 0; - public static String voteSender; - public static int pushTime = 0; - public static String pushSender; + private static int voteTime = 0; + /** + * 切歌发起人 + */ + private static String voteSender; + /** + * 切歌投票的玩家 + */ + private static final Set votePlayer = new HashSet<>(); + /** + * 插歌投票时间 + */ + private static int pushTime = 0; + /** + * 插歌发起人 + */ + private static String pushSender; + /** + * 插歌投票的玩家 + */ + private static final Set pushPlayer = new HashSet<>(); + /** + * 插歌目标 + */ + private static SongInfoObj push; /** * 总歌曲长度 */ @@ -62,7 +83,6 @@ public class PlayMusic { * 错误次数 */ public static int error; - public static SongInfoObj push; private static boolean isRun; private static int idleNow; @@ -83,6 +103,113 @@ public static void start() { addT.start(); } + /** + * 添加投票的玩家 + * + * @param player 用户名 + */ + public static void addVote(String player) { + player = player.toLowerCase(); + votePlayer.add(player); + } + + public static void startVote(String player) { + voteTime = AllMusic.getConfig().voteTime; + player = player.toLowerCase(); + voteSender = player; + votePlayer.add(player); + } + + /** + * 添加投票的玩家 + * + * @param player 用户名 + */ + public static void addPush(String player) { + player = player.toLowerCase(); + pushPlayer.add(player); + } + + public static void startPush(String player, SongInfoObj music) { + player = player.toLowerCase(); + push = music; + pushSender = player; + pushPlayer.add(player); + pushTime = AllMusic.getConfig().voteTime; + } + + public static void pushTick() { + pushTime--; + } + + public static void voteTick() { + voteTime--; + } + + public static SongInfoObj getPush() { + return push; + } + + public static int getPushTime() { + return pushTime; + } + + public static String getPushSender() { + return pushSender; + } + + public static int getVoteTime() { + return voteTime; + } + + public static String getVoteSender() { + return voteSender; + } + + /** + * 获取投票数量 + * + * @return 数量 + */ + public static int getVoteCount() { + return votePlayer.size(); + } + + /** + * 清空投票 + */ + public static void clearVote() { + voteTime = -1; + voteSender = null; + votePlayer.clear(); + } + + /** + * 清空插歌 + */ + public static void clearPush() { + pushTime = -1; + push = null; + pushSender = null; + pushPlayer.clear(); + } + + /** + * 是否已经投票了 + * + * @param player 用户名 + * @return 结果 + */ + public static boolean containVote(String player) { + player = player.toLowerCase(); + return votePlayer.contains(player); + } + + public static boolean containPush(String player) { + player = player.toLowerCase(); + return pushPlayer.contains(player); + }; + /** * 添加点歌任务 * @@ -180,10 +307,9 @@ public static void addMusic(Object sender, String id, String player, boolean isL /** * 将歌曲移动到队列头 - * - * @param obj */ - public static void pushMusic(SongInfoObj obj) { + public static void pushMusic() { + SongInfoObj obj = push; synchronized (playList) { playList.remove(obj); playList.add(0, obj); diff --git a/core/music/play/PlayRuntime.java b/core/music/play/PlayRuntime.java index 63bb369..2031c07 100644 --- a/core/music/play/PlayRuntime.java +++ b/core/music/play/PlayRuntime.java @@ -137,11 +137,9 @@ private static void time2() { } private static boolean checkPush() { - if (PlayMusic.push != null) { - SongInfoObj push = PlayMusic.push; - if (PlayMusic.nowPlayMusic.getID().equalsIgnoreCase(push.getID())) { - PlayMusic.voteTime = 0; - AllMusic.side.bqTask(AllMusic.getMessage().push.cancel); + SongInfoObj music = PlayMusic.getPush(); + if (music != null) { + if (PlayMusic.nowPlayMusic.getID().equalsIgnoreCase(music.getID())) { return false; } List list = PlayMusic.getList(); @@ -149,12 +147,12 @@ private static boolean checkPush() { return false; } SongInfoObj id1 = list.get(0); - if (id1 != null && id1.getID().equalsIgnoreCase(push.getID())) { + if (id1 != null && id1.getID().equalsIgnoreCase(music.getID())) { return false; } for (int a = 1; a < list.size(); a++) { id1 = list.get(a); - if (id1.getID().equalsIgnoreCase(push.getID())) + if (id1.getID().equalsIgnoreCase(music.getID())) return true; } } @@ -170,46 +168,40 @@ private static void time3() { if (ping >= 10) { AllMusic.side.ping(); } - if (PlayMusic.pushTime > 0) { + if (PlayMusic.getPushTime() > 0) { if (!checkPush()) { - PlayMusic.push = null; - PlayMusic.pushTime = 0; + PlayMusic.clearPush(); AllMusic.side.bqTask(AllMusic.getMessage().push.cancel); } else { - PlayMusic.pushTime--; - if (PlayMusic.pushTime == 0) { - PlayMusic.push = null; - AllMusic.clearPush(); + PlayMusic.pushTick(); + if (PlayMusic.getPushTime() == 0) { + PlayMusic.clearPush(); AllMusic.side.bqTask(AllMusic.getMessage().push.timeOut); } else { int players = AllMusic.side.getPlayerSize(); - if (AllMusic.getVoteCount() >= AllMusic.getConfig().minVote + if (PlayMusic.getVoteCount() >= AllMusic.getConfig().minVote || (players <= AllMusic.getConfig().minVote - && players <= AllMusic.getVoteCount())) { - SongInfoObj info = PlayMusic.push; - PlayMusic.push = null; - PlayMusic.pushMusic(info); + && players <= PlayMusic.getVoteCount())) { + PlayMusic.pushMusic(); + PlayMusic.clearPush(); AllMusic.side.bqTask(AllMusic.getMessage().push.doPush); - AllMusic.clearPush(); - PlayMusic.pushTime = 0; } } } } - if (PlayMusic.voteTime > 0) { - PlayMusic.voteTime--; - if (PlayMusic.voteTime == 0) { - AllMusic.clearPush(); + if (PlayMusic.getVoteTime() > 0) { + PlayMusic.voteTick(); + if (PlayMusic.getVoteTime() == 0) { + PlayMusic.clearVote(); AllMusic.side.bqTask(AllMusic.getMessage().vote.timeOut); } else { int players = AllMusic.side.getPlayerSize(); - if (AllMusic.getVoteCount() >= AllMusic.getConfig().minVote + if (PlayMusic.getVoteCount() >= AllMusic.getConfig().minVote || (players <= AllMusic.getConfig().minVote - && players <= AllMusic.getVoteCount())) { - AllMusic.side.bqTask(AllMusic.getMessage().vote.voteDone); - AllMusic.clearVote(); + && players <= PlayMusic.getVoteCount())) { + PlayMusic.clearVote(); PlayMusic.musicLessTime = 0; - PlayMusic.voteTime = 0; + AllMusic.side.bqTask(AllMusic.getMessage().vote.voteDone); } } } diff --git a/version b/version index a4f52a5..0444f32 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.2.0 \ No newline at end of file +3.2.1 \ No newline at end of file