Skip to content

Commit

Permalink
up 修正切歌和点歌问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Aug 16, 2024
1 parent 2891cf9 commit c80f0e5
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 142 deletions.
72 changes: 3 additions & 69 deletions core/AllMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AllMusic {
/**
* 插件版本号
*/
public static final String version = "3.2.0";
public static final String version = "3.2.1";
/**
* 配置文件版本号
*/
Expand All @@ -50,14 +50,6 @@ public class AllMusic {
* 玩家名 结果
*/
private static final Map<String, SearchPageObj> searchSave = new HashMap<>();
/**
* 切歌投票的玩家
*/
private static final Set<String> votePlayer = new HashSet<>();
/**
* 插歌投票的玩家
*/
private static final Set<String> pushPlayer = new HashSet<>();
/**
* 正在播放的玩家
*/
Expand Down Expand Up @@ -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);
}

/**
* 添加正在播放的玩家
*
Expand Down Expand Up @@ -375,7 +308,8 @@ public static void start() {
*/
public static void stop() {
try {
clearVote();
PlayMusic.clearVote();
PlayMusic.clearPush();
Logs.stop();
side.sendStop();
MusicSearch.stop();
Expand Down
40 changes: 18 additions & 22 deletions core/command/CommandPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions core/command/CommandVote.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,40 @@ 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);
}
return;
} 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);
Expand Down
Loading

0 comments on commit c80f0e5

Please sign in to comment.