Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not unregister commands of other plugins #33

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/main/java/net/elytrium/velocitytools/VelocityTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
package net.elytrium.velocitytools;

import com.google.inject.Inject;
import com.velocitypowered.api.command.Command;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
Expand Down Expand Up @@ -138,29 +141,29 @@ public void reload() {
}

List<String> aliases = Settings.IMP.COMMANDS.HUB.ALIASES;
aliases.forEach(alias -> this.server.getCommandManager().unregister(alias));
aliases.forEach(this::unregisterCommand);
if (Settings.IMP.COMMANDS.HUB.ENABLED && !aliases.isEmpty()) {
this.server.getCommandManager().register(aliases.get(0), new HubCommand(this.server), aliases.toArray(new String[0]));
}

this.server.getCommandManager().unregister("alert");
this.server.getCommandManager().unregister("find");
this.server.getCommandManager().unregister("send");
this.server.getCommandManager().unregister("velocitytools");
this.unregisterCommand("alert");
this.unregisterCommand("find");
this.unregisterCommand("send");
this.unregisterCommand("velocitytools");

if (Settings.IMP.COMMANDS.ALERT.ENABLED) {
this.server.getCommandManager().register("alert", new AlertCommand(this.server));
this.registerCommand("alert", new AlertCommand(this.server));
}

if (Settings.IMP.COMMANDS.FIND.ENABLED) {
this.server.getCommandManager().register("find", new FindCommand(this.server));
this.registerCommand("find", new FindCommand(this.server));
}

if (Settings.IMP.COMMANDS.SEND.ENABLED) {
this.server.getCommandManager().register("send", new SendCommand(this.server));
this.registerCommand("send", new SendCommand(this.server));
}

this.server.getCommandManager().register("velocitytools", new VelocityToolsCommand(this), "vtools");
this.registerCommand("velocitytools", new VelocityToolsCommand(this), "vtools");

this.server.getEventManager().unregisterListeners(this);

Expand All @@ -178,7 +181,19 @@ public void reload() {

HandshakeHook.reload(this.packetFactory);
}

private void registerCommand(String alias, Command command, String... aliases) {
CommandManager commandManager = this.server.getCommandManager();
CommandMeta meta = commandManager.metaBuilder(alias).aliases(aliases).plugin(this).build();
commandManager.register(meta, command);
}

private void unregisterCommand(String command) {
CommandMeta meta = this.server.getCommandManager().getCommandMeta(command);
if (meta != null && this.equals(meta.getPlugin())) {
this.server.getCommandManager().unregister(command);
}
}

private static void setLogger(Logger logger) {
LOGGER = logger;
Expand Down
Loading