mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-12 18:57:36 +00:00
up
This commit is contained in:
1 parent
accea52f5d
commit
13b01757f6
43 files changed
+615
-440
No files matched your search
@@ -1,7 +1,8 @@
|
||||
package coloryr.allmusic;
|
||||
|
||||
import coloryr.allmusic.api.IMyLogger;
|
||||
import coloryr.allmusic.api.ISide;
|
||||
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;
|
||||
@@ -12,7 +13,7 @@ import coloryr.allmusic.music.play.PlayGo;
|
||||
import coloryr.allmusic.music.play.PlayMusic;
|
||||
import coloryr.allmusic.music.search.SearchPage;
|
||||
import coloryr.allmusic.side.bukkit.hooks.VaultHook;
|
||||
import coloryr.allmusic.utils.logs;
|
||||
import coloryr.allmusic.utils.Logs;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
@@ -168,8 +169,8 @@ public class AllMusic {
|
||||
public static void stop() {
|
||||
try {
|
||||
clearVote();
|
||||
logs.stop();
|
||||
side.send("[Stop]", false);
|
||||
Logs.stop();
|
||||
side.sendStop();
|
||||
MusicSearch.stop();
|
||||
PlayMusic.stop();
|
||||
PlayGo.stop();
|
||||
@@ -261,8 +262,8 @@ public class AllMusic {
|
||||
messageFile = new File(file, "message.json");
|
||||
if (cookieFile == null)
|
||||
cookieFile = new File(file, "cookie.json");
|
||||
if (logs.file == null)
|
||||
logs.file = new File(file, "logs.log");
|
||||
if (Logs.file == null)
|
||||
Logs.file = new File(file, "logs.log");
|
||||
if (DataSql.sqlFile == null)
|
||||
DataSql.sqlFile = new File(file, "data.db");
|
||||
if (!configFile.exists()) {
|
||||
@@ -274,8 +275,8 @@ public class AllMusic {
|
||||
if (!cookieFile.exists()) {
|
||||
cookieFile.createNewFile();
|
||||
}
|
||||
if (!logs.file.exists()) {
|
||||
logs.file.createNewFile();
|
||||
if (!Logs.file.exists()) {
|
||||
Logs.file.createNewFile();
|
||||
}
|
||||
loadConfig();
|
||||
isRun = true;
|
||||
|
||||
@@ -11,7 +11,7 @@ public class AllMusicBC extends Plugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
AllMusic.log = new BCLog(ProxyServer.getInstance().getLogger());
|
||||
AllMusic.log = new LogBC(ProxyServer.getInstance().getLogger());
|
||||
AllMusic.side = new SideBC();
|
||||
|
||||
new AllMusic().init(plugin.getDataFolder());
|
||||
@@ -20,7 +20,7 @@ public class AllMusicBC extends Plugin {
|
||||
return;
|
||||
ProxyServer.getInstance().registerChannel(AllMusic.channelBC);
|
||||
ProxyServer.getInstance().getPluginManager().registerCommand(this, new CommandBC());
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(this, new EventBC());
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(this, new ListenerBC());
|
||||
new MetricsBC(this, 6720);
|
||||
|
||||
AllMusic.start();
|
||||
|
||||
@@ -20,7 +20,7 @@ public class AllMusicBukkit extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
AllMusic.log = new BukkitLog(getLogger());
|
||||
AllMusic.log = new LogBukkit(getLogger());
|
||||
AllMusic.side = new SideBukkit();
|
||||
|
||||
try {
|
||||
@@ -79,7 +79,7 @@ public class AllMusicBukkit extends JavaPlugin {
|
||||
PluginCommand command1 = Bukkit.getPluginCommand("music");
|
||||
command1.setExecutor(command);
|
||||
command1.setTabCompleter(command);
|
||||
Bukkit.getPluginManager().registerEvents(new EventBukkit(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ListenerBukkit(), this);
|
||||
AllMusic.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class AllMusicVelocity {
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
plugin = this;
|
||||
AllMusic.log = new VelocityLog(logger);
|
||||
AllMusic.log = new LogVelocity(logger);
|
||||
new AllMusic().init(dataDirectory.toFile());
|
||||
CommandMeta meta = server.getCommandManager().metaBuilder("music")
|
||||
// Specify other aliases (optional)
|
||||
@@ -49,7 +49,7 @@ public class AllMusicVelocity {
|
||||
AllMusic.side = new SideVelocity();
|
||||
server.getChannelRegistrar().register(channelBC);
|
||||
server.getCommandManager().register(meta, new CommandVelocity());
|
||||
server.getEventManager().register(this, new EventVelocity());
|
||||
server.getEventManager().register(this, new ListenerVelocity());
|
||||
metricsFactory.make(this, 6720);
|
||||
|
||||
AllMusic.start();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package coloryr.allmusic.api;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.hud.obj.HudPos;
|
||||
|
||||
public class AllMusicAPI {
|
||||
public static void playMusic(String name, String url) {
|
||||
AllMusic.side.send(name, "[url]" + url, false);
|
||||
}
|
||||
|
||||
public static void sendHud(String name, HudPos pos, String data) {
|
||||
|
||||
}
|
||||
|
||||
public static void sendPic(String name, String url) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class MetricsBase {
|
||||
/**
|
||||
* The version of the Metrics class.
|
||||
*/
|
||||
public static final String METRICS_VERSION = "2.1.0";
|
||||
public static final String METRICS_VERSION = "3.0.1-SNAPSHOT";
|
||||
|
||||
private static final ScheduledExecutorService scheduler =
|
||||
Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics"));
|
||||
@@ -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,
|
||||
@@ -99,28 +99,11 @@ public class MetricsBase {
|
||||
|
||||
checkRelocation();
|
||||
|
||||
if (enabled) {
|
||||
if (enabled) { // WARNING: Removing the option to opt-out will get your plugin banned from bStats
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given string.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped string.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
this.customCharts.add(chart);
|
||||
}
|
||||
@@ -235,4 +218,21 @@ public class MetricsBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given string.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped string.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -77,11 +77,11 @@ public class MetricsConfig {
|
||||
*/
|
||||
private void writeConfig() throws IOException {
|
||||
List<String> configContent = new ArrayList<>();
|
||||
configContent.add("# bStats collects some basic information for plugin authors, like how many people use");
|
||||
configContent.add("# their plugin and their total player count. It's recommend to keep bStats enabled, but");
|
||||
configContent.add("# if you're not comfortable with this, you can turn this setting off. There is no");
|
||||
configContent.add("# performance penalty associated with having metrics enabled, and data sent to bStats");
|
||||
configContent.add("# can't identify your server.");
|
||||
configContent.add("# bStats (https://bStats.org) collects some basic information for plugin authors, like");
|
||||
configContent.add("# how many people use their plugin and their total player count. It's recommended to keep");
|
||||
configContent.add("# bStats enabled, but if you're not comfortable with this, you can turn this setting off.");
|
||||
configContent.add("# There is no performance penalty associated with having metrics enabled, and data sent to");
|
||||
configContent.add("# bStats is fully anonymous.");
|
||||
configContent.add("enabled=" + defaultEnabled);
|
||||
configContent.add("server-uuid=" + UUID.randomUUID().toString());
|
||||
configContent.add("log-errors=false");
|
||||
@@ -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 {
|
||||
|
||||
@@ -18,34 +18,6 @@ public class JsonObjectBuilder {
|
||||
builder.append("{");
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
|
||||
*
|
||||
* <p>This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
|
||||
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
|
||||
*
|
||||
* @param value The value to escape.
|
||||
* @return The escaped value.
|
||||
*/
|
||||
private static String escape(String value) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '"') {
|
||||
builder.append("\\\"");
|
||||
} else if (c == '\\') {
|
||||
builder.append("\\\\");
|
||||
} else if (c <= '\u000F') {
|
||||
builder.append("\\u000").append(Integer.toHexString(c));
|
||||
} else if (c <= '\u001F') {
|
||||
builder.append("\\u00").append(Integer.toHexString(c));
|
||||
} else {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a null field to the JSON.
|
||||
*
|
||||
@@ -60,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.
|
||||
*/
|
||||
@@ -75,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.
|
||||
*/
|
||||
@@ -87,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.
|
||||
*/
|
||||
@@ -102,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.
|
||||
*/
|
||||
@@ -120,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.
|
||||
*/
|
||||
@@ -138,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.
|
||||
*/
|
||||
@@ -156,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) {
|
||||
@@ -188,6 +160,34 @@ public class JsonObjectBuilder {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
|
||||
*
|
||||
* <p>This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
|
||||
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
|
||||
*
|
||||
* @param value The value to escape.
|
||||
* @return The escaped value.
|
||||
*/
|
||||
private static String escape(String value) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '"') {
|
||||
builder.append("\\\"");
|
||||
} else if (c == '\\') {
|
||||
builder.append("\\\\");
|
||||
} else if (c <= '\u000F') {
|
||||
builder.append("\\u000").append(Integer.toHexString(c));
|
||||
} else if (c <= '\u001F') {
|
||||
builder.append("\\u00").append(Integer.toHexString(c));
|
||||
} else {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A super simple representation of a JSON object.
|
||||
*
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CommandEX {
|
||||
}
|
||||
}
|
||||
AllMusic.getConfig().RemoveNoMusicPlayer(name);
|
||||
if (AllMusic.side.NeedPlay()) {
|
||||
if (AllMusic.side.needPlay()) {
|
||||
MusicObj obj = new MusicObj();
|
||||
obj.sender = sender;
|
||||
obj.id = musicID;
|
||||
|
||||
@@ -41,9 +41,9 @@ public class TabCommand {
|
||||
this.add("list");
|
||||
this.add("lyric");
|
||||
this.add("pic");
|
||||
this.add("picsize");
|
||||
this.add("enable");
|
||||
this.add("reset");
|
||||
this.add("picsize");
|
||||
}};
|
||||
|
||||
public static List<String> getTabList(String name, String[] arg) {
|
||||
|
||||
@@ -12,9 +12,11 @@ import java.sql.Statement;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
public class DataSql {
|
||||
private static final Queue<Runnable> tasks = new ConcurrentLinkedQueue<>();
|
||||
private static final Semaphore semaphore = new Semaphore(0);
|
||||
private static boolean isRun;
|
||||
|
||||
private static Connection connection;
|
||||
@@ -41,6 +43,7 @@ public class DataSql {
|
||||
|
||||
public static void init() {
|
||||
try {
|
||||
AllMusic.log.info("正在初始化数据库");
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
@@ -127,6 +130,7 @@ public class DataSql {
|
||||
|
||||
private static void readAll() {
|
||||
try {
|
||||
AllMusic.log.info("正在读取数据库所有内容");
|
||||
if (connection.isReadOnly() || connection.isClosed()) {
|
||||
init();
|
||||
}
|
||||
@@ -166,6 +170,7 @@ public class DataSql {
|
||||
|
||||
public static void task(Runnable runnable) {
|
||||
tasks.add(runnable);
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
@@ -178,6 +183,7 @@ public class DataSql {
|
||||
|
||||
public static void stop() {
|
||||
isRun = false;
|
||||
semaphore.release();
|
||||
HudSave.save();
|
||||
}
|
||||
|
||||
@@ -185,11 +191,16 @@ public class DataSql {
|
||||
Runnable runnable;
|
||||
while (isRun) {
|
||||
try {
|
||||
runnable = tasks.poll();
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
semaphore.acquire();
|
||||
if (!isRun)
|
||||
return;
|
||||
do {
|
||||
runnable = tasks.poll();
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
Thread.sleep(50);
|
||||
while (runnable != null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package coloryr.allmusic.hud;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.hud.obj.Pos;
|
||||
import coloryr.allmusic.hud.obj.HudPos;
|
||||
import coloryr.allmusic.hud.obj.PosOBJ;
|
||||
import coloryr.allmusic.hud.obj.SaveOBJ;
|
||||
import coloryr.allmusic.music.api.SongInfo;
|
||||
@@ -15,7 +15,7 @@ public class HudUtils {
|
||||
SaveOBJ obj = HudSave.get(player);
|
||||
if (obj == null)
|
||||
obj = AllMusic.getConfig().getDefaultHud().copy();
|
||||
Pos pos1 = Pos.valueOf(pos);
|
||||
HudPos pos1 = HudPos.valueOf(pos);
|
||||
PosOBJ posOBJ = new PosOBJ(0, 0);
|
||||
if (!Function.isInteger(x) && !Function.isInteger(y))
|
||||
return null;
|
||||
@@ -68,8 +68,8 @@ public class HudUtils {
|
||||
if (info == null)
|
||||
continue;
|
||||
now = info.getInfo();
|
||||
if (now.length() > 30)
|
||||
now = now.substring(0, 29) + "...";
|
||||
if (now.length() > AllMusic.getConfig().getMessageLimitSize())
|
||||
now = now.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
list.append(now).append("\n");
|
||||
}
|
||||
}
|
||||
@@ -84,34 +84,35 @@ public class HudUtils {
|
||||
}
|
||||
|
||||
public static void sendHudNowData() {
|
||||
StringBuilder list = new StringBuilder();
|
||||
String info;
|
||||
if (PlayMusic.nowPlayMusic == null) {
|
||||
list.append(AllMusic.getMessage().getHud().getNoMusic());
|
||||
info = AllMusic.getMessage().getHud().getNoMusic();
|
||||
} else {
|
||||
list.append(PlayMusic.nowPlayMusic.getName()).append(" ")
|
||||
.append(tranTime(PlayMusic.musicAllTime)).append("/")
|
||||
.append(tranTime(PlayMusic.musicNowTime / 1000)).append("\n");
|
||||
list.append(PlayMusic.nowPlayMusic.getAuthor()).append("\n");
|
||||
list.append(PlayMusic.nowPlayMusic.getAlia()).append("\n");
|
||||
list.append(PlayMusic.nowPlayMusic.getAl()).append("\n");
|
||||
list.append("by:").append(PlayMusic.nowPlayMusic.getCall());
|
||||
info = AllMusic.getMessage().getHud().getMusic()
|
||||
.replace("%Name%", PlayMusic.nowPlayMusic.getName())
|
||||
.replace("%AllTime%", tranTime(PlayMusic.musicAllTime))
|
||||
.replace("%NowTime%", tranTime(PlayMusic.musicNowTime / 1000))
|
||||
.replace("%Author%", PlayMusic.nowPlayMusic.getAuthor())
|
||||
.replace("%Alia%", PlayMusic.nowPlayMusic.getAlia())
|
||||
.replace("%Al%", PlayMusic.nowPlayMusic.getAl())
|
||||
.replace("%Player%", PlayMusic.nowPlayMusic.getCall());
|
||||
}
|
||||
|
||||
AllMusic.side.sendHudInfo(list.toString());
|
||||
AllMusic.side.sendHudInfo(info);
|
||||
}
|
||||
|
||||
public static void sendHudLyricData(LyricItem showobj) {
|
||||
StringBuilder list = new StringBuilder();
|
||||
String info;
|
||||
if (showobj == null) {
|
||||
list.append(AllMusic.getMessage().getHud().getNoLyric());
|
||||
info = AllMusic.getMessage().getHud().getNoLyric();
|
||||
} else {
|
||||
if (showobj.getLyric() != null)
|
||||
list.append(showobj.getLyric()).append("\n");
|
||||
if (showobj.isHaveT() && showobj.getTlyric() != null)
|
||||
list.append(showobj.getTlyric());
|
||||
info = AllMusic.getMessage().getHud().getLyric()
|
||||
.replace("%Lyric%", showobj.getLyric() == null ? "" : showobj.getLyric())
|
||||
.replace("%Tlyric%", (showobj.isHaveT() && showobj.getTlyric() != null) ?
|
||||
showobj.getTlyric() : "");
|
||||
}
|
||||
|
||||
AllMusic.side.sendHudLyric(list.toString());
|
||||
AllMusic.side.sendHudLyric(info);
|
||||
}
|
||||
|
||||
public static boolean setHudEnable(String player, String pos) {
|
||||
@@ -136,7 +137,7 @@ public class HudUtils {
|
||||
a = true;
|
||||
}
|
||||
} else {
|
||||
Pos pos1 = Pos.valueOf(pos);
|
||||
HudPos pos1 = HudPos.valueOf(pos);
|
||||
switch (pos1) {
|
||||
case info:
|
||||
obj.setEnableInfo(!obj.isEnableInfo());
|
||||
@@ -160,7 +161,7 @@ public class HudUtils {
|
||||
if (pos == null) {
|
||||
return a;
|
||||
} else {
|
||||
Pos pos1 = Pos.valueOf(pos);
|
||||
HudPos pos1 = HudPos.valueOf(pos);
|
||||
switch (pos1) {
|
||||
case info:
|
||||
return obj.isEnableInfo();
|
||||
@@ -176,7 +177,7 @@ public class HudUtils {
|
||||
}
|
||||
|
||||
public static void clearHud() {
|
||||
AllMusic.side.clearHudAll();
|
||||
AllMusic.side.clearHud();
|
||||
}
|
||||
|
||||
public static void clearHud(String Name) {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package coloryr.allmusic.hud.obj;
|
||||
|
||||
public enum Pos {
|
||||
public enum HudPos {
|
||||
info, list, lyric, pic
|
||||
}
|
||||
@@ -8,6 +8,8 @@ public class HudOBJ {
|
||||
private String NoList;
|
||||
private String NoLyric;
|
||||
private String PicSize;
|
||||
private String Music;
|
||||
private String Lyric;
|
||||
|
||||
public HudOBJ() {
|
||||
State = "§d[ALLMusic]§2设置信息位置:%Hud%,状态:%State%";
|
||||
@@ -17,27 +19,41 @@ public class HudOBJ {
|
||||
NoList = "队列中无歌曲";
|
||||
NoLyric = "无歌词";
|
||||
PicSize = "§d[ALLMusic]§2设置图片尺寸为%Size%";
|
||||
Music = "%Name% %AllTime%/%NowTime%\n%Author%\n%Alia%\n%Al%\nby: %Player%";
|
||||
Lyric = "%Lyric%\n%Tlyric%";
|
||||
}
|
||||
|
||||
public boolean check(){
|
||||
if(State == null)
|
||||
public boolean check() {
|
||||
if (State == null)
|
||||
return true;
|
||||
if(Set == null)
|
||||
if (Set == null)
|
||||
return true;
|
||||
if(Reset == null)
|
||||
if (Reset == null)
|
||||
return true;
|
||||
if(NoMusic == null)
|
||||
if (NoMusic == null)
|
||||
return true;
|
||||
if(NoList == null)
|
||||
if (NoList == null)
|
||||
return true;
|
||||
if(NoLyric == null)
|
||||
if (NoLyric == null)
|
||||
return true;
|
||||
if(PicSize == null)
|
||||
if (PicSize == null)
|
||||
return true;
|
||||
if (Music == null)
|
||||
return true;
|
||||
if (Lyric == null)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getLyric() {
|
||||
return Lyric;
|
||||
}
|
||||
|
||||
public String getMusic() {
|
||||
return Music;
|
||||
}
|
||||
|
||||
public String getPicSize() {
|
||||
return PicSize;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package coloryr.allmusic.music.api;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.http.EncryptType;
|
||||
import coloryr.allmusic.http.HttpClientUtil;
|
||||
import coloryr.allmusic.http.Res;
|
||||
import coloryr.allmusic.music.api.http.EncryptType;
|
||||
import coloryr.allmusic.music.api.http.HttpClientUtil;
|
||||
import coloryr.allmusic.music.api.http.HttpRes;
|
||||
import coloryr.allmusic.music.api.obj.music.info.InfoOBJ;
|
||||
import coloryr.allmusic.music.api.obj.music.list.DataOBJ;
|
||||
import coloryr.allmusic.music.api.obj.music.lyric.WLyricOBJ;
|
||||
@@ -16,7 +16,7 @@ import coloryr.allmusic.music.lyric.LyricSave;
|
||||
import coloryr.allmusic.music.play.PlayMusic;
|
||||
import coloryr.allmusic.music.search.SearchOBJ;
|
||||
import coloryr.allmusic.music.search.SearchPage;
|
||||
import coloryr.allmusic.utils.logs;
|
||||
import coloryr.allmusic.utils.Logs;
|
||||
import com.google.gson.JsonObject;
|
||||
import okhttp3.Cookie;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class APIMain {
|
||||
public APIMain() {
|
||||
AllMusic.log.info("§d[AllMusic]§e正在初始化网络爬虫");
|
||||
HttpClientUtil.init();
|
||||
Res res = HttpClientUtil.get("https://music.163.com", "");
|
||||
HttpRes res = HttpClientUtil.get("https://music.163.com", "");
|
||||
if (res == null || !res.isOk()) {
|
||||
AllMusic.log.info("§d[AllMusic]§c初始化网络爬虫连接失败");
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class APIMain {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("ctcode", "86");
|
||||
params.addProperty("cellphone", AllMusic.getConfig().getLoginUser());
|
||||
Res res = HttpClientUtil.post("https://music.163.com/api/sms/captcha/sent", params, EncryptType.WEAPI, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/api/sms/captcha/sent", params, EncryptType.WEAPI, null);
|
||||
AllMusic.side.sendMessage(sender, "§d[AllMusic]§d已发送验证码\n" + res.getData());
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class APIMain {
|
||||
params.addProperty("countrycode", "86");
|
||||
params.addProperty("phone", AllMusic.getConfig().getLoginUser());
|
||||
params.addProperty("captcha", code);
|
||||
Res res = HttpClientUtil.post("https://music.163.com/eapi/w/login/cellphone", params, EncryptType.WEAPI, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/eapi/w/login/cellphone", params, EncryptType.WEAPI, null);
|
||||
if (res == null || !res.isOk()) {
|
||||
if (sender == null)
|
||||
AllMusic.log.info("§d[AllMusic]§c登录失败");
|
||||
@@ -99,7 +99,7 @@ public class APIMain {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("c", "[{\"id\":" + ID + "}]");
|
||||
|
||||
Res res = HttpClientUtil.post("https://music.163.com/api/v3/song/detail", params, EncryptType.WEAPI, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/api/v3/song/detail", params, EncryptType.WEAPI, null);
|
||||
if (res != null && res.isOk()) {
|
||||
InfoOBJ temp = AllMusic.gson.fromJson(res.getData(), InfoOBJ.class);
|
||||
if (temp.isok()) {
|
||||
@@ -126,7 +126,7 @@ public class APIMain {
|
||||
return info;
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("id", ID);
|
||||
Res res = HttpClientUtil.post("https://music.163.com/api/dj/program/detail", params, EncryptType.WEAPI, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/api/dj/program/detail", params, EncryptType.WEAPI, null);
|
||||
if (res != null && res.isOk()) {
|
||||
PrInfoOBJ temp = AllMusic.gson.fromJson(res.getData(), PrInfoOBJ.class);
|
||||
if (temp.isOK()) {
|
||||
@@ -144,13 +144,13 @@ public class APIMain {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("ids", "[" + ID + "]");
|
||||
params.addProperty("br", AllMusic.getConfig().getMusicBR());
|
||||
Res res = HttpClientUtil.post("https://music.163.com/weapi/song/enhance/player/url", params, EncryptType.WEAPI, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/weapi/song/enhance/player/url", params, EncryptType.WEAPI, null);
|
||||
if (res != null && res.isOk()) {
|
||||
try {
|
||||
TrialInfoObj obj = AllMusic.gson.fromJson(res.getData(), TrialInfoObj.class);
|
||||
return obj.getUrl();
|
||||
} catch (Exception e) {
|
||||
logs.logWrite(res.getData());
|
||||
Logs.logWrite(res.getData());
|
||||
AllMusic.log.warning("§d[AllMusic]§c播放连接解析错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class APIMain {
|
||||
params.addProperty("id", ID);
|
||||
params.addProperty("n", 100000);
|
||||
params.addProperty("s", 8);
|
||||
Res res = HttpClientUtil.post("https://music.163.com/api/v6/playlist/detail", params, EncryptType.API, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/api/v6/playlist/detail", params, EncryptType.API, null);
|
||||
if (res != null && res.isOk())
|
||||
try {
|
||||
isUpdata = true;
|
||||
@@ -188,7 +188,7 @@ public class APIMain {
|
||||
params.addProperty("lv", -1);
|
||||
params.addProperty("kv", -1);
|
||||
params.addProperty("tv", -1);
|
||||
Res res = HttpClientUtil.post("https://music.163.com/api/song/lyric", params, EncryptType.API, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/api/song/lyric", params, EncryptType.API, null);
|
||||
if (res != null && res.isOk()) {
|
||||
try {
|
||||
WLyricOBJ obj = AllMusic.gson.fromJson(res.getData(), WLyricOBJ.class);
|
||||
@@ -231,7 +231,7 @@ public class APIMain {
|
||||
params.addProperty("limit", 30);
|
||||
params.addProperty("offset", 0);
|
||||
|
||||
Res res = HttpClientUtil.post("https://music.163.com/weapi/search/get", params, EncryptType.WEAPI, null);
|
||||
HttpRes res = HttpClientUtil.post("https://music.163.com/weapi/search/get", params, EncryptType.WEAPI, null);
|
||||
if (res != null && res.isOk()) {
|
||||
SearchDataOBJ obj = AllMusic.gson.fromJson(res.getData(), SearchDataOBJ.class);
|
||||
if (obj != null && obj.isok()) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package coloryr.allmusic;
|
||||
package coloryr.allmusic.music.api.http;
|
||||
|
||||
import okhttp3.Cookie;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package coloryr.allmusic.http;
|
||||
package coloryr.allmusic.music.api.http;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import com.google.gson.JsonObject;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package coloryr.allmusic.http;
|
||||
package coloryr.allmusic.music.api.http;
|
||||
|
||||
public class EncRes {
|
||||
public String params;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package coloryr.allmusic.http;
|
||||
package coloryr.allmusic.music.api.http;
|
||||
|
||||
public enum EncryptType {
|
||||
WEAPI, EAPI, API
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package coloryr.allmusic.http;
|
||||
package coloryr.allmusic.music.api.http;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -34,7 +34,7 @@ public class HttpClientUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Res get(String path, String data) {
|
||||
public static HttpRes get(String path, String data) {
|
||||
try {
|
||||
data = URLEncoder.encode(data, "UTF-8");
|
||||
Request request = new Request.Builder().url(path + data)
|
||||
@@ -62,7 +62,7 @@ public class HttpClientUtil {
|
||||
if (!ok) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c服务器返回错误:" + data1);
|
||||
}
|
||||
return new Res(data1, ok);
|
||||
return new HttpRes(data1, ok);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c获取网页错误");
|
||||
e.printStackTrace();
|
||||
@@ -70,7 +70,7 @@ public class HttpClientUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Res post(String url, JsonObject data, EncryptType type, String ourl) {
|
||||
public static HttpRes post(String url, JsonObject data, EncryptType type, String ourl) {
|
||||
try {
|
||||
RequestBody formBody;
|
||||
Request.Builder request = new Request.Builder();
|
||||
@@ -158,7 +158,7 @@ public class HttpClientUtil {
|
||||
if (!ok) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c服务器返回错误:" + data1);
|
||||
}
|
||||
return new Res(data1, ok);
|
||||
return new HttpRes(data1, ok);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c获取网页错误");
|
||||
e.printStackTrace();
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
package coloryr.allmusic.http;
|
||||
package coloryr.allmusic.music.api.http;
|
||||
|
||||
public class Res {
|
||||
public class HttpRes {
|
||||
private final String data;
|
||||
private final boolean ok;
|
||||
|
||||
public Res(String data, boolean ok) {
|
||||
public HttpRes(String data, boolean ok) {
|
||||
this.data = data;
|
||||
this.ok = ok;
|
||||
}
|
||||
+4
-3
@@ -1,16 +1,17 @@
|
||||
package coloryr.allmusic.http;
|
||||
package coloryr.allmusic.music.api.http;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.CookieJar;
|
||||
import okhttp3.HttpUrl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class MyCookieJar implements CookieJar {
|
||||
@Override
|
||||
public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
|
||||
public void saveFromResponse(HttpUrl httpUrl, @NotNull List<Cookie> list) {
|
||||
if (AllMusic.cookie.cookieStore.containsKey(httpUrl.host())) {
|
||||
List<Cookie> cookies = AllMusic.cookie.cookieStore.get(httpUrl.host());
|
||||
for (Cookie item : list) {
|
||||
@@ -30,7 +31,7 @@ public class MyCookieJar implements CookieJar {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cookie> loadForRequest(HttpUrl httpUrl) {
|
||||
public @NotNull List<Cookie> loadForRequest(HttpUrl httpUrl) {
|
||||
List<Cookie> cookies = AllMusic.cookie.cookieStore.get(httpUrl.host());
|
||||
return cookies != null ? cookies : new CopyOnWriteArrayList<>();
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class PlayGo {
|
||||
HudUtils.sendHudNowData();
|
||||
HudUtils.sendHudLyricData(null);
|
||||
HudUtils.sendHudListData();
|
||||
if (AllMusic.side.NeedPlay()) {
|
||||
if (AllMusic.side.needPlay()) {
|
||||
String ID = AllMusic.getMusicApi().getListMusic();
|
||||
if (ID != null) {
|
||||
MusicObj obj = new MusicObj();
|
||||
@@ -148,10 +148,9 @@ public class PlayGo {
|
||||
AllMusic.side.bqt(info);
|
||||
}
|
||||
startTimer();
|
||||
AllMusic.side.send("[Play]" + url, true);
|
||||
AllMusic.side.sendMusic(url);
|
||||
if (!PlayMusic.nowPlayMusic.isUrl() && PlayMusic.nowPlayMusic.getPicUrl() != null) {
|
||||
AllMusic.side.task(() ->
|
||||
AllMusic.side.send("[Img]" + PlayMusic.nowPlayMusic.getPicUrl(), true), 10);
|
||||
AllMusic.side.sendPic(PlayMusic.nowPlayMusic.getPicUrl());
|
||||
}
|
||||
if (PlayMusic.nowPlayMusic.isTrial()) {
|
||||
AllMusic.side.bqt(AllMusic.getMessage().getMusicPlay().getTrail());
|
||||
@@ -164,7 +163,7 @@ public class PlayGo {
|
||||
while (PlayMusic.musicLessTime > 0) {
|
||||
HudUtils.sendHudNowData();
|
||||
HudUtils.sendHudListData();
|
||||
if (!AllMusic.side.NeedPlay()) {
|
||||
if (!AllMusic.side.needPlay()) {
|
||||
PlayMusic.musicLessTime = 1;
|
||||
}
|
||||
if (PlayMusic.voteTime > 0) {
|
||||
@@ -186,7 +185,7 @@ public class PlayGo {
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
AllMusic.side.send("[Stop]", false);
|
||||
AllMusic.side.sendStop();
|
||||
} else {
|
||||
String data = AllMusic.getMessage().getMusicPlay().getNoCanPlay();
|
||||
AllMusic.side.bqt(data.replace("%MusicID%", PlayMusic.nowPlayMusic.getID()));
|
||||
|
||||
@@ -6,7 +6,7 @@ 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.utils.logs;
|
||||
import coloryr.allmusic.utils.Logs;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.net.URL;
|
||||
@@ -75,7 +75,7 @@ public class PlayMusic {
|
||||
text = text.replace("%MusicID%", id);
|
||||
AllMusic.side.sendMessaget(sender, text);
|
||||
}
|
||||
logs.logWrite("玩家:" + player + " 点歌:" + id);
|
||||
Logs.logWrite("玩家:" + player + " 点歌:" + id);
|
||||
try {
|
||||
SongInfo info = AllMusic.getMusicApi().getMusic(id, player, isList);
|
||||
if (info != null) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package coloryr.allmusic.side;
|
||||
|
||||
public class ComType {
|
||||
public static final String lyric = "[Lyric]";
|
||||
public static final String info = "[Info]";
|
||||
public static final String list = "[List]";
|
||||
public static final String play = "[Play]";
|
||||
public static final String img = "[Img]";
|
||||
public static final String stop = "[Stop]";
|
||||
public static final String clear = "[clear]";
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package coloryr.allmusic.api;
|
||||
package coloryr.allmusic.side;
|
||||
|
||||
public interface IMyLogger {
|
||||
void warning(String data);
|
||||
+7
-26
@@ -1,49 +1,30 @@
|
||||
package coloryr.allmusic.api;
|
||||
package coloryr.allmusic.side;
|
||||
|
||||
public interface ISide {
|
||||
void send(String data, String player, Boolean isplay);
|
||||
|
||||
void send(String data, Boolean isplay);
|
||||
|
||||
int getAllPlayer();
|
||||
|
||||
void bq(String data);
|
||||
|
||||
void bqt(String data);
|
||||
|
||||
boolean NeedPlay();
|
||||
|
||||
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 clearHud(String player);
|
||||
|
||||
void clearHudAll();
|
||||
|
||||
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();
|
||||
}
|
||||
+1
-9
@@ -1,8 +1,6 @@
|
||||
package coloryr.allmusic.side.bc;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
@@ -10,13 +8,7 @@ import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public class EventBC implements Listener {
|
||||
public class ListenerBC implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerquit(final PlayerDisconnectEvent event) {
|
||||
AllMusic.removeNowPlayPlayer(event.getPlayer().getName());
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
package coloryr.allmusic.side.bc;
|
||||
|
||||
import coloryr.allmusic.api.IMyLogger;
|
||||
import coloryr.allmusic.side.IMyLogger;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BCLog implements IMyLogger {
|
||||
public class LogBC implements IMyLogger {
|
||||
private final Logger Logger;
|
||||
|
||||
public BCLog(Logger Logger) {
|
||||
public LogBC(Logger Logger) {
|
||||
this.Logger = Logger;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
*/
|
||||
@@ -70,10 +70,11 @@ public class MetricsBC {
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
writeFile(configFile,
|
||||
"#bStats collects some data for plugin authors like how many servers are using their plugins.",
|
||||
"#To honor their work, you should not disable it.",
|
||||
"#This has nearly no effect on the server performance!",
|
||||
"#Check out https://bStats.org/ to learn more :)",
|
||||
"# bStats (https://bStats.org) collects some basic information for plugin authors, like how",
|
||||
"# many people use their plugin and their total player count. It's recommended to keep bStats",
|
||||
"# enabled, but if you're not comfortable with this, you can turn this setting off. There is no",
|
||||
"# performance penalty associated with having metrics enabled, and data sent to bStats is fully",
|
||||
"# anonymous.",
|
||||
"enabled: true",
|
||||
"serverUuid: \"" + UUID.randomUUID() + "\"",
|
||||
"logFailedRequests: false",
|
||||
@@ -110,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,13 +2,13 @@ package coloryr.allmusic.side.bc;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.AllMusicBC;
|
||||
import coloryr.allmusic.api.ISide;
|
||||
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.play.PlayMusic;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@@ -28,38 +28,11 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SideBC implements ISide {
|
||||
public static final Set<Server> TopServers = new CopyOnWriteArraySet<>();
|
||||
private boolean isOK(ProxiedPlayer player, boolean in) {
|
||||
if (player == null || player.getServer() == null)
|
||||
return false;
|
||||
if (AllMusic.getConfig().getNoMusicServer()
|
||||
.contains(player.getServer().getInfo().getName()))
|
||||
return false;
|
||||
String name = player.getName();
|
||||
if (AllMusic.getConfig().getNoMusicPlayer().contains(player.getName()))
|
||||
return false;
|
||||
return !in || AllMusic.containNowPlay(name);
|
||||
}
|
||||
|
||||
@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) {
|
||||
try {
|
||||
Collection<ProxiedPlayer> values = ProxyServer.getInstance().getPlayers();
|
||||
for (ProxiedPlayer player : values) {
|
||||
if (isplay && !isOK(player, false))
|
||||
continue;
|
||||
send(player, data, isplay);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌曲发送发生错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAllPlayer() {
|
||||
return ProxyServer.getInstance().getOnlineCount();
|
||||
@@ -69,12 +42,12 @@ public class SideBC implements ISide {
|
||||
public void sendHudLyric(String data) {
|
||||
try {
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
if (!isOK(player, true))
|
||||
if (isOK(player))
|
||||
continue;
|
||||
SaveOBJ obj = HudSave.get(player.getName());
|
||||
if (!obj.isEnableLyric())
|
||||
continue;
|
||||
send(player, "[Lyric]" + data, null);
|
||||
send(player, ComType.lyric + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词发送出错");
|
||||
@@ -86,12 +59,12 @@ public class SideBC implements ISide {
|
||||
public void sendHudInfo(String data) {
|
||||
try {
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
if (!isOK(player, true))
|
||||
if (isOK(player))
|
||||
continue;
|
||||
SaveOBJ obj = HudSave.get(player.getName());
|
||||
if (!obj.isEnableInfo())
|
||||
continue;
|
||||
send(player, "[Info]" + data, null);
|
||||
send(player, ComType.info + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词信息发送出错");
|
||||
@@ -103,13 +76,13 @@ public class SideBC implements ISide {
|
||||
public void sendHudList(String data) {
|
||||
try {
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
if (!isOK(player, true))
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getName();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnableList())
|
||||
continue;
|
||||
send(player, "[List]" + data, null);
|
||||
send(player, ComType.list + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌曲列表发送出错");
|
||||
@@ -119,12 +92,11 @@ public class SideBC implements ISide {
|
||||
|
||||
@Override
|
||||
public void sendHudSaveAll() {
|
||||
for (ProxiedPlayer players : ProxyServer.getInstance().getPlayers()) {
|
||||
String Name = players.getName();
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
try {
|
||||
SaveOBJ obj = HudSave.get(Name);
|
||||
String data = new Gson().toJson(obj);
|
||||
send(data, Name, null);
|
||||
SaveOBJ obj = HudSave.get(player.getName());
|
||||
String data = AllMusic.gson.toJson(obj);
|
||||
send(player, data, null);
|
||||
} catch (Exception e1) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
|
||||
e1.printStackTrace();
|
||||
@@ -133,16 +105,72 @@ public class SideBC implements ISide {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHud(String player) {
|
||||
send("[clear]", player, null);
|
||||
public void sendMusic(String url){
|
||||
try {
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
send(player, ComType.play + url, true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c图片数据发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void sendPic(String url){
|
||||
try {
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getName();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnablePic())
|
||||
continue;
|
||||
send(player, ComType.img + url, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c图片数据发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHudAll() {
|
||||
public void sendStop() {
|
||||
try {
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
send(player, ComType.stop, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStop(String name) {
|
||||
try {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(name);
|
||||
if (player == null)
|
||||
return;
|
||||
send(player, ComType.stop, false);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHud(String player) {
|
||||
send(ComType.clear, player, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHud() {
|
||||
try {
|
||||
Collection<ProxiedPlayer> values = ProxyServer.getInstance().getPlayers();
|
||||
for (ProxiedPlayer players : values) {
|
||||
send(players, "[clear]", null);
|
||||
send(players, ComType.clear, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词发生出错");
|
||||
@@ -154,15 +182,13 @@ public class SideBC implements ISide {
|
||||
public void bq(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, 30) + "...";
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
}
|
||||
TextComponent message = new TextComponent(data);
|
||||
for (ServerInfo server : ProxyServer.getInstance().getServers().values()) {
|
||||
if (AllMusic.getConfig().getNoMusicServer().contains(server.getName()))
|
||||
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
for (ProxiedPlayer player : server.getPlayers())
|
||||
if (!AllMusic.getConfig().getNoMusicPlayer().contains(player.getName()))
|
||||
player.sendMessage(message);
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +198,7 @@ public class SideBC implements ISide {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean NeedPlay() {
|
||||
public boolean needPlay() {
|
||||
int online = 0;
|
||||
for (ServerInfo server : ProxyServer.getInstance().getServers().values()) {
|
||||
if (AllMusic.getConfig().getNoMusicServer().contains(server.getName()))
|
||||
@@ -235,7 +261,8 @@ public class SideBC implements ISide {
|
||||
|
||||
@Override
|
||||
public void task(Runnable run, int delay) {
|
||||
ProxyServer.getInstance().getScheduler().schedule(AllMusicBC.plugin, run, delay, TimeUnit.MICROSECONDS);
|
||||
ProxyServer.getInstance().getScheduler()
|
||||
.schedule(AllMusicBC.plugin, run, delay, TimeUnit.MICROSECONDS);
|
||||
}
|
||||
|
||||
public static void sendAllToServer(Server server){
|
||||
@@ -306,6 +333,11 @@ public class SideBC implements ISide {
|
||||
else
|
||||
out.writeUTF(PlayMusic.lyricItem.getTlyric());
|
||||
server.sendData(AllMusic.channelBC, out.toByteArray());
|
||||
|
||||
out = ByteStreams.newDataOutput();
|
||||
out.writeInt(9);
|
||||
out.writeBoolean(PlayMusic.lyricItem.isHaveT());
|
||||
server.sendData(AllMusic.channelBC, out.toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -330,19 +362,15 @@ public class SideBC implements ISide {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPingToServer(Server server){
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeInt(200);
|
||||
server.sendData(AllMusic.channelBC, out.toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ping() {
|
||||
Iterator<Server> iterator = TopServers.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Server server = iterator.next();
|
||||
if (server.isConnected()) {
|
||||
sendPingToServer(server);
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeInt(200);
|
||||
server.sendData(AllMusic.channelBC, out.toByteArray());
|
||||
} else {
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -370,4 +398,16 @@ public class SideBC implements ISide {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOK(ProxiedPlayer player) {
|
||||
if (player == null || player.getServer() == null)
|
||||
return true;
|
||||
if (AllMusic.getConfig().getNoMusicServer()
|
||||
.contains(player.getServer().getInfo().getName()))
|
||||
return true;
|
||||
String name = player.getName();
|
||||
if (AllMusic.getConfig().getNoMusicPlayer().contains(player.getName()))
|
||||
return true;
|
||||
return !AllMusic.containNowPlay(name);
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -1,18 +1,12 @@
|
||||
package coloryr.allmusic.side.bukkit;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.music.api.TopSongInfo;
|
||||
import coloryr.allmusic.music.play.PlayMusic;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
public class EventBukkit implements Listener {
|
||||
public class ListenerBukkit implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent e) {
|
||||
AllMusic.removeNowPlayPlayer(e.getPlayer().getName());
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
package coloryr.allmusic.side.bukkit;
|
||||
|
||||
import coloryr.allmusic.api.IMyLogger;
|
||||
import coloryr.allmusic.side.IMyLogger;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BukkitLog implements IMyLogger {
|
||||
public class LogBukkit implements IMyLogger {
|
||||
private final Logger Logger;
|
||||
|
||||
public BukkitLog(Logger Logger) {
|
||||
public LogBukkit(Logger Logger) {
|
||||
this.Logger = Logger;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
*/
|
||||
@@ -44,15 +44,15 @@ public class MetricsBukkit {
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
"bStats (https://bStats.org) collects some basic information for plugin authors, like how\n" +
|
||||
"many people use their plugin and their total player count. It's recommended to keep bStats\n" +
|
||||
"enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n" +
|
||||
"performance penalty associated with having metrics enabled, and data sent to bStats is fully\n" +
|
||||
"anonymous."
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
// Load the data
|
||||
|
||||
@@ -89,6 +89,9 @@ public class PluginMessage implements PluginMessageListener {
|
||||
case 8:
|
||||
lyric.setTlyric(in.readUTF());
|
||||
break;
|
||||
case 9:
|
||||
lyric.setHaveT(in.readBoolean());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package coloryr.allmusic.side.bukkit;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.AllMusicBukkit;
|
||||
import coloryr.allmusic.api.ISide;
|
||||
import coloryr.allmusic.side.ComType;
|
||||
import coloryr.allmusic.side.ISide;
|
||||
import coloryr.allmusic.hud.HudSave;
|
||||
import coloryr.allmusic.hud.obj.SaveOBJ;
|
||||
import coloryr.allmusic.side.bukkit.hooks.CitizensNPC;
|
||||
@@ -61,28 +62,11 @@ public class SideBukkit implements ISide {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOK(String player, boolean in) {
|
||||
if (AllMusic.getConfig().getNoMusicPlayer().contains(player))
|
||||
return false;
|
||||
return !in || AllMusic.containNowPlay(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String data, String player, Boolean isplay) {
|
||||
send(Bukkit.getPlayer(player), data, isplay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String data, Boolean isplay) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!AllMusic.getConfig().getNoMusicPlayer().contains(player.getName())) {
|
||||
if (isplay && !isOK(player.getName(), false))
|
||||
continue;
|
||||
send(player, data, isplay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAllPlayer() {
|
||||
return Bukkit.getOnlinePlayers().size();
|
||||
@@ -90,14 +74,142 @@ public class SideBukkit implements ISide {
|
||||
|
||||
@Override
|
||||
public void sendHudLyric(String data) {
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getName();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnableLyric())
|
||||
continue;
|
||||
send(player, ComType.lyric + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHudInfo(String data) {
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getName();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnableInfo())
|
||||
continue;
|
||||
send(player, ComType.info + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词信息发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHudList(String data) {
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getName();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnableList())
|
||||
continue;
|
||||
send(player, ComType.list + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌曲列表发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHudSaveAll() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
String name = player.getName();
|
||||
if (!isOK(player.getName(), true))
|
||||
continue;
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnableLyric())
|
||||
continue;
|
||||
send(player, "[Lyric]" + data, null);
|
||||
String Name = player.getName();
|
||||
try {
|
||||
SaveOBJ obj = HudSave.get(Name);
|
||||
String data = new Gson().toJson(obj);
|
||||
send(player, data, null);
|
||||
} catch (Exception e1) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMusic(String url) {
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
send(player, ComType.play + url, true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c图片数据发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPic(String url) {
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getName();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnablePic())
|
||||
continue;
|
||||
send(player, ComType.img + url, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c图片数据发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStop() {
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
send(player, ComType.stop, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStop(String name) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null)
|
||||
return;
|
||||
send(player, ComType.stop, false);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHud(String player) {
|
||||
send(ComType.clear, player, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHud() {
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
send(player, ComType.clear, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词发生出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,10 +217,10 @@ public class SideBukkit implements ISide {
|
||||
public void bq(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, 30) + "...";
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
}
|
||||
for(Player player : Bukkit.getOnlinePlayers()){
|
||||
if(!AllMusic.getConfig().getNoMusicPlayer().contains(player.getName())){
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!AllMusic.getConfig().getNoMusicPlayer().contains(player.getName())) {
|
||||
player.sendMessage(data);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +230,7 @@ public class SideBukkit implements ISide {
|
||||
public void bqt(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, 30) + "...";
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
}
|
||||
String finalData = data;
|
||||
Bukkit.getScheduler().runTask(AllMusicBukkit.plugin, () -> {
|
||||
@@ -131,7 +243,7 @@ public class SideBukkit implements ISide {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean NeedPlay() {
|
||||
public boolean needPlay() {
|
||||
int online = getAllPlayer();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (CitizensNPC.isNPC(player))
|
||||
@@ -143,59 +255,6 @@ public class SideBukkit implements ISide {
|
||||
return online > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHudInfo(String data) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
String Name = player.getName();
|
||||
if (!isOK(player.getName(), true))
|
||||
continue;
|
||||
SaveOBJ obj = HudSave.get(Name);
|
||||
if (!obj.isEnableInfo())
|
||||
continue;
|
||||
send(player, "[Info]" + data, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHudList(String data) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
String Name = player.getName();
|
||||
if (!isOK(player.getName(), true))
|
||||
continue;
|
||||
SaveOBJ obj = HudSave.get(Name);
|
||||
if (!obj.isEnableList())
|
||||
continue;
|
||||
send(player, "[List]" + data, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHudSaveAll() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
String Name = player.getName();
|
||||
try {
|
||||
SaveOBJ obj = HudSave.get(Name);
|
||||
String data = new Gson().toJson(obj);
|
||||
send(data, Name, null);
|
||||
} catch (Exception e1) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHud(String player) {
|
||||
send("[clear]", player, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHudAll() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
send(player, "[clear]", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessaget(Object obj, String message) {
|
||||
Bukkit.getScheduler().runTask(AllMusicBukkit.plugin, () -> ((CommandSender) obj).sendMessage(message));
|
||||
@@ -300,4 +359,13 @@ public class SideBukkit implements ISide {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOK(Player player) {
|
||||
if (player == null)
|
||||
return true;
|
||||
String name = player.getName();
|
||||
if (AllMusic.getConfig().getNoMusicPlayer().contains(name))
|
||||
return true;
|
||||
return !AllMusic.containNowPlay(name);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,6 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class SpigotApi {
|
||||
public SpigotApi() {
|
||||
new TextComponent();
|
||||
}
|
||||
|
||||
public static void sendMessageRun(Object obj, String Message, String Command) {
|
||||
CommandSender sender = (CommandSender) obj;
|
||||
TextComponent send = new TextComponent(Message);
|
||||
|
||||
@@ -10,7 +10,8 @@ public class VaultHook {
|
||||
private Economy econ = null;
|
||||
|
||||
public VaultHook() {
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
RegisteredServiceProvider<Economy> rsp =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,14 +1,13 @@
|
||||
package coloryr.allmusic.side.velocity;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.side.bc.SideBC;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
|
||||
public class EventVelocity {
|
||||
public class ListenerVelocity {
|
||||
@Subscribe
|
||||
public void onPlayerQuit(final DisconnectEvent event) {
|
||||
AllMusic.removeNowPlayPlayer(event.getPlayer().getUsername());
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
package coloryr.allmusic.side.velocity;
|
||||
|
||||
import coloryr.allmusic.api.IMyLogger;
|
||||
import coloryr.allmusic.side.IMyLogger;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class VelocityLog implements IMyLogger {
|
||||
public class LogVelocity implements IMyLogger {
|
||||
private final Logger logger;
|
||||
|
||||
public VelocityLog(Logger logger) {
|
||||
public LogVelocity(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package coloryr.allmusic.side.velocity;
|
||||
|
||||
import coloryr.allmusic.AllMusic;
|
||||
import coloryr.allmusic.AllMusicVelocity;
|
||||
import coloryr.allmusic.api.ISide;
|
||||
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.play.PlayMusic;
|
||||
@@ -20,52 +21,17 @@ import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SideVelocity implements ISide {
|
||||
public static final Set<ServerConnection> TopServers = new CopyOnWriteArraySet<>();
|
||||
private boolean isOK(Player player, boolean in) {
|
||||
try {
|
||||
if (player == null)
|
||||
return false;
|
||||
if (AllMusic.getConfig().getNoMusicServer()
|
||||
.contains(player.getCurrentServer().get().getServerInfo().getName()))
|
||||
return false;
|
||||
String name = player.getUsername();
|
||||
if (AllMusic.getConfig().getNoMusicPlayer().contains(player.getUsername()))
|
||||
return false;
|
||||
return !in || AllMusic.containNowPlay(name);
|
||||
} catch (NoSuchElementException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String data, String player, Boolean isplay) {
|
||||
if (AllMusicVelocity.plugin.server.getPlayer(player).isPresent()) {
|
||||
send(AllMusicVelocity.plugin.server.getPlayer(player).get(), data, isplay);
|
||||
} else {
|
||||
AllMusic.log.warning("§d[AllMusic]§c找不到玩家:" + player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String data, Boolean isplay) {
|
||||
try {
|
||||
Collection<Player> values = AllMusicVelocity.plugin.server.getAllPlayers();
|
||||
for (Player player : values) {
|
||||
if (isplay && !isOK(player, false))
|
||||
continue;
|
||||
send(player, data, isplay);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌曲发送发生错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +44,7 @@ public class SideVelocity implements ISide {
|
||||
public void bq(String data) {
|
||||
if (AllMusic.getConfig().isMessageLimit()
|
||||
&& data.length() > AllMusic.getConfig().getMessageLimitSize()) {
|
||||
data = data.substring(0, 30) + "...";
|
||||
data = data.substring(0, AllMusic.getConfig().getMessageLimitSize() - 1) + "...";
|
||||
}
|
||||
Component message = Component.text(data);
|
||||
for (RegisteredServer server : AllMusicVelocity.plugin.server.getAllServers()) {
|
||||
@@ -96,7 +62,7 @@ public class SideVelocity implements ISide {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean NeedPlay() {
|
||||
public boolean needPlay() {
|
||||
int online = 0;
|
||||
for (RegisteredServer server : AllMusicVelocity.plugin.server.getAllServers()) {
|
||||
if (AllMusic.getConfig().getNoMusicServer().contains(server.getServerInfo().getName()))
|
||||
@@ -108,16 +74,73 @@ public class SideVelocity implements ISide {
|
||||
return online > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStop() {
|
||||
try {
|
||||
for (Player player : AllMusicVelocity.plugin.server.getAllPlayers()) {
|
||||
send(player, ComType.stop, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStop(String name) {
|
||||
try {
|
||||
Optional<Player> player = AllMusicVelocity.plugin.server.getPlayer(name);
|
||||
if (!player.isPresent())
|
||||
return;
|
||||
send(player.get(), ComType.stop, false);
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMusic(String url) {
|
||||
try {
|
||||
for (Player player : AllMusicVelocity.plugin.server.getAllPlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
send(player, ComType.play + url, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPic(String url) {
|
||||
try {
|
||||
for (Player player : AllMusicVelocity.plugin.server.getAllPlayers()) {
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getUsername();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnablePic())
|
||||
continue;
|
||||
send(player, ComType.img + url, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendHudLyric(String data) {
|
||||
try {
|
||||
for (Player player : AllMusicVelocity.plugin.server.getAllPlayers()) {
|
||||
if (!isOK(player, true))
|
||||
if (isOK(player))
|
||||
continue;
|
||||
SaveOBJ obj = HudSave.get(player.getUsername());
|
||||
if (!obj.isEnableLyric())
|
||||
continue;
|
||||
send(player, "[Lyric]" + data, null);
|
||||
send(player, ComType.lyric + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词发送出错");
|
||||
@@ -129,12 +152,12 @@ public class SideVelocity implements ISide {
|
||||
public void sendHudInfo(String data) {
|
||||
try {
|
||||
for (Player player : AllMusicVelocity.plugin.server.getAllPlayers()) {
|
||||
if (!isOK(player, true))
|
||||
if (isOK(player))
|
||||
continue;
|
||||
SaveOBJ obj = HudSave.get(player.getUsername());
|
||||
if (!obj.isEnableInfo())
|
||||
continue;
|
||||
send(player, "[Info]" + data, null);
|
||||
send(player, ComType.info + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词信息发送出错");
|
||||
@@ -146,13 +169,13 @@ public class SideVelocity implements ISide {
|
||||
public void sendHudList(String data) {
|
||||
try {
|
||||
for (Player player : AllMusicVelocity.plugin.server.getAllPlayers()) {
|
||||
if (!isOK(player, true))
|
||||
if (isOK(player))
|
||||
continue;
|
||||
String name = player.getUsername();
|
||||
SaveOBJ obj = HudSave.get(name);
|
||||
if (!obj.isEnableList())
|
||||
continue;
|
||||
send(player, "[List]" + data, null);
|
||||
send(player, ComType.list + data, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌曲列表发送出错");
|
||||
@@ -177,15 +200,15 @@ public class SideVelocity implements ISide {
|
||||
|
||||
@Override
|
||||
public void clearHud(String player) {
|
||||
send("[clear]", player, null);
|
||||
send(ComType.clear, player, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHudAll() {
|
||||
public void clearHud() {
|
||||
try {
|
||||
Collection<Player> values = AllMusicVelocity.plugin.server.getAllPlayers();
|
||||
for (Player players : values) {
|
||||
send(players, "[clear]", null);
|
||||
send(players, ComType.clear, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
AllMusic.log.warning("§d[AllMusic]§c歌词发生出错");
|
||||
@@ -318,11 +341,10 @@ public class SideVelocity implements ISide {
|
||||
else
|
||||
out.writeUTF(PlayMusic.lyricItem.getTlyric());
|
||||
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
|
||||
}
|
||||
|
||||
public static void sendPingToServer(ServerConnection server) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeInt(200);
|
||||
out = ByteStreams.newDataOutput();
|
||||
out.writeInt(9);
|
||||
out.writeBoolean(PlayMusic.lyricItem.isHaveT());
|
||||
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
|
||||
}
|
||||
|
||||
@@ -332,7 +354,9 @@ public class SideVelocity implements ISide {
|
||||
while (iterator.hasNext()) {
|
||||
ServerConnection server = iterator.next();
|
||||
try{
|
||||
sendPingToServer(server);
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeInt(200);
|
||||
server.sendPluginMessage(AllMusicVelocity.channelBC, out.toByteArray());
|
||||
}catch (Exception e){
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -369,7 +393,7 @@ public class SideVelocity implements ISide {
|
||||
ByteBuf buf = Unpooled.buffer(bytes.length + 1);
|
||||
buf.writeByte(666);
|
||||
buf.writeBytes(bytes);
|
||||
runTask(() -> players.sendPluginMessage(AllMusicVelocity.plugin.channel, buf.array()));
|
||||
runTask(() -> players.sendPluginMessage(AllMusicVelocity.channel, buf.array()));
|
||||
if (isplay != null) {
|
||||
if (isplay) {
|
||||
AllMusic.addNowPlayPlayer(players.getUsername());
|
||||
@@ -382,4 +406,20 @@ public class SideVelocity implements ISide {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOK(Player player) {
|
||||
try {
|
||||
if (player == null)
|
||||
return true;
|
||||
if (AllMusic.getConfig().getNoMusicServer()
|
||||
.contains(player.getCurrentServer().get().getServerInfo().getName()))
|
||||
return true;
|
||||
String name = player.getUsername();
|
||||
if (AllMusic.getConfig().getNoMusicPlayer().contains(player.getUsername()))
|
||||
return true;
|
||||
return !AllMusic.containNowPlay(name);
|
||||
} catch (NoSuchElementException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Date;
|
||||
|
||||
public class logs {
|
||||
public class Logs {
|
||||
private static final Date date = new Date();
|
||||
public static File file;
|
||||
private static FileWriter fw;
|
||||
@@ -62,7 +62,9 @@
|
||||
"NoMusic": "没有播放的音乐",
|
||||
"NoList": "队列中无歌曲",
|
||||
"NoLyric": "无歌词",
|
||||
"PicSize": "§d[ALLMusic]§e设置图片尺寸为%Size%"
|
||||
"PicSize": "§d[ALLMusic]§e设置图片尺寸为%Size%",
|
||||
"Music": "%Name% %AllTime%/%NowTime%\n%Author%\n%Alia%\n%Al%\nby: %Player%",
|
||||
"Lyric": "%Lyric%\n%Tlyric%"
|
||||
},
|
||||
"Command": {
|
||||
"Error": "§d[AllMusic]§c参数错误,请输入/music help获取帮助",
|
||||
|
||||
Reference in new issue
Block a user