|
| 1 | +/* |
| 2 | + * This file is part of Debuggery. |
| 3 | + * |
| 4 | + * Debuggery is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * Debuggery is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with Debuggery. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package io.zachbr.debuggery; |
| 19 | + |
| 20 | +import com.google.inject.Inject; |
| 21 | +import com.velocitypowered.api.plugin.Plugin; |
| 22 | +import com.velocitypowered.api.plugin.PluginContainer; |
| 23 | +import com.velocitypowered.api.proxy.ProxyServer; |
| 24 | +import io.zachbr.debuggery.commands.*; |
| 25 | +import io.zachbr.debuggery.commands.base.CommandBase; |
| 26 | +import io.zachbr.debuggery.util.PlatformType; |
| 27 | + |
| 28 | +import java.util.HashMap; |
| 29 | +import java.util.Map; |
| 30 | + |
| 31 | +@Plugin(id = "debuggery", |
| 32 | + name = "Debuggery", |
| 33 | + version = "1.3.0-SNAPSHOT", // todo - make gradle deal with this |
| 34 | + description = "A small plugin designed to expose API values at runtime.", |
| 35 | + authors = {"Z750"}, |
| 36 | + url = "https://github.com/zachbr/Debuggery") |
| 37 | +public class DebuggeryVelocity extends DebuggeryBase { |
| 38 | + private final ProxyServer server; |
| 39 | + private final Map<String, CommandBase> commands = new HashMap<>(); |
| 40 | + private PluginContainer container; |
| 41 | + |
| 42 | + @Inject |
| 43 | + DebuggeryVelocity(ProxyServer server, org.slf4j.Logger logger) { |
| 44 | + super(new VelocityLogger(logger), PlatformType.VELOCITY); |
| 45 | + this.server = server; |
| 46 | + |
| 47 | + registerCommand(new ProxyPlayerCommand(this)); |
| 48 | + registerCommand(new ProxyServerCommand(this)); |
| 49 | + registerCommand(new ServerConnectionCommand(this)); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + String getPluginVersion() { |
| 54 | + if (this.container == null) { |
| 55 | + this.container = server.getPluginManager().getPlugin("debuggery").orElseThrow(); |
| 56 | + } |
| 57 | + |
| 58 | + return this.container.getDescription().getVersion().orElseThrow(); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + String getPlatformName() { |
| 63 | + return server.getVersion().getName(); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + String getPlatformVersion() { |
| 68 | + return server.getVersion().getVersion(); |
| 69 | + } |
| 70 | + |
| 71 | + public ProxyServer getProxyServer() { |
| 72 | + return this.server; |
| 73 | + } |
| 74 | + |
| 75 | + private void registerCommand(CommandBase base) { |
| 76 | + this.commands.put(base.getName(), base); |
| 77 | + this.server.getCommandManager().register(base, base.getName()); |
| 78 | + } |
| 79 | +} |
0 commit comments