mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-26 02:13:05 +00:00
up
This commit is contained in:
1 parent
8a627d755f
commit
43e2563c4a
13 files changed
+103
-59
No files matched your search
@@ -13,5 +13,5 @@ public class ALLMusic {
|
||||
public static ISide Side;
|
||||
public static final String channel = "allmusic:channel";
|
||||
|
||||
public static final String Version = "1.3.0";
|
||||
public static final String Version = "1.4.0";
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class ALLMusicBC extends Plugin {
|
||||
|
||||
public static Plugin ALLMusicP;
|
||||
public static void save() {
|
||||
try {
|
||||
String data = new Gson().toJson(ALLMusic.Config);
|
||||
@@ -29,7 +29,7 @@ public class ALLMusicBC extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadConfig() throws FileNotFoundException {
|
||||
private static void LoadConfig() throws FileNotFoundException {
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(ALLMusic.ConfigFile), StandardCharsets.UTF_8);
|
||||
BufferedReader bf = new BufferedReader(reader);
|
||||
@@ -51,15 +51,15 @@ public class ALLMusicBC extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfig() {
|
||||
public static void setConfig() {
|
||||
try {
|
||||
if (ALLMusic.ConfigFile == null) {
|
||||
ALLMusic.ConfigFile = new File(getDataFolder(), "config.json");
|
||||
logs.file = new File(getDataFolder(), "logs.log");
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
ALLMusic.ConfigFile = new File(ALLMusicP.getDataFolder(), "config.json");
|
||||
logs.file = new File(ALLMusicP.getDataFolder(), "logs.log");
|
||||
if (!ALLMusicP.getDataFolder().exists())
|
||||
ALLMusicP.getDataFolder().mkdir();
|
||||
if (!ALLMusic.ConfigFile.exists()) {
|
||||
InputStream in = getResourceAsStream("config_BC.json");
|
||||
InputStream in = ALLMusicP.getResourceAsStream("config_BC.json");
|
||||
Files.copy(in, ALLMusic.ConfigFile.toPath());
|
||||
}
|
||||
if (!logs.file.exists()) {
|
||||
@@ -76,6 +76,7 @@ public class ALLMusicBC extends Plugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
ALLMusicP = this;
|
||||
ALLMusic.log = ProxyServer.getInstance().getLogger();
|
||||
ALLMusic.log.info("§d[ALLMusic]§e正在启动,感谢使用,本插件交流群:571239090");
|
||||
setConfig();
|
||||
@@ -88,6 +89,7 @@ public class ALLMusicBC extends Plugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PlayMusic.stop();
|
||||
PlayMusic.PlayList.clear();
|
||||
PlayMusic.Vote.clear();
|
||||
ALLMusic.Side.Send("[Stop]", false);
|
||||
|
||||
@@ -6,7 +6,6 @@ import Color_yr.ALLMusic.Play.PlayMusic;
|
||||
import Color_yr.ALLMusic.Side.SideBukkit;
|
||||
import Color_yr.ALLMusic.Utils.logs;
|
||||
import com.google.gson.Gson;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -33,7 +32,7 @@ public class ALLMusicBukkit extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadConfig() throws FileNotFoundException {
|
||||
private static void LoadConfig() throws FileNotFoundException {
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(new FileInputStream(ALLMusic.ConfigFile), StandardCharsets.UTF_8);
|
||||
BufferedReader bf = new BufferedReader(reader);
|
||||
@@ -55,15 +54,15 @@ public class ALLMusicBukkit extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfig() {
|
||||
public static void setConfig() {
|
||||
try {
|
||||
if (ALLMusic.ConfigFile == null) {
|
||||
ALLMusic.ConfigFile = new File(getDataFolder(), "config.json");
|
||||
logs.file = new File(getDataFolder(), "logs.log");
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
ALLMusic.ConfigFile = new File(ALLMusicP.getDataFolder(), "config.json");
|
||||
logs.file = new File(ALLMusicP.getDataFolder(), "logs.log");
|
||||
if (!ALLMusicP.getDataFolder().exists())
|
||||
ALLMusicP.getDataFolder().mkdir();
|
||||
if (!ALLMusic.ConfigFile.exists()) {
|
||||
InputStream in = getResource("config_BC.json");
|
||||
InputStream in = ALLMusicP.getResource("config_BC.json");
|
||||
Files.copy(in, ALLMusic.ConfigFile.toPath());
|
||||
}
|
||||
if (!logs.file.exists()) {
|
||||
@@ -95,6 +94,7 @@ public class ALLMusicBukkit extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PlayMusic.stop();
|
||||
PlayMusic.PlayList.clear();
|
||||
PlayMusic.Vote.clear();
|
||||
ALLMusic.Side.Send("[Stop]", false);
|
||||
|
||||
@@ -95,8 +95,7 @@ public class CommandBC extends Command implements TabExecutor {
|
||||
}
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
ALLMusicBC music = new ALLMusicBC();
|
||||
music.setConfig();
|
||||
ALLMusicBC.setConfig();
|
||||
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已重读配置文件"));
|
||||
} else if (args[0].equalsIgnoreCase("v")) {
|
||||
if (args.length == 2) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package Color_yr.ALLMusic.Command;
|
||||
|
||||
import Color_yr.ALLMusic.ALLMusic;
|
||||
import Color_yr.ALLMusic.ALLMusicBC;
|
||||
import Color_yr.ALLMusic.ALLMusicBukkit;
|
||||
import Color_yr.ALLMusic.Play.PlayMusic;
|
||||
import Color_yr.ALLMusic.Utils.Function;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -93,8 +94,7 @@ public class CommandBukkit implements CommandExecutor, TabExecutor {
|
||||
}
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
ALLMusicBC music = new ALLMusicBC();
|
||||
music.setConfig();
|
||||
ALLMusicBukkit.setConfig();
|
||||
sender.sendMessage("§d[ALLMusic]§2已重读配置文件");
|
||||
} else if (args[0].equalsIgnoreCase("v")) {
|
||||
if (args.length == 2) {
|
||||
|
||||
@@ -22,8 +22,7 @@ public class Get {
|
||||
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
|
||||
Bitstream bt = new Bitstream(bis);
|
||||
Header h = bt.readFrame();
|
||||
int time = (int) h.total_ms(b);
|
||||
return time / 1000;
|
||||
return (int) h.total_ms(b) / 1000;
|
||||
} catch (Exception e) {
|
||||
ALLMusic.log.warning("§d[ALLMusic]§c获取音乐长度错误");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -29,30 +29,40 @@ public class LyricDo {
|
||||
}
|
||||
String min;
|
||||
String sec;
|
||||
String mil;
|
||||
String Tlyric = null;
|
||||
String temp;
|
||||
String temp2;
|
||||
int time;
|
||||
for (int now = 0; now < lyric.length; now++) {
|
||||
if (Function.countChar(lyric[now], ':') > 1) {
|
||||
String[] a = lyric[now].split(":");
|
||||
int milt;
|
||||
for (String s : lyric) {
|
||||
if (Function.countChar(Function.getString(s, "[", "]"), ':') > 1) {
|
||||
String[] a = s.split(":");
|
||||
min = a[0].substring(1);
|
||||
sec = a[1];
|
||||
mil = a[2];
|
||||
} else {
|
||||
min = Function.getString(lyric[now], "[", ":");
|
||||
sec = Function.getString(lyric[now], ":", ".");
|
||||
min = Function.getString(s, "[", ":");
|
||||
sec = Function.getString(s, ":", ".");
|
||||
mil = Function.getString(s, ".", "]");
|
||||
}
|
||||
if (!Function.isInteger(min))
|
||||
continue;
|
||||
if (!Function.isInteger(sec))
|
||||
continue;
|
||||
if(min.isEmpty() || sec.isEmpty())
|
||||
if (!Function.isInteger(mil))
|
||||
continue;
|
||||
time = Integer.parseInt(min) * 60 + Integer.parseInt(sec);
|
||||
if (time > 0)
|
||||
time -= ALLMusic.Config.getDelay();
|
||||
if (min.isEmpty() || sec.isEmpty() || mil.isEmpty())
|
||||
continue;
|
||||
milt = Integer.parseInt(mil);
|
||||
if(mil.length() == 3) {
|
||||
milt /= 10;
|
||||
}
|
||||
time = Integer.parseInt(min) * 60 * 1000 + Integer.parseInt(sec) * 1000 + milt * 10;
|
||||
if (time > 0 && time + ALLMusic.Config.getDelay() > 0)
|
||||
time += ALLMusic.Config.getDelay();
|
||||
if (haveT) {
|
||||
temp = Function.getString(lyric[now], "[", "]");
|
||||
temp = Function.getString(s, "[", "]");
|
||||
for (String item : tlyric) {
|
||||
temp2 = Function.getString(item, "[", "]");
|
||||
if (temp.startsWith(temp2) || temp2.startsWith(temp)) {
|
||||
@@ -63,7 +73,7 @@ public class LyricDo {
|
||||
}
|
||||
}
|
||||
Lyric.put(time, new ShowOBJ(time, haveT,
|
||||
Function.getString(lyric[now], "]", null), Tlyric));
|
||||
Function.getString(s, "]", null), Tlyric));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,44 @@ import Color_yr.ALLMusic.ALLMusic;
|
||||
import Color_yr.ALLMusic.Http.Get;
|
||||
import Color_yr.ALLMusic.Lyric.LyricDo;
|
||||
import Color_yr.ALLMusic.Lyric.ShowOBJ;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
import java.security.AlgorithmConstraints;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
class PlayGo extends Thread {
|
||||
|
||||
public void close() {
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
service.shutdownNow();
|
||||
}
|
||||
if (service1 != null) {
|
||||
service1.shutdown();
|
||||
service1.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
private ScheduledExecutorService service;
|
||||
private ScheduledExecutorService service1;
|
||||
//创建 run 方法
|
||||
Runnable runnable = () -> PlayMusic.MusicNowTime += 10;
|
||||
Runnable runnable1 = () -> {
|
||||
ShowOBJ show = PlayMusic.Lyric.checkTime(PlayMusic.MusicNowTime);
|
||||
if (show != null) {
|
||||
String now = show.toString();
|
||||
PlayMusic.nowLyric = now != null ? now : PlayMusic.nowLyric;
|
||||
}
|
||||
ALLMusic.Side.SendLyric(PlayMusic.nowLyric);
|
||||
};
|
||||
|
||||
private void startTime() {
|
||||
service = Executors.newSingleThreadScheduledExecutor();
|
||||
service.scheduleAtFixedRate(runnable, 0, 10, TimeUnit.MILLISECONDS);
|
||||
service1 = Executors.newSingleThreadScheduledExecutor();
|
||||
service1.scheduleAtFixedRate(runnable1, 0, 2, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
while (true) {
|
||||
@@ -28,6 +59,7 @@ class PlayGo extends Thread {
|
||||
PlayMusic.Lyric = null;
|
||||
PlayMusic.MusicNowTime = 0;
|
||||
PlayMusic.MusicAllTime = 0;
|
||||
close();
|
||||
ALLMusic.Side.SendLyric("");
|
||||
String songURL = Get.realURL(ALLMusic.Config.getMusic_Api1() + PlayMusic.NowPlayMusic.getID());
|
||||
String Lyric = Get.realData(ALLMusic.Config.getLyric_Api1() + PlayMusic.NowPlayMusic.getID());
|
||||
@@ -44,43 +76,37 @@ class PlayGo extends Thread {
|
||||
if (songURL != null) {
|
||||
PlayMusic.MusicAllTime = Get.getMusicTime(songURL);
|
||||
ALLMusic.Side.bq("§d[ALLMusic]§2" + "正在播放歌曲" + PlayMusic.NowPlayMusic.getInfo());
|
||||
if (PlayMusic.haveLyric)
|
||||
startTime();
|
||||
ALLMusic.Side.Send("[Play]" + songURL, true);
|
||||
try {
|
||||
while (PlayMusic.MusicAllTime > 0) {
|
||||
if (PlayMusic.Vote_time > 0) {
|
||||
PlayMusic.Vote_time--;
|
||||
PlayMusic.Vote_time --;
|
||||
if (PlayMusic.Vote_time == 0) {
|
||||
PlayMusic.Vote.clear();
|
||||
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + "切歌时间结束"));
|
||||
ALLMusic.Side.bq("§d[ALLMusic]§2" + "切歌时间结束");
|
||||
} else {
|
||||
int players = ALLMusic.Side.GetAllPlayer();
|
||||
if (PlayMusic.Vote.size() >= ALLMusic.Config.getMinVote() || (players <= ALLMusic.Config.getMinVote() && players == PlayMusic.Vote.size())) {
|
||||
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + "已切歌"));
|
||||
if (PlayMusic.Vote.size() >= ALLMusic.Config.getMinVote() || (players <= ALLMusic.Config.getMinVote() && players <= PlayMusic.Vote.size())) {
|
||||
ALLMusic.Side.bq("§d[ALLMusic]§2" + "已切歌");
|
||||
ALLMusic.Side.Send("[Stop]", false);
|
||||
PlayMusic.Vote.clear();
|
||||
PlayMusic.MusicAllTime = 1;
|
||||
if (PlayMusic.PlayList.size() == 0) {
|
||||
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + "队列中无歌曲"));
|
||||
ALLMusic.Side.bq("§d[ALLMusic]§2" + "队列中无歌曲");
|
||||
}
|
||||
PlayMusic.Vote_time = 0;
|
||||
PlayMusic.NowPlayMusic = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PlayMusic.haveLyric) {
|
||||
ShowOBJ show = PlayMusic.Lyric.checkTime(PlayMusic.MusicNowTime);
|
||||
if (show != null) {
|
||||
String now = show.toString();
|
||||
PlayMusic.nowLyric = now != null ? now : PlayMusic.nowLyric;
|
||||
}
|
||||
ALLMusic.Side.SendLyric(PlayMusic.nowLyric);
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
PlayMusic.MusicAllTime--;
|
||||
PlayMusic.MusicNowTime++;
|
||||
PlayMusic.MusicAllTime --;
|
||||
}
|
||||
close();
|
||||
} catch (InterruptedException e) {
|
||||
e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ALLMusic.Side.bq("§d[ALLMusic]§2" + "无效歌曲歌曲" + PlayMusic.NowPlayMusic.getID());
|
||||
|
||||
@@ -31,9 +31,17 @@ public class PlayMusic {
|
||||
public static boolean haveLyric;
|
||||
public static String nowLyric = "";
|
||||
|
||||
private static Thread PlayGo = new PlayGo();
|
||||
private static PlayGo PlayGo;
|
||||
|
||||
public static void stop() {
|
||||
if (PlayGo != null && PlayGo.isAlive()) {
|
||||
PlayGo.close();
|
||||
PlayGo.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Start() {
|
||||
PlayGo = new PlayGo();
|
||||
PlayGo.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import Color_yr.ALLMusic.ALLMusic;
|
||||
import Color_yr.ALLMusic.ALLMusicBukkit;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.server.v1_15_R1.*;
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: ALLMusic
|
||||
main: Color_yr.ALLMusic.ALLMusicBC
|
||||
author: Color_yr
|
||||
version: 1.3.0
|
||||
version: 1.4.0
|
||||
@@ -9,5 +9,5 @@
|
||||
"NoMusicServer": [],
|
||||
"NoMusicPlayer": [],
|
||||
"BanMusic": [],
|
||||
"Version": "1.3.0"
|
||||
"Version": "1.4.0"
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
name: ALLMusic
|
||||
main: Color_yr.ALLMusic.ALLMusicBukkit
|
||||
author: Color_yr
|
||||
version: 1.3.0
|
||||
version: 1.4.0
|
||||
|
||||
commands:
|
||||
music:
|
||||
|
||||
Reference in new issue
Block a user