mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-26 17:22:55 +00:00
Initial commit
This commit is contained in:
commit
7dc46ca13c
16 files changed
+1255
No files matched your search
@@ -0,0 +1,79 @@
|
||||
package Color_yr.ALLmusic_BC;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ALLmusic_BC extends Plugin {
|
||||
|
||||
public static String Version = "1.0.0";
|
||||
|
||||
public static Configuration config;
|
||||
private static File FileName;
|
||||
|
||||
public static Logger log = ProxyServer.getInstance().getLogger();
|
||||
|
||||
public static void loadconfig() {
|
||||
ProxyServer.getInstance().getLogger().info("§d[ALLmusic_BC]§e当前插件版本为:" + Version
|
||||
+ ",你的配置文件版本为:" + config.getString("Version"));
|
||||
}
|
||||
|
||||
public static void reloadConfig() {
|
||||
try {
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(FileName);
|
||||
loadconfig();
|
||||
} catch (Exception arg0) {
|
||||
log.warning("§d[ALLmusic_BC]§c配置文件读取失败:" + arg0);
|
||||
}
|
||||
}
|
||||
|
||||
public static Configuration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig() {
|
||||
FileName = new File(getDataFolder(), "config.yml");
|
||||
logs.file = new File(getDataFolder(), "logs.log");
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
if (!FileName.exists()) {
|
||||
try (InputStream in = getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, FileName.toPath());
|
||||
} catch (IOException e) {
|
||||
log.warning("§d[ALLmusic_BC]§c配置文件创建失败:" + e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (!logs.file.exists()) {
|
||||
logs.file.createNewFile();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.warning("§d[ALLmusic_BC]§c日志文件错误:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log.info("§d[ALLmusic_BC]§e正在启动,感谢使用,本插件交流群:571239090");
|
||||
setConfig();
|
||||
reloadConfig();
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(this, new ChannelListener());
|
||||
ProxyServer.getInstance().registerChannel("ALLmusic");
|
||||
ProxyServer.getInstance().getPluginManager().registerCommand(this, new command());
|
||||
log.info("§d[ALLmusic_BC]§e已启动-" + Version);;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
log.info("§d[ALLmusic_BC]§e已停止,感谢使用");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package Color_yr.ALLmusic_BC;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPluginMessage(PluginMessageEvent e) {
|
||||
if (e.getTag().equalsIgnoreCase("ALLmusic")) {
|
||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
|
||||
try {
|
||||
String channel = in.readUTF(); // channel we delivered
|
||||
if (channel.equals("get")) {
|
||||
ServerInfo server = ProxyServer.getInstance().getPlayer(e.getReceiver().toString()).getServer().getInfo();
|
||||
String input = in.readUTF(); // the inputstring
|
||||
if (input.equals("test")) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToBukkit(String channel, String message) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(stream);
|
||||
try {
|
||||
out.writeUTF(channel);
|
||||
out.writeUTF(message);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<String, ServerInfo> Server = ProxyServer.getInstance().getServers();
|
||||
Collection<ServerInfo> values = Server.values();
|
||||
Iterator<ServerInfo> iterator2 = values.iterator();
|
||||
while (iterator2.hasNext()) {
|
||||
ServerInfo server = iterator2.next();
|
||||
server.sendData("ALLmusic", stream.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package Color_yr.ALLmusic_BC;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class command extends Command {
|
||||
|
||||
public command() {
|
||||
super("music");
|
||||
}
|
||||
|
||||
public boolean isInteger(String str) {
|
||||
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
|
||||
return pattern.matcher(str).matches();
|
||||
}
|
||||
|
||||
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2帮助手册"));
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music play [音乐ID] 来点歌"));
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music stop 停止播放歌曲"));
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music start 开始播放歌曲"));
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2使用/music vote 投票切歌"));
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("play")) {
|
||||
if(args.length<1){
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§c错误,请输入歌曲ID"));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (isInteger(args[1])==true) {
|
||||
ChannelListener.sendToBukkit("ALLmusic", args[1]);
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已发送" + args[1]));
|
||||
} else
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§c错误,请输入歌曲数字ID"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§c错误,请使用/music help 获取帮助"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package Color_yr.ALLmusic_BC;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Date;
|
||||
|
||||
public class logs {
|
||||
public static File file;
|
||||
|
||||
public static Boolean Socket_log = false;
|
||||
public static Boolean Group_log = false;
|
||||
public static Boolean Send_log = false;
|
||||
public static Boolean Error_log = false;
|
||||
|
||||
public void log_write(String text) {
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
fw = new FileWriter(file, true);
|
||||
Date date = new Date();
|
||||
String year = String.format("%tF", date);
|
||||
String time = String.format("%tT", date);
|
||||
String write = "[" + year + "]" + "[" + time + "]" + text;
|
||||
PrintWriter pw = new PrintWriter(fw);
|
||||
pw.println(write);
|
||||
pw.flush();
|
||||
fw.flush();
|
||||
pw.close();
|
||||
fw.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c日志文件写入失败" + e);
|
||||
} catch (IOException e) {
|
||||
Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c日志文件写入失败" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user