mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-25 05:14:22 +00:00
歌词渲染更新
This commit is contained in:
1 parent
316562a21e
commit
834eedc120
51 files changed
+1110
-1292
No files matched your search
@@ -11,10 +11,14 @@
|
||||
|
||||
</div>
|
||||
|
||||
**不提供任何技术支持**
|
||||
**AllMusic 4.0制作中**
|
||||
暂时设想
|
||||
|
||||
**This project only can use in china main land**
|
||||
**Chinese only**
|
||||
- 圆形图片渲染将分为3层 底层 圆形图片覆盖层 顶层,例如底层放唱片机,覆盖层放唱片覆盖,让其看起来像唱片,顶层指针唱片
|
||||
- 播放进度条3张图片 未播放 指针 已播放
|
||||
- 字体过长滚动,例如信息设置最大值后横向滚动,待播放列表纵向滚动,然后每一待播放显示一段时间
|
||||
- 删除音乐API,需要自己另外装
|
||||
- 删除sqlite,改用文件存储数据
|
||||
|
||||

|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ object Versions {
|
||||
const val httpcore5 = "5.4.2"
|
||||
const val httpcore5_h2 = "5.4.2"
|
||||
const val gson = "2.14.0"
|
||||
const val sqlite = "3.53.1.0"
|
||||
const val minimessage = "4.26.1"
|
||||
const val adventure = "4.8.1"
|
||||
}
|
||||
+1
-1
Submodule client updated: 6bedff2e4c...ecbf61ffdc.
@@ -8,10 +8,12 @@ import com.coloryr.allmusic.server.core.objs.CookieObj;
|
||||
import com.coloryr.allmusic.server.core.objs.config.ConfigObj;
|
||||
import com.coloryr.allmusic.server.core.objs.message.MessageObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.MusicListSave;
|
||||
import com.coloryr.allmusic.server.core.saves.SaveTask;
|
||||
import com.coloryr.allmusic.server.core.side.BaseSide;
|
||||
import com.coloryr.allmusic.server.core.side.IAllMusicLogger;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.sql.IEconomy;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.utils.StringReplacer;
|
||||
import com.coloryr.allmusic.server.netapi.NetiApiMain;
|
||||
import com.google.gson.Gson;
|
||||
@@ -137,12 +139,11 @@ public class AllMusic {
|
||||
*/
|
||||
public static boolean isSkip(String name, String server, boolean checkPlay) {
|
||||
try {
|
||||
name = name.toLowerCase();
|
||||
if (server != null && AllMusic.getConfig().muteServer.contains(server))
|
||||
if (server != null && BanSave.haveBanServer(server))
|
||||
return true;
|
||||
if (DataSql.checkMutePlayer(name))
|
||||
if (BanSave.checkMutePlayer(name))
|
||||
return true;
|
||||
if (PlayMusic.nowPlayMusic != null && PlayMusic.nowPlayMusic.isList() && DataSql.checkMuteListPlayer(name))
|
||||
if (PlayMusic.nowPlayMusic != null && PlayMusic.nowPlayMusic.isList() && BanSave.checkMuteListPlayer(name))
|
||||
return true;
|
||||
if (!checkPlay)
|
||||
return false;
|
||||
@@ -164,11 +165,11 @@ public class AllMusic {
|
||||
public static boolean isSkip(String name, String server, boolean checkPlay, boolean islist) {
|
||||
try {
|
||||
name = name.toLowerCase();
|
||||
if (server != null && AllMusic.getConfig().muteServer.contains(server))
|
||||
if (server != null && BanSave.haveBanServer(server))
|
||||
return true;
|
||||
if (DataSql.checkMutePlayer(name))
|
||||
if (BanSave.checkMutePlayer(name))
|
||||
return true;
|
||||
if (islist && DataSql.checkMuteListPlayer(name))
|
||||
if (islist && BanSave.checkMuteListPlayer(name))
|
||||
return true;
|
||||
if (!checkPlay)
|
||||
return false;
|
||||
@@ -217,7 +218,7 @@ public class AllMusic {
|
||||
write.close();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
log.data("<light_purple>[AllMusic3]<red>配置文件保存错误");
|
||||
log.data("<light_purple>[AllMusic3]<red>配置文件config.json保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -232,7 +233,7 @@ public class AllMusic {
|
||||
write.close();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
log.data("<light_purple>[AllMusic3]<red>配置文件保存错误");
|
||||
log.data("<light_purple>[AllMusic3]<red>配置文件message.json保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -249,7 +250,7 @@ public class AllMusic {
|
||||
write.write(data);
|
||||
write.close();
|
||||
} catch (Exception e) {
|
||||
log.data("<light_purple>[AllMusic3]<red>配置文件保存错误");
|
||||
log.data("<light_purple>[AllMusic3]<red>配置文件cookie.json保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -268,7 +269,7 @@ public class AllMusic {
|
||||
PlayMusic.start();
|
||||
PlayRuntime.start();
|
||||
MusicSearch.start();
|
||||
DataSql.start();
|
||||
SaveTask.start();
|
||||
|
||||
log.data("<light_purple>[AllMusic3]<yellow>已启动-" + version);
|
||||
}
|
||||
@@ -279,7 +280,7 @@ public class AllMusic {
|
||||
public static void stop() {
|
||||
isRun = false;
|
||||
PlayRuntime.stop();
|
||||
DataSql.stop();
|
||||
SaveTask.stop();
|
||||
side.sendStop();
|
||||
log.data("<light_purple>[AllMusic3]<dark_green><yellow>已停止,感谢使用");
|
||||
}
|
||||
@@ -336,6 +337,10 @@ public class AllMusic {
|
||||
replacer.put(item.getKey(), item.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
BanSave.loadBan();
|
||||
HudSave.loadHud();
|
||||
MusicListSave.loadMusic();
|
||||
} catch (Exception e) {
|
||||
log.data("<light_purple>[AllMusic3]<red>读取配置文件错误");
|
||||
e.printStackTrace();
|
||||
@@ -352,17 +357,17 @@ public class AllMusic {
|
||||
}
|
||||
|
||||
public static void joinPlayNow(String player) {
|
||||
DataSql.task(() -> {
|
||||
SaveTask.task(() -> {
|
||||
String player1 = player.toLowerCase();
|
||||
Object player2 = AllMusic.side.getPlayer(player1);
|
||||
String server = AllMusic.side.getPlayerServer(player2);
|
||||
if (server != null && AllMusic.getConfig().muteServer.contains(server)) {
|
||||
if (server != null && BanSave.haveBanServer(server)) {
|
||||
return;
|
||||
}
|
||||
if (DataSql.checkMutePlayer(player1)) {
|
||||
if (BanSave.checkMutePlayer(player1)) {
|
||||
return;
|
||||
}
|
||||
if (DataSql.checkMuteListPlayer(player1)) {
|
||||
if (BanSave.checkMuteListPlayer(player1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -403,14 +408,9 @@ public class AllMusic {
|
||||
try {
|
||||
if (!file.exists())
|
||||
file.mkdir();
|
||||
if (configFile == null)
|
||||
configFile = new File(file, "config.json");
|
||||
if (messageFile == null)
|
||||
messageFile = new File(file, "message.json");
|
||||
if (cookieFile == null)
|
||||
cookieFile = new File(file, "cookie.json");
|
||||
if (DataSql.sqlFile == null)
|
||||
DataSql.sqlFile = new File(file, "data.db");
|
||||
configFile = new File(file, "config.json");
|
||||
messageFile = new File(file, "message.json");
|
||||
cookieFile = new File(file, "cookie.json");
|
||||
if (!configFile.exists()) {
|
||||
configFile.createNewFile();
|
||||
}
|
||||
@@ -420,6 +420,11 @@ public class AllMusic {
|
||||
if (!cookieFile.exists()) {
|
||||
cookieFile.createNewFile();
|
||||
}
|
||||
|
||||
BanSave.init(file);
|
||||
HudSave.init(file);
|
||||
MusicListSave.init(file);
|
||||
|
||||
loadConfig();
|
||||
isRun = true;
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.coloryr.allmusic.server.core;
|
||||
|
||||
import com.coloryr.allmusic.codec.HudPosObj;
|
||||
import com.coloryr.allmusic.codec.HudType;
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.utils.HudUtils;
|
||||
|
||||
public class AllMusicApi {
|
||||
@@ -57,6 +59,16 @@ public class AllMusicApi {
|
||||
AllMusic.side.sendHud(name, pos, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新玩家Hud歌词
|
||||
*
|
||||
* @param name 用户名
|
||||
* @param pack 位置
|
||||
*/
|
||||
public static void sendLyric(String name, MusicPack.LyricMusicPack pack) {
|
||||
AllMusic.side.sendLyric(name, pack);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送图片
|
||||
*
|
||||
@@ -77,13 +89,13 @@ public class AllMusicApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取玩家Hud信息,这个操作会读取数据库,首次读取会有一点卡
|
||||
* 获取玩家Hud信息
|
||||
*
|
||||
* @param player 玩家
|
||||
* @return Hud信息
|
||||
*/
|
||||
public static HudPosObj getHud(String player) {
|
||||
return HudUtils.get(player);
|
||||
return HudSave.getOrNew(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,6 +105,6 @@ public class AllMusicApi {
|
||||
* @param hud Hud信息
|
||||
*/
|
||||
public static void setHud(String player, HudPosObj hud) {
|
||||
HudUtils.set(player, hud);
|
||||
HudSave.update(player, hud);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.coloryr.allmusic.server.core.sql;
|
||||
package com.coloryr.allmusic.server.core;
|
||||
|
||||
public interface IEconomy {
|
||||
/**
|
||||
@@ -7,7 +7,9 @@ import com.coloryr.allmusic.server.core.music.MusicSearch;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.saves.SaveTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -179,13 +181,13 @@ public class CommandEX {
|
||||
if (api1.checkId(musicID)) {
|
||||
if (PlayMusic.getListSize() >= AllMusic.getConfig().maxPlayList) {
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.listFull);
|
||||
} else if (DataSql.checkBanMusic(musicID)) {
|
||||
} else if (BanSave.checkBanMusic(musicID, api)) {
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.banMusic);
|
||||
} else if (PlayMusic.haveMusic(musicID, api)) {
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.existMusic);
|
||||
} else if (PlayMusic.isPlayerMax(name)) {
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.playerToMany);
|
||||
} else if (DataSql.checkBanPlayer(name)) {
|
||||
} else if (BanSave.checkBanPlayer(name)) {
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.playerBan);
|
||||
} else {
|
||||
if (checkMoney(sender, name, AllMusic.getConfig().cost.addMusicCost)) {
|
||||
@@ -195,7 +197,7 @@ public class CommandEX {
|
||||
AllMusic.getMessage().cost.addMusic)) {
|
||||
return;
|
||||
}
|
||||
DataSql.removeMutePlayer(name);
|
||||
BanSave.removeMutePlayer(name);
|
||||
if (AllMusic.side.needPlay(false)) {
|
||||
PlayerAddMusicObj obj = new PlayerAddMusicObj();
|
||||
obj.sender = sender;
|
||||
@@ -264,9 +266,9 @@ public class CommandEX {
|
||||
case 0:
|
||||
default:
|
||||
if (args.length == 1) {
|
||||
DataSql.task(() -> addMusic(sender, name, AllMusic.getConfig().defaultApi, args[0]));
|
||||
SaveTask.task(() -> addMusic(sender, name, AllMusic.getConfig().defaultApi, args[0]));
|
||||
} else if (args.length == 2) {
|
||||
DataSql.task(() -> addMusic(sender, name, args[0], args[1]));
|
||||
SaveTask.task(() -> addMusic(sender, name, args[0], args[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -5,7 +5,8 @@ import com.coloryr.allmusic.server.core.IMusicApi;
|
||||
import com.coloryr.allmusic.server.core.command.ACommand;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -38,7 +39,7 @@ public class CommandBan extends ACommand {
|
||||
}
|
||||
|
||||
if (api.checkId(musicID)) {
|
||||
DataSql.addBanMusic(musicID, api.getId());
|
||||
BanSave.addBanMusic(musicID, api.getId());
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>音乐API " + api.getId() + " 已禁止点歌" + musicID);
|
||||
} else {
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>请输入有效的ID");
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@ package com.coloryr.allmusic.server.core.command.sub;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.command.ICommand;
|
||||
import com.coloryr.allmusic.server.core.sql.Cache;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -16,7 +16,7 @@ public class CommandBanPlayer implements ICommand {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
}
|
||||
DataSql.addBanPlayer(args[1]);
|
||||
BanSave.addBanPlayer(args[1]);
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>已禁止玩家" + args[1] + "点歌");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CommandBanPlayer implements ICommand {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Object item : AllMusic.side.getPlayers()) {
|
||||
String name1 = AllMusic.side.getPlayerName(item);
|
||||
if (name1 != null && !Cache.haveBan(name1)) {
|
||||
if (name1 != null && !BanSave.haveBanPlayer(name1)) {
|
||||
list.add(name1);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,12 +2,13 @@ package com.coloryr.allmusic.server.core.command.sub;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.command.ACommand;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
public class CommandClearBanList extends ACommand {
|
||||
@Override
|
||||
public void execute(Object sender, String name, String[] args) {
|
||||
DataSql.clearBan();
|
||||
BanSave.clearBan();
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>禁止点歌列表已清空");
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -2,12 +2,13 @@ package com.coloryr.allmusic.server.core.command.sub;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.command.ACommand;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
public class CommandClearBanPlayerList extends ACommand {
|
||||
@Override
|
||||
public void execute(Object sender, String name, String[] args) {
|
||||
DataSql.clearBanPlayer();
|
||||
BanSave.clearBanPlayer();
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>禁止玩家点歌列表已清空");
|
||||
}
|
||||
}
|
||||
+2
@@ -50,6 +50,8 @@ public class CommandHelp extends ACommand {
|
||||
.append(AllMusic.miniMessageSuggest(AllMusic.getMessage().click.clickCheck, "/music hud ")));
|
||||
AllMusic.side.sendMessage(sender, AllMusic.miniMessage(AllMusic.getMessage().help.normal.hud8)
|
||||
.append(AllMusic.miniMessageSuggest(AllMusic.getMessage().click.clickCheck, "/music hud ")));
|
||||
AllMusic.side.sendMessage(sender, AllMusic.miniMessage(AllMusic.getMessage().help.normal.hud11)
|
||||
.append(AllMusic.miniMessageSuggest(AllMusic.getMessage().click.clickCheck, "/music hud ")));
|
||||
AllMusic.side.sendMessage(sender, AllMusic.miniMessage(AllMusic.getMessage().help.normal.hud3)
|
||||
.append(AllMusic.miniMessageSuggest(AllMusic.getMessage().click.clickCheck, "/music hud pic size ")));
|
||||
AllMusic.side.sendMessage(sender, AllMusic.miniMessage(AllMusic.getMessage().help.normal.hud4)
|
||||
|
||||
+37
-5
@@ -1,6 +1,7 @@
|
||||
package com.coloryr.allmusic.server.core.command.sub;
|
||||
|
||||
import com.coloryr.allmusic.codec.HudDirType;
|
||||
import com.coloryr.allmusic.codec.HudBasePosObj;
|
||||
import com.coloryr.allmusic.codec.HudPosType;
|
||||
import com.coloryr.allmusic.codec.HudItemPosObj;
|
||||
import com.coloryr.allmusic.codec.HudType;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
@@ -52,6 +53,7 @@ public class CommandHudSet extends AHudCommand {
|
||||
} else {
|
||||
commandList.put("color", new HudColor(type));
|
||||
commandList.put("shadow", new HudShadow(type));
|
||||
commandList.put("loop", new HudLoop(type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +144,7 @@ public class CommandHudSet extends AHudCommand {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
}
|
||||
HudItemPosObj obj = HudUtils.setHudPos(name, type, args[3], args[4]);
|
||||
HudBasePosObj obj = HudUtils.setHudPos(name, type, args[3], args[4]);
|
||||
if (obj == null) {
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
@@ -170,7 +172,7 @@ public class CommandHudSet extends AHudCommand {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
}
|
||||
HudItemPosObj obj = HudUtils.setHudAlpha(name, type, args[3]);
|
||||
HudBasePosObj obj = HudUtils.setHudAlpha(name, type, args[3]);
|
||||
if (obj == null) {
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
@@ -187,7 +189,7 @@ public class CommandHudSet extends AHudCommand {
|
||||
|
||||
private static class HudDir extends AHudCommand {
|
||||
private static final List<String> dir = new ArrayList<String>() {{
|
||||
for (HudDirType type : HudDirType.values()) {
|
||||
for (HudPosType type : HudPosType.values()) {
|
||||
this.add(type.name());
|
||||
}
|
||||
}};
|
||||
@@ -202,7 +204,7 @@ public class CommandHudSet extends AHudCommand {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
}
|
||||
HudDirType type1 = HudUtils.setDir(name, type, args[3]);
|
||||
HudPosType type1 = HudUtils.setPos(name, type, args[3]);
|
||||
if (type1 == null) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
@@ -270,6 +272,36 @@ public class CommandHudSet extends AHudCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private static class HudLoop extends AHudCommand {
|
||||
public HudLoop(HudType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Object sender, String name, String[] args) {
|
||||
if (args.length != 4) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
}
|
||||
String loop = HudUtils.setLoop(name, type, args[3]);
|
||||
if (loop == null) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
}
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().hud.set2
|
||||
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type))
|
||||
.replace(ARG.color, loop));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tab(Object player, String name, String[] args, int index) {
|
||||
if (args.length == index + 1) {
|
||||
return tf;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private static class PicSize extends ACommand {
|
||||
@Override
|
||||
public void execute(Object sender, String name, String[] args) {
|
||||
|
||||
+32
-42
@@ -4,7 +4,9 @@ import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.command.ACommand;
|
||||
import com.coloryr.allmusic.server.core.command.CommandEX;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.saves.SaveTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,51 +16,39 @@ public class CommandMute extends ACommand {
|
||||
public void execute(Object sender, String name, String[] args) {
|
||||
if (args.length == 2) {
|
||||
if (args[1].equalsIgnoreCase("list")) {
|
||||
DataSql.task(() -> {
|
||||
if (DataSql.checkMuteListPlayer(name)) {
|
||||
DataSql.removeMuteListPlayer(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute2);
|
||||
} else {
|
||||
DataSql.addMuteListPlayer(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute1);
|
||||
if (PlayMusic.nowPlayMusic != null && PlayMusic.nowPlayMusic.isList()) {
|
||||
AllMusic.side.runTask(() -> {
|
||||
AllMusic.side.sendStop(name);
|
||||
AllMusic.side.clearHud(name);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (CommandEX.checkAdmin(sender, name)) {
|
||||
String finalName = args[1];
|
||||
DataSql.task(() -> {
|
||||
if (DataSql.checkMutePlayer(finalName)) {
|
||||
DataSql.removeMutePlayer(finalName);
|
||||
AllMusic.side.sendMessage(sender, "已取消玩家:" + finalName + "的静音");
|
||||
} else {
|
||||
DataSql.addMutePlayer(finalName);
|
||||
AllMusic.side.runTask(() -> {
|
||||
AllMusic.side.sendStop(finalName);
|
||||
AllMusic.side.clearHud(finalName);
|
||||
AllMusic.side.sendMessage(sender, "已设置玩家:" + finalName + "的静音");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
DataSql.task(() -> {
|
||||
if (DataSql.checkMutePlayer(name)) {
|
||||
DataSql.removeMutePlayer(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute3);
|
||||
if (BanSave.checkMuteListPlayer(name)) {
|
||||
BanSave.removeMuteListPlayer(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute2);
|
||||
} else {
|
||||
DataSql.addMutePlayer(name);
|
||||
AllMusic.side.runTask(() -> {
|
||||
BanSave.addMuteListPlayer(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute1);
|
||||
if (PlayMusic.nowPlayMusic != null && PlayMusic.nowPlayMusic.isList()) {
|
||||
AllMusic.side.sendStop(name);
|
||||
AllMusic.side.clearHud(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (CommandEX.checkAdmin(sender, name)) {
|
||||
String finalName = args[1];
|
||||
if (BanSave.checkMutePlayer(finalName)) {
|
||||
BanSave.removeMutePlayer(finalName);
|
||||
AllMusic.side.sendMessage(sender, "已取消玩家:" + finalName + "的静音");
|
||||
} else {
|
||||
BanSave.addMutePlayer(finalName);
|
||||
AllMusic.side.sendStop(finalName);
|
||||
AllMusic.side.clearHud(finalName);
|
||||
AllMusic.side.sendMessage(sender, "已设置玩家:" + finalName + "的静音");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (BanSave.checkMutePlayer(name)) {
|
||||
BanSave.removeMutePlayer(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute3);
|
||||
} else {
|
||||
BanSave.addMutePlayer(name);
|
||||
AllMusic.side.sendStop(name);
|
||||
AllMusic.side.clearHud(name);
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -3,7 +3,8 @@ package com.coloryr.allmusic.server.core.command.sub;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.command.ACommand;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
public class CommandNext extends ACommand {
|
||||
|
||||
@@ -11,6 +12,6 @@ public class CommandNext extends ACommand {
|
||||
public void execute(Object sender, String name, String[] args) {
|
||||
PlayMusic.musicLessTime = 1;
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>已强制切歌");
|
||||
DataSql.removeMutePlayer(name);
|
||||
BanSave.removeMutePlayer(name);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -7,7 +7,8 @@ import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.music.PlayRuntime;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -98,7 +99,7 @@ public class CommandPush extends ACommand {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.arAgree);
|
||||
}
|
||||
}
|
||||
DataSql.removeMutePlayer(name);
|
||||
BanSave.removeMutePlayer(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -7,7 +7,8 @@ import com.coloryr.allmusic.server.core.command.PermissionList;
|
||||
import com.coloryr.allmusic.server.core.music.MusicSearch;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SearchPageObj;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.saves.SaveTask;
|
||||
import com.coloryr.allmusic.server.core.utils.Function;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,7 +35,7 @@ public class CommandSelect extends ACommand {
|
||||
String id = obj.getSong((obj.getPage() * 10) + (a - 1));
|
||||
AllMusic.side.sendMessage(sender,
|
||||
AllMusic.getMessage().search.choice.replace(ARG.index, "" + a));
|
||||
DataSql.task(() -> CommandEX.addMusic(sender, name, obj.getApi(), id));
|
||||
SaveTask.task(() -> CommandEX.addMusic(sender, name, obj.getApi(), id));
|
||||
MusicSearch.removeSearch(name);
|
||||
} else {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.errorNum);
|
||||
|
||||
+3
-12
@@ -3,8 +3,8 @@ package com.coloryr.allmusic.server.core.command.sub;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.IMusicApi;
|
||||
import com.coloryr.allmusic.server.core.command.ACommand;
|
||||
import com.coloryr.allmusic.server.core.sql.Cache;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -40,19 +40,10 @@ public class CommandUnban extends ACommand {
|
||||
|
||||
if (api.checkId(musicID)) {
|
||||
api.setList(musicID, sender);
|
||||
DataSql.removeBanMusic(args[1]);
|
||||
BanSave.removeBanMusic(args[1], api.getId());
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>音乐API " + api.getId() + "已解封点歌" + musicID);
|
||||
} else {
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>请输入有效的ID");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tab(Object player, String name, String[] args, int index) {
|
||||
if (args.length == index || (args.length == index + 1)) {
|
||||
return new ArrayList<>(Cache.banMusic);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -2,8 +2,8 @@ package com.coloryr.allmusic.server.core.command.sub;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.command.ICommand;
|
||||
import com.coloryr.allmusic.server.core.sql.Cache;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -16,14 +16,14 @@ public class CommandUnbanPlayer implements ICommand {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
||||
return;
|
||||
}
|
||||
DataSql.removeBanPlayer(args[1]);
|
||||
BanSave.removeBanPlayer(args[1]);
|
||||
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>已解封玩家" + args[1] + "点歌");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tab(Object player, String name, String[] args, int index) {
|
||||
if (args.length == index || (args.length == index + 1)) {
|
||||
return new ArrayList<>(Cache.banPlayers);
|
||||
return new ArrayList<>(BanSave.getBanPlayers());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
|
||||
+3
-2
@@ -6,7 +6,8 @@ import com.coloryr.allmusic.server.core.command.PermissionList;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.music.PlayRuntime;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
public class CommandVote extends ACommand {
|
||||
@Override
|
||||
@@ -60,6 +61,6 @@ public class CommandVote extends ACommand {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().vote.arAgree);
|
||||
}
|
||||
}
|
||||
DataSql.removeMutePlayer(name);
|
||||
BanSave.removeMutePlayer(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.coloryr.allmusic.server.core.music;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KtvLyric {
|
||||
public List<KtvItem> items = new ArrayList<>();
|
||||
public long start;
|
||||
public long time;
|
||||
|
||||
public static class KtvItem {
|
||||
public long time;
|
||||
public long start;
|
||||
public String key;
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,23 @@ package com.coloryr.allmusic.server.core.music;
|
||||
import com.coloryr.allmusic.server.core.objs.music.LyricItemObj;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class LyricSave {
|
||||
public int lastIndex = 0;
|
||||
protected boolean haveLyric;
|
||||
protected String lly = "";
|
||||
protected String kly = "";
|
||||
protected String tly = "";
|
||||
protected float kly = 0;
|
||||
protected LyricItemObj now;
|
||||
private Map<Long, LyricItemObj> lyric;
|
||||
private Map<Long, String> klyric;
|
||||
private LyricItemObj now;
|
||||
private long last;
|
||||
private String kNow;
|
||||
private Map<Long, KtvLyric> klyric;
|
||||
private KtvLyric ktvNow;
|
||||
|
||||
public LyricSave() {
|
||||
haveLyric = false;
|
||||
lyric = new HashMap<>();
|
||||
}
|
||||
|
||||
public void setKlyric(Map<Long, String> klyric) {
|
||||
public void setKlyric(Map<Long, KtvLyric> klyric) {
|
||||
this.klyric = klyric;
|
||||
}
|
||||
|
||||
@@ -36,7 +32,7 @@ public class LyricSave {
|
||||
}
|
||||
|
||||
public String getLyric() {
|
||||
return lly;
|
||||
return now.lyric;
|
||||
}
|
||||
|
||||
public void setLyric(Map<Long, LyricItemObj> lyric) {
|
||||
@@ -44,69 +40,76 @@ public class LyricSave {
|
||||
}
|
||||
|
||||
public String getTlyric() {
|
||||
return tly;
|
||||
return now.tlyric;
|
||||
}
|
||||
|
||||
public String getKly() {
|
||||
public float getKly() {
|
||||
return kly;
|
||||
}
|
||||
|
||||
public boolean kUpdate() {
|
||||
if (lastIndex >= now.lyric.length()) {
|
||||
kly = now.lyric;
|
||||
lly = "";
|
||||
} else if (kNow != null) {
|
||||
int index = now.lyric.toLowerCase(Locale.ROOT).indexOf(kNow, lastIndex);
|
||||
if (index != -1) {
|
||||
lastIndex = index + kNow.length();
|
||||
public void kUpdate(long playNow) {
|
||||
if (now == null || now.lyric == null || now.lyric.isEmpty()
|
||||
|| ktvNow == null || ktvNow.items == null || ktvNow.items.isEmpty()) {
|
||||
kly = 0.0f;
|
||||
}
|
||||
|
||||
kly = now.lyric.substring(0, lastIndex);
|
||||
lly = now.lyric.substring(lastIndex);
|
||||
return true;
|
||||
// 查找当前时间落在哪个 KTV 字的时间段内
|
||||
for (int i = 0; i < ktvNow.items.size(); i++) {
|
||||
KtvLyric.KtvItem item = ktvNow.items.get(i);
|
||||
if (playNow >= item.start && playNow < item.start + item.time) {
|
||||
// 当前字内的进度
|
||||
float progressInChar = (float) (playNow - item.start) / item.time;
|
||||
// 整体进度 = (已完成的字 + 当前字的进度) / 总字数
|
||||
kly = (i + progressInChar) / ktvNow.items.size();
|
||||
lastIndex = i; // 记录当前字索引,可选
|
||||
}
|
||||
} else {
|
||||
kly = "";
|
||||
}
|
||||
|
||||
return false;
|
||||
// 如果时间超过了最后一个字
|
||||
if (playNow >= ktvNow.start + ktvNow.time) {
|
||||
kly = 1.0f;
|
||||
lastIndex = ktvNow.items.size();
|
||||
}
|
||||
|
||||
// 还没到第一个字的时间
|
||||
kly = 0.0f;
|
||||
lastIndex = 0;
|
||||
}
|
||||
|
||||
public boolean ktv(long time) {
|
||||
if (last == time || klyric == null)
|
||||
return false;
|
||||
private void ktvGetNext(long time) {
|
||||
if (klyric == null)
|
||||
return;
|
||||
|
||||
String temp = klyric.get(time);
|
||||
KtvLyric temp = klyric.get(time);
|
||||
if (temp != null) {
|
||||
kNow = temp.toLowerCase(Locale.ROOT);
|
||||
last = time;
|
||||
return kUpdate();
|
||||
ktvNow = temp;
|
||||
}
|
||||
|
||||
return false;
|
||||
kUpdate(time);
|
||||
}
|
||||
|
||||
public boolean checkTime(long playNow, boolean ktv) {
|
||||
public boolean lyricGetNext(long playNow) {
|
||||
if (lyric == null)
|
||||
return false;
|
||||
|
||||
boolean res = false;
|
||||
LyricItemObj temp = lyric.get(playNow);
|
||||
if (temp != null) {
|
||||
now = temp;
|
||||
lly = now.lyric;
|
||||
tly = now.tlyric;
|
||||
if (tly == null)
|
||||
tly = "";
|
||||
kly = null;
|
||||
if (temp != null && now != temp) {
|
||||
now = temp.copy();
|
||||
if (now.tlyric == null) {
|
||||
now.tlyric = "";
|
||||
}
|
||||
kly = 0.0f;
|
||||
lastIndex = 0;
|
||||
kUpdate();
|
||||
ktvGetNext(playNow);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ktv && now != null) {
|
||||
res = ktv(playNow);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return res;
|
||||
public void updateKtv(long playNow) {
|
||||
if (now != null) {
|
||||
kUpdate(playNow);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,8 @@ import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.saves.MusicListSave;
|
||||
import com.coloryr.allmusic.server.core.utils.HudUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -454,11 +455,11 @@ public class PlayMusic {
|
||||
|
||||
public static void clearIdleList() {
|
||||
deep.clear();
|
||||
DataSql.clearIdleList();
|
||||
MusicListSave.clearIdleList();
|
||||
}
|
||||
|
||||
public static int getIdleListSize() {
|
||||
return DataSql.getListSize();
|
||||
return MusicListSave.getListSize();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -483,12 +484,12 @@ public class PlayMusic {
|
||||
*/
|
||||
public static MusicObj getIdleMusic() {
|
||||
MusicObj music;
|
||||
int len = DataSql.getListSize();
|
||||
int len = MusicListSave.getListSize();
|
||||
if (len == 0)
|
||||
return null;
|
||||
if (AllMusic.getConfig().playListRandom) {
|
||||
if (len == 1)
|
||||
return DataSql.readListItem();
|
||||
return MusicListSave.readListItem();
|
||||
if (len > 10) {
|
||||
int size = AllMusic.getConfig().playListEscapeDeep;
|
||||
if (size > len / 2) {
|
||||
@@ -498,15 +499,15 @@ public class PlayMusic {
|
||||
deep.poll();
|
||||
}
|
||||
do {
|
||||
music = DataSql.readListItem();
|
||||
music = MusicListSave.readListItem();
|
||||
}
|
||||
while (checkDeep(music));
|
||||
deep.add(music);
|
||||
} else {
|
||||
music = DataSql.readListItem();
|
||||
music = MusicListSave.readListItem();
|
||||
}
|
||||
} else {
|
||||
music = DataSql.readListItem(idleIndex);
|
||||
music = MusicListSave.readListItem(idleIndex);
|
||||
idleIndex++;
|
||||
if (idleIndex >= len) {
|
||||
idleIndex = 0;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PlayRuntime {
|
||||
/**
|
||||
* 歌曲更新计数器
|
||||
*/
|
||||
private static int times = 0;
|
||||
private static long times = 0;
|
||||
/**
|
||||
* 歌曲定时器
|
||||
*/
|
||||
@@ -77,6 +77,7 @@ public class PlayRuntime {
|
||||
HudUtils.sendHudListData();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 歌曲时间定时器
|
||||
*/
|
||||
@@ -94,17 +95,17 @@ public class PlayRuntime {
|
||||
try {
|
||||
if (PlayMusic.lyric == null)
|
||||
return;
|
||||
boolean res = PlayMusic.lyric.checkTime(PlayMusic.musicNowTime, AllMusic.getConfig().ktvMode);
|
||||
boolean res = PlayMusic.lyric.lyricGetNext(PlayMusic.musicNowTime);
|
||||
if (res) {
|
||||
times = 0;
|
||||
HudUtils.sendHudLyricData();
|
||||
AllMusic.side.updateLyric();
|
||||
} else {
|
||||
times++;
|
||||
if (times == AllMusic.getConfig().sendDelay / 2 && PlayMusic.lyric != null) {
|
||||
times = 0;
|
||||
HudUtils.sendHudLyricData();
|
||||
AllMusic.side.updateLyric();
|
||||
}
|
||||
|
||||
if (AllMusic.getConfig().ktvMode) {
|
||||
PlayMusic.lyric.updateKtv(PlayMusic.musicNowTime);
|
||||
if ((PlayMusic.musicNowTime - times) > AllMusic.getConfig().ktvSendDelay) {
|
||||
times = PlayMusic.musicNowTime;
|
||||
HudUtils.sendHudKtv();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
|
||||
package com.coloryr.allmusic.server.core.music;
|
||||
|
||||
import com.coloryr.allmusic.server.core.objs.music.LyricItemObj;
|
||||
|
||||
public class TopLyricSave extends LyricSave {
|
||||
|
||||
public void setTlyric(String data) {
|
||||
tly = data;
|
||||
if (now == null) {
|
||||
now = new LyricItemObj(data, "");
|
||||
}
|
||||
now.lyric = data;
|
||||
}
|
||||
|
||||
public void setLyric(String data) {
|
||||
lly = data;
|
||||
if (now == null) {
|
||||
now = new LyricItemObj("", data);
|
||||
}
|
||||
now.lyric = data;
|
||||
}
|
||||
|
||||
public void setKly(String data) {
|
||||
public void setKly(float data) {
|
||||
kly = data;
|
||||
}
|
||||
|
||||
public void setHaveK(boolean data) {
|
||||
if (!data) {
|
||||
kly = null;
|
||||
kly = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setHaveT(boolean data) {
|
||||
if (!data) {
|
||||
tly = null;
|
||||
now = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.coloryr.allmusic.server.core.objs.config;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BanObj {
|
||||
public Set<String> banPlayers;
|
||||
public Set<String> banServer;
|
||||
public Set<String> mutePlayers;
|
||||
public Set<String> muteListPlayers;
|
||||
public Map<String, List<String>> banMusics;
|
||||
|
||||
public boolean check() {
|
||||
return banPlayers == null || banServer == null || banMusics == null || mutePlayers == null
|
||||
|| muteListPlayers == null;
|
||||
}
|
||||
|
||||
public static BanObj make() {
|
||||
BanObj obj = new BanObj();
|
||||
obj.banMusics = new HashMap<>();
|
||||
obj.banPlayers = new HashSet<>();
|
||||
obj.banServer = new HashSet<>();
|
||||
obj.mutePlayers = new HashSet<>();
|
||||
obj.muteListPlayers = new HashSet<>();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+9
-20
@@ -3,7 +3,10 @@ package com.coloryr.allmusic.server.core.objs.config;
|
||||
import com.coloryr.allmusic.codec.HudPosObj;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 配置文件对象
|
||||
@@ -29,6 +32,10 @@ public class ConfigObj {
|
||||
* 歌曲延迟
|
||||
*/
|
||||
public int lyricDelay;
|
||||
/**
|
||||
* KTV歌词更新延迟
|
||||
*/
|
||||
public int ktvSendDelay;
|
||||
/**
|
||||
* 默认添加歌曲方式
|
||||
*/
|
||||
@@ -41,10 +48,6 @@ public class ConfigObj {
|
||||
* 管理员ID列表
|
||||
*/
|
||||
public Set<String> adminList;
|
||||
/**
|
||||
* 不参与点歌的服务器列表
|
||||
*/
|
||||
public Set<String> muteServer;
|
||||
/**
|
||||
* 玩家点歌后是否直接从空闲歌单切换至玩家歌曲
|
||||
*/
|
||||
@@ -93,10 +96,6 @@ public class ConfigObj {
|
||||
* 配置文件版本号
|
||||
*/
|
||||
public String version;
|
||||
/**
|
||||
* 默认的Hud配置
|
||||
*/
|
||||
public HudPosObj defaultHud;
|
||||
/**
|
||||
* 经济插件挂钩
|
||||
*/
|
||||
@@ -143,14 +142,6 @@ public class ConfigObj {
|
||||
saveConfig = true;
|
||||
adminList = new HashSet<>();
|
||||
}
|
||||
if (defaultHud == null) {
|
||||
saveConfig = true;
|
||||
defaultHud = HudPosObj.make();
|
||||
}
|
||||
if (muteServer == null) {
|
||||
saveConfig = true;
|
||||
muteServer = new HashSet<>();
|
||||
}
|
||||
if (economy == null || economy.check()) {
|
||||
saveConfig = true;
|
||||
economy = EconomyObj.make();
|
||||
@@ -180,16 +171,14 @@ public class ConfigObj {
|
||||
maxPlayList = 10;
|
||||
minVote = 3;
|
||||
voteTime = 30;
|
||||
|
||||
adminList = new HashSet<>();
|
||||
adminList.add("color_yr");
|
||||
muteServer = new HashSet<>();
|
||||
playListSwitch = true;
|
||||
playListRandom = true;
|
||||
playListEscapeDeep = 40;
|
||||
ktvSendDelay = 50;
|
||||
sendLyric = true;
|
||||
needPermission = false;
|
||||
defaultHud = HudPosObj.make();
|
||||
mutePlayMessage = false;
|
||||
muteAddMessage = false;
|
||||
showInBar = false;
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.coloryr.allmusic.server.core.objs.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MusicListObj {
|
||||
public Map<String, List<String>> musics;
|
||||
|
||||
public boolean check() {
|
||||
return musics == null;
|
||||
}
|
||||
|
||||
public static MusicListObj make() {
|
||||
MusicListObj obj = new MusicListObj();
|
||||
obj.musics = new HashMap<>();
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ public class ARG {
|
||||
public static String nowTime = "%NowTime%";
|
||||
public static String player = "%Player%";
|
||||
public static String lyric = "%Lyric%";
|
||||
public static String tlyric = "%Tlyric%";
|
||||
public static String klyric = "%KLyric%";
|
||||
public static String list = "%List%";
|
||||
public static String count = "%Count%";
|
||||
public static String countAll = "%CountAll%";
|
||||
|
||||
+10
@@ -26,6 +26,8 @@ public class HelpNormalObj {
|
||||
public String hud8;
|
||||
public String hud9;
|
||||
public String hud10;
|
||||
public String hud11;
|
||||
public String hud12;
|
||||
public String join;
|
||||
|
||||
public static HelpNormalObj make() {
|
||||
@@ -86,6 +88,10 @@ public class HelpNormalObj {
|
||||
return true;
|
||||
if (join == null)
|
||||
return true;
|
||||
if (hud11 == null)
|
||||
return true;
|
||||
if (hud12 == null)
|
||||
return true;
|
||||
return hud5 == null;
|
||||
}
|
||||
|
||||
@@ -134,6 +140,10 @@ public class HelpNormalObj {
|
||||
hud7 = "<light_purple>[AllMusic3]<yellow>/music hud [位置] color [颜色HEX] 设置某个界面的颜色";
|
||||
if (hud8 == null)
|
||||
hud8 = "<light_purple>[AllMusic3]<yellow>/music hud [位置] reset 重置单一界面";
|
||||
if (hud11 == null)
|
||||
hud11 = "<light_purple>[AllMusic3]<yellow>/music hud [位置] alpha 设置透明度";
|
||||
if (hud12 == null)
|
||||
hud12 = "<light_purple>[AllMusic3]<yellow>/music hud [位置] loop [模式] 设置文字滚动模式";
|
||||
if (hud3 == null)
|
||||
hud3 = "<light_purple>[AllMusic3]<yellow>/music hud pic size [尺寸] 设置图片尺寸";
|
||||
if (hud4 == null)
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.coloryr.allmusic.server.core.objs.message;
|
||||
|
||||
import com.coloryr.allmusic.codec.HudDirType;
|
||||
import com.coloryr.allmusic.codec.HudPosType;
|
||||
import com.coloryr.allmusic.codec.HudType;
|
||||
|
||||
public class HudNameObj {
|
||||
@@ -83,7 +83,7 @@ public class HudNameObj {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getDir(HudDirType data) {
|
||||
public String getDir(HudPosType data) {
|
||||
if (data == null) {
|
||||
return all;
|
||||
}
|
||||
|
||||
+10
-5
@@ -16,8 +16,9 @@ public class HudObj {
|
||||
public String picSpeed;
|
||||
public String music;
|
||||
public String lyric;
|
||||
public String tlyric;
|
||||
public String list;
|
||||
public String ktv;
|
||||
public String klyric;
|
||||
|
||||
public static HudObj make() {
|
||||
HudObj obj = new HudObj();
|
||||
@@ -53,13 +54,15 @@ public class HudObj {
|
||||
return true;
|
||||
if (lyric == null)
|
||||
return true;
|
||||
if (tlyric == null)
|
||||
return true;
|
||||
if (list == null)
|
||||
return true;
|
||||
if (picRotate == null)
|
||||
return true;
|
||||
if (picSpeed == null)
|
||||
return true;
|
||||
return ktv == null;
|
||||
return klyric == null;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
@@ -94,9 +97,11 @@ public class HudObj {
|
||||
+ "\n" + ARG.musicAuthor + "\n" + ARG.musicAlia + "\n" + ARG.musicAl
|
||||
+ "\nby: " + ARG.player;
|
||||
if (lyric == null)
|
||||
lyric = ARG.lyric + "\n" + ARG.tlyric;
|
||||
if (ktv == null)
|
||||
ktv = "§e" + ARG.klyric + "§f" + ARG.lyric + "§r\n" + ARG.tlyric;
|
||||
lyric = ARG.lyric;
|
||||
if (tlyric == null)
|
||||
tlyric = ARG.lyric;
|
||||
if (klyric == null)
|
||||
klyric = "§e" + ARG.lyric;
|
||||
if (list == null)
|
||||
list = "播放列表里面有" + ARG.size + "首歌\n" + ARG.list;
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class LyricObj {
|
||||
if (data == null)
|
||||
data = ARG.lyric;
|
||||
if (tdata == null)
|
||||
tdata = ARG.lyric + "(" + ARG.tlyric + ")";
|
||||
tdata = ARG.lyric + "(" + ARG.lyric + ")";
|
||||
if (empty1 == null)
|
||||
empty1 = "没有歌词";
|
||||
if (empty2 == null)
|
||||
|
||||
+2
-15
@@ -1,8 +1,5 @@
|
||||
package com.coloryr.allmusic.server.core.objs.music;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
|
||||
public class LyricItemObj {
|
||||
public String lyric;
|
||||
public String tlyric;
|
||||
@@ -12,17 +9,7 @@ public class LyricItemObj {
|
||||
this.tlyric = tlyric;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
if (lyric == null || lyric.isEmpty())
|
||||
return "";
|
||||
String data;
|
||||
if (tlyric != null && !tlyric.isEmpty()) {
|
||||
data = AllMusic.getMessage().lyric.tdata;
|
||||
return data.replace(ARG.lyric, lyric)
|
||||
.replace(ARG.tlyric, tlyric);
|
||||
}
|
||||
|
||||
data = AllMusic.getMessage().lyric.data;
|
||||
return data.replace(ARG.lyric, lyric);
|
||||
public LyricItemObj copy() {
|
||||
return new LyricItemObj(this.lyric, this.tlyric);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.coloryr.allmusic.server.core.saves;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.config.BanObj;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class BanSave {
|
||||
private static BanObj ban = new BanObj();
|
||||
private static File banFile;
|
||||
|
||||
public static boolean haveBanPlayer(String player) {
|
||||
return ban.banPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static boolean haveBanServer(String name) {
|
||||
name = name.toLowerCase();
|
||||
return ban.banServer.contains(name);
|
||||
}
|
||||
|
||||
public static void init(File file) throws IOException {
|
||||
banFile = new File(file, "ban.json");
|
||||
if (!banFile.exists()) {
|
||||
banFile.createNewFile();
|
||||
}
|
||||
}
|
||||
|
||||
private static void banCheck() {
|
||||
if (ban == null || ban.check()) {
|
||||
ban = BanObj.make();
|
||||
AllMusic. log.data("<light_purple>[AllMusic3]<red>配置文件ban.json错误,已覆盖");
|
||||
saveBan();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveBan() {
|
||||
try {
|
||||
String data = AllMusic.gson.toJson(ban);
|
||||
FileOutputStream out = new FileOutputStream(banFile);
|
||||
OutputStreamWriter write = new OutputStreamWriter(
|
||||
out, StandardCharsets.UTF_8);
|
||||
write.write(data);
|
||||
write.close();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>配置文件ban.json保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadBan() throws IOException {
|
||||
InputStreamReader reader = new InputStreamReader(
|
||||
Files.newInputStream(banFile.toPath()), StandardCharsets.UTF_8);
|
||||
BufferedReader bf = new BufferedReader(reader);
|
||||
ban = AllMusic.gson.fromJson(bf, BanObj.class);
|
||||
bf.close();
|
||||
reader.close();
|
||||
banCheck();
|
||||
}
|
||||
|
||||
public static void addBanMusic(String music, String api) {
|
||||
SaveTask.task(() -> {
|
||||
List<String> ids = ban.banMusics.get(api);
|
||||
if (ids == null)
|
||||
{
|
||||
ids = new ArrayList<>();
|
||||
}
|
||||
ids.add(music);
|
||||
ban.banMusics.put(api, ids);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeBanMusic(String id, String api) {
|
||||
SaveTask.task(() -> {
|
||||
List<String> ids = ban.banMusics.get(api);
|
||||
if (ids == null)
|
||||
{
|
||||
ids = new ArrayList<>();
|
||||
}
|
||||
ids.remove(id);
|
||||
ban.banMusics.put(api, ids);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id 歌曲ID
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean checkBanMusic(String id, String api) {
|
||||
List<String> ids = ban.banMusics.get(api);
|
||||
if (ids == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ids.contains(id);
|
||||
}
|
||||
|
||||
public static void clearBan() {
|
||||
SaveTask.task(() -> {
|
||||
ban.banMusics.clear();
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static void addBanPlayer(String player) {
|
||||
SaveTask.task(() -> {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
ban.banPlayers.add(player1);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeBanPlayer(String player) {
|
||||
SaveTask.task(() -> {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
ban.banPlayers.remove(player1);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查玩家是否在数据库
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean checkBanPlayer(String name) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
return ban.banPlayers.contains(name);
|
||||
}
|
||||
|
||||
public static void clearBanPlayer() {
|
||||
SaveTask.task(() -> {
|
||||
ban.banPlayers.clear();
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static void addMutePlayer(String player) {
|
||||
SaveTask.task(() -> {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
ban.mutePlayers.add(player1);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeMutePlayer(String player) {
|
||||
SaveTask.task(() -> {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
ban.mutePlayers.remove(player1);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean checkMutePlayer(String name) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
return ban.mutePlayers.contains(name);
|
||||
}
|
||||
|
||||
public static void addMuteListPlayer(String player) {
|
||||
SaveTask.task(() -> {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
ban.muteListPlayers.add(player1);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeMuteListPlayer(String player) {
|
||||
SaveTask.task(() -> {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
ban.muteListPlayers.remove(player1);
|
||||
saveBan();
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean checkMuteListPlayer(String name) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
return ban.muteListPlayers.contains(name);
|
||||
}
|
||||
|
||||
public static Set<String> getBanPlayers() {
|
||||
return ban.banPlayers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.coloryr.allmusic.server.core.saves;
|
||||
|
||||
import com.coloryr.allmusic.codec.HudPosObj;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
public class HudSave {
|
||||
|
||||
private static File players;
|
||||
private static File defaultFile;
|
||||
|
||||
public static final Map<String, HudPosObj> HudList = new ConcurrentHashMap<>();
|
||||
|
||||
public static HudPosObj defaultHud;
|
||||
|
||||
public static void init(File file) throws IOException {
|
||||
players = new File(file, "players");
|
||||
players.mkdirs();
|
||||
|
||||
defaultFile = new File(file, "hud.json");
|
||||
if (!defaultFile.exists()) {
|
||||
defaultFile.createNewFile();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveDefaultHud() {
|
||||
try {
|
||||
String data = AllMusic.gson.toJson(defaultHud);
|
||||
FileOutputStream out = new FileOutputStream(defaultFile);
|
||||
OutputStreamWriter write = new OutputStreamWriter(
|
||||
out, StandardCharsets.UTF_8);
|
||||
write.write(data);
|
||||
write.close();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>配置文件hud.json保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void defaultHudCheck() {
|
||||
if (defaultHud == null || defaultHud.check()) {
|
||||
defaultHud = HudPosObj.make();
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>配置文件hud.json错误,已覆盖");
|
||||
saveDefaultHud();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadHud() throws IOException {
|
||||
File[] list = players.listFiles();
|
||||
if (list != null) {
|
||||
for (File item : list) {
|
||||
if (item.isFile() && item.getName().endsWith(".json")) {
|
||||
try {
|
||||
InputStreamReader reader = new InputStreamReader(
|
||||
Files.newInputStream(item.toPath()), StandardCharsets.UTF_8);
|
||||
BufferedReader bf = new BufferedReader(reader);
|
||||
HudPosObj hud = AllMusic.gson.fromJson(bf, HudPosObj.class);
|
||||
bf.close();
|
||||
reader.close();
|
||||
|
||||
String name = item.getName().replace(".json", "").toLowerCase(Locale.ROOT);
|
||||
if (hud != null) {
|
||||
HudList.put(name, hud);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(
|
||||
Files.newInputStream(defaultFile.toPath()), StandardCharsets.UTF_8);
|
||||
BufferedReader bf = new BufferedReader(reader);
|
||||
defaultHud = AllMusic.gson.fromJson(bf, HudPosObj.class);
|
||||
bf.close();
|
||||
reader.close();
|
||||
defaultHudCheck();
|
||||
}
|
||||
|
||||
private static void saveHud(String name) {
|
||||
try {
|
||||
HudPosObj hud = HudList.get(name);
|
||||
if (hud == null) {
|
||||
return;
|
||||
}
|
||||
String data = AllMusic.gson.toJson(hud);
|
||||
File file = new File(players, name + ".json");
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
OutputStreamWriter write = new OutputStreamWriter(
|
||||
out, StandardCharsets.UTF_8);
|
||||
write.write(data);
|
||||
write.close();
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>玩家信息保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查玩家是否在数据库
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean check(String name) {
|
||||
try {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
return HudList.containsKey(name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static HudPosObj getOrNew(String name) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
if (HudList.containsKey(name)) {
|
||||
return HudList.get(name);
|
||||
}
|
||||
|
||||
HudPosObj hud = defaultHud.copy();
|
||||
HudList.put(name, hud);
|
||||
String finalName = name;
|
||||
SaveTask.task(() -> update(finalName, hud));
|
||||
|
||||
return hud;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新玩家Hud数据
|
||||
*
|
||||
* @param name 用户名
|
||||
* @param hud Hud数据
|
||||
*/
|
||||
public static void update(String name, HudPosObj hud) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
HudList.put(name, hud);
|
||||
saveHud(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取所有数据
|
||||
*/
|
||||
public static HudPosObj readHud(String name) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
return HudList.get(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.coloryr.allmusic.server.core.saves;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.config.MusicListObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MusicListSave {
|
||||
private static File musicFile;
|
||||
|
||||
private static MusicListObj musicObj;
|
||||
|
||||
public static void init(File file) throws IOException {
|
||||
musicFile = new File(file, "music.json");
|
||||
if (!musicFile.exists()) {
|
||||
musicFile.createNewFile();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveMusicList() {
|
||||
try {
|
||||
String data = AllMusic.gson.toJson(musicObj);
|
||||
FileOutputStream out = new FileOutputStream(musicFile);
|
||||
OutputStreamWriter write = new OutputStreamWriter(
|
||||
out, StandardCharsets.UTF_8);
|
||||
write.write(data);
|
||||
write.close();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>配置文件music.json保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void musicListCheck() {
|
||||
if (musicObj == null || musicObj.check()) {
|
||||
musicObj = MusicListObj.make();
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>配置文件hud.json错误,已覆盖");
|
||||
saveMusicList();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadMusic() throws IOException {
|
||||
InputStreamReader reader = new InputStreamReader(
|
||||
Files.newInputStream(musicFile.toPath()), StandardCharsets.UTF_8);
|
||||
BufferedReader bf = new BufferedReader(reader);
|
||||
musicObj = AllMusic.gson.fromJson(bf, MusicListObj.class);
|
||||
bf.close();
|
||||
reader.close();
|
||||
musicListCheck();
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机获取空闲歌单歌曲
|
||||
*/
|
||||
public static MusicObj readListItem() {
|
||||
int count = getListSize();
|
||||
|
||||
return readListItem(AllMusic.random.nextInt(count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取空闲歌单列表
|
||||
*/
|
||||
public static MusicObj readListItem(int index) {
|
||||
for (Map.Entry<String, List<String>> item : musicObj.musics.entrySet()) {
|
||||
if (item.getValue().size() > index) {
|
||||
String id = item.getValue().get(index);
|
||||
MusicObj obj = new MusicObj();
|
||||
obj.api = item.getKey();
|
||||
obj.id = id;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
index -= item.getValue().size();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取空闲歌单歌曲数量
|
||||
*
|
||||
* @return 歌曲数量
|
||||
*/
|
||||
public static int getListSize() {
|
||||
int count = 0;
|
||||
for (Map.Entry<String, List<String>> item : musicObj.musics.entrySet()) {
|
||||
count += item.getValue().size();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void addIdleList(List<String> list, String api) {
|
||||
SaveTask.task(() -> {
|
||||
List<String> ids = musicObj.musics.get(api);
|
||||
if (ids == null) {
|
||||
ids = new ArrayList<>();
|
||||
}
|
||||
|
||||
ids.addAll(list);
|
||||
|
||||
musicObj.musics.put(api, ids);
|
||||
saveMusicList();
|
||||
});
|
||||
}
|
||||
|
||||
public static void clearIdleList() {
|
||||
SaveTask.task(() -> {
|
||||
musicObj.musics.clear();
|
||||
saveMusicList();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.coloryr.allmusic.server.core.saves;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
public class SaveTask {
|
||||
private static final Queue<Runnable> tasks = new LinkedBlockingDeque<>();
|
||||
private static final Semaphore semaphore = new Semaphore(0);
|
||||
|
||||
public static void start() {
|
||||
new Thread(SaveTask::run).start();
|
||||
}
|
||||
|
||||
public static void task(Runnable runnable) {
|
||||
tasks.add(runnable);
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止
|
||||
*/
|
||||
public static void stop() {
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
AllMusic.log.data("数据库线程启动");
|
||||
Runnable runnable;
|
||||
while (AllMusic.isRun) {
|
||||
try {
|
||||
semaphore.acquire();
|
||||
if (!AllMusic.isRun)
|
||||
break;
|
||||
do {
|
||||
runnable = tasks.poll();
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
while (runnable != null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
AllMusic.log.data("数据库线程关闭");
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@ package com.coloryr.allmusic.server.core.side;
|
||||
import com.coloryr.allmusic.codec.CommandType;
|
||||
import com.coloryr.allmusic.codec.HudPosObj;
|
||||
import com.coloryr.allmusic.codec.HudType;
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.utils.HudUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@@ -89,11 +91,9 @@ public abstract class BaseSide {
|
||||
* 向玩家发送数据包
|
||||
*
|
||||
* @param player 玩家
|
||||
* @param type 数据
|
||||
* @param data 数据
|
||||
* @param data1 数据
|
||||
* @param pack 数据
|
||||
*/
|
||||
public abstract void send(Object player, CommandType type, String data, int data1);
|
||||
public abstract void send(Object player, MusicPack pack);
|
||||
|
||||
/**
|
||||
* 根据名字获取玩家
|
||||
@@ -170,7 +170,7 @@ public abstract class BaseSide {
|
||||
if (AllMusic.isSkip(player, getPlayerServer(player), true))
|
||||
return;
|
||||
try {
|
||||
send(player1, CommandType.POS, null, pos);
|
||||
send(player1, new MusicPack.IntMusicPack(CommandType.POS, pos));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>清空Hud发生出错");
|
||||
e.printStackTrace();
|
||||
@@ -188,7 +188,7 @@ public abstract class BaseSide {
|
||||
if (player == null)
|
||||
return;
|
||||
try {
|
||||
send(player, CommandType.STOP, null, 0);
|
||||
send(player, new MusicPack(CommandType.STOP));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -202,7 +202,7 @@ public abstract class BaseSide {
|
||||
PlayMusic.clearNowPlayer();
|
||||
try {
|
||||
for (Object player : getPlayers()) {
|
||||
send(player, CommandType.STOP, null, 0);
|
||||
send(player, new MusicPack(CommandType.STOP));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>停止指令发送出错");
|
||||
@@ -224,7 +224,7 @@ public abstract class BaseSide {
|
||||
try {
|
||||
if (AllMusic.isSkip(player, getPlayerServer(player), false))
|
||||
return;
|
||||
send(player1, CommandType.PLAY, url, 0);
|
||||
send(player1, new MusicPack.StringMusicPack(CommandType.PLAY, url));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>歌曲指令发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -234,9 +234,9 @@ public abstract class BaseSide {
|
||||
/**
|
||||
* 发送Hud的歌词数据
|
||||
*
|
||||
* @param data 数据
|
||||
* @param pack 数据
|
||||
*/
|
||||
public final void sendHudLyric(String data) {
|
||||
public final void sendHudLyric(MusicPack.LyricMusicPack pack) {
|
||||
for (Object player : getPlayers()) {
|
||||
String name = getPlayerName(player);
|
||||
if (name == null)
|
||||
@@ -245,10 +245,35 @@ public abstract class BaseSide {
|
||||
if (AllMusic.isSkip(name, getPlayerServer(player), true))
|
||||
continue;
|
||||
try {
|
||||
HudPosObj obj = HudUtils.get(name);
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
if (!obj.lyric.enable)
|
||||
continue;
|
||||
send(player, CommandType.LYRIC, data, 0);
|
||||
send(player, pack);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>歌词发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Hud的歌词数据
|
||||
*
|
||||
* @param state 数据
|
||||
*/
|
||||
public final void sendHudKtv(float state) {
|
||||
for (Object player : getPlayers()) {
|
||||
String name = getPlayerName(player);
|
||||
if (name == null)
|
||||
continue;
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
if (AllMusic.isSkip(name, getPlayerServer(player), true))
|
||||
continue;
|
||||
try {
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
if (!obj.lyric.enable)
|
||||
continue;
|
||||
send(player, new MusicPack.FloatMusicPack(CommandType.LYRIC_STATE, state));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>歌词发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -270,10 +295,10 @@ public abstract class BaseSide {
|
||||
if (AllMusic.isSkip(name, getPlayerServer(player), true))
|
||||
continue;
|
||||
try {
|
||||
HudPosObj obj = HudUtils.get(name);
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
if (!obj.lyric.enable)
|
||||
continue;
|
||||
send(player, CommandType.INFO, data, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.INFO, data));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>歌词信息发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -293,9 +318,9 @@ public abstract class BaseSide {
|
||||
if (AllMusic.isSkip(name, null, false))
|
||||
return;
|
||||
try {
|
||||
HudPosObj obj = HudUtils.get(name);
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
String data = AllMusic.gson.toJson(obj);
|
||||
send(player, CommandType.HUD_DATA, data, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.HUD_DATA, data));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>界面位置发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -321,13 +346,10 @@ public abstract class BaseSide {
|
||||
return;
|
||||
switch (pos) {
|
||||
case INFO:
|
||||
send(player, CommandType.INFO, data, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.INFO, data));
|
||||
break;
|
||||
case LIST:
|
||||
send(player, CommandType.LIST, data, 0);
|
||||
break;
|
||||
case LYRIC:
|
||||
send(player, CommandType.LYRIC, data, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.LIST, data));
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -336,6 +358,26 @@ public abstract class BaseSide {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Hud数据
|
||||
*
|
||||
* @param name 用户名
|
||||
* @param pack 数据
|
||||
*/
|
||||
public final void sendLyric(String name, MusicPack.LyricMusicPack pack) {
|
||||
try {
|
||||
Object player = getPlayer(name);
|
||||
if (player == null)
|
||||
return;
|
||||
if (AllMusic.isSkip(name, getPlayerServer(player), true))
|
||||
return;
|
||||
send(player, pack);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Hud的歌曲列表数据
|
||||
*
|
||||
@@ -350,10 +392,10 @@ public abstract class BaseSide {
|
||||
if (AllMusic.isSkip(name, getPlayerServer(player), true))
|
||||
continue;
|
||||
try {
|
||||
HudPosObj obj = HudUtils.get(name);
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
if (!obj.list.enable)
|
||||
continue;
|
||||
send(player, CommandType.LIST, data, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.LIST, data));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>歌曲列表发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -371,9 +413,9 @@ public abstract class BaseSide {
|
||||
continue;
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
try {
|
||||
HudPosObj obj = HudUtils.get(name);
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
String data = AllMusic.gson.toJson(obj);
|
||||
send(player, CommandType.HUD_DATA, data, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.HUD_DATA, data));
|
||||
} catch (Exception e1) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>数据发送发生错误");
|
||||
e1.printStackTrace();
|
||||
@@ -417,7 +459,7 @@ public abstract class BaseSide {
|
||||
if (AllMusic.isSkip(name, getPlayerServer(player), false))
|
||||
continue;
|
||||
try {
|
||||
send(player, CommandType.PLAY, url, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.PLAY, url));
|
||||
PlayMusic.addNowPlayPlayer(name);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>歌曲指令发送出错");
|
||||
@@ -439,11 +481,11 @@ public abstract class BaseSide {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
if (AllMusic.isSkip(name, getPlayerServer(player), true))
|
||||
continue;
|
||||
HudPosObj obj = HudUtils.get(name);
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
if (!obj.pic.enable)
|
||||
continue;
|
||||
try {
|
||||
send(player, CommandType.IMG, url, 0);
|
||||
send(player, new MusicPack.StringMusicPack(CommandType.IMG, url));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>图片指令发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -464,7 +506,7 @@ public abstract class BaseSide {
|
||||
if (AllMusic.isSkip(player, getPlayerServer(player), true))
|
||||
return;
|
||||
try {
|
||||
send(player1, CommandType.IMG, url, 0);
|
||||
send(player1, new MusicPack.StringMusicPack(CommandType.IMG, url));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>图片指令发送出错");
|
||||
e.printStackTrace();
|
||||
@@ -481,7 +523,7 @@ public abstract class BaseSide {
|
||||
if (player == null)
|
||||
return;
|
||||
try {
|
||||
send(player, CommandType.CLEAR, null, 0);
|
||||
send(player, new MusicPack(CommandType.CLEAR));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>清空Hud发生出错");
|
||||
e.printStackTrace();
|
||||
@@ -494,7 +536,7 @@ public abstract class BaseSide {
|
||||
public final void clearHud() {
|
||||
for (Object player : getPlayers()) {
|
||||
try {
|
||||
send(player, CommandType.CLEAR, null, 0);
|
||||
send(player, new MusicPack(CommandType.CLEAR));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic]<red>清空Hud发生出错");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.coloryr.allmusic.server.core.sql;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public class Cache {
|
||||
public static Set<String> banPlayers = new CopyOnWriteArraySet<>();
|
||||
public static Set<String> banMusic = new CopyOnWriteArraySet<>();
|
||||
|
||||
public static boolean haveBan(String player) {
|
||||
return banPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static void updateData() {
|
||||
updatePlayer();
|
||||
updateMusic();
|
||||
}
|
||||
|
||||
private static void updatePlayer() {
|
||||
banPlayers.clear();
|
||||
banPlayers.addAll(DataSql.getBanPlayerList());
|
||||
}
|
||||
|
||||
private static void updateMusic() {
|
||||
banMusic.clear();
|
||||
banMusic.addAll(DataSql.getBanMusicList());
|
||||
}
|
||||
}
|
||||
@@ -1,790 +0,0 @@
|
||||
package com.coloryr.allmusic.server.core.sql;
|
||||
|
||||
import com.coloryr.allmusic.codec.HudDirType;
|
||||
import com.coloryr.allmusic.codec.HudItemPosObj;
|
||||
import com.coloryr.allmusic.codec.HudPosObj;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
public class DataSql {
|
||||
private static final Queue<Runnable> tasks = new LinkedBlockingDeque<>();
|
||||
private static final Semaphore semaphore = new Semaphore(0);
|
||||
/**
|
||||
* 创建表用
|
||||
*/
|
||||
private static final String table = "CREATE TABLE IF NOT EXISTS \"allmusic\" (\n" +
|
||||
" \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" \"name\" TEXT(60),\n" +
|
||||
" \"info_x\" integer(6),\n" +
|
||||
" \"info_y\" integer(6),\n" +
|
||||
" \"info_color\" integer(20),\n" +
|
||||
" \"info_dir\" integer(6),\n" +
|
||||
" \"info_shadow\" integer(1),\n" +
|
||||
" \"info_enable\" integer(1),\n" +
|
||||
" \"info_alpha\" float,\n" +
|
||||
" \"lyric_x\" integer(6),\n" +
|
||||
" \"lyric_y\" integer(6),\n" +
|
||||
" \"lyric_color\" integer(20),\n" +
|
||||
" \"lyric_dir\" integer(6),\n" +
|
||||
" \"lyric_shadow\" integer(1),\n" +
|
||||
" \"lyric_enable\" integer(1),\n" +
|
||||
" \"lyric_alpha\" float,\n" +
|
||||
" \"list_x\" integer(6),\n" +
|
||||
" \"list_y\" integer(6),\n" +
|
||||
" \"list_color\" integer(20),\n" +
|
||||
" \"list_dir\" integer(6),\n" +
|
||||
" \"list_shadow\" integer(1),\n" +
|
||||
" \"list_enable\" integer(1),\n" +
|
||||
" \"list_alpha\" float,\n" +
|
||||
" \"pic_x\" integer(6),\n" +
|
||||
" \"pic_y\" integer(6),\n" +
|
||||
" \"pic_dir\" integer(6),\n" +
|
||||
" \"pic_size\" integer(6),\n" +
|
||||
" \"pic_enable\" integer(1),\n" +
|
||||
" \"pic_alpha\" float,\n" +
|
||||
" \"pic_rotate\" integer(1),\n" +
|
||||
" \"pic_rotate_speed\" integer(6)\n" +
|
||||
");";
|
||||
|
||||
private static final String table1 = "CREATE TABLE IF NOT EXISTS \"allmusic_list\" (\n" +
|
||||
" \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" \"sid\" TEXT(40),\n" +
|
||||
" \"api\" TEXT(40)\n" +
|
||||
");";
|
||||
|
||||
private static final String table2 = "CREATE TABLE IF NOT EXISTS \"allmusic_mute\" (\n" +
|
||||
" \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" \"sid\" TEXT(60)\n" +
|
||||
");";
|
||||
|
||||
private static final String table3 = "CREATE TABLE IF NOT EXISTS \"allmusic_mutelist\" (\n" +
|
||||
" \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" \"sid\" TEXT(60)\n" +
|
||||
");";
|
||||
|
||||
private static final String table4 = "CREATE TABLE IF NOT EXISTS \"allmusic_banlist\" (\n" +
|
||||
" \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" \"sid\" TEXT(40),\n" +
|
||||
" \"api\" TEXT(40)\n" +
|
||||
");";
|
||||
|
||||
private static final String table5 = "CREATE TABLE IF NOT EXISTS \"allmusic_banplayer\" (\n" +
|
||||
" \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
|
||||
" \"sid\" TEXT(60)\n" +
|
||||
");";
|
||||
/**
|
||||
* 数据库文件
|
||||
*/
|
||||
public static File sqlFile;
|
||||
/**
|
||||
* 数据库链接对象
|
||||
*/
|
||||
private static Connection connection;
|
||||
|
||||
/**
|
||||
* 初始化数据库
|
||||
*/
|
||||
public static void init() {
|
||||
try {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<yellow>正在初始化数据库");
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + sqlFile.getPath());
|
||||
Statement stat = connection.createStatement();
|
||||
stat.execute(table);
|
||||
stat.execute(table1);
|
||||
stat.execute(table2);
|
||||
stat.execute(table3);
|
||||
stat.execute(table4);
|
||||
stat.execute(table5);
|
||||
stat.close();
|
||||
|
||||
Cache.updateData();
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<yellow>数据库初始化完成");
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>数据库初始化错误,请删除关闭服务器删除数据库,再启动服务器");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查玩家是否在数据库
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean check(String name) {
|
||||
try {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
boolean have = false;
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT id FROM allmusic WHERE name ='" + name + "'");
|
||||
if (set.next()) {
|
||||
have = true;
|
||||
}
|
||||
set.close();
|
||||
stat.close();
|
||||
return have;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新玩家Hud数据
|
||||
*
|
||||
* @param name 用户名
|
||||
* @param hud Hud数据
|
||||
*/
|
||||
private static void update(String name, HudPosObj hud) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
String sql = "";
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
sql = "UPDATE allmusic SET " +
|
||||
"info_x=" + hud.info.x + "," +
|
||||
"info_y=" + hud.info.y + "," +
|
||||
"info_color=" + hud.info.color + "," +
|
||||
"info_dir=" + hud.info.dir.ordinal() + "," +
|
||||
"info_shadow=" + (hud.info.shadow ? 1 : 0) + "," +
|
||||
"info_enable=" + (hud.info.enable ? 1 : 0) + "," +
|
||||
"info_alpha=" + hud.info.alpha + "," +
|
||||
"lyric_x=" + hud.lyric.x + "," +
|
||||
"lyric_y=" + hud.lyric.y + "," +
|
||||
"lyric_color=" + hud.lyric.color + "," +
|
||||
"lyric_dir=" + hud.lyric.dir.ordinal() + "," +
|
||||
"lyric_shadow=" + (hud.lyric.shadow ? 1 : 0) + "," +
|
||||
"lyric_enable=" + (hud.lyric.enable ? 1 : 0) + "," +
|
||||
"lyric_alpha=" + hud.lyric.alpha + "," +
|
||||
"list_x=" + hud.list.x + "," +
|
||||
"list_y=" + hud.list.y + "," +
|
||||
"list_color=" + hud.list.color + "," +
|
||||
"list_dir=" + hud.list.dir.ordinal() + "," +
|
||||
"list_shadow=" + (hud.list.shadow ? 1 : 0) + "," +
|
||||
"list_enable=" + (hud.list.enable ? 1 : 0) + "," +
|
||||
"list_alpha=" + hud.list.alpha + "," +
|
||||
"pic_x=" + hud.pic.x + "," +
|
||||
"pic_y=" + hud.pic.y + "," +
|
||||
"pic_dir=" + hud.pic.dir.ordinal() + "," +
|
||||
"pic_enable=" + (hud.pic.enable ? 1 : 0) + "," +
|
||||
"pic_alpha=" + hud.pic.alpha + "," +
|
||||
"pic_size=" + hud.pic.color + "," +
|
||||
"pic_rotate=" + (hud.pic.shadow ? 1 : 0) + "," +
|
||||
"pic_rotate_speed=" + hud.picRotateSpeed + " WHERE name='" + name + "'";
|
||||
stat.execute(sql);
|
||||
stat.close();
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data(sql);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户Hud数据
|
||||
*
|
||||
* @param name 用户名
|
||||
* @param hud 数据
|
||||
*/
|
||||
public static void addUser(String name, HudPosObj hud) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
String sql = "";
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
if (check(name)) {
|
||||
update(name, hud);
|
||||
} else {
|
||||
Statement stat = connection.createStatement();
|
||||
sql = "INSERT INTO allmusic (name," +
|
||||
"info_x,info_y,info_enable,lyric_x,lyric_y,lyric_enable," +
|
||||
"list_x,list_y,list_enable," +
|
||||
"pic_x,pic_y,pic_enable,pic_size,pic_rotate,pic_rotate_speed," +
|
||||
"info_color,info_dir,info_shadow,lyric_color,lyric_dir," +
|
||||
"lyric_shadow,list_color,list_dir,list_shadow,pic_dir," +
|
||||
"info_alpha,lyric_alpha,list_alpha,pic_alpha)" +
|
||||
"VALUES ('" + name + "'," +
|
||||
hud.info.x + "," +
|
||||
hud.info.y + "," +
|
||||
(hud.info.enable ? 1 : 0) + "," +
|
||||
hud.lyric.x + "," +
|
||||
hud.lyric.y + "," +
|
||||
(hud.lyric.enable ? 1 : 0) + "," +
|
||||
hud.list.x + "," +
|
||||
hud.list.y + "," +
|
||||
(hud.list.enable ? 1 : 0) + "," +
|
||||
hud.pic.x + "," +
|
||||
hud.pic.y + "," +
|
||||
(hud.pic.enable ? 1 : 0) + "," +
|
||||
hud.pic.color + "," +
|
||||
(hud.pic.shadow ? 1 : 0) + "," +
|
||||
hud.picRotateSpeed + "," +
|
||||
hud.info.color + "," +
|
||||
hud.info.dir.ordinal() + "," +
|
||||
(hud.info.shadow ? 1 : 0) + "," +
|
||||
hud.lyric.color + "," +
|
||||
hud.lyric.dir.ordinal() + "," +
|
||||
(hud.lyric.shadow ? 1 : 0) + "," +
|
||||
hud.list.color + "," +
|
||||
hud.list.dir.ordinal() + "," +
|
||||
(hud.list.shadow ? 1 : 0) + "," +
|
||||
hud.pic.dir.ordinal() + "," +
|
||||
hud.info.alpha + "," +
|
||||
hud.lyric.alpha + "," +
|
||||
hud.list.alpha + "," +
|
||||
hud.pic.alpha +
|
||||
")";
|
||||
stat.execute(sql);
|
||||
stat.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data(sql);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取所有数据
|
||||
*/
|
||||
public static HudPosObj readHud(String name) {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT info_x,info_y,info_enable,lyric_x," +
|
||||
"lyric_y,lyric_enable,list_x,list_y,list_enable,pic_x,pic_y,pic_enable,pic_size," +
|
||||
"pic_rotate,pic_rotate_speed,info_color,info_dir,info_shadow,lyric_color," +
|
||||
"lyric_dir,lyric_shadow,list_color,list_dir,list_shadow,pic_dir," +
|
||||
"info_alpha,lyric_alpha,list_alpha,pic_alpha FROM allmusic WHERE name='" + name + "'");
|
||||
HudDirType[] vas = HudDirType.values();
|
||||
HudPosObj obj = null;
|
||||
if (set.next()) {
|
||||
obj = new HudPosObj();
|
||||
HudItemPosObj pos1 = new HudItemPosObj();
|
||||
pos1.x = set.getInt(1);
|
||||
pos1.y = set.getInt(2);
|
||||
obj.info = pos1;
|
||||
obj.info.enable = set.getInt(3) == 1;
|
||||
HudItemPosObj pos2 = new HudItemPosObj();
|
||||
pos2.x = set.getInt(4);
|
||||
pos2.y = set.getInt(5);
|
||||
obj.lyric = pos2;
|
||||
obj.lyric.enable = set.getInt(6) == 1;
|
||||
HudItemPosObj pos3 = new HudItemPosObj();
|
||||
pos3.x = set.getInt(7);
|
||||
pos3.y = set.getInt(8);
|
||||
obj.list = pos3;
|
||||
obj.list.enable = set.getInt(9) == 1;
|
||||
HudItemPosObj pos4 = new HudItemPosObj();
|
||||
pos4.x = set.getInt(10);
|
||||
pos4.y = set.getInt(11);
|
||||
obj.pic = pos4;
|
||||
obj.pic.enable = set.getInt(12) == 1;
|
||||
obj.pic.color = set.getInt(13);
|
||||
obj.pic.shadow = set.getInt(14) == 1;
|
||||
obj.picRotateSpeed = set.getInt(15);
|
||||
obj.info.color = set.getInt(16);
|
||||
obj.info.dir = vas[set.getInt(17)];
|
||||
obj.info.shadow = set.getInt(18) == 1;
|
||||
obj.lyric.color = set.getInt(19);
|
||||
obj.lyric.dir = vas[set.getInt(20)];
|
||||
obj.lyric.shadow = set.getInt(21) == 1;
|
||||
obj.list.color = set.getInt(22);
|
||||
obj.list.dir = vas[set.getInt(23)];
|
||||
obj.list.shadow = set.getInt(24) == 1;
|
||||
obj.pic.dir = vas[set.getInt(25)];
|
||||
obj.info.alpha = set.getFloat(26);
|
||||
obj.lyric.alpha = set.getFloat(27);
|
||||
obj.list.alpha = set.getFloat(28);
|
||||
obj.pic.alpha = set.getFloat(29);
|
||||
}
|
||||
stat.close();
|
||||
|
||||
return obj;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机获取空闲歌单歌曲
|
||||
*/
|
||||
public static MusicObj readListItem() {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT sid,api FROM allmusic_list ORDER BY random() limit 1");
|
||||
String id = null;
|
||||
String api = null;
|
||||
if (set.next()) {
|
||||
id = set.getString(1);
|
||||
api = set.getString(2);
|
||||
}
|
||||
stat.close();
|
||||
MusicObj obj = new MusicObj();
|
||||
obj.id = id;
|
||||
obj.api = api;
|
||||
return obj;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取空闲歌单列表
|
||||
*/
|
||||
public static MusicObj readListItem(int index) {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT sid,api FROM allmusic_list limit 1 offset " + index);
|
||||
String id = null;
|
||||
String index1 = null;
|
||||
if (set.next()) {
|
||||
id = set.getString(1);
|
||||
index1 = set.getString(2);
|
||||
}
|
||||
stat.close();
|
||||
MusicObj obj = new MusicObj();
|
||||
obj.id = id;
|
||||
obj.api = index1;
|
||||
return obj;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取空闲歌单歌曲数量
|
||||
*
|
||||
* @return 歌曲数量
|
||||
*/
|
||||
public static int getListSize() {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT count(sid) FROM allmusic_list");
|
||||
int count = 0;
|
||||
if (set.next()) {
|
||||
count = set.getInt(1);
|
||||
}
|
||||
stat.close();
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void addIdleList(List<String> list, String api) {
|
||||
task(() -> {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO allmusic_list (sid,api) VALUES (?,?)");
|
||||
// 遍历 List<String> 并插入每个字符串
|
||||
for (String str : list) {
|
||||
pstmt.setString(1, str); // 设置参数
|
||||
pstmt.setString(2, api);
|
||||
pstmt.addBatch(); // 添加到批处理
|
||||
}
|
||||
pstmt.executeBatch();
|
||||
pstmt.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void clearIdleList() {
|
||||
task(() -> {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
stat.execute("DELETE FROM allmusic_list");
|
||||
stat.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addBanMusic(String music, String api) {
|
||||
task(() -> {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO allmusic_banlist (sid,api) VALUES (?)");
|
||||
pstmt.setString(1, music); // 设置参数
|
||||
pstmt.setString(2, api);
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
Cache.banMusic.add(music);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeBanMusic(String music) {
|
||||
task(() -> {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("DELETE FROM allmusic_banlist WHERE sid=?");
|
||||
pstmt.setString(1, music); // 设置参数
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
Cache.banMusic.remove(music);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* check a music in ban list?
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean checkBanMusic(String name) {
|
||||
return Cache.banMusic.contains(name);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* a way to get ban music list
|
||||
* @return ban music list
|
||||
*/
|
||||
public static List<String> getBanMusicList() {
|
||||
try {
|
||||
List<String> banList = new ArrayList<>();
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT sid FROM allmusic_banlist");
|
||||
while (set.next()) {
|
||||
String musicName = set.getString("sid");
|
||||
if (musicName != null) {
|
||||
banList.add(musicName);
|
||||
}
|
||||
}
|
||||
set.close();
|
||||
stat.close();
|
||||
return banList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public static void clearBan() {
|
||||
task(() -> {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
stat.execute("DELETE FROM allmusic_banlist");
|
||||
stat.close();
|
||||
Cache.banMusic.clear();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addBanPlayer(String player) {
|
||||
task(() -> {
|
||||
try {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO allmusic_banplayer (sid) VALUES (?)");
|
||||
pstmt.setString(1, player1); // 设置参数
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
Cache.banPlayers.add(player);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeBanPlayer(String player) {
|
||||
task(() -> {
|
||||
try {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("DELETE FROM allmusic_banplayer WHERE sid=?");
|
||||
pstmt.setString(1, player1); // 设置参数
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
Cache.banPlayers.remove(player);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查玩家是否在数据库
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean checkBanPlayer(String name) {
|
||||
return Cache.banPlayers.contains(name);
|
||||
}
|
||||
|
||||
/***
|
||||
* @return a list of ban players
|
||||
*/
|
||||
public static List<String> getBanPlayerList() {
|
||||
try {
|
||||
List<String> banList = new ArrayList<>();
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT sid FROM allmusic_banplayer");
|
||||
while (set.next()) {
|
||||
String playerName = set.getString("sid");
|
||||
if (playerName != null) {
|
||||
banList.add(playerName);
|
||||
}
|
||||
}
|
||||
set.close();
|
||||
stat.close();
|
||||
return banList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public static void clearBanPlayer() {
|
||||
task(() -> {
|
||||
try {
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
stat.execute("DELETE FROM allmusic_banlist");
|
||||
stat.close();
|
||||
Cache.banPlayers.clear();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addMutePlayer(String player) {
|
||||
task(() -> {
|
||||
try {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO allmusic_mute (sid) VALUES (?)");
|
||||
pstmt.setString(1, player1); // 设置参数
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeMutePlayer(String player) {
|
||||
task(() -> {
|
||||
try {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("DELETE FROM allmusic_mute WHERE sid=?");
|
||||
pstmt.setString(1, player1); // 设置参数
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查玩家是否在数据库
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean checkMutePlayer(String name) {
|
||||
try {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
boolean have = false;
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT id FROM allmusic_mute WHERE sid ='" + name + "'");
|
||||
if (set.next()) {
|
||||
have = true;
|
||||
}
|
||||
set.close();
|
||||
stat.close();
|
||||
return have;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void addMuteListPlayer(String player) {
|
||||
task(() -> {
|
||||
try {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO allmusic_mutelist (sid) VALUES (?)");
|
||||
pstmt.setString(1, player1); // 设置参数
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeMuteListPlayer(String player) {
|
||||
task(() -> {
|
||||
try {
|
||||
String player1 = player.toLowerCase(Locale.ROOT);
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
PreparedStatement pstmt = connection.prepareStatement("DELETE FROM allmusic_mutelist WHERE sid=?");
|
||||
pstmt.setString(1, player1); // 设置参数
|
||||
pstmt.execute();
|
||||
pstmt.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查玩家是否在数据库
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean checkMuteListPlayer(String name) {
|
||||
try {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
boolean have = false;
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
Statement stat = connection.createStatement();
|
||||
ResultSet set = stat.executeQuery("SELECT id FROM allmusic_mutelist WHERE sid ='" + name + "'");
|
||||
if (set.next()) {
|
||||
have = true;
|
||||
}
|
||||
set.close();
|
||||
stat.close();
|
||||
return have;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void task(Runnable runnable) {
|
||||
tasks.add(runnable);
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用Hud数据库
|
||||
*/
|
||||
public static void start() {
|
||||
init();
|
||||
new Thread(DataSql::run).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止数据库
|
||||
*/
|
||||
public static void stop() {
|
||||
semaphore.release();
|
||||
try {
|
||||
if (connection != null && connection.isClosed()) {
|
||||
connection.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void run() {
|
||||
AllMusic.log.data("数据库线程启动");
|
||||
Runnable runnable;
|
||||
while (AllMusic.isRun) {
|
||||
try {
|
||||
semaphore.acquire();
|
||||
if (!AllMusic.isRun)
|
||||
break;
|
||||
do {
|
||||
runnable = tasks.poll();
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
while (runnable != null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
AllMusic.log.data("数据库线程关闭");
|
||||
}
|
||||
}
|
||||
@@ -1,55 +1,15 @@
|
||||
package com.coloryr.allmusic.server.core.utils;
|
||||
|
||||
import com.coloryr.allmusic.codec.HudDirType;
|
||||
import com.coloryr.allmusic.codec.HudItemPosObj;
|
||||
import com.coloryr.allmusic.codec.HudPosObj;
|
||||
import com.coloryr.allmusic.codec.HudType;
|
||||
import com.coloryr.allmusic.codec.*;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.music.LyricSave;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.config.LimitObj;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
|
||||
public class HudUtils {
|
||||
private static final Map<String, HudPosObj> HudList = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 获取玩家的Hud储存
|
||||
*
|
||||
* @param name 玩家名
|
||||
* @return Hud储存
|
||||
*/
|
||||
public static HudPosObj get(String name) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
if (!HudList.containsKey(name)) {
|
||||
HudPosObj obj1 = DataSql.readHud(name);
|
||||
if (obj1 == null) {
|
||||
HudPosObj obj = AllMusic.getConfig().defaultHud.copy();
|
||||
HudList.put(name, obj);
|
||||
String finalName = name;
|
||||
DataSql.task(() -> DataSql.addUser(finalName, obj));
|
||||
return obj;
|
||||
}
|
||||
|
||||
HudList.put(name, obj1);
|
||||
return obj1;
|
||||
}
|
||||
return HudList.get(name);
|
||||
}
|
||||
|
||||
public static void addAndSave(String name, HudPosObj hud) {
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
HudList.put(name, hud);
|
||||
String finalName = name;
|
||||
DataSql.task(() -> DataSql.addUser(finalName, hud));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置组件位置
|
||||
*
|
||||
@@ -59,17 +19,15 @@ public class HudUtils {
|
||||
* @param y y
|
||||
* @return 组件数据
|
||||
*/
|
||||
public static HudItemPosObj setHudPos(String player, HudType pos, String x, String y) {
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
public static HudBasePosObj setHudPos(String player, HudType pos, String x, String y) {
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
|
||||
if (!Function.isInteger(x) && !Function.isInteger(y))
|
||||
return null;
|
||||
int x1 = Integer.parseInt(x);
|
||||
int y1 = Integer.parseInt(y);
|
||||
|
||||
HudItemPosObj posOBJ;
|
||||
HudBasePosObj posOBJ;
|
||||
switch (pos) {
|
||||
case LYRIC:
|
||||
posOBJ = obj.lyric;
|
||||
@@ -89,29 +47,29 @@ public class HudUtils {
|
||||
posOBJ.x = x1;
|
||||
posOBJ.y = y1;
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
return posOBJ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置组件透明度
|
||||
*
|
||||
* @param player 用户名
|
||||
* @param pos 位置
|
||||
* @param alpha 透明度
|
||||
* @param pos 位置
|
||||
* @param alpha 透明度
|
||||
* @return 组件数据
|
||||
*/
|
||||
public static HudItemPosObj setHudAlpha(String player, HudType pos, String alpha) {
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
public static HudBasePosObj setHudAlpha(String player, HudType pos, String alpha) {
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
|
||||
if (!Function.isInteger(alpha))
|
||||
return null;
|
||||
float alpha1 = Float.parseFloat(alpha);
|
||||
if (alpha1 > 1 || alpha1 < 0) {
|
||||
alpha1 = 1;
|
||||
}
|
||||
HudItemPosObj posOBJ;
|
||||
HudBasePosObj posOBJ;
|
||||
switch (pos) {
|
||||
case LYRIC:
|
||||
posOBJ = obj.lyric;
|
||||
@@ -130,7 +88,7 @@ public class HudUtils {
|
||||
}
|
||||
posOBJ.alpha = alpha1;
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
return posOBJ;
|
||||
}
|
||||
@@ -202,27 +160,38 @@ public class HudUtils {
|
||||
* 更新Hud的歌词数据
|
||||
*/
|
||||
public static void sendHudLyricData() {
|
||||
String info;
|
||||
String lyr;
|
||||
String tran;
|
||||
String ktv;
|
||||
LyricSave obj = PlayMusic.lyric;
|
||||
if (obj == null) {
|
||||
info = AllMusic.getMessage().hud.emptyLyric;
|
||||
lyr = AllMusic.getMessage().hud.emptyLyric;
|
||||
tran = "";
|
||||
ktv = "";
|
||||
} else {
|
||||
String lyric = obj.getLyric();
|
||||
String tLyric = obj.getTlyric();
|
||||
String kLyric = obj.getKly();
|
||||
if (!AllMusic.getConfig().ktvMode) {
|
||||
info = AllMusic.getMessage().hud.lyric
|
||||
.replace(ARG.lyric, lyric == null ? "" : lyric)
|
||||
.replace(ARG.tlyric, tLyric != null ? tLyric : "");
|
||||
} else {
|
||||
info = AllMusic.getMessage().hud.ktv
|
||||
.replace(ARG.lyric, lyric != null ? lyric : "")
|
||||
.replace(ARG.klyric, kLyric != null ? kLyric : "")
|
||||
.replace(ARG.tlyric, tLyric != null ? tLyric : "");
|
||||
}
|
||||
lyr = AllMusic.getMessage().hud.lyric
|
||||
.replace(ARG.lyric, lyric == null ? "" : lyric);
|
||||
tran = AllMusic.getMessage().hud.tlyric
|
||||
.replace(ARG.lyric, tLyric == null ? "" : tLyric);
|
||||
ktv = AllMusic.getMessage().hud.klyric
|
||||
.replace(ARG.lyric, lyric == null ? "" : lyric);
|
||||
}
|
||||
|
||||
AllMusic.side.sendHudLyric(info);
|
||||
AllMusic.side.sendHudLyric(new MusicPack.LyricMusicPack(lyr, tran, ktv));
|
||||
}
|
||||
|
||||
public static void sendHudKtv() {
|
||||
float kLyric;
|
||||
LyricSave obj = PlayMusic.lyric;
|
||||
if (obj == null) {
|
||||
kLyric = 0.0f;
|
||||
} else {
|
||||
kLyric = obj.getKly();
|
||||
|
||||
}
|
||||
AllMusic.side.sendHudKtv(kLyric);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,7 +202,7 @@ public class HudUtils {
|
||||
* @return 设置结果
|
||||
*/
|
||||
public static boolean setHudEnable(String player, HudType pos, String arg) {
|
||||
HudPosObj obj = get(player);
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
boolean res = false;
|
||||
boolean value = false;
|
||||
boolean have = false;
|
||||
@@ -245,41 +214,32 @@ public class HudUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (obj == null) {
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
if (pos == null) {
|
||||
if (have) {
|
||||
res = obj.info.enable = obj.list.enable = obj.lyric.enable = obj.pic.enable = value;
|
||||
} else if (obj.info.enable && obj.list.enable && obj.lyric.enable && obj.pic.enable) {
|
||||
obj.info.enable = obj.list.enable = obj.lyric.enable = obj.pic.enable = false;
|
||||
} else {
|
||||
res = obj.info.enable = obj.list.enable = obj.lyric.enable = obj.pic.enable = true;
|
||||
}
|
||||
} else {
|
||||
if (pos == null) {
|
||||
if (have) {
|
||||
res = obj.info.enable = obj.list.enable = obj.lyric.enable = obj.pic.enable = value;
|
||||
} else if (obj.info.enable && obj.list.enable && obj.lyric.enable && obj.pic.enable) {
|
||||
obj.info.enable = obj.list.enable = obj.lyric.enable = obj.pic.enable = false;
|
||||
} else {
|
||||
res = obj.info.enable = obj.list.enable = obj.lyric.enable = obj.pic.enable = true;
|
||||
}
|
||||
} else {
|
||||
switch (pos) {
|
||||
case INFO:
|
||||
res = obj.info.enable = have ? value : !obj.info.enable;
|
||||
break;
|
||||
case LIST:
|
||||
res = obj.list.enable = have ? value : !obj.list.enable;
|
||||
break;
|
||||
case LYRIC:
|
||||
res = obj.lyric.enable = have ? value : !obj.lyric.enable;
|
||||
break;
|
||||
case PIC:
|
||||
res = obj.pic.enable = have ? value : !obj.pic.enable;
|
||||
break;
|
||||
}
|
||||
switch (pos) {
|
||||
case INFO:
|
||||
res = obj.info.enable = have ? value : !obj.info.enable;
|
||||
break;
|
||||
case LIST:
|
||||
res = obj.list.enable = have ? value : !obj.list.enable;
|
||||
break;
|
||||
case LYRIC:
|
||||
res = obj.lyric.enable = have ? value : !obj.lyric.enable;
|
||||
break;
|
||||
case PIC:
|
||||
res = obj.pic.enable = have ? value : !obj.pic.enable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
|
||||
return res;
|
||||
@@ -309,11 +269,6 @@ public class HudUtils {
|
||||
public static void sendHudPos(String player) {
|
||||
AllMusic.side.runTask(() -> {
|
||||
try {
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null) {
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
addAndSave(player, obj);
|
||||
}
|
||||
AllMusic.side.sendHudPos(player);
|
||||
} catch (Exception e1) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>数据发送发生错误");
|
||||
@@ -328,14 +283,14 @@ public class HudUtils {
|
||||
* @param player 用户名
|
||||
*/
|
||||
public static void reset(String player) {
|
||||
HudPosObj obj = AllMusic.getConfig().defaultHud.copy();
|
||||
addAndSave(player, obj);
|
||||
HudPosObj obj = HudSave.defaultHud.copy();
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
}
|
||||
|
||||
public static void reset(String player, HudType type) {
|
||||
HudPosObj obj = AllMusic.getConfig().defaultHud.copy();
|
||||
HudPosObj obj1 = get(player);
|
||||
HudPosObj obj = HudSave.defaultHud.copy();
|
||||
HudPosObj obj1 = HudSave.getOrNew(player);
|
||||
switch (type) {
|
||||
case INFO:
|
||||
obj1.info = obj.info;
|
||||
@@ -348,11 +303,10 @@ public class HudUtils {
|
||||
break;
|
||||
case PIC:
|
||||
obj1.pic = obj.pic;
|
||||
obj1.picRotateSpeed = obj.picRotateSpeed;
|
||||
break;
|
||||
}
|
||||
|
||||
addAndSave(player, obj1);
|
||||
HudSave.update(player, obj1);
|
||||
HudUtils.sendHudPos(player);
|
||||
}
|
||||
|
||||
@@ -364,15 +318,13 @@ public class HudUtils {
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean setPicSize(String player, String size) {
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
if (!Function.isInteger(size))
|
||||
return false;
|
||||
|
||||
obj.pic.color = Integer.parseInt(size);
|
||||
obj.pic.size = Integer.parseInt(size);
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
return true;
|
||||
}
|
||||
@@ -385,19 +337,17 @@ public class HudUtils {
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean setPicRotate(String player, String open) {
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
|
||||
if (open != null) {
|
||||
obj.pic.shadow = Boolean.parseBoolean(open);
|
||||
obj.pic.rotate = Boolean.parseBoolean(open);
|
||||
} else {
|
||||
obj.pic.shadow = !obj.pic.shadow;
|
||||
obj.pic.rotate = !obj.pic.rotate;
|
||||
}
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
return obj.pic.shadow;
|
||||
return obj.pic.rotate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -408,27 +358,25 @@ public class HudUtils {
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean setPicRotateSpeed(String player, String size) {
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
if (!Function.isInteger(size))
|
||||
return false;
|
||||
|
||||
obj.picRotateSpeed = Integer.parseInt(size);
|
||||
obj.pic.speed = Integer.parseInt(size);
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static HudDirType setDir(String player, HudType hud, String arg) {
|
||||
HudDirType type = null;
|
||||
public static HudPosType setPos(String player, HudType hud, String arg) {
|
||||
HudPosType type = null;
|
||||
try {
|
||||
if (Function.isInteger(arg)) {
|
||||
int index = Integer.parseInt(arg);
|
||||
type = HudDirType.values()[index];
|
||||
type = HudPosType.values()[index];
|
||||
} else {
|
||||
type = HudDirType.valueOf(arg);
|
||||
type = HudPosType.valueOf(arg);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
|
||||
@@ -437,26 +385,23 @@ public class HudUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
switch (hud) {
|
||||
case INFO:
|
||||
obj.info.dir = type;
|
||||
obj.info.pos = type;
|
||||
break;
|
||||
case LIST:
|
||||
obj.list.dir = type;
|
||||
obj.list.pos = type;
|
||||
break;
|
||||
case LYRIC:
|
||||
obj.lyric.dir = type;
|
||||
obj.lyric.pos = type;
|
||||
break;
|
||||
case PIC:
|
||||
obj.pic.dir = type;
|
||||
obj.pic.pos = type;
|
||||
break;
|
||||
}
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
|
||||
return type;
|
||||
@@ -478,10 +423,7 @@ public class HudUtils {
|
||||
|
||||
color = (color & -67108864) == 0 ? color | 0xFF000000 : color;
|
||||
|
||||
HudPosObj obj = get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
|
||||
HudPosObj obj = HudSave.getOrNew(player);
|
||||
switch (type) {
|
||||
case INFO:
|
||||
obj.info.color = color;
|
||||
@@ -493,18 +435,17 @@ public class HudUtils {
|
||||
obj.lyric.color = color;
|
||||
break;
|
||||
case PIC:
|
||||
obj.pic.color = color;
|
||||
break;
|
||||
return -1;
|
||||
}
|
||||
|
||||
addAndSave(player, obj);
|
||||
HudSave.update(player, obj);
|
||||
HudUtils.sendHudPos(player);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
public static boolean setShadow(String name, HudType pos, String arg) {
|
||||
HudPosObj obj = get(name);
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
boolean res = false;
|
||||
boolean value = false;
|
||||
boolean have = false;
|
||||
@@ -516,51 +457,35 @@ public class HudUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (obj == null) {
|
||||
obj = AllMusic.getConfig().defaultHud.copy();
|
||||
|
||||
if (pos == null) {
|
||||
if (have) {
|
||||
res = obj.info.shadow = obj.list.shadow = obj.lyric.shadow = obj.pic.shadow = value;
|
||||
res = obj.info.shadow = obj.list.shadow = obj.lyric.shadow = value;
|
||||
} else if (obj.info.shadow && obj.list.shadow && obj.lyric.shadow) {
|
||||
obj.info.shadow = obj.list.shadow = obj.lyric.shadow = false;
|
||||
} else {
|
||||
res = obj.info.shadow = obj.list.shadow = obj.lyric.shadow = obj.pic.shadow = true;
|
||||
res = obj.info.shadow = obj.list.shadow = obj.lyric.shadow = true;
|
||||
}
|
||||
} else {
|
||||
if (pos == null) {
|
||||
if (have) {
|
||||
res = obj.info.shadow = obj.list.shadow = obj.lyric.shadow = obj.pic.shadow = value;
|
||||
} else if (obj.info.shadow && obj.list.shadow && obj.lyric.shadow && obj.pic.shadow) {
|
||||
obj.info.shadow = obj.list.shadow = obj.lyric.shadow = obj.pic.shadow = false;
|
||||
} else {
|
||||
res = obj.info.shadow = obj.list.shadow = obj.lyric.shadow = obj.pic.shadow = true;
|
||||
}
|
||||
} else {
|
||||
switch (pos) {
|
||||
case INFO:
|
||||
res = obj.info.shadow = have ? value : !obj.info.shadow;
|
||||
break;
|
||||
case LIST:
|
||||
res = obj.list.shadow = have ? value : !obj.list.shadow;
|
||||
break;
|
||||
case LYRIC:
|
||||
res = obj.lyric.shadow = have ? value : !obj.lyric.shadow;
|
||||
break;
|
||||
case PIC:
|
||||
res = obj.pic.shadow = have ? value : !obj.pic.shadow;
|
||||
break;
|
||||
}
|
||||
switch (pos) {
|
||||
case INFO:
|
||||
res = obj.info.shadow = have ? value : !obj.info.shadow;
|
||||
break;
|
||||
case LIST:
|
||||
res = obj.list.shadow = have ? value : !obj.list.shadow;
|
||||
break;
|
||||
case LYRIC:
|
||||
res = obj.lyric.shadow = have ? value : !obj.lyric.shadow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
addAndSave(name, obj);
|
||||
HudSave.update(name, obj);
|
||||
HudUtils.sendHudPos(name);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void set(String name, HudPosObj obj) {
|
||||
addAndSave(name, obj);
|
||||
HudUtils.sendHudPos(name);
|
||||
}
|
||||
|
||||
public static String infoLimit(String info) {
|
||||
LimitObj limit = AllMusic.getConfig().limit;
|
||||
if (limit.infoLimit && info.length() > limit.infoLimitSize)
|
||||
@@ -584,4 +509,33 @@ public class HudUtils {
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public static String setLoop(String name, HudType type, String arg) {
|
||||
LoopType loop;
|
||||
try {
|
||||
loop = LoopType.valueOf(arg);
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HudPosObj obj = HudSave.getOrNew(name);
|
||||
switch (type) {
|
||||
case INFO:
|
||||
obj.info.loop = loop;
|
||||
break;
|
||||
case LIST:
|
||||
obj.list.loop = loop;
|
||||
break;
|
||||
case LYRIC:
|
||||
obj.lyric.loop = loop;
|
||||
break;
|
||||
case PIC:
|
||||
return null;
|
||||
}
|
||||
|
||||
HudSave.update(name, obj);
|
||||
HudUtils.sendHudPos(name);
|
||||
|
||||
return loop.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.coloryr.allmusic.server.netapi;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.music.KtvLyric;
|
||||
import com.coloryr.allmusic.server.core.objs.music.LyricItemObj;
|
||||
import com.coloryr.allmusic.server.core.utils.Function;
|
||||
import com.coloryr.allmusic.server.netapi.obj.music.lyric.WLyricObj;
|
||||
@@ -14,13 +15,13 @@ public class LyricDecoder {
|
||||
private final Map<Long, LyricItemObj> lyrics = new LinkedHashMap<>();
|
||||
public boolean isHave = false;
|
||||
public boolean isHaveK = false;
|
||||
public Map<Long, String> kly = new LinkedHashMap<>();
|
||||
public Map<Long, KtvLyric> kly = new LinkedHashMap<>();
|
||||
|
||||
public Map<Long, LyricItemObj> getLyrics() {
|
||||
return lyrics;
|
||||
}
|
||||
|
||||
public Map<Long, String> getKLyric() {
|
||||
public Map<Long, KtvLyric> getKLyric() {
|
||||
return kly;
|
||||
}
|
||||
|
||||
@@ -54,9 +55,9 @@ public class LyricDecoder {
|
||||
if (temp2 != null && !temp2.isEmpty()) {
|
||||
String[] klyric = temp2.split("\n");
|
||||
for (String item : klyric) {
|
||||
Map<Long, String> temp4 = getKTime(item, obj.getVersion());
|
||||
KtvLyric temp4 = getKTime(item, obj.getVersion());
|
||||
if (temp4 != null) {
|
||||
kly.putAll(temp4);
|
||||
kly.put(temp4.start, temp4);
|
||||
}
|
||||
}
|
||||
isHaveK = true;
|
||||
@@ -127,8 +128,7 @@ public class LyricDecoder {
|
||||
return res;
|
||||
}
|
||||
|
||||
private Map<Long, String> getKTime(String lyric, boolean yrc) {
|
||||
Map<Long, String> res = new LinkedHashMap<>();
|
||||
private KtvLyric getKTime(String lyric, boolean yrc) {
|
||||
if (!lyric.startsWith("[") || !lyric.contains("]("))
|
||||
return null;
|
||||
|
||||
@@ -146,16 +146,21 @@ public class LyricDecoder {
|
||||
String temp = Function.getString(lyric, "[", "]");
|
||||
String[] temp11 = temp.split(",");
|
||||
long now = Integer.parseInt(temp11[0]) / 10 * 10;
|
||||
long time = Integer.parseInt(temp11[1]) / 10 * 10;
|
||||
|
||||
KtvLyric ktv = new KtvLyric();
|
||||
ktv.start = now;
|
||||
ktv.time = time;
|
||||
for (int a = 1; a < datas.length; a++) {
|
||||
String data = datas[a];
|
||||
KtvLyric.KtvItem item = new KtvLyric.KtvItem();
|
||||
item.key = datas[a];
|
||||
String temp3 = temp1111.get(a - 1);
|
||||
String[] temp8 = temp3.split(",");
|
||||
long temp5;
|
||||
if (yrc) {
|
||||
temp5 = (Integer.parseInt(temp8[0]) / 10 * 10);
|
||||
if (temp5 > 0 && temp5 + AllMusic.getConfig().ktvLyricDelay > 0)
|
||||
temp5 += (AllMusic.getConfig().ktvLyricDelay / 10 * 10);
|
||||
res.put(temp5, data);
|
||||
item.start = (Integer.parseInt(temp8[0]) / 10 * 10);
|
||||
item.time = (Integer.parseInt(temp8[1]) / 10 * 10);
|
||||
ktv.items.add(item);
|
||||
} else {
|
||||
try {
|
||||
temp5 = (Integer.parseInt(temp8[1]) / 10 * 10);
|
||||
@@ -165,13 +170,12 @@ public class LyricDecoder {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (temp5 > 0 && temp5 + AllMusic.getConfig().ktvLyricDelay > 0)
|
||||
temp5 += (AllMusic.getConfig().ktvLyricDelay / 10 * 10);
|
||||
res.put(now, data);
|
||||
item.start = now;
|
||||
item.time = temp5;
|
||||
now += temp5;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return ktv;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ import com.coloryr.allmusic.server.core.objs.SearchMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SearchPageObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.sql.DataSql;
|
||||
import com.coloryr.allmusic.server.core.saves.HudSave;
|
||||
import com.coloryr.allmusic.server.core.saves.MusicListSave;
|
||||
import com.coloryr.allmusic.server.core.utils.Function;
|
||||
import com.coloryr.allmusic.server.netapi.obj.music.info.InfoObj;
|
||||
import com.coloryr.allmusic.server.netapi.obj.music.list.DataObj;
|
||||
@@ -171,7 +172,7 @@ public class NetiApiMain implements IMusicApi {
|
||||
try {
|
||||
isUpdate = true;
|
||||
DataObj obj = AllMusic.gson.fromJson(res.data, DataObj.class);
|
||||
DataSql.addIdleList(obj.getPlaylist(), getId());
|
||||
MusicListSave.addIdleList(obj.getPlaylist(), getId());
|
||||
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().musicPlay.listMusic.get.replace(ARG.name, obj.getName()));
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.data("<light_purple>[AllMusic3]<red>歌曲列表获取错误");
|
||||
|
||||
@@ -16,8 +16,6 @@ dependencies {
|
||||
shadowImplementation("net.kyori:adventure-text-serializer-legacy:${Versions.adventure}")
|
||||
shadowImplementation("net.kyori:adventure-text-serializer-plain:${Versions.adventure}")
|
||||
shadowImplementation("net.kyori:adventure-key:${Versions.adventure}")
|
||||
|
||||
include("org.xerial:sqlite-jdbc:${Versions.sqlite}")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -25,8 +25,6 @@ dependencies {
|
||||
// shadowImplementation("net.kyori:adventure-text-serializer-legacy:4.8.1")
|
||||
// shadowImplementation("net.kyori:adventure-text-serializer-plain:4.8.1")
|
||||
// shadowImplementation("net.kyori:adventure-key:4.8.1")
|
||||
|
||||
include("org.xerial:sqlite-jdbc:${Versions.sqlite}")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.buffercodec.MusicPacketCodec;
|
||||
import com.coloryr.allmusic.codec.CommandType;
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
@@ -79,9 +80,9 @@ public class SideFabric extends BaseSide {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object player, CommandType type, String data, int data1) {
|
||||
public void send(Object player, MusicPack pack) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
send(player1, MusicPacketCodec.pack(type, data, data1));
|
||||
send(player1, MusicPacketCodec.pack(pack));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.coloryr.allmusic.server.hooks;
|
||||
|
||||
import com.coloryr.allmusic.server.core.sql.IEconomy;
|
||||
import com.coloryr.allmusic.server.core.IEconomy;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.coloryr.allmusic.server.hooks;
|
||||
|
||||
import com.coloryr.allmusic.server.core.sql.IEconomy;
|
||||
import com.coloryr.allmusic.server.core.IEconomy;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.coloryr.allmusic.server.side.bukkit.hooks;
|
||||
|
||||
import com.coloryr.allmusic.server.core.sql.IEconomy;
|
||||
import com.coloryr.allmusic.server.core.IEconomy;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.side.BaseSide;
|
||||
import com.coloryr.allmusic.server.core.sql.IEconomy;
|
||||
import com.coloryr.allmusic.server.core.IEconomy;
|
||||
import com.coloryr.allmusic.server.side.velocity.event.MusicAddEvent;
|
||||
import com.coloryr.allmusic.server.side.velocity.event.MusicPlayEvent;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
Reference in new issue
Block a user