mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-20 01:49:35 +00:00
up
This commit is contained in:
1 parent
062905b0f8
commit
eef0662964
15 files changed
+269
-132
No files matched your search
@@ -352,7 +352,7 @@ public class AllMusic {
|
||||
log.info("§d[AllMusic]§e当前语言配置文件版本为:" + messageVersion
|
||||
+ ",你的语言文件版本为:" + config.Version);
|
||||
|
||||
if (!message.getVersion().equalsIgnoreCase(messageVersion)) {
|
||||
if (!message.Version.equalsIgnoreCase(messageVersion)) {
|
||||
log.warning("§d[AllMusic]§c语言文件版本号错误,运行可能会发生问题,请删除后重载");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class AllMusicAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新玩家Hud
|
||||
* 更新玩家Hud数据
|
||||
* @param name 用户名
|
||||
* @param pos 位置
|
||||
* @param data 数据
|
||||
|
||||
@@ -190,7 +190,7 @@ public class DataSql {
|
||||
obj.Pic = pos4;
|
||||
obj.EnablePic = set.getInt(13) == 1;
|
||||
obj.PicSize = set.getInt(14);
|
||||
HudSave.add1(name, obj);
|
||||
HudSave.add(name, obj);
|
||||
}
|
||||
stat.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -19,11 +19,11 @@ public class HudSave {
|
||||
return huds.get(name);
|
||||
}
|
||||
|
||||
public static void add1(String name, SaveOBJ hud) {
|
||||
public static void add(String name, SaveOBJ hud) {
|
||||
huds.put(name, hud);
|
||||
}
|
||||
|
||||
public static void add(String name, SaveOBJ hud) {
|
||||
public static void addAndSave(String name, SaveOBJ hud) {
|
||||
huds.put(name, hud);
|
||||
DataSql.task(() -> DataSql.addUser(name, hud));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,14 @@ import coloryr.allmusic.utils.Function;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class HudUtils {
|
||||
/**
|
||||
* 设置玩家Hud位置
|
||||
* @param player 用户名
|
||||
* @param pos 位置
|
||||
* @param x x
|
||||
* @param y y
|
||||
* @return 位置数据
|
||||
*/
|
||||
public static PosOBJ setHudPos(String player, String pos, String x, String y) {
|
||||
SaveOBJ obj = HudSave.get(player);
|
||||
if (obj == null)
|
||||
@@ -35,45 +43,34 @@ public class HudUtils {
|
||||
case pic:
|
||||
posOBJ = obj.Pic;
|
||||
}
|
||||
posOBJ.setX(x1);
|
||||
posOBJ.setY(y1);
|
||||
switch (pos1) {
|
||||
case lyric:
|
||||
obj.setLyric(posOBJ);
|
||||
break;
|
||||
case list:
|
||||
obj.setList(posOBJ);
|
||||
break;
|
||||
case info:
|
||||
obj.setInfo(posOBJ);
|
||||
break;
|
||||
case pic:
|
||||
obj.setPic(posOBJ);
|
||||
break;
|
||||
}
|
||||
posOBJ.x = x1;
|
||||
posOBJ.y = y1;
|
||||
|
||||
HudSave.add(player, obj);
|
||||
HudSave.addAndSave(player, obj);
|
||||
AllMusic.save();
|
||||
HudUtils.sendHudSave(player);
|
||||
HudUtils.sendHudPos(player);
|
||||
return posOBJ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Hud的List数据
|
||||
*/
|
||||
public static void sendHudListData() {
|
||||
String info;
|
||||
if (PlayMusic.getSize() == 0) {
|
||||
info = AllMusic.getMessage().Hud.getNoList();
|
||||
info = AllMusic.getMessage().Hud.NoList;
|
||||
} else {
|
||||
String now;
|
||||
StringBuilder list = new StringBuilder();
|
||||
for (SongInfo info1 : PlayMusic.getList()) {
|
||||
if (info1 == null)
|
||||
continue;
|
||||
now = info1.Info;
|
||||
if (now.length() > AllMusic.getConfig().getMessageLimitSize())
|
||||
now = now.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
now = info1.getInfo();
|
||||
if (now.length() > AllMusic.getConfig().MessageLimitSize)
|
||||
now = now.substring(0, AllMusic.getConfig().MessageLimitSize - 1) + "...";
|
||||
list.append(now).append("\n");
|
||||
}
|
||||
info = AllMusic.getMessage().hud.List
|
||||
info = AllMusic.getMessage().Hud.List
|
||||
.replace("%Size%", String.valueOf(PlayMusic.getList().size()))
|
||||
.replace("%List%", list.toString());
|
||||
}
|
||||
@@ -81,18 +78,27 @@ public class HudUtils {
|
||||
AllMusic.side.sendHudList(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间转换
|
||||
*
|
||||
* @param time 时间
|
||||
* @return 结果
|
||||
*/
|
||||
private static String tranTime(int time) {
|
||||
int m = time / 60;
|
||||
int s = time - m * 60;
|
||||
return (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Hud的信息数据
|
||||
*/
|
||||
public static void sendHudNowData() {
|
||||
String info;
|
||||
if (PlayMusic.nowPlayMusic == null) {
|
||||
info = AllMusic.getMessage().Hud.NoMusic;
|
||||
} else {
|
||||
info = AllMusic.getMessage().Hud.getMusic()
|
||||
info = AllMusic.getMessage().Hud.Music
|
||||
.replace("%Name%", PlayMusic.nowPlayMusic.getName())
|
||||
.replace("%AllTime%", tranTime(PlayMusic.musicAllTime))
|
||||
.replace("%NowTime%", tranTime(PlayMusic.musicNowTime / 1000))
|
||||
@@ -105,12 +111,17 @@ public class HudUtils {
|
||||
AllMusic.side.sendHudInfo(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Hud的歌词数据
|
||||
*
|
||||
* @param showobj 显示的歌词
|
||||
*/
|
||||
public static void sendHudLyricData(LyricItem showobj) {
|
||||
String info;
|
||||
if (showobj == null) {
|
||||
info = AllMusic.getMessage().Hud.getNoLyric();
|
||||
info = AllMusic.getMessage().Hud.NoLyric;
|
||||
} else {
|
||||
info = AllMusic.getMessage().hud.Lyric
|
||||
info = AllMusic.getMessage().Hud.Lyric
|
||||
.replace("%Lyric%", showobj.getLyric() == null ? "" : showobj.getLyric())
|
||||
.replace("%Tlyric%", (showobj.isHaveT() && showobj.getTlyric() != null) ?
|
||||
showobj.getTlyric() : "");
|
||||
@@ -119,51 +130,57 @@ public class HudUtils {
|
||||
AllMusic.side.sendHudLyric(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Hud的开启关闭数据
|
||||
*
|
||||
* @param player 用户名
|
||||
* @param pos 输入数据
|
||||
* @return 设置结果
|
||||
*/
|
||||
public static boolean setHudEnable(String player, String pos) {
|
||||
SaveOBJ obj = HudSave.get(player);
|
||||
boolean a = false;
|
||||
boolean res = false;
|
||||
if (obj == null) {
|
||||
obj = AllMusic.getConfig().DefaultHud.copy();
|
||||
a = obj.EnableInfo && obj.EnableList && obj.EnableLyric;
|
||||
res = obj.EnableInfo && obj.EnableList && obj.EnableLyric;
|
||||
} else {
|
||||
if (pos == null) {
|
||||
if (obj.EnableInfo && obj.EnableList && obj.EnableLyric) {
|
||||
obj.setEnableInfo(false);
|
||||
obj.setEnableList(false);
|
||||
obj.setEnableLyric(false);
|
||||
obj.setEnablePic(false);
|
||||
a = false;
|
||||
obj.EnableInfo = false;
|
||||
obj.EnableList = false;
|
||||
obj.EnableLyric = false;
|
||||
obj.EnablePic = false;
|
||||
} else {
|
||||
obj.setEnableInfo(true);
|
||||
obj.setEnableList(true);
|
||||
obj.setEnableLyric(true);
|
||||
obj.setEnablePic(true);
|
||||
a = true;
|
||||
obj.EnableInfo = true;
|
||||
obj.EnableList = true;
|
||||
obj.EnableLyric = true;
|
||||
obj.EnablePic = true;
|
||||
res = true;
|
||||
}
|
||||
} else {
|
||||
HudPos pos1 = HudPos.valueOf(pos);
|
||||
switch (pos1) {
|
||||
case info:
|
||||
obj.setEnableInfo(!obj.EnableInfo);
|
||||
obj.EnableInfo = !obj.EnableInfo;
|
||||
break;
|
||||
case list:
|
||||
obj.setEnableList(!obj.EnableList);
|
||||
obj.EnableList = !obj.EnableList;
|
||||
break;
|
||||
case lyric:
|
||||
obj.setEnableLyric(!obj.EnableLyric);
|
||||
obj.EnableLyric = !obj.EnableLyric;
|
||||
break;
|
||||
case pic:
|
||||
obj.setEnablePic(!obj.EnablePic);
|
||||
obj.EnablePic = !obj.EnablePic;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
clearHud(player);
|
||||
HudSave.add(player, obj);
|
||||
HudSave.addAndSave(player, obj);
|
||||
AllMusic.save();
|
||||
HudUtils.sendHudSave(player);
|
||||
HudUtils.sendHudPos(player);
|
||||
if (pos == null) {
|
||||
return a;
|
||||
return res;
|
||||
} else {
|
||||
HudPos pos1 = HudPos.valueOf(pos);
|
||||
switch (pos1) {
|
||||
@@ -180,25 +197,38 @@ public class HudUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空Hud数据
|
||||
*/
|
||||
public static void clearHud() {
|
||||
AllMusic.side.clearHud();
|
||||
}
|
||||
|
||||
public static void clearHud(String Name) {
|
||||
AllMusic.side.clearHud(Name);
|
||||
/**
|
||||
* 清空Hud数
|
||||
*
|
||||
* @param player 用户名
|
||||
*/
|
||||
public static void clearHud(String player) {
|
||||
AllMusic.side.clearHud(player);
|
||||
}
|
||||
|
||||
public static void sendHudSave(String Name) {
|
||||
/**
|
||||
* 发送Hud位置信息
|
||||
*
|
||||
* @param player 用户名
|
||||
*/
|
||||
public static void sendHudPos(String player) {
|
||||
AllMusic.side.runTask(() -> {
|
||||
try {
|
||||
SaveOBJ obj = HudSave.get(Name);
|
||||
SaveOBJ obj = HudSave.get(player);
|
||||
if (obj == null) {
|
||||
obj = AllMusic.getConfig().DefaultHud.copy();
|
||||
HudSave.add(Name, obj);
|
||||
HudSave.addAndSave(player, obj);
|
||||
AllMusic.save();
|
||||
}
|
||||
String data = new Gson().toJson(obj);
|
||||
AllMusic.side.send(data, Name, null);
|
||||
AllMusic.side.send(data, player, null);
|
||||
} catch (Exception e1) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
|
||||
e1.printStackTrace();
|
||||
@@ -206,27 +236,38 @@ public class HudUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void reset(String name) {
|
||||
/**
|
||||
* 重置Hud位置
|
||||
*
|
||||
* @param player 用户名
|
||||
*/
|
||||
public static void reset(String player) {
|
||||
SaveOBJ obj = AllMusic.getConfig().DefaultHud.copy();
|
||||
clearHud(name);
|
||||
HudSave.add(name, obj);
|
||||
clearHud(player);
|
||||
HudSave.addAndSave(player, obj);
|
||||
AllMusic.save();
|
||||
HudUtils.sendHudSave(name);
|
||||
HudUtils.sendHudPos(player);
|
||||
}
|
||||
|
||||
public static boolean setPicSize(String name, String size) {
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
/**
|
||||
* 设置Hud的图片大小
|
||||
*
|
||||
* @param player 用户名
|
||||
* @param size 大小
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean setPicSize(String player, String size) {
|
||||
SaveOBJ obj = HudSave.get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().DefaultHud.copy();
|
||||
if (!Function.isInteger(size))
|
||||
return false;
|
||||
int size1 = Integer.parseInt(size);
|
||||
|
||||
obj.setPicSize(size1);
|
||||
obj.PicSize = Integer.parseInt(size);
|
||||
|
||||
HudSave.add(name, obj);
|
||||
HudSave.addAndSave(player, obj);
|
||||
AllMusic.save();
|
||||
HudUtils.sendHudSave(name);
|
||||
HudUtils.sendHudPos(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -31,12 +31,12 @@ public class LyricItem {
|
||||
String data;
|
||||
if (haveT) {
|
||||
if (tlyric != null && !tlyric.isEmpty()) {
|
||||
data = AllMusic.getMessage().getLyric().getTData();
|
||||
data = AllMusic.getMessage().Lyric.TData;
|
||||
return data.replace("%Lyric%", lyric)
|
||||
.replace("%TLyric%", tlyric);
|
||||
}
|
||||
}
|
||||
data = AllMusic.getMessage().getLyric().getData();
|
||||
data = AllMusic.getMessage().Lyric.Data;
|
||||
return data.replace("%Lyric%", lyric);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,32 @@
|
||||
package coloryr.allmusic.music.play;
|
||||
|
||||
public class MusicObj {
|
||||
/**
|
||||
* 发送者
|
||||
*/
|
||||
public Object sender;
|
||||
/**
|
||||
* 歌曲ID
|
||||
*/
|
||||
public String id;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
public String[] args;
|
||||
/**
|
||||
* 是否是默认点歌方式
|
||||
*/
|
||||
public boolean isDefault;
|
||||
/**
|
||||
* 是否是Url歌曲
|
||||
*/
|
||||
public boolean isUrl;
|
||||
/**
|
||||
* 歌曲Url
|
||||
*/
|
||||
public String url;
|
||||
}
|
||||
@@ -19,9 +19,9 @@ public class MusicSearch {
|
||||
SearchPage search = AllMusic.getMusicApi().search(obj.args, obj.isDefault);
|
||||
if (search == null)
|
||||
AllMusic.side.sendMessaget(obj.sender, AllMusic.getMessage().Search
|
||||
.getCantSearch().replace("%Music%", obj.isDefault ? obj.args[0] : obj.args[1]));
|
||||
.CantSearch.replace("%Music%", obj.isDefault ? obj.args[0] : obj.args[1]));
|
||||
else {
|
||||
AllMusic.side.sendMessaget(obj.sender, AllMusic.getMessage().Search.getRes());
|
||||
AllMusic.side.sendMessaget(obj.sender, AllMusic.getMessage().Search.Res);
|
||||
AllMusic.addSearch(obj.name, search);
|
||||
AllMusic.side.runTask(() -> CommandEX.showSearch(obj.sender, search));
|
||||
}
|
||||
|
||||
@@ -10,15 +10,27 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PlayGo {
|
||||
/**
|
||||
* 倒数计数器
|
||||
*/
|
||||
private static int count = 0;
|
||||
private static boolean isRun;
|
||||
/**
|
||||
* 歌曲更新计数器
|
||||
*/
|
||||
private static int times = 0;
|
||||
/**
|
||||
* 播放链接
|
||||
*/
|
||||
public static String url;
|
||||
|
||||
private static ScheduledExecutorService service;
|
||||
private static ScheduledExecutorService service1;
|
||||
private static ScheduledExecutorService service2;
|
||||
|
||||
/**
|
||||
* 启动歌曲工作
|
||||
*/
|
||||
public static void start() {
|
||||
Thread taskT = new Thread(PlayGo::task, "AllMusic_Play");
|
||||
isRun = true;
|
||||
@@ -28,13 +40,16 @@ public class PlayGo {
|
||||
service2.scheduleAtFixedRate(PlayGo::time3, 0, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止歌曲工作
|
||||
*/
|
||||
public static void stop() {
|
||||
closeTimer();
|
||||
isRun = false;
|
||||
PlayMusic.musicLessTime = 0;
|
||||
}
|
||||
|
||||
public static void closeTimer() {
|
||||
private static void closeTimer() {
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
service = null;
|
||||
@@ -58,7 +73,10 @@ public class PlayGo {
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
/**
|
||||
* 清空歌曲数据
|
||||
*/
|
||||
private static void clear() {
|
||||
PlayMusic.musicNowTime = 0;
|
||||
PlayMusic.musicAllTime = 0;
|
||||
PlayMusic.musicLessTime = 0;
|
||||
@@ -108,7 +126,7 @@ public class PlayGo {
|
||||
HudUtils.sendHudLyricData(null);
|
||||
HudUtils.sendHudListData();
|
||||
if (AllMusic.side.needPlay()) {
|
||||
String ID = AllMusic.getMusicApi().ListMusic;
|
||||
String ID = AllMusic.getMusicApi().getListMusic();
|
||||
if (ID != null) {
|
||||
MusicObj obj = new MusicObj();
|
||||
obj.sender = ID;
|
||||
@@ -122,7 +140,7 @@ public class PlayGo {
|
||||
AllMusic.side.sendHudSaveAll();
|
||||
PlayMusic.nowPlayMusic = PlayMusic.remove(0);
|
||||
if (AllMusic.side.onMusicPlay(PlayMusic.nowPlayMusic)) {
|
||||
AllMusic.side.bqt(AllMusic.getMessage().MusicPlay.getCancel());
|
||||
AllMusic.side.bqt(AllMusic.getMessage().MusicPlay.Cancel);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -130,7 +148,7 @@ public class PlayGo {
|
||||
AllMusic.getMusicApi().getPlayUrl(PlayMusic.nowPlayMusic.getID()) :
|
||||
PlayMusic.nowPlayMusic.getPlayerUrl();
|
||||
if (url == null) {
|
||||
String data = AllMusic.getMessage().MusicPlay.getNoCanPlay();
|
||||
String data = AllMusic.getMessage().MusicPlay.NoCanPlay;
|
||||
AllMusic.side.bqt(data.replace("%MusicID%", PlayMusic.nowPlayMusic.getID()));
|
||||
continue;
|
||||
}
|
||||
@@ -142,14 +160,14 @@ public class PlayGo {
|
||||
|
||||
if (PlayMusic.nowPlayMusic.getLength() != 0) {
|
||||
PlayMusic.musicAllTime = PlayMusic.musicLessTime = (PlayMusic.nowPlayMusic.getLength() / 1000) + 3;
|
||||
if (!AllMusic.getConfig().isMutePlayMessage()) {
|
||||
if (!AllMusic.getConfig().MutePlayMessage) {
|
||||
String info = AllMusic.getMessage().MusicPlay.Play;
|
||||
info = info.replace("%MusicName%", PlayMusic.nowPlayMusic.getName())
|
||||
.replace("%MusicAuthor%", PlayMusic.nowPlayMusic.getAuthor())
|
||||
.replace("%MusicAl%", PlayMusic.nowPlayMusic.getAl())
|
||||
.replace("%MusicAlia%", PlayMusic.nowPlayMusic.getAlia())
|
||||
.replace("%PlayerName%", PlayMusic.nowPlayMusic.getCall());
|
||||
if (AllMusic.getConfig().isShowInBar())
|
||||
if (AllMusic.getConfig().ShowInBar)
|
||||
AllMusic.side.sendBar(info);
|
||||
else
|
||||
AllMusic.side.bqt(info);
|
||||
@@ -177,13 +195,13 @@ public class PlayGo {
|
||||
PlayMusic.voteTime--;
|
||||
if (PlayMusic.voteTime == 0) {
|
||||
AllMusic.clearVote();
|
||||
AllMusic.side.bqt(AllMusic.getMessage().Vote.getTimeOut());
|
||||
AllMusic.side.bqt(AllMusic.getMessage().Vote.TimeOut);
|
||||
} else {
|
||||
int players = AllMusic.side.getAllPlayer();
|
||||
if (AllMusic.getVoteCount() >= AllMusic.getConfig().getMinVote()
|
||||
|| (players <= AllMusic.getConfig().getMinVote()
|
||||
if (AllMusic.getVoteCount() >= AllMusic.getConfig().MinVote
|
||||
|| (players <= AllMusic.getConfig().MinVote
|
||||
&& players <= AllMusic.getVoteCount())) {
|
||||
AllMusic.side.bqt(AllMusic.getMessage().Vote.getDo());
|
||||
AllMusic.side.bqt(AllMusic.getMessage().Vote.Do);
|
||||
AllMusic.clearVote();
|
||||
PlayMusic.voteTime = 0;
|
||||
break;
|
||||
@@ -194,7 +212,7 @@ public class PlayGo {
|
||||
}
|
||||
AllMusic.side.sendStop();
|
||||
} else {
|
||||
String data = AllMusic.getMessage().MusicPlay.getNoCanPlay();
|
||||
String data = AllMusic.getMessage().MusicPlay.NoCanPlay;
|
||||
AllMusic.side.bqt(data.replace("%MusicID%", PlayMusic.nowPlayMusic.getID()));
|
||||
}
|
||||
clear();
|
||||
|
||||
@@ -19,31 +19,68 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class PlayMusic {
|
||||
|
||||
public static final List<SongInfo> playList = new CopyOnWriteArrayList<>();
|
||||
/**
|
||||
* 播放列表
|
||||
*/
|
||||
private static final List<SongInfo> playList = new CopyOnWriteArrayList<>();
|
||||
/**
|
||||
* 投票时间
|
||||
*/
|
||||
public static int voteTime = 0;
|
||||
/**
|
||||
* 总歌曲长度
|
||||
*/
|
||||
public static int musicAllTime = 0;
|
||||
/**
|
||||
* 剩余歌曲长度
|
||||
*/
|
||||
public static int musicLessTime = 0;
|
||||
/**
|
||||
* 歌曲现在位置
|
||||
*/
|
||||
public static int musicNowTime = 0;
|
||||
/**
|
||||
* 当前歌曲信息
|
||||
*/
|
||||
public static SongInfo nowPlayMusic;
|
||||
|
||||
/**
|
||||
* 当前歌词信息
|
||||
*/
|
||||
public static LyricSave lyric;
|
||||
/**
|
||||
* 当前歌词
|
||||
*/
|
||||
public static LyricItem lyricItem;
|
||||
/**
|
||||
* 错误次数
|
||||
*/
|
||||
public static int error;
|
||||
|
||||
private static boolean isRun;
|
||||
private static final Queue<MusicObj> tasks = new ConcurrentLinkedQueue<>();
|
||||
|
||||
/**
|
||||
* 停止歌曲逻辑
|
||||
*/
|
||||
public static void stop() {
|
||||
PlayMusic.clear();
|
||||
isRun = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始歌曲逻辑
|
||||
*/
|
||||
public static void start() {
|
||||
Thread addT = new Thread(PlayMusic::task, "AllMusic_list");
|
||||
isRun = true;
|
||||
addT.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加点歌任务
|
||||
* @param obj 歌曲
|
||||
*/
|
||||
public static void addTask(MusicObj obj) {
|
||||
tasks.add(obj);
|
||||
}
|
||||
@@ -67,11 +104,18 @@ public class PlayMusic {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加歌曲
|
||||
* @param sender 发送者
|
||||
* @param id 歌曲ID
|
||||
* @param player 用户名
|
||||
* @param isList 是否是空闲歌单
|
||||
*/
|
||||
public static void addMusic(Object sender, String id, String player, boolean isList) {
|
||||
if (isHave(id))
|
||||
return;
|
||||
if (sender != null) {
|
||||
String text = AllMusic.getMessage().MusicPlay.getCheckMusic();
|
||||
String text = AllMusic.getMessage().MusicPlay.CheckMusic;
|
||||
text = text.replace("%MusicID%", id);
|
||||
AllMusic.side.sendMessaget(sender, text);
|
||||
}
|
||||
@@ -80,29 +124,33 @@ public class PlayMusic {
|
||||
SongInfo info = AllMusic.getMusicApi().getMusic(id, player, isList);
|
||||
if (info == null) {
|
||||
if (sender != null) {
|
||||
String data = AllMusic.getMessage().MusicPlay.getNoCanPlay();
|
||||
String data = AllMusic.getMessage().MusicPlay.NoCanPlay;
|
||||
AllMusic.side.sendMessaget(sender, data.replace("%MusicID%", id));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (info.getLength() / 1000 > AllMusic.getConfig().getMaxMusicTime()) {
|
||||
AllMusic.side.sendMessaget(sender, AllMusic.getMessage().getAddMusic().getTimeOut());
|
||||
if (info.getLength() / 1000 > AllMusic.getConfig().MaxMusicTime) {
|
||||
AllMusic.side.sendMessaget(sender, AllMusic.getMessage().AddMusic.TimeOut);
|
||||
return;
|
||||
}
|
||||
playList.add(info);
|
||||
if (!AllMusic.getConfig().isMuteAddMessage()) {
|
||||
String data = AllMusic.getMessage().MusicPlay.getAddMusic();
|
||||
if (!AllMusic.getConfig().MuteAddMessage) {
|
||||
String data = AllMusic.getMessage().MusicPlay.AddMusic;
|
||||
data = data.replace("%MusicName%", info.getName())
|
||||
.replace("%MusicAuthor%", info.getAuthor())
|
||||
.replace("%MusicAl%", info.getAl())
|
||||
.replace("%MusicAlia%", info.getAlia());
|
||||
AllMusic.side.bqt(data);
|
||||
if (AllMusic.getConfig().ShowInBar) {
|
||||
AllMusic.side.sendBar(data);
|
||||
} else {
|
||||
AllMusic.side.bqt(data);
|
||||
}
|
||||
}
|
||||
if (AllMusic.getConfig().isPlayListSwitch()
|
||||
if (AllMusic.getConfig().PlayListSwitch
|
||||
&& (PlayMusic.nowPlayMusic != null && PlayMusic.nowPlayMusic.isList())) {
|
||||
PlayMusic.musicLessTime = 1;
|
||||
if (!isList)
|
||||
AllMusic.side.bqt(AllMusic.getMessage().MusicPlay.getSwitch());
|
||||
AllMusic.side.bqt(AllMusic.getMessage().MusicPlay.Switch);
|
||||
}
|
||||
error = 0;
|
||||
} catch (Exception e) {
|
||||
@@ -114,29 +162,49 @@ public class PlayMusic {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取播放列表长度
|
||||
* @return 长度
|
||||
*/
|
||||
public static int getSize() {
|
||||
return playList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前播放列表
|
||||
* @return 播放列表
|
||||
*/
|
||||
public static List<SongInfo> getList() {
|
||||
return new ArrayList<>(playList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理播放列表
|
||||
*/
|
||||
public static void clear() {
|
||||
playList.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从播放列表删除
|
||||
* @param index 标号
|
||||
* @return 结果
|
||||
*/
|
||||
public static SongInfo remove(int index) {
|
||||
return playList.remove(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取播放列表所有信息
|
||||
* @return 信息
|
||||
*/
|
||||
public static String getAllList() {
|
||||
StringBuilder list = new StringBuilder();
|
||||
String a;
|
||||
SongInfo info;
|
||||
for (int i = 0; i < playList.size(); i++) {
|
||||
info = playList.get(i);
|
||||
a = AllMusic.getMessage().MusicPlay.ListMusic.getItem();
|
||||
a = AllMusic.getMessage().MusicPlay.ListMusic.Item;
|
||||
a = a.replace("%index%", "" + (i + 1))
|
||||
.replace("%MusicName%", info.getName())
|
||||
.replace("%MusicAuthor%", info.getAuthor())
|
||||
@@ -150,19 +218,28 @@ public class PlayMusic {
|
||||
return temp.substring(0, temp.length() - 1);
|
||||
}
|
||||
|
||||
public static boolean isHave(String ID) {
|
||||
if (nowPlayMusic != null && nowPlayMusic.getID().equalsIgnoreCase(ID))
|
||||
/**
|
||||
* 是否在播放列表中
|
||||
* @param id 音乐ID
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isHave(String id) {
|
||||
if (nowPlayMusic != null && nowPlayMusic.getID().equalsIgnoreCase(id))
|
||||
return true;
|
||||
for (SongInfo item : playList) {
|
||||
if (item.getID().equalsIgnoreCase(ID))
|
||||
if (item.getID().equalsIgnoreCase(id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void addUrl(String arg) {
|
||||
/**
|
||||
* 添加Url歌曲
|
||||
* @param url 链接
|
||||
*/
|
||||
private static void addUrl(String url) {
|
||||
try {
|
||||
URL urlfile = new URL(arg);
|
||||
URL urlfile = new URL(url);
|
||||
URLConnection con = urlfile.openConnection();
|
||||
int b = con.getContentLength();// 得到音乐文件的总长度
|
||||
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
|
||||
@@ -174,7 +251,7 @@ public class PlayMusic {
|
||||
} else {
|
||||
le = (int) h.total_ms(b);
|
||||
}
|
||||
SongInfo info = new SongInfo(AllMusic.getMessage().getCustom().Info, arg, le);
|
||||
SongInfo info = new SongInfo(AllMusic.getMessage().Custom.Info, url, le);
|
||||
playList.add(info);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌曲信息解析错误");
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package coloryr.allmusic.music.search;
|
||||
|
||||
public class SearchOBJ {
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final String author;
|
||||
private final String al;
|
||||
public final String id;
|
||||
public final String name;
|
||||
public final String author;
|
||||
public final String al;
|
||||
|
||||
public SearchOBJ(String ID, String Name, String Author, String Al) {
|
||||
this.id = ID;
|
||||
@@ -12,20 +12,4 @@ public class SearchOBJ {
|
||||
this.author = Author;
|
||||
this.al = Al;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAl() {
|
||||
return al;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class SearchPage {
|
||||
}
|
||||
|
||||
public String getSong(int index) {
|
||||
return resData.get(index).getId();
|
||||
return resData.get(index).id;
|
||||
}
|
||||
|
||||
public SearchOBJ getRes(int a) {
|
||||
@@ -46,8 +46,4 @@ public class SearchPage {
|
||||
public boolean haveLastPage() {
|
||||
return page != 0;
|
||||
}
|
||||
|
||||
public int Page {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
@@ -202,8 +202,8 @@ public class SideBC implements ISide {
|
||||
@Override
|
||||
public void bq(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
&& data.length() > AllMusic.getConfig().MessageLimitSize) {
|
||||
data = data.substring(0, AllMusic.getConfig().MessageLimitSize - 1) + "...";
|
||||
}
|
||||
TextComponent message = new TextComponent(data);
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
|
||||
@@ -233,8 +233,8 @@ public class SideBukkit implements ISide {
|
||||
@Override
|
||||
public void bq(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
&& data.length() > AllMusic.getConfig().MessageLimitSize) {
|
||||
data = data.substring(0, AllMusic.getConfig().MessageLimitSize - 1) + "...";
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!AllMusic.getConfig().getNoMusicPlayer().contains(player.getName())) {
|
||||
@@ -246,8 +246,8 @@ public class SideBukkit implements ISide {
|
||||
@Override
|
||||
public void bqt(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
&& data.length() > AllMusic.getConfig().MessageLimitSize) {
|
||||
data = data.substring(0, AllMusic.getConfig().MessageLimitSize - 1) + "...";
|
||||
}
|
||||
String finalData = data;
|
||||
Bukkit.getScheduler().runTask(AllMusicBukkit.plugin, () -> {
|
||||
|
||||
@@ -47,8 +47,8 @@ public class SideVelocity implements ISide {
|
||||
@Override
|
||||
public void bq(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
&& data.length() > AllMusic.getConfig().MessageLimitSize) {
|
||||
data = data.substring(0, AllMusic.getConfig().MessageLimitSize - 1) + "...";
|
||||
}
|
||||
Component message = Component.text(data);
|
||||
for (RegisteredServer server : AllMusicVelocity.plugin.server.getAllServers()) {
|
||||
|
||||
Reference in new issue
Block a user