This commit is contained in:
Coloryr committed 2020-02-20 23:22:58 +08:00
1 parent c0f11ea347
commit a382cf3eaa
26 files changed
+856 -507

No files matched your search

+3 -2
View File
@@ -23,14 +23,15 @@ repositories {
}
dependencies {
compile 'net.md-5:bungeecord-api:1.14-SNAPSHOT'
compile 'net.md-5:bungeecord-api:1.15-SNAPSHOT'
compile 'org.spigotmc:spigot-api:1.8-R0.1-SNAPSHOT'
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId "Color_yr"
artifactId "ALLmusic_BC"
artifactId "ALLmusic"
version "$majorVersion.$minorVersion-SNAPSHOT"
from components.java
}
+1 -1
View File
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
+1 -1
View File
@@ -15,4 +15,4 @@ include 'api'
include 'services:webservice'
*/
rootProject.name = 'ALLmusic_BC'
rootProject.name = 'ALLmusic'
@@ -0,0 +1,16 @@
package Color_yr.ALLMusic;
import Color_yr.ALLMusic.Side.ISide;
import java.io.File;
import java.util.logging.Logger;
public class ALLMusic {
public static ConfigOBJ Config;
public static Logger log;
public static File ConfigFile;
public static ISide Side;
public static final String Version = "1.3.0";
}
@@ -0,0 +1,95 @@
package Color_yr.ALLMusic;
import Color_yr.ALLMusic.Play.PlayMusic;
import Color_yr.ALLMusic.Side.SideBC;
import com.google.gson.Gson;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
public class ALLMusicBC extends Plugin {
public static void save()
{
try {
String data = new Gson().toJson(ALLMusic.Config);
if (ALLMusic.ConfigFile.exists()) {
Writer out = new FileWriter(ALLMusic.ConfigFile);
out.write(data);
out.close();
}
}
catch (Exception e)
{
ALLMusic.log.warning("§d[ALLMusic]§c配置文件错误");
e.printStackTrace();
}
}
private void LoadConfig() throws FileNotFoundException {
InputStreamReader reader = new InputStreamReader(new FileInputStream(ALLMusic.ConfigFile), StandardCharsets.UTF_8);
BufferedReader bf = new BufferedReader(reader);
ALLMusic.Config = new Gson().fromJson(bf, ConfigOBJ.class);
if (ALLMusic.Config == null) {
ALLMusic.Config = new ConfigOBJ();
}
ALLMusic.log.info("§d[ALLMusic]§e当前插件版本为:" + ALLMusic.Version
+ ",你的配置文件版本为:" + ALLMusic.Config.getVersion());
for (String item : ALLMusic.Config.getNoMusicPlayer()) {
ALLMusic.log.info("玩家:" + item + "不参与点歌");
}
for (String item : ALLMusic.Config.getNoMusicServer()) {
ALLMusic.log.info("服务器:" + item + "不参与点歌");
}
}
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();
if (!ALLMusic.ConfigFile.exists()) {
InputStream in = getResourceAsStream("config_BC.json");
Files.copy(in, ALLMusic.ConfigFile.toPath());
}
if (!logs.file.exists()) {
logs.file.createNewFile();
}
}
LoadConfig();
} catch (IOException e) {
ALLMusic.log.warning("§d[ALLMusic]§c配置文件错误");
e.printStackTrace();
}
}
@Override
public void onEnable() {
ALLMusic.log = ProxyServer.getInstance().getLogger();
ALLMusic.log.info("§d[ALLMusic]§e正在启动,感谢使用,本插件交流群:571239090");
setConfig();
PlayMusic.Start();
ALLMusic.Side = new SideBC();
ProxyServer.getInstance().getPluginManager().registerCommand(this, new CommandBC());
ALLMusic.log.info("§d[ALLMusic]§e已启动-" + ALLMusic.Version);
}
@Override
public void onDisable() {
PlayMusic.PlayList.clear();
PlayMusic.Vote.clear();
ALLMusic.Side.Send("[Stop]", false);
ALLMusic.log.info("§d[ALLMusic]§e已停止,感谢使用");
}
}
@@ -0,0 +1,5 @@
package Color_yr.ALLMusic;
public class ALLMusicBukkit {
}
@@ -0,0 +1,153 @@
package Color_yr.ALLMusic;
import Color_yr.ALLMusic.Play.PlayMusic;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
import java.util.regex.Pattern;
public class CommandBC extends Command {
CommandBC() {
super("music");
}
private boolean isInteger(String str) {
Pattern pattern = Pattern.compile("^[-+]?[\\d]*$");
return pattern.matcher(str).matches();
}
private String get_string(String a, String b, String c) {
int x = a.indexOf(b) + b.length();
int y;
if (c != null)
y = a.indexOf(c);
else y = a.length();
return a.substring(x, y);
}
private void add_music(CommandSender sender, String[] args) {
String MusicID;
if (args[0].contains("id=")) {
if (args[0].contains("&user"))
MusicID = get_string(args[0], "id=", "&user");
else
MusicID = get_string(args[0], "id=", null);
} else if (args[0].contains("song/")) {
if (args[0].contains("/?userid"))
MusicID = get_string(args[0], "song/", "/?userid");
else
MusicID = get_string(args[0], "song/", null);
} else
MusicID = args[0];
if (isInteger(MusicID)) {
if (PlayMusic.PlayList.size() == ALLMusic.Config.getMaxList()) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§c错误,队列已满"));
return;
} else if (ALLMusic.Config.getBanMusic().contains(MusicID)) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§c错误,这首歌被禁点了"));
} else if (PlayMusic.PlayList.contains(MusicID)) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§c错误,这首歌已经在队列了"));
} else {
PlayMusic.PlayList.add(MusicID);
sender.sendMessage(new TextComponent("§d[ALLMusic]§c点歌" + MusicID + "成功"));
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + sender.getName() +
"点歌" + MusicID));
logs.log_write("玩家:" + sender.getName() + " 点歌:" + MusicID);
}
ALLMusic.Config.RemoveNoMusicPlayer(sender.getName());
} else
sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,请输入歌曲数字ID"));
}
public void execute(CommandSender sender, String[] args) {
String name = sender.getName();
if (args.length == 0) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§c错误,请使用/music help 获取帮助"));
} else if (args[0].equalsIgnoreCase("help")) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2帮助手册"));
sender.sendMessage(new TextComponent("§d[ALLMusic]§2使用/music [音乐ID] 来点歌"));
sender.sendMessage(new TextComponent("§d[ALLMusic]§2使用/music stop 停止播放歌曲"));
sender.sendMessage(new TextComponent("§d[ALLMusic]§2使用/music list 查看歌曲队列"));
sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music vote 投票切歌"));
sender.sendMessage(new TextComponent("§d[ALLMusic]§2使用/music nomusic 不再参与点歌"));
} else if (args[0].equalsIgnoreCase("stop")) {
ALLMusic.Side.Send("[Stop]", name, false);
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已停止" + name + "的音乐播放"));
} else if (args[0].equalsIgnoreCase("list")) {
if (PlayMusic.NowPlayMusic == null) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2无正在播放的歌曲"));
} else {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2正在播放:" + PlayMusic.NowPlayMusic));
}
if (PlayMusic.PlayList.size() == 0) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2队列中无歌曲"));
} else {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2队列中有歌曲数:" + PlayMusic.PlayList.size()));
for (int now = 0; now < PlayMusic.PlayList.size(); now++) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2当前队列" + now + "->" + PlayMusic.PlayList.get(now)));
}
}
} else if (args[0].equalsIgnoreCase("vote")) {
if (PlayMusic.PlayList.size() == 0) {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2队列中无歌曲"));
} else if (PlayMusic.Vote_time == 0) {
PlayMusic.Vote_time = 30;
PlayMusic.Vote.add(name);
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已发起切歌投票"));
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + name +
"发起了切歌投票,30秒后结束,输入/music vote 同意切歌。"));
} else if (PlayMusic.Vote_time > 0) {
if (!PlayMusic.Vote.contains(name)) {
PlayMusic.Vote.add(name);
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + name + "同意切歌,共有" +
PlayMusic.Vote.size() + "名玩家同意切歌。"));
} else {
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2你已申请切歌"));
}
}
} else if (args[0].equalsIgnoreCase("reload")) {
ALLMusicBC music = new ALLMusicBC();
music.setConfig();
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已重读配置文件"));
} else if (args[0].equalsIgnoreCase("v")) {
if (args.length == 2) {
ALLMusic.Side.Send("[V]" + args[1], sender.getName(), null);
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已设置你的音量为:" + args[1]));
} else
sender.sendMessage(new TextComponent("§d[ALLMusic]§4请输入音量"));
} else if (args[0].equalsIgnoreCase("next") && ALLMusic.Config.getAdmin().contains(name)) {
PlayMusic.MusicAllTime = 1;
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已强制切歌"));
} else if (args[0].equalsIgnoreCase("nomusic")) {
ALLMusic.Side.Send("[Stop]", name, false);
ALLMusic.Config.AddNoMusicPlayer(sender.getName());
sender.sendMessage(new TextComponent("§d[ALLMusic]§2你不会再收到点歌了!想要再次参与点歌就点一首歌吧!"));
} else if (args[0].equalsIgnoreCase("ban") && args.length == 2
&& ALLMusic.Config.getAdmin().contains(name)) {
if (isInteger(args[1])) {
ALLMusic.Config.addBanID(args[1]);
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已禁止" + args[1]));
} else {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2请输入有效的ID"));
}
} else if (args[0].equalsIgnoreCase("delete") && args.length == 2
&& ALLMusic.Config.getAdmin().contains(name)) {
if (isInteger(args[1])) {
String music = args[1];
if (PlayMusic.PlayList.contains(music)) {
PlayMusic.PlayList.remove(music);
sender.sendMessage(new TextComponent("§d[ALLMusic]§2已删除" + music));
} else {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2找不到" + music));
}
} else {
sender.sendMessage(new TextComponent("§d[ALLMusic]§2请输入有效的ID"));
}
} else
add_music(sender, args);
}
}
@@ -0,0 +1,90 @@
package Color_yr.ALLMusic;
import java.util.ArrayList;
import java.util.List;
public class ConfigOBJ {
private String Music_Api1;
private String Lyric_Api1;
private int MaxList;
private int MinVote;
private int Delay;
private List<String> Admin;
private List<String> NoMusicServer;
private List<String> NoMusicPlayer;
private List<String> BanMusic;
private String Version;
public ConfigOBJ() {
Music_Api1 = "http://music.163.com/song/media/outer/url?id=";
Lyric_Api1 = "https://api.imjad.cn/cloudmusic/?type=lyric&id=";
MaxList = 10;
MinVote = 3;
Delay = 2;
Admin = new ArrayList<>();
NoMusicServer = new ArrayList<>();
NoMusicPlayer = new ArrayList<>();
BanMusic = new ArrayList<>();
Version = ALLMusic.Version;
}
public String getLyric_Api1() {
return Lyric_Api1;
}
public int getDelay() {
return Delay;
}
public String getVersion() {
return Version;
}
public int getMaxList() {
return MaxList;
}
public int getMinVote() {
return MinVote;
}
public List<String> getAdmin() {
return Admin;
}
public List<String> getNoMusicPlayer() {
return NoMusicPlayer;
}
public List<String> getNoMusicServer() {
return NoMusicServer;
}
public String getMusic_Api1() {
return Music_Api1;
}
public List<String> getBanMusic() {
return BanMusic;
}
public void addBanID(String ID) {
if (!BanMusic.contains(ID))
BanMusic.add(ID);
ALLMusicBC.save();
}
public void AddNoMusicPlayer(String ID) {
if (!NoMusicPlayer.contains(ID))
NoMusicPlayer.add(ID);
ALLMusicBC.save();
}
public void RemoveNoMusicPlayer(String ID) {
NoMusicPlayer.remove(ID);
ALLMusicBC.save();
}
}
@@ -0,0 +1,90 @@
package Color_yr.ALLMusic.Http;
import Color_yr.ALLMusic.ALLMusic;
import javazoom.jl.decoder.Bitstream;
import javazoom.jl.decoder.Header;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
public class Get {
public static int getMusicTime(String music) {
try {
URL urlfile = new URL(music);
URLConnection con = urlfile.openConnection();
int b = con.getContentLength();// 得到音乐文件的总长度
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;
} catch (Exception e) {
ALLMusic.log.warning("§d[ALLMusic]§c获取音乐长度错误");
e.printStackTrace();
}
return 0;
}
public static String realURL(String path) {
HttpURLConnection connection = null;
try {
URL realUrl = new URL(path);
connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
connection.getContent();
return connection.getURL().toString();
} catch (IOException e) {
if (connection == null) {
ALLMusic.log.warning("§d[ALLMusic]§c获取网页错误");
e.printStackTrace();
return null;
}
} catch (NullPointerException e) {
ALLMusic.log.warning("§d[ALLMusic]§c获取网页错误");
e.printStackTrace();
}
return null;
}
public static String realData(String path) {
HttpURLConnection connection = null;
try {
URL realUrl = new URL(path);
connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
connection.getContent();
InputStream inputStream = connection.getInputStream();
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
} catch (IOException e) {
if (connection == null) {
ALLMusic.log.warning("§d[ALLMusic]§c获取网页错误");
e.printStackTrace();
return null;
}
} catch (NullPointerException e) {
ALLMusic.log.warning("§d[ALLMusic]§c获取网页错误");
e.printStackTrace();
}
return null;
}
}
@@ -0,0 +1,72 @@
package Color_yr.ALLMusic.Lyric;
import Color_yr.ALLMusic.ALLMusic;
import com.google.gson.Gson;
import java.util.*;
public class LyricDo {
private Map<Integer, ShowOBJ> Lyric = new HashMap<>();
private LyricOBJ obj;
private String GetString(String a, String b, String c) {
int x = a.indexOf(b) + b.length();
int y;
if (c != null)
y = a.indexOf(c);
else y = a.length();
return a.substring(x, y);
}
public LyricDo(String obj) {
this.obj = new Gson().fromJson(obj, LyricOBJ.class);
}
public void Check() {
String[] lyric;
boolean haveT = false;
if (obj.getLyric() == null)
return;
lyric = obj.getLyric().split("\n");
List<String> tlyric = new ArrayList<>();
if (obj.getTlyric() != null) {
tlyric = Arrays.asList( obj.getTlyric().split("\n"));
haveT = true;
}
String min;
String sec;
String Tlyric = null;
String temp;
int time;
for (int now = 0; now < lyric.length; now++) {
if (lyric[now].startsWith("[by"))
continue;
min = GetString(lyric[now], "[", ":");
sec = GetString(lyric[now], ":", ".");
time = Integer.parseInt(min) * 60 + Integer.parseInt(sec);
if (time > 0)
time -= ALLMusic.Config.getDelay();
if (haveT) {
temp = GetString(lyric[now], "[", "]");
for(String item : tlyric) {
if (temp.equalsIgnoreCase(GetString(item, "[", "]"))) {
Tlyric = GetString(item, "]", null);
break;
}
else
Tlyric = null;
}
}
Lyric.put(time, new ShowOBJ(time, haveT,
GetString(lyric[now], "]", null), Tlyric));
}
}
public ShowOBJ checkTime(int playNow) {
if (Lyric.containsKey(playNow))
return Lyric.get(playNow);
return null;
}
}
@@ -0,0 +1,33 @@
package Color_yr.ALLMusic.Lyric;
public class LyricOBJ {
private boolean sgc;
private boolean sfy;
private boolean qfy;
private lrc lrc;
private tlyric tlyric;
public String getLyric() {
return lrc.getLyric();
}
public String getTlyric() {
return tlyric.getLyric();
}
}
class lrc {
private int version;
private String lyric;
public String getLyric() {
return lyric;
}
}
class tlyric {
private int version;
private String lyric;
public String getLyric() {
return lyric;
}
}
@@ -0,0 +1,42 @@
package Color_yr.ALLMusic.Lyric;
public class ShowOBJ {
private int time;
private boolean haveT;
private String lyric;
private String tlyric;
public ShowOBJ(int time, boolean haveT, String lyric, String tlyric) {
this.time = time;
this.haveT = haveT;
this.lyric = lyric;
this.tlyric = tlyric;
}
public String getLyric() {
return lyric;
}
public boolean isHaveT() {
return haveT;
}
public int getTime() {
return time;
}
public String getTlyric() {
return tlyric;
}
@Override
public String toString() {
if (lyric == null || lyric.isEmpty())
return null;
if (haveT) {
if (tlyric == null || !tlyric.isEmpty())
return lyric + (haveT ? "(" + tlyric + ")" : null);
}
return lyric;
}
}
@@ -0,0 +1,87 @@
package Color_yr.ALLMusic.Play;
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;
class PlayGo extends Thread {
@Override
public synchronized void run() {
while (true) {
if (PlayMusic.PlayList.size() == 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.getMessage();
}
} else {
PlayMusic.NowPlayMusic = PlayMusic.PlayList.get(0);
PlayMusic.PlayList.remove(0);
PlayMusic.nowLyric = "";
PlayMusic.haveLyric = false;
PlayMusic.Lyric = null;
ALLMusic.Side.SendLyric("");
String songURL = Get.realURL(ALLMusic.Config.getMusic_Api1() + PlayMusic.NowPlayMusic);
String Lyric = Get.realData(ALLMusic.Config.getLyric_Api1() + PlayMusic.NowPlayMusic);
if (Lyric != null) {
try {
PlayMusic.Lyric = new LyricDo(Lyric);
PlayMusic.Lyric.Check();
PlayMusic.haveLyric = true;
} catch (Exception e) {
ALLMusic.log.warning("§d[ALLMusic]§c歌词解析错误");
e.printStackTrace();
}
}
if (songURL != null) {
PlayMusic.MusicAllTime = Get.getMusicTime(songURL);
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + "正在播放歌曲" + PlayMusic.NowPlayMusic));
ALLMusic.Side.Send("[Play]" + songURL, true);
try {
while (PlayMusic.MusicAllTime > 0) {
if (PlayMusic.Vote_time > 0) {
PlayMusic.Vote_time--;
if (PlayMusic.Vote_time == 0) {
PlayMusic.Vote.clear();
ProxyServer.getInstance().broadcast(new TextComponent("§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" + "已切歌"));
ALLMusic.Side.Send("[Stop]", false);
PlayMusic.MusicAllTime = 1;
if (PlayMusic.PlayList.size() == 0) {
ProxyServer.getInstance().broadcast(new TextComponent("§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++;
}
} catch (InterruptedException e) {
e.getMessage();
}
} else {
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLMusic]§2" + "无效歌曲歌曲" + PlayMusic.NowPlayMusic));
PlayMusic.NowPlayMusic = null;
}
}
}
}
}
@@ -0,0 +1,35 @@
package Color_yr.ALLMusic.Play;
import Color_yr.ALLMusic.Lyric.LyricDo;
import javazoom.jl.decoder.Bitstream;
import javazoom.jl.decoder.Header;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
public class PlayMusic {
public static List<String> PlayList = new ArrayList<>();
public static List<String> Vote = new ArrayList<String>();
public static List<String> NowPlay = new ArrayList<>();
public static int Vote_time = 0;
public static int MusicAllTime = 0;
public static int MusicNowTime = 0;
public static String NowPlayMusic;
public static LyricDo Lyric;
public static boolean haveLyric;
public static String nowLyric = "";
private static Thread PlayGo = new PlayGo();
public static void Start() {
PlayGo.start();
}
}
@@ -0,0 +1,8 @@
package Color_yr.ALLMusic.Side;
public interface ISide {
void Send(String player, String data, Boolean isplay);
void Send(String data, Boolean isplay);
int GetAllPlayer();
void SendLyric(String data);
}
@@ -0,0 +1,71 @@
package Color_yr.ALLMusic.Side;
import Color_yr.ALLMusic.ALLMusic;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.Title;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import static Color_yr.ALLMusic.Play.PlayMusic.NowPlay;
import static Color_yr.ALLMusic.Play.PlayMusic.PlayList;
public class SideBC implements ISide {
@Override
public void Send(String data, String player, Boolean isplay) {
Send(ProxyServer.getInstance().getPlayer(player), data, isplay);
}
@Override
public void Send(String data, Boolean isplay) {
Collection<ProxiedPlayer> values = ProxyServer.getInstance().getPlayers();
for (ProxiedPlayer players : values) {
if (!ALLMusic.Config.getNoMusicServer().contains(players.getServer().getInfo().getName())) {
if (!ALLMusic.Config.getNoMusicPlayer().contains(players.getName())) {
Send(players, data, isplay);
}
}
}
}
@Override
public int GetAllPlayer() {
return ProxyServer.getInstance().getOnlineCount();
}
@Override
public void SendLyric(String data) {
Collection<ProxiedPlayer> values = ProxyServer.getInstance().getPlayers();
for (ProxiedPlayer players : values) {
if (!ALLMusic.Config.getNoMusicServer().contains(players.getServer().getInfo().getName())) {
if (!ALLMusic.Config.getNoMusicPlayer().contains(players.getName()))
if (NowPlay.contains(players.getName()))
players.sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(data));
}
}
}
private void Send(ProxiedPlayer players, String data,Boolean isplay) {
try {
byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
ByteBuf buf = Unpooled.buffer(bytes.length + 1);
buf.writeByte(666);
buf.writeBytes(bytes);
players.sendData("allmusic:channel", buf.array());
if (isplay != null) {
if (isplay) {
NowPlay.add(players.getName());
} else {
NowPlay.remove(players.getName());
}
}
} catch (Exception e) {
ALLMusic.log.warning("§d[ALLMusic]§c数据发送发生错误");
e.printStackTrace();
}
}
}
@@ -0,0 +1,24 @@
package Color_yr.ALLMusic.Side;
public class SideBukkit implements ISide {
@Override
public void Send(String player, String data, Boolean isplay) {
}
@Override
public void Send(String data, Boolean isplay) {
}
@Override
public int GetAllPlayer() {
return 0;
}
@Override
public void SendLyric(String data) {
}
}
@@ -1,4 +1,4 @@
package Color_yr.ALLmusic;
package Color_yr.ALLMusic;
import java.io.File;
import java.io.FileWriter;
@@ -8,12 +8,12 @@ import java.util.Date;
class logs {
static File file;
static FileWriter fw;
static Date date = new Date();
void log_write(String text) {
FileWriter fw = null;
public static void log_write(String text) {
try {
fw = new FileWriter(file, true);
Date date = new Date();
String year = String.format("%tF", date);
String time = String.format("%tT", date);
String write = "[" + year + "]" + "[" + time + "]" + text;
@@ -24,7 +24,8 @@ class logs {
pw.close();
fw.close();
} catch (IOException e) {
ALLmusic_BC.log.warning("§d[ALLmusic_BC]§c日志文件写入失败" + e);
ALLMusic.log.warning("§d[AllMusic]§c日志文件写入失败");
e.printStackTrace();
}
}
}
@@ -1,102 +0,0 @@
package Color_yr.ALLmusic;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
import static Color_yr.ALLmusic.PlayMusic.PlayMusic_Start;
public class ALLmusic_BC extends Plugin {
private static final String Version = "1.1.0";
public static int Maxlist = 0;
public static int min_vote = 0;
public static String Music_Api1 = null;
public static Configuration config;
public static File FileName;
public static Configuration Banconfig;
public static File BanFileName;
public static List<String> Admin = new ArrayList<String>();
public static List<String> server = new ArrayList<String>();
public static Logger log = ProxyServer.getInstance().getLogger();
private void loadconfig() {
ProxyServer.getInstance().getLogger().info("§d[ALLmusic]§e当前插件版本为:" + Version
+ ",你的配置文件版本为:" + config.getString("Version"));
Maxlist = config.getInt("Maxlist", 10);
min_vote = config.getInt("min_vote", 3);
Music_Api1 = config.getString("Music_Api1", "http://music.163.com/song/media/outer/url?id=");
Admin = config.getStringList("Admin");
server = config.getStringList("nomusic_server");
Configuration a = config.getSection("nomusic");
Collection<String> b = a.getKeys();
for (String c : b) {
boolean d = a.getBoolean(c, false);
PlayMusic.stop.put(c, d);
log.info("玩家:" + c + "的点歌状态:" + !d);
}
}
void setConfig() {
try {
if (FileName == null) {
FileName = new File(getDataFolder(), "config.yml");
BanFileName = new File(getDataFolder(), "banlist.yml");
logs.file = new File(getDataFolder(), "logs.log");
if (!getDataFolder().exists())
getDataFolder().mkdir();
if (!FileName.exists()) {
InputStream in = getResourceAsStream("config.yml");
Files.copy(in, FileName.toPath());
in = getResourceAsStream("banlist.yml");
Files.copy(in, BanFileName.toPath());
}
if (!logs.file.exists()) {
logs.file.createNewFile();
}
}
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(FileName);
Banconfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(BanFileName);
loadconfig();
} catch (IOException e) {
log.warning("§d[ALLmusic]§c日志文件错误:" + e);
}
}
@Override
public void onEnable() {
log.info("§d[ALLmusic]§e正在启动,感谢使用,本插件交流群:571239090");
setConfig();
PlayMusic_Start();
ProxyServer.getInstance().getPluginManager().registerCommand(this, new command());
log.info("§d[ALLmusic]§e已启动-" + Version);
}
@Override
public void onDisable() {
PlayMusic.playlist.clear();
PlayMusic.Vote.clear();
PlayMusic.SendToPlayer("[Stop]");
log.info("§d[ALLmusic]§e已停止,感谢使用");
}
}
@@ -1,182 +0,0 @@
package Color_yr.ALLmusic;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import javazoom.jl.decoder.Bitstream;
import javazoom.jl.decoder.Header;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.*;
public class PlayMusic {
public static Map<Integer, String> playlist = new HashMap<Integer, String>();
public static List<String> Vote = new ArrayList<String>();
public static Map<String, Boolean> stop = new HashMap<String, Boolean>();
public static int Vote_time = 0;
public static int All_music = 0;
public static int Music_time = 0;
public static String now_music;
private static Thread playgo = new playgo();
static void PlayMusic_Start() {
playgo.start();
}
static void SendToPlayer(String data) {
Collection<ProxiedPlayer> values = ProxyServer.getInstance().getPlayers();
try {
byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
ByteBuf buf = Unpooled.buffer(bytes.length + 1);
buf.writeByte(666);
buf.writeBytes(bytes);
for (ProxiedPlayer players : values) {
if (!ALLmusic_BC.server.contains(players.getServer().getInfo().getName())) {
if (stop.containsKey(players.getName()) && !stop.get(players.getName()))
players.sendData("allmusic:channel", buf.array());
}
}
} catch (Exception e) {
logs logs = new logs();
logs.log_write(e.toString());
logs.log_write(Arrays.toString(e.getStackTrace()));
}
}
static void SendToOnePlayer(String data, String Player) {
try {
ProxiedPlayer players = ProxyServer.getInstance().getPlayer(Player);
byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
ByteBuf buf = Unpooled.buffer(bytes.length + 1);
buf.writeByte(666);
buf.writeBytes(bytes);
players.sendData("allmusic:channel", buf.array());
} catch (Exception ignored) {
}
}
static int Music_Time(String music) {
try {
URL urlfile = new URL(music);
URLConnection con = urlfile.openConnection();
int b = con.getContentLength();// 得到音乐文件的总长度
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;
} catch (Exception ignored) {
ignored.getMessage();
}
return 0;
}
static String realURL(String path) {
HttpURLConnection connection = null;
try {
URL realUrl = new URL(path);
connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
connection.getContent();
return connection.getURL().toString();
} catch (IOException var5) {
if (connection == null) {
var5.printStackTrace();
return null;
}
} catch (NullPointerException e) {
e.getMessage();
return null;
}
return null;
}
}
class playgo extends Thread {
private static void music_list() {
String a;
if (PlayMusic.playlist.size() == 1) {
a = PlayMusic.playlist.get(1);
PlayMusic.playlist.put(0, a);
PlayMusic.playlist.remove(1);
} else if (PlayMusic.playlist.size() > 1) {
for (int i = 0; PlayMusic.playlist.size() - 1 > i; i++) {
a = PlayMusic.playlist.get(i + 1);
PlayMusic.playlist.put(i, a);
}
PlayMusic.playlist.remove(PlayMusic.playlist.size() - 1);
}
PlayMusic.All_music = PlayMusic.playlist.size();
}
@Override
public synchronized void run() {
while (true) {
if (PlayMusic.playlist.size() == 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.getMessage();
}
} else {
PlayMusic.now_music = PlayMusic.playlist.get(0);
String song = PlayMusic.realURL(ALLmusic_BC.Music_Api1 + PlayMusic.now_music);
if (song != null) {
PlayMusic.Music_time = PlayMusic.Music_Time(song);
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "正在播放歌曲" + PlayMusic.now_music));
PlayMusic.SendToPlayer("[Play]" + song);
PlayMusic.playlist.remove(0);
music_list();
try {
while (PlayMusic.Music_time > 0) {
Thread.sleep(1000);
PlayMusic.Music_time--;
if (PlayMusic.Vote_time > 0) {
PlayMusic.Vote_time--;
if (PlayMusic.Vote_time == 0) {
PlayMusic.Vote.clear();
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "切歌时间结束"));
}
else {
int players = ProxyServer.getInstance().getOnlineCount();
if (PlayMusic.Vote.size() >= ALLmusic_BC.min_vote || (players <= ALLmusic_BC.min_vote && players == PlayMusic.Vote.size())) {
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "已切歌"));
PlayMusic.SendToPlayer("[Stop]");
PlayMusic.Music_time = 1;
if (PlayMusic.All_music == 0) {
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "队列中无歌曲"));
}
PlayMusic.Vote_time = 0;
PlayMusic.now_music = null;
}
}
}
}
} catch (InterruptedException e) {
e.getMessage();
}
} else {
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + "无效歌曲歌曲" + PlayMusic.now_music));
PlayMusic.playlist.remove(0);
PlayMusic.now_music = null;
music_list();
}
}
}
}
}
@@ -1,195 +0,0 @@
package Color_yr.ALLmusic;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import java.util.Map;
import java.util.regex.Pattern;
public class command extends Command {
command() {
super("music");
}
private boolean isInteger(String str) {
Pattern pattern = Pattern.compile("^[-+]?[\\d]*$");
return pattern.matcher(str).matches();
}
private String get_string(String a, String b, String c) {
int x = a.indexOf(b) + b.length();
int y;
if (c != null)
y = a.indexOf(c);
else y = a.length();
return a.substring(x, y);
}
private void add_music(CommandSender sender, String[] args) {
String music_id;
if (args[0].contains("id=")) {
if (args[0].contains("&user"))
music_id = get_string(args[0], "id=", "&user");
else
music_id = get_string(args[0], "id=", null);
} else if (args[0].contains("song/")) {
if (args[0].contains("/?userid"))
music_id = get_string(args[0], "song/", "/?userid");
else
music_id = get_string(args[0], "song/", null);
} else
music_id = args[0];
if (isInteger(music_id)) {
if (PlayMusic.playlist.size() == ALLmusic_BC.Maxlist) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,队列已满"));
return;
} else if (ALLmusic_BC.Banconfig.getBoolean(music_id, false)) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,这首歌被禁点了"));
} else if (PlayMusic.playlist.containsValue(music_id)) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,这首歌已经在队列了"));
} else {
PlayMusic.playlist.put(PlayMusic.All_music, music_id);
PlayMusic.All_music++;
sender.sendMessage(new TextComponent("§d[ALLmusic]§c点歌" + music_id + "成功"));
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + sender.getName() +
"点歌" + music_id));
logs logs = new logs();
logs.log_write("玩家:" + sender.getName() + " 点歌:" + music_id);
}
PlayMusic.stop.put(sender.getName(), false);
ALLmusic_BC.config.set("nomusic", PlayMusic.stop);
try {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(ALLmusic_BC.config, ALLmusic_BC.FileName);
} catch (Exception e) {
logs log = new logs();
log.log_write(e.getMessage());
}
} else
sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,请输入歌曲数字ID"));
}
public void execute(CommandSender sender, String[] args) {
String name = sender.getName();
if (args.length == 0) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§c错误,请使用/music help 获取帮助"));
} else if (args[0].equalsIgnoreCase("help")) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2帮助手册"));
sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music [音乐ID] 来点歌"));
sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music stop 停止播放歌曲"));
sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music list 查看歌曲队列"));
sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music vote 投票切歌"));
sender.sendMessage(new TextComponent("§d[ALLmusic]§2使用/music nomusic 不再参与点歌"));
} else if (args[0].equalsIgnoreCase("stop")) {
PlayMusic.SendToOnePlayer("[Stop]", name);
sender.sendMessage(new TextComponent("§d[ALLmusic]§2已停止" + name + "的音乐播放"));
} else if (args[0].equalsIgnoreCase("list")) {
if (PlayMusic.now_music == null) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2无正在播放的歌曲"));
} else {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2正在播放:" + PlayMusic.now_music));
}
if (PlayMusic.playlist.size() == 0) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2队列中无歌曲"));
} else {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2队列中有歌曲数:" + PlayMusic.playlist.size()));
for (Map.Entry<Integer, String> music : PlayMusic.playlist.entrySet()) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2当前队列" + music.getKey() + "->" + music.getValue()));
}
}
} else if (args[0].equalsIgnoreCase("vote")) {
if (PlayMusic.playlist.size() == 0) {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2队列中无歌曲"));
} else if (PlayMusic.Vote_time == 0) {
PlayMusic.Vote_time = 30;
PlayMusic.Vote.add(name);
sender.sendMessage(new TextComponent("§d[ALLmusic]§2已发起切歌投票"));
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + name +
"发起了切歌投票,30秒后结束,输入/music vote 同意切歌。"));
} else if (PlayMusic.Vote_time > 0) {
if (!PlayMusic.Vote.contains(name)) {
PlayMusic.Vote.add(name);
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2" + name + "同意切歌,共有" +
PlayMusic.Vote.size() + "名玩家同意切歌。"));
} else {
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic]§2你已申请切歌"));
}
}
} else if (args[0].equalsIgnoreCase("reload")) {
ALLmusic_BC music = new ALLmusic_BC();
music.setConfig();
sender.sendMessage(new TextComponent("§d[ALLmusic]§2已重读配置文件"));
} else if (args[0].equalsIgnoreCase("v")) {
if (args.length == 2) {
PlayMusic.SendToOnePlayer("[V]" + args[1], sender.getName());
sender.sendMessage(new TextComponent("§d[ALLmusic]§2已设置你的音量为:" + args[1]));
} else
sender.sendMessage(new TextComponent("§d[ALLmusic]§4请输入音量"));
} else if (args[0].equalsIgnoreCase("next") && ALLmusic_BC.Admin.contains(name)) {
PlayMusic.Music_time = 1;
sender.sendMessage(new TextComponent("§d[ALLmusic]§2已强制切歌"));
} else if (args[0].equalsIgnoreCase("nomusic")) {
PlayMusic.stop.put(name, true);
PlayMusic.SendToOnePlayer("[Stop]", name);
sender.sendMessage(new TextComponent("§d[ALLmusic]§2你不会再收到点歌了!想要再次参与点歌就点一首歌吧!"));
ALLmusic_BC.config.set("nomusic", PlayMusic.stop);
try {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(ALLmusic_BC.config, ALLmusic_BC.FileName);
} catch (Exception e) {
logs log = new logs();
log.log_write(e.getMessage());
}
} else if (args[0].equalsIgnoreCase("ban") && args.length == 2
&& ALLmusic_BC.Admin.contains(name)) {
if (isInteger(args[1])) {
ALLmusic_BC.Banconfig.set(args[1], "true");
try {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(ALLmusic_BC.Banconfig, ALLmusic_BC.BanFileName);
sender.sendMessage(new TextComponent("§d[ALLmusic]§2已禁止" + args[1]));
} catch (Exception e) {
logs log = new logs();
log.log_write(e.getMessage());
}
} else {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2请输入有效的ID"));
}
} else if (args[0].equalsIgnoreCase("delete") && args.length == 2
&& ALLmusic_BC.Admin.contains(name)) {
if (isInteger(args[1])) {
String music = args[1];
if (PlayMusic.playlist.containsValue(music)) {
String a;
if (PlayMusic.playlist.size() == 1) {
PlayMusic.playlist.remove(1);
} else if (PlayMusic.playlist.size() > 1) {
int i = 0;
for (Map.Entry<Integer, String> b : PlayMusic.playlist.entrySet()) {
if (b.getValue().equalsIgnoreCase(music))
break;
else
i++;
}
for (; PlayMusic.playlist.size() - 1 > i; i++) {
a = PlayMusic.playlist.get(i + 1);
PlayMusic.playlist.put(i, a);
}
PlayMusic.playlist.remove(i);
}
PlayMusic.All_music = PlayMusic.playlist.size();
sender.sendMessage(new TextComponent("§d[ALLmusic]§2已删除" + music));
} else {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2找不到" + music));
}
} else {
sender.sendMessage(new TextComponent("§d[ALLmusic]§2请输入有效的ID"));
}
} else
add_music(sender, args);
}
}
-1
View File
@@ -1 +0,0 @@
#用法: [歌曲ID]: true
+4
View File
@@ -0,0 +1,4 @@
name: ALLMusic
main: Color_yr.ALLMusic.ALLMusicBC
author: Color_yr
version: 1.3.0
-15
View File
@@ -1,15 +0,0 @@
#最大音乐队列
Maxlist: 10
#音乐网页API
Music_Api1: http://music.163.com/song/media/outer/url?id=
#最小投票人数
min_vote: 3
#不参与点歌的人
nomusic:
Color_yr: true
Admin:
- Color_yr
nomusic_server:
- lobby
#配置文件版本号
Version: 1.1.0
+12
View File
@@ -0,0 +1,12 @@
{
"Music_Api1": "http://music.163.com/song/media/outer/url?id=",
"Lyric_Api1": "https://api.imjad.cn/cloudmusic/?type=lyric&id=",
"MaxList": 10,
"MinVote": 3,
"Delay": 2,
"Admin": [],
"NoMusicServer": [],
"NoMusicPlayer": [],
"BanMusic": [],
"Version": "1.3.0"
}
+8 -3
View File
@@ -1,4 +1,9 @@
name: ALLmusic_BC
main: Color_yr.ALLmusic.ALLmusic_BC
name: ALLMusic
main: Color_yr.ALLMusic.ALLMusicBukkit
author: Color_yr
version: 1.1.0
version: 1.3.0
commands:
music:
description: ALLmusic的主要指令
usage: §4[ALLmusic]§6/music help来查看帮助