Some adjustment in Bungee commands

This commit is contained in:
Marc Baloup 2022-12-24 12:08:36 +01:00
parent 0756781b26
commit e43fc292ba
2 changed files with 13 additions and 8 deletions

View File

@ -28,18 +28,12 @@ public abstract class BungeeBrigadierCommand extends BrigadierCommand<CommandSen
/**
* The command dispatcher.
*/
protected BungeeBrigadierDispatcher dispatcher;
protected BungeeBrigadierDispatcher dispatcher = BungeeBrigadierDispatcher.getInstance();
/**
* Instanciate this command instance.
* @param d the dispatcher in which to register this command.
*/
public BungeeBrigadierCommand(BungeeBrigadierDispatcher d) {
if (d == null) {
throw new IllegalStateException("BungeeBrigadierDispatcher not provided.");
}
dispatcher = d;
public BungeeBrigadierCommand() {
LiteralCommandNode<CommandSender> commandNode;
String[] aliases;

View File

@ -1,5 +1,6 @@
package fr.pandacube.lib.bungee.commands;
import fr.pandacube.lib.bungee.PandaLibBungee;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.commands.BrigadierDispatcher;
import net.kyori.adventure.text.ComponentLike;
@ -18,6 +19,13 @@ import net.md_5.bungee.event.EventHandler;
public class BungeeBrigadierDispatcher extends BrigadierDispatcher<CommandSender> implements Listener {
private static BungeeBrigadierDispatcher instance = null;
public static synchronized BungeeBrigadierDispatcher getInstance() {
return instance;
}
/* package */ final Plugin plugin;
@ -27,6 +35,9 @@ public class BungeeBrigadierDispatcher extends BrigadierDispatcher<CommandSender
* @param pl the plugin that creates this dispatcher.
*/
public BungeeBrigadierDispatcher(Plugin pl) {
if (instance != null)
throw new IllegalStateException("Cannot instanciante more than one BungeeBrigadierDispatcher");
instance = this;
plugin = pl;
ProxyServer.getInstance().getPluginManager().registerListener(plugin, this);
}