|
| 1 | +package me.zhenxin.zmusic; |
| 2 | + |
| 3 | +import com.google.inject.Inject; |
| 4 | +import com.velocitypowered.api.event.Subscribe; |
| 5 | +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; |
| 6 | +import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; |
| 7 | +import com.velocitypowered.api.plugin.Plugin; |
| 8 | +import com.velocitypowered.api.plugin.annotation.DataDirectory; |
| 9 | +import com.velocitypowered.api.command.CommandManager; |
| 10 | +import com.velocitypowered.api.command.CommandMeta; |
| 11 | +import com.velocitypowered.api.proxy.ProxyServer; |
| 12 | +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; |
| 13 | +import me.zhenxin.zmusic.command.CmdVelocity; |
| 14 | +import me.zhenxin.zmusic.config.Config; |
| 15 | +import me.zhenxin.zmusic.event.EventVelocity; |
| 16 | +import me.zhenxin.zmusic.utils.CookieUtils; |
| 17 | +import me.zhenxin.zmusic.utils.log.LogVelocity; |
| 18 | +import me.zhenxin.zmusic.utils.message.MessageVelocity; |
| 19 | +import me.zhenxin.zmusic.utils.mod.SendVelocity; |
| 20 | +import me.zhenxin.zmusic.utils.music.Music; |
| 21 | +import me.zhenxin.zmusic.utils.player.PlayerVelocity; |
| 22 | +import me.zhenxin.zmusic.utils.runtask.RunTaskVelocity; |
| 23 | +import org.slf4j.Logger; |
| 24 | + |
| 25 | +import java.nio.file.Path; |
| 26 | + |
| 27 | +@Plugin( |
| 28 | + id = "zmusic", |
| 29 | + name = "ZMusic", |
| 30 | + version = "2.11.0", |
| 31 | + description = "A Minecraft music plugin supporting Bukkit, BungeeCord, and Velocity", |
| 32 | + url = "https://github.com/zhenxin/ZMusic", |
| 33 | + authors = {"ZhenXin"} |
| 34 | +) |
| 35 | +public class ZMusicVelocity { |
| 36 | + |
| 37 | + public static ProxyServer server; |
| 38 | + public static ZMusicVelocity plugin; |
| 39 | + public static Logger logger; |
| 40 | + public static Path dataDirectory; |
| 41 | + |
| 42 | + // 插件消息通道 |
| 43 | + public static final MinecraftChannelIdentifier ZMUSIC_CHANNEL = |
| 44 | + MinecraftChannelIdentifier.create("zmusic", "channel"); |
| 45 | + public static final MinecraftChannelIdentifier ALLMUSIC_CHANNEL = |
| 46 | + MinecraftChannelIdentifier.create("allmusic", "channel"); |
| 47 | + |
| 48 | + @Inject |
| 49 | + public ZMusicVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) { |
| 50 | + ZMusicVelocity.server = server; |
| 51 | + ZMusicVelocity.logger = logger; |
| 52 | + ZMusicVelocity.dataDirectory = dataDirectory; |
| 53 | + ZMusicVelocity.plugin = this; |
| 54 | + } |
| 55 | + |
| 56 | + @Subscribe |
| 57 | + public void onProxyInitialization(ProxyInitializeEvent event) { |
| 58 | + ZMusic.log = new LogVelocity(); |
| 59 | + ZMusic.isBC = false; |
| 60 | + ZMusic.isVelocity = true; |
| 61 | + ZMusic.runTask = new RunTaskVelocity(); |
| 62 | + ZMusic.message = new MessageVelocity(); |
| 63 | + ZMusic.music = new Music(); |
| 64 | + ZMusic.send = new SendVelocity(); |
| 65 | + ZMusic.player = new PlayerVelocity(); |
| 66 | + ZMusic.dataFolder = dataDirectory.toFile(); |
| 67 | + if (!ZMusic.dataFolder.exists()) { |
| 68 | + ZMusic.dataFolder.mkdir(); |
| 69 | + } |
| 70 | + Config.debug = true; |
| 71 | + ZMusic.thisVer = "2.11.0"; |
| 72 | + ZMusic.log.sendNormalMessage("正在加载中...."); |
| 73 | + CookieUtils.initCookieManager(); |
| 74 | + |
| 75 | + // 注册插件消息通道 |
| 76 | + server.getChannelRegistrar().register(ZMUSIC_CHANNEL); |
| 77 | + server.getChannelRegistrar().register(ALLMUSIC_CHANNEL); |
| 78 | + |
| 79 | + // 注册命令 |
| 80 | + CommandManager commandManager = server.getCommandManager(); |
| 81 | + CommandMeta meta = commandManager.metaBuilder("zm") |
| 82 | + .aliases("zmusic", "music") |
| 83 | + .plugin(this) |
| 84 | + .build(); |
| 85 | + commandManager.register(meta, new CmdVelocity()); |
| 86 | + |
| 87 | + // 注册事件监听器 |
| 88 | + server.getEventManager().register(this, new EventVelocity()); |
| 89 | + |
| 90 | + ZMusic.loadEnd(null); |
| 91 | + } |
| 92 | + |
| 93 | + @Subscribe |
| 94 | + public void onProxyShutdown(ProxyShutdownEvent event) { |
| 95 | + ZMusic.disable(); |
| 96 | + } |
| 97 | +} |
0 commit comments