Fix registering of commands
Some checks failed
SteamWarCI Build failed

This commit is contained in:
2025-11-23 08:32:44 +01:00
parent b627b3b4a6
commit fd22c1cccc
3 changed files with 17 additions and 12 deletions

View File

@@ -19,6 +19,7 @@
package de.steamwar.command;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player;
@@ -41,6 +42,7 @@ public class VelocityCommand extends AbstractCommand<CommandSource> {
}
private SimpleCommand command;
private CommandMeta commandMeta;
private List<String> defaultHelpMessages = new ArrayList<>();
@@ -72,16 +74,20 @@ public class VelocityCommand extends AbstractCommand<CommandSource> {
return invocation.source().hasPermission(permission);
}
};
commandMeta = VelocityCommandFrameworkPlugin.getProxy().getCommandManager().metaBuilder(super.command)
.aliases(aliases)
.plugin(VelocityCommandFrameworkPlugin.getInstance())
.build();
}
@Override
public void unregister() {
VelocityCommandRegistering.unregister(command);
VelocityCommandRegistering.unregister(commandMeta);
}
@Override
public void register() {
VelocityCommandRegistering.register(command);
VelocityCommandRegistering.register(commandMeta, command);
}
@Override

View File

@@ -33,6 +33,10 @@ public class VelocityCommandFrameworkPlugin {
private static VelocityCommandFrameworkPlugin instance;
public static VelocityCommandFrameworkPlugin getInstance() {
return instance;
}
public static ProxyServer getProxy() {
return instance.proxyServer;
}

View File

@@ -19,23 +19,18 @@
package de.steamwar.command;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.proxy.Velocity;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.plugin.Plugin;
@UtilityClass
class VelocityCommandRegistering {
private static final Plugin plugin = ProxyServer.getInstance().getPluginManager().getPlugins().iterator().next();
static void unregister(SimpleCommand command) {
VelocityCommandFrameworkPlugin.getProxy().
ProxyServer.getInstance().getPluginManager().unregisterCommand(command);
static void unregister(CommandMeta command) {
VelocityCommandFrameworkPlugin.getProxy().getCommandManager().unregister(command);
}
static void register(SimpleCommand command) {
ProxyServer.getInstance().getPluginManager().registerCommand(plugin, command);
static void register(CommandMeta command, SimpleCommand commandInstance) {
VelocityCommandFrameworkPlugin.getProxy().getCommandManager().register(command, commandInstance);
}
}