This commit is contained in:
Color_yr committed 2022-12-27 11:33:26 +08:00
1 parent 92630717fc
commit b2d8a95441
43 files changed
+510 -142

No files matched your search

+3 -3
View File
@@ -1,17 +1,17 @@
package coloryr.allmusic;
import coloryr.allmusic.music.api.http.CookieObj;
import coloryr.allmusic.side.IMyLogger;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.hud.DataSql;
import coloryr.allmusic.hud.HudSave;
import coloryr.allmusic.hud.obj.SaveOBJ;
import coloryr.allmusic.message.MessageOBJ;
import coloryr.allmusic.music.api.APIMain;
import coloryr.allmusic.music.api.http.CookieObj;
import coloryr.allmusic.music.play.MusicSearch;
import coloryr.allmusic.music.play.PlayGo;
import coloryr.allmusic.music.play.PlayMusic;
import coloryr.allmusic.music.search.SearchPage;
import coloryr.allmusic.side.IMyLogger;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.side.bukkit.hooks.VaultHook;
import coloryr.allmusic.utils.Logs;
import com.google.gson.Gson;
@@ -1,9 +1,8 @@
package coloryr.allmusic.api;
package coloryr.allmusic;
import coloryr.allmusic.AllMusic;
import coloryr.allmusic.hud.obj.HudPos;
import coloryr.allmusic.side.ComType;
import org.checkerframework.checker.units.qual.A;
public class AllMusicAPI {
public static void playMusic(String name, String url) {
@@ -41,6 +41,7 @@ public class ConfigOBJ {
private boolean MutePlayMessage;
private boolean MuteAddMessage;
private boolean ShowInBar;
public ConfigOBJ() {
MaxList = 10;
@@ -63,6 +64,7 @@ public class ConfigOBJ {
SearchCost = 20;
MutePlayMessage = false;
MuteAddMessage = false;
ShowInBar = false;
AddMusicCost = 10;
DefaultAddMusic = 0;
@@ -77,6 +79,10 @@ public class ConfigOBJ {
Version = AllMusic.version;
}
public boolean isShowInBar() {
return ShowInBar;
}
public boolean isMuteAddMessage() {
return MuteAddMessage;
}
@@ -50,23 +50,23 @@ public class MetricsBase {
/**
* Creates a new MetricsBase class instance.
*
* @param platform The platform of the service.
* @param serviceId The id of the service.
* @param serverUuid The server uuid.
* @param enabled Whether or not data sending is enabled.
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and appends all
* platform-specific data.
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and appends all
* service-specific data.
* @param submitTaskConsumer A consumer that takes a runnable with the submit task.
* This can be used to delegate the data collection to a another thread to prevent
* errors caused by concurrency. Can be {@code null}.
* @param platform The platform of the service.
* @param serviceId The id of the service.
* @param serverUuid The server uuid.
* @param enabled Whether or not data sending is enabled.
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and appends all
* platform-specific data.
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and appends all
* service-specific data.
* @param submitTaskConsumer A consumer that takes a runnable with the submit task.
* This can be used to delegate the data collection to a another thread to prevent
* errors caused by concurrency. Can be {@code null}.
* @param checkServiceEnabledSupplier A supplier to check if the service is still enabled.
* @param errorLogger A consumer that accepts log message and an error.
* @param infoLogger A consumer that accepts info log messages.
* @param logErrors Whether or not errors should be logged.
* @param logSentData Whether or not the sent data should be logged.
* @param logResponseStatusText Whether or not the response status text should be logged.
* @param errorLogger A consumer that accepts log message and an error.
* @param infoLogger A consumer that accepts info log messages.
* @param logErrors Whether or not errors should be logged.
* @param logSentData Whether or not the sent data should be logged.
* @param logResponseStatusText Whether or not the response status text should be logged.
*/
public MetricsBase(
String platform,
@@ -102,14 +102,14 @@ public class MetricsConfig {
enabled = getConfigValue("enabled", lines).map("true"::equals).orElse(true);
serverUUID = getConfigValue("server-uuid", lines).orElse(null);
logErrors = getConfigValue("log-errors", lines).map("true"::equals).orElse(false);
logSentData = getConfigValue("log-sent-data", lines).map("true"::equals).orElse(false);
logResponseStatusText = getConfigValue("log-response-status-text", lines).map("true"::equals).orElse(false);
logSentData = getConfigValue("log-sent-data", lines).map("true"::equals).orElse(false);
logResponseStatusText = getConfigValue("log-response-status-text", lines).map("true"::equals).orElse(false);
}
/**
* Gets a config setting from the given list of lines of the file.
*
* @param key The key for the setting.
* @param key The key for the setting.
* @param lines The lines of the file.
* @return The value of the setting.
*/
@@ -141,7 +141,7 @@ public class MetricsConfig {
/**
* Writes the given lines to the given file.
*
* @param file The file to write to.
* @param file The file to write to.
* @param lines The lines to write.
*/
private void writeFile(File file, List<String> lines) throws IOException {
@@ -32,7 +32,7 @@ public class JsonObjectBuilder {
/**
* Appends a string field to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param value The value of the field.
* @return A reference to this object.
*/
@@ -47,7 +47,7 @@ public class JsonObjectBuilder {
/**
* Appends an integer field to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param value The value of the field.
* @return A reference to this object.
*/
@@ -59,7 +59,7 @@ public class JsonObjectBuilder {
/**
* Appends an object to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param object The object.
* @return A reference to this object.
*/
@@ -74,7 +74,7 @@ public class JsonObjectBuilder {
/**
* Appends a string array to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param values The string array.
* @return A reference to this object.
*/
@@ -92,7 +92,7 @@ public class JsonObjectBuilder {
/**
* Appends an integer array to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param values The integer array.
* @return A reference to this object.
*/
@@ -110,7 +110,7 @@ public class JsonObjectBuilder {
/**
* Appends an object array to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param values The integer array.
* @return A reference to this object.
*/
@@ -128,7 +128,7 @@ public class JsonObjectBuilder {
/**
* Appends a field to the object.
*
* @param key The key of the field.
* @param key The key of the field.
* @param escapedValue The escaped value of the field.
*/
private void appendFieldUnescaped(String key, String escapedValue) {
@@ -19,6 +19,12 @@ public class CommandEX {
obj.name = name;
obj.args = args;
obj.isDefault = isDefault;
if (AllMusic.side.onMusicAdd(sender, obj)) {
AllMusic.side.sendMessage(sender, AllMusic.getMessage().getAddMusic().getCancel());
return;
}
MusicSearch.addSearch(obj);
}
@@ -57,6 +63,12 @@ public class CommandEX {
obj.id = musicID;
obj.name = name;
obj.isDefault = false;
if (AllMusic.side.onMusicAdd(sender, obj)) {
AllMusic.side.sendMessage(sender, AllMusic.getMessage().getAddMusic().getCancel());
return;
}
PlayMusic.addTask(obj);
AllMusic.side.sendMessage(sender, AllMusic.getMessage().getAddMusic().getSuccess());
if (AllMusic.getConfig().isUseCost() && AllMusic.vault != null) {
@@ -210,7 +210,7 @@ public class HudUtils {
HudUtils.sendHudSave(name);
}
public static boolean setPicSize(String name, String size){
public static boolean setPicSize(String name, String size) {
SaveOBJ obj = HudSave.get(name);
if (obj == null)
obj = AllMusic.getConfig().getDefaultHud().copy();
@@ -7,6 +7,7 @@ public class AddMusicOBJ {
private String Success;
private String NoPlayer;
private String NoID;
private String Cancel;
public AddMusicOBJ() {
ListFull = "§d[AllMusic]§c错误,队列已满";
@@ -15,6 +16,7 @@ public class AddMusicOBJ {
Success = "§d[AllMusic]§2点歌成功";
NoPlayer = "§d[AllMusic]§c没有播放的玩家";
NoID = "§d[AllMusic]§c错误,请输入歌曲数字ID";
Cancel = "§d[AllMusic]§e点歌被取消";
}
public boolean check() {
@@ -30,10 +32,16 @@ public class AddMusicOBJ {
return true;
if (NoID == null)
return true;
if(Cancel == null)
return true;
return false;
}
public String getCancel() {
return Cancel;
}
public String getNoID() {
return NoID;
}
@@ -9,10 +9,10 @@ public class ClickObj {
Check = "§b[§n点我查看§r§b]";
}
public boolean check(){
if(This == null)
public boolean check() {
if (This == null)
return true;
if(Check == null)
if (Check == null)
return true;
return false;
@@ -9,10 +9,10 @@ public class CommandOBJ {
NoPer = "§d[AllMusic]§c你没有权限点歌";
}
public boolean check(){
if(Error == null)
public boolean check() {
if (Error == null)
return true;
if(NoPer == null)
if (NoPer == null)
return true;
return false;
@@ -11,12 +11,12 @@ public class CostObj {
NoMoney = "§d[ALLMusic]§c你没有足够的钱";
}
public boolean check(){
if(Search == null)
public boolean check() {
if (Search == null)
return true;
if(AddMusic == null)
if (AddMusic == null)
return true;
if(NoMoney == null)
if (NoMoney == null)
return true;
return false;
@@ -7,8 +7,8 @@ public class CustomOBJ {
Info = "自定义音乐";
}
public boolean check(){
if(Info == null)
public boolean check() {
if (Info == null)
return true;
return false;
@@ -27,28 +27,28 @@ public class HelpNormalObj {
Hud3 = "§d[AllMusic]§2使用/music hud picsize [尺寸] 设置图片尺寸";
}
public boolean check(){
if(Head == null)
public boolean check() {
if (Head == null)
return true;
if(Base == null)
if (Base == null)
return true;
if(Stop == null)
if (Stop == null)
return true;
if(List == null)
if (List == null)
return true;
if(Vote == null)
if (Vote == null)
return true;
if(NoMusic == null)
if (NoMusic == null)
return true;
if(Search == null)
if (Search == null)
return true;
if(Select == null)
if (Select == null)
return true;
if(Hud1 == null)
if (Hud1 == null)
return true;
if(Hud2 == null)
if (Hud2 == null)
return true;
if(Hud3 == null)
if (Hud3 == null)
return true;
return false;
@@ -15,16 +15,16 @@ public class HudListOBJ {
All = "所有位置";
}
public boolean check(){
if(List == null)
public boolean check() {
if (List == null)
return true;
if(Lyric == null)
if (Lyric == null)
return true;
if(Info == null)
if (Info == null)
return true;
if(All == null)
if (All == null)
return true;
if(Pic == null)
if (Pic == null)
return true;
return false;
@@ -9,10 +9,10 @@ public class LyricOBJ {
TData = "%Lyric%(%TLyric%)";
}
public boolean check(){
if(Data == null)
public boolean check() {
if (Data == null)
return true;
if(TData == null)
if (TData == null)
return true;
return false;
@@ -13,6 +13,7 @@ public class MusicPlayOBJ {
private String CheckMusic;
private String MusicInfo;
private String Trail;
private String Cancel;
public MusicPlayOBJ() {
StopPlay = "§d[AllMusic]§2已停止你的音乐播放";
@@ -27,6 +28,7 @@ public class MusicPlayOBJ {
CheckMusic = "§d[AllMusic]§2正在解析歌曲%MusicID%";
MusicInfo = "%MusicName% | %MusicAuthor% | %MusicAl% | %MusicAlia% | by: %PlayerName%";
Trail = "§d[AllMusic]§2该音乐为试听音乐";
Cancel = "§d[AllMusic]§e播放被取消";
}
public boolean check() {
@@ -55,10 +57,16 @@ public class MusicPlayOBJ {
res = true;
if (Trail == null)
res = true;
if(Cancel == null)
res = true;
return res;
}
public String getCancel() {
return Cancel;
}
public String getTrail() {
return Trail;
}
@@ -7,8 +7,8 @@ public class PAPIOBJ {
NoMusic = "没有播放的音乐";
}
public boolean check(){
if(NoMusic == null)
public boolean check() {
if (NoMusic == null)
return true;
return false;
@@ -23,24 +23,24 @@ public class SearchOBJ {
CantLast = "§d[AllMusic]§c无法上一页";
}
public boolean check(){
if(NoPer == null)
public boolean check() {
if (NoPer == null)
return true;
if(CantSearch == null)
if (CantSearch == null)
return true;
if(Res == null)
if (Res == null)
return true;
if(NoSearch == null)
if (NoSearch == null)
return true;
if(ErrorNum == null)
if (ErrorNum == null)
return true;
if(Chose == null)
if (Chose == null)
return true;
if(CantNext == null)
if (CantNext == null)
return true;
if(CantLast == null)
if (CantLast == null)
return true;
if(StartSearch == null)
if (StartSearch == null)
return true;
return false;
@@ -21,22 +21,22 @@ public class VoteOBJ {
Do = "§d[AllMusic]§2已切歌";
}
public boolean check(){
if(NoPermission == null)
public boolean check() {
if (NoPermission == null)
return true;
if(DoVote == null)
if (DoVote == null)
return true;
if(BQ == null)
if (BQ == null)
return true;
if(Agree == null)
if (Agree == null)
return true;
if(BQAgree == null)
if (BQAgree == null)
return true;
if(ARAgree == null)
if (ARAgree == null)
return true;
if(TimeOut == null)
if (TimeOut == null)
return true;
if(Do == null)
if (Do == null)
return true;
return false;
@@ -1,6 +1,5 @@
package coloryr.allmusic.music.api;
import coloryr.allmusic.AllMusic;
import coloryr.allmusic.music.api.obj.music.trialinfo.freeTrialInfo;
public class TopSongInfo extends SongInfo {
@@ -5,15 +5,15 @@ public class TopLyricItem extends LyricItem {
super(false, null, null);
}
public void setTlyric(String data){
public void setTlyric(String data) {
tlyric = data;
}
public void setLyric(String data){
public void setLyric(String data) {
lyric = data;
}
public void setHaveT(boolean data){
public void setHaveT(boolean data) {
haveT = data;
}
}
@@ -2,8 +2,8 @@ package coloryr.allmusic.music.play;
import coloryr.allmusic.AllMusic;
import coloryr.allmusic.hud.HudUtils;
import coloryr.allmusic.music.lyric.LyricSave;
import coloryr.allmusic.music.lyric.LyricItem;
import coloryr.allmusic.music.lyric.LyricSave;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -121,6 +121,10 @@ public class PlayGo {
} else {
AllMusic.side.sendHudSaveAll();
PlayMusic.nowPlayMusic = PlayMusic.remove(0);
if (AllMusic.side.onMusicPlay(PlayMusic.nowPlayMusic)) {
AllMusic.side.bqt(AllMusic.getMessage().getMusicPlay().getCancel());
continue;
}
url = PlayMusic.nowPlayMusic.getPlayerUrl() == null ?
AllMusic.getMusicApi().getPlayUrl(PlayMusic.nowPlayMusic.getID()) :
@@ -145,7 +149,10 @@ public class PlayGo {
.replace("%MusicAl%", PlayMusic.nowPlayMusic.getAl())
.replace("%MusicAlia%", PlayMusic.nowPlayMusic.getAlia())
.replace("%PlayerName%", PlayMusic.nowPlayMusic.getCall());
AllMusic.side.bqt(info);
if (AllMusic.getConfig().isShowInBar())
AllMusic.side.sendBar(info);
else
AllMusic.side.bqt(info);
}
startTimer();
AllMusic.side.sendMusic(url);
@@ -4,8 +4,8 @@ import coloryr.allmusic.AllMusic;
import coloryr.allmusic.decoder.Bitstream;
import coloryr.allmusic.decoder.Header;
import coloryr.allmusic.music.api.SongInfo;
import coloryr.allmusic.music.lyric.LyricSave;
import coloryr.allmusic.music.lyric.LyricItem;
import coloryr.allmusic.music.lyric.LyricSave;
import coloryr.allmusic.utils.Logs;
import java.io.BufferedInputStream;
@@ -70,7 +70,7 @@ public class PlayMusic {
public static void addMusic(Object sender, String id, String player, boolean isList) {
if (isHave(id))
return;
if(sender != null) {
if (sender != null) {
String text = AllMusic.getMessage().getMusicPlay().getCheckMusic();
text = text.replace("%MusicID%", id);
AllMusic.side.sendMessaget(sender, text);
@@ -80,7 +80,7 @@ public class PlayMusic {
SongInfo info = AllMusic.getMusicApi().getMusic(id, player, isList);
if (info != null) {
playList.add(info);
if(!AllMusic.getConfig().isMuteAddMessage()) {
if (!AllMusic.getConfig().isMuteAddMessage()) {
String data = AllMusic.getMessage().getMusicPlay().getAddMusic();
data = data.replace("%MusicName%", info.getName())
.replace("%MusicAuthor%", info.getAuthor())
@@ -123,7 +123,7 @@ public class PlayMusic {
}
public static SongInfo remove(int index) {
return playList.remove(index);
return playList.remove(index);
}
public static String getAllList() {
@@ -167,8 +167,7 @@ public class PlayMusic {
int le = 6000000;
if (h == null) {
AllMusic.side.bqt("§d[AllMusic]§c未知音乐类型");
}
else {
} else {
le = (int) h.total_ms(b);
}
SongInfo info = new SongInfo(AllMusic.getMessage().getCustom().getInfo(), arg, le);
@@ -1,30 +1,64 @@
package coloryr.allmusic.side;
import coloryr.allmusic.music.api.SongInfo;
import coloryr.allmusic.music.play.MusicObj;
public interface ISide {
void send(String data, String player, Boolean isplay);
int getAllPlayer();
void bq(String data);
void bqt(String data);
boolean needPlay();
void sendStop();
void sendStop(String name);
void sendMusic(String url);
void sendPic(String url);
void sendHudLyric(String data);
void sendHudInfo(String data);
void sendHudList(String data);
void sendHudSaveAll();
void sendBar(String data);
void clearHud(String player);
void clearHud();
void sendMessaget(Object obj, String message);
void sendMessage(Object obj, String message);
void sendMessageRun(Object obj, String message, String end, String command);
void sendMessageSuggest(Object obj, String message, String end, String command);
void runTask(Runnable run);
void reload();
boolean checkPermission(String player, String permission);
void task(Runnable run, int delay);
void updateInfo();
void updateLyric();
void ping();
boolean onMusicPlay(SongInfo obj);
boolean onMusicAdd(Object obj, MusicObj music);
}
@@ -28,7 +28,7 @@ public class MetricsBC {
/**
* Creates a new Metrics instance.
*
* @param plugin Your plugin instance.
* @param plugin Your plugin instance.
* @param serviceId The id of the service.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
@@ -111,7 +111,7 @@ public class MetricsBC {
}
private void appendPlatformData(JsonObjectBuilder builder) {
builder.appendField("playerAmount", plugin.getProxy().getOnlineCount());
builder.appendField("playerAmount", plugin.getProxy().getOnlineCount());
builder.appendField("managedServers", plugin.getProxy().getServers().size());
builder.appendField("onlineMode", plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0);
builder.appendField("bungeecordVersion", plugin.getProxy().getVersion());
@@ -2,17 +2,23 @@ package coloryr.allmusic.side.bc;
import coloryr.allmusic.AllMusic;
import coloryr.allmusic.AllMusicBC;
import coloryr.allmusic.side.ComType;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.hud.HudSave;
import coloryr.allmusic.hud.obj.SaveOBJ;
import coloryr.allmusic.music.api.SongInfo;
import coloryr.allmusic.music.play.MusicObj;
import coloryr.allmusic.music.play.PlayMusic;
import coloryr.allmusic.side.ComType;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.side.bc.event.MusicAddEvent;
import coloryr.allmusic.side.bc.event.MusicPlayEvent;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
@@ -33,6 +39,7 @@ public class SideBC implements ISide {
public void send(String data, String player, Boolean isplay) {
send(ProxyServer.getInstance().getPlayer(player), data, isplay);
}
@Override
public int getAllPlayer() {
return ProxyServer.getInstance().getOnlineCount();
@@ -105,7 +112,20 @@ public class SideBC implements ISide {
}
@Override
public void sendMusic(String url){
public void sendBar(String data) {
BaseComponent[] message = TextComponent.fromLegacyText(data);
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
try {
player.sendMessage(ChatMessageType.ACTION_BAR, message);
} catch (Exception e1) {
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
e1.printStackTrace();
}
}
}
@Override
public void sendMusic(String url) {
try {
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
if (isOK(player))
@@ -117,8 +137,9 @@ public class SideBC implements ISide {
e.printStackTrace();
}
}
@Override
public void sendPic(String url){
public void sendPic(String url) {
try {
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
if (isOK(player))
@@ -265,7 +286,7 @@ public class SideBC implements ISide {
.schedule(AllMusicBC.plugin, run, delay, TimeUnit.MICROSECONDS);
}
public static void sendAllToServer(Server server){
public static void sendAllToServer(Server server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(0);
if (PlayMusic.nowPlayMusic == null)
@@ -317,7 +338,7 @@ public class SideBC implements ISide {
server.sendData(AllMusic.channelBC, out.toByteArray());
}
public static void sendLyricToServer(Server server){
public static void sendLyricToServer(Server server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(7);
if (PlayMusic.lyricItem == null)
@@ -342,7 +363,7 @@ public class SideBC implements ISide {
@Override
public void updateInfo() {
for(Server server : TopServers) {
for (Server server : TopServers) {
if (server.isConnected()) {
sendAllToServer(server);
} else {
@@ -353,7 +374,7 @@ public class SideBC implements ISide {
@Override
public void updateLyric() {
for(Server server : TopServers) {
for (Server server : TopServers) {
if (server.isConnected()) {
sendLyricToServer(server);
} else {
@@ -377,6 +398,20 @@ public class SideBC implements ISide {
}
}
@Override
public boolean onMusicPlay(SongInfo obj) {
MusicPlayEvent event = new MusicPlayEvent(obj);
ProxyServer.getInstance().getPluginManager().callEvent(event);
return event.isCancel();
}
@Override
public boolean onMusicAdd(Object obj, MusicObj music) {
MusicAddEvent event = new MusicAddEvent(music, (CommandSender) obj);
ProxyServer.getInstance().getPluginManager().callEvent(event);
return event.isCancel();
}
private void send(ProxiedPlayer players, String data, Boolean isplay) {
if (players == null)
return;
@@ -0,0 +1,32 @@
package coloryr.allmusic.side.bc.event;
import coloryr.allmusic.music.play.MusicObj;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Event;
public class MusicAddEvent extends Event {
private final MusicObj music;
private final CommandSender player;
private boolean cancel = false;
public MusicAddEvent(MusicObj id, CommandSender player){
this.music = id;
this.player = player;
}
public boolean isCancel() {
return cancel;
}
public void setCancel(boolean cancel) {
this.cancel = cancel;
}
public CommandSender getPlayer() {
return player;
}
public MusicObj getMusic() {
return music;
}
}
@@ -0,0 +1,25 @@
package coloryr.allmusic.side.bc.event;
import coloryr.allmusic.music.api.SongInfo;
import net.md_5.bungee.api.plugin.Event;
public class MusicPlayEvent extends Event {
private final SongInfo music;
private boolean cancel = false;
public MusicPlayEvent(SongInfo music) {
this.music = music;
}
public SongInfo getMusic() {
return music;
}
public void setCancel(boolean cancel) {
this.cancel = cancel;
}
public boolean isCancel() {
return cancel;
}
}
@@ -23,7 +23,7 @@ public class MetricsBukkit {
/**
* Creates a new Metrics instance.
*
* @param plugin Your plugin instance.
* @param plugin Your plugin instance.
* @param serviceId The id of the service.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
@@ -52,7 +52,8 @@ public class MetricsBukkit {
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) { }
} catch (IOException ignored) {
}
}
// Load the data
@@ -4,7 +4,6 @@ import coloryr.allmusic.AllMusic;
import coloryr.allmusic.AllMusicBukkit;
import coloryr.allmusic.music.api.TopSongInfo;
import coloryr.allmusic.music.lyric.TopLyricItem;
import coloryr.allmusic.music.play.PlayGo;
import coloryr.allmusic.music.play.PlayMusic;
import com.google.common.collect.Iterables;
import com.google.common.io.ByteArrayDataInput;
@@ -36,11 +35,11 @@ public class PluginMessage implements PluginMessageListener {
service.scheduleAtFixedRate(PluginMessage::clear, 0, 30, TimeUnit.SECONDS);
}
private static void clear(){
private static void clear() {
update = false;
}
public void stop(){
public void stop() {
service.shutdownNow();
}
@@ -2,10 +2,14 @@ package coloryr.allmusic.side.bukkit;
import coloryr.allmusic.AllMusic;
import coloryr.allmusic.AllMusicBukkit;
import coloryr.allmusic.side.ComType;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.hud.HudSave;
import coloryr.allmusic.hud.obj.SaveOBJ;
import coloryr.allmusic.music.api.SongInfo;
import coloryr.allmusic.music.play.MusicObj;
import coloryr.allmusic.side.ComType;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.side.bukkit.event.MusicAddEvent;
import coloryr.allmusic.side.bukkit.event.MusicPlayEvent;
import coloryr.allmusic.side.bukkit.hooks.CitizensNPC;
import coloryr.allmusic.side.bukkit.hooks.SpigotApi;
import com.google.gson.Gson;
@@ -141,6 +145,21 @@ public class SideBukkit implements ISide {
}
}
@Override
public void sendBar(String data) {
if(AllMusicBukkit.spigotSet) {
for (Player player : Bukkit.getOnlinePlayers()) {
try {
SpigotApi.sendBar(player, data);
} catch (Exception e1) {
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
e1.printStackTrace();
}
}
}
}
@Override
public void sendMusic(String url) {
try {
for (Player player : Bukkit.getOnlinePlayers()) {
@@ -326,6 +345,20 @@ public class SideBukkit implements ISide {
}
@Override
public boolean onMusicPlay(SongInfo obj) {
MusicPlayEvent event = new MusicPlayEvent(obj);
Bukkit.getPluginManager().callEvent(event);
return event.isCancel();
}
@Override
public boolean onMusicAdd(Object obj, MusicObj music) {
MusicAddEvent event = new MusicAddEvent(music, (CommandSender) obj);
Bukkit.getPluginManager().callEvent(event);
return event.isCancel();
}
private void send(Player players, String data, Boolean isplay) {
if (players == null)
return;
@@ -0,0 +1,41 @@
package coloryr.allmusic.side.bukkit.event;
import coloryr.allmusic.music.play.MusicObj;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class MusicAddEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final MusicObj music;
private final CommandSender player;
private boolean cancel = false;
public MusicAddEvent(MusicObj id, CommandSender player){
this.music = id;
this.player = player;
}
public boolean isCancel() {
return cancel;
}
public void setCancel(boolean cancel) {
this.cancel = cancel;
}
public CommandSender getPlayer() {
return player;
}
public MusicObj getMusic() {
return music;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
}
@@ -0,0 +1,35 @@
package coloryr.allmusic.side.bukkit.event;
import coloryr.allmusic.music.api.SongInfo;
import coloryr.allmusic.music.play.MusicObj;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class MusicPlayEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final SongInfo music;
private boolean cancel = false;
public MusicPlayEvent(SongInfo music) {
this.music = music;
}
public SongInfo getMusic() {
return music;
}
public void setCancel(boolean cancel) {
this.cancel = cancel;
}
public boolean isCancel() {
return cancel;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
}
@@ -55,8 +55,8 @@ public class AllMusicPAPI extends PlaceholderExpansion {
@Override
public String onRequest(OfflinePlayer player, @NotNull String identifier) {
if(AllMusic.getConfig().isTopPAPI()){
if(!PluginMessage.update){
if (AllMusic.getConfig().isTopPAPI()) {
if (!PluginMessage.update) {
PluginMessage.startUpdate();
return "";
}
@@ -92,8 +92,7 @@ public class AllMusicPAPI extends PlaceholderExpansion {
return PlayMusic.lyricItem.getTlyric();
}
}
}
else {
} else {
switch (identifier) {
case "now_music_name": {
if (PlayMusic.nowPlayMusic == null)
@@ -3,7 +3,7 @@ package coloryr.allmusic.side.bukkit.hooks;
import org.bukkit.entity.Entity;
public class CitizensNPC {
public static boolean isNPC(Entity entity){
public static boolean isNPC(Entity entity) {
return entity.hasMetadata("NPC");
}
}
@@ -1,21 +1,27 @@
package coloryr.allmusic.side.bukkit.hooks;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SpigotApi {
public static void sendMessageRun(Object obj, String Message, String Command) {
public static void sendMessageRun(Object obj, String message, String command) {
CommandSender sender = (CommandSender) obj;
TextComponent send = new TextComponent(Message);
send.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, Command));
TextComponent send = new TextComponent(message);
send.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
sender.spigot().sendMessage(send);
}
public static void sendMessageSuggest(Object obj, String Message, String Command) {
public static void sendMessageSuggest(Object obj, String message, String command) {
CommandSender sender = (CommandSender) obj;
TextComponent send = new TextComponent(Message);
send.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, Command));
TextComponent send = new TextComponent(message);
send.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
sender.spigot().sendMessage(send);
}
public static void sendBar(Player player, String message) {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
}
}
@@ -19,7 +19,7 @@ public class ListenerVelocity {
}
@Subscribe
public void onPluginMessageEvent(final PluginMessageEvent event){
public void onPluginMessageEvent(final PluginMessageEvent event) {
if (event.getIdentifier().getId().equals(AllMusic.channelBC)) {
event.setResult(PluginMessageEvent.ForwardResult.handled());
if (event.getSource() instanceof ServerConnection) {
@@ -2,11 +2,15 @@ package coloryr.allmusic.side.velocity;
import coloryr.allmusic.AllMusic;
import coloryr.allmusic.AllMusicVelocity;
import coloryr.allmusic.side.ComType;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.hud.HudSave;
import coloryr.allmusic.hud.obj.SaveOBJ;
import coloryr.allmusic.music.api.SongInfo;
import coloryr.allmusic.music.play.MusicObj;
import coloryr.allmusic.music.play.PlayMusic;
import coloryr.allmusic.side.ComType;
import coloryr.allmusic.side.ISide;
import coloryr.allmusic.side.velocity.event.MusicAddEvent;
import coloryr.allmusic.side.velocity.event.MusicPlayEvent;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.google.gson.Gson;
@@ -198,6 +202,19 @@ public class SideVelocity implements ISide {
}
}
@Override
public void sendBar(String data) {
Component message = Component.text(data);
for (Player player : AllMusicVelocity.plugin.server.getAllPlayers()) {
try {
player.sendActionBar(message);
} catch (Exception e1) {
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
e1.printStackTrace();
}
}
}
@Override
public void clearHud(String player) {
send(ComType.clear, player, null);
@@ -273,7 +290,7 @@ public class SideVelocity implements ISide {
.delay(delay, TimeUnit.MICROSECONDS).schedule();
}
public static void sendAllToServer(ServerConnection server){
public static void sendAllToServer(ServerConnection server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(0);
if (PlayMusic.nowPlayMusic == null)
@@ -325,7 +342,7 @@ public class SideVelocity implements ISide {
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
}
public static void sendLyricToServer(ServerConnection server){
public static void sendLyricToServer(ServerConnection server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(7);
if (PlayMusic.lyricItem == null)
@@ -349,26 +366,40 @@ public class SideVelocity implements ISide {
}
@Override
public void ping(){
public void ping() {
Iterator<ServerConnection> iterator = TopServers.iterator();
while (iterator.hasNext()) {
ServerConnection server = iterator.next();
try{
try {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(200);
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
}catch (Exception e){
} catch (Exception e) {
iterator.remove();
}
}
}
@Override
public boolean onMusicPlay(SongInfo obj) {
MusicPlayEvent event = new MusicPlayEvent(obj);
AllMusicVelocity.plugin.server.getEventManager().fire(event).join();
return event.isCancel();
}
@Override
public boolean onMusicAdd(Object obj, MusicObj music) {
MusicAddEvent event = new MusicAddEvent(music, (CommandSource) obj);
AllMusicVelocity.plugin.server.getEventManager().fire(event).join();
return event.isCancel();
}
@Override
public void updateInfo() {
for(ServerConnection server : TopServers) {
try {
for (ServerConnection server : TopServers) {
try {
sendAllToServer(server);
} catch(Exception e) {
} catch (Exception e) {
TopServers.remove(server);
}
}
@@ -376,10 +407,10 @@ public class SideVelocity implements ISide {
@Override
public void updateLyric() {
for(ServerConnection server : TopServers) {
for (ServerConnection server : TopServers) {
try {
sendLyricToServer(server);
} catch(Exception e) {
} catch (Exception e) {
TopServers.remove(server);
}
}
@@ -0,0 +1,31 @@
package coloryr.allmusic.side.velocity.event;
import coloryr.allmusic.music.play.MusicObj;
import com.velocitypowered.api.command.CommandSource;
public class MusicAddEvent {
private final MusicObj music;
private final CommandSource player;
private boolean cancel = false;
public MusicAddEvent(MusicObj id, CommandSource player){
this.music = id;
this.player = player;
}
public boolean isCancel() {
return cancel;
}
public void setCancel(boolean cancel) {
this.cancel = cancel;
}
public CommandSource getPlayer() {
return player;
}
public MusicObj getMusic() {
return music;
}
}
@@ -0,0 +1,25 @@
package coloryr.allmusic.side.velocity.event;
import coloryr.allmusic.music.api.SongInfo;
import coloryr.allmusic.music.play.MusicObj;
public class MusicPlayEvent {
private final SongInfo music;
private boolean cancel = false;
public MusicPlayEvent(SongInfo music) {
this.music = music;
}
public SongInfo getMusic() {
return music;
}
public void setCancel(boolean cancel) {
this.cancel = cancel;
}
public boolean isCancel() {
return cancel;
}
}
+1
View File
@@ -18,6 +18,7 @@
"MessageLimitSize": 40,
"MutePlayMessage": false,
"MuteAddMessage": false,
"ShowInBar": false,
"DefaultHud": {
"List": {
"x": 2,
+4 -2
View File
@@ -15,7 +15,8 @@
"AddMusic": "§d[AllMusic]§e音乐列表添加%MusicName% | %MusicAuthor% | %MusicAl% | %MusicAlia%",
"CheckMusic": "§d[AllMusic]§2正在解析歌曲%MusicID%",
"MusicInfo": "%MusicName% | %MusicAuthor% | %MusicAl% | %MusicAlia% | by: %PlayerName%",
"Trail": "§d[AllMusic]§e该音乐为试听音乐"
"Trail": "§d[AllMusic]§e该音乐为试听音乐",
"Cancel": "§d[AllMusic]§e播放被取消"
},
"AddMusic": {
"ListFull": "§d[AllMusic]§c错误,队列已满",
@@ -23,7 +24,8 @@
"ExistMusic": "§d[AllMusic]§c错误,这首歌已经存在了",
"Success": "§d[AllMusic]§e点歌成功",
"NoPlayer": "§d[AllMusic]§c没有播放的玩家",
"NoID": "§d[AllMusic]§c错误,请输入歌曲数字ID"
"NoID": "§d[AllMusic]§c错误,请输入歌曲数字ID",
"Cancel": "§d[AllMusic]§e点歌被取消"
},
"Page": {
"Choice": "§e%index%->%MusicName% | %MusicAuthor% | %MusicAl%",