Mostly javadoc, and also some fixes there and there
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
package fr.pandacube.lib.bungee.commands;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.context.ParsedCommandNode;
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import fr.pandacube.lib.commands.BrigadierCommand;
|
||||
import fr.pandacube.lib.commands.SuggestionsSupplier;
|
||||
import fr.pandacube.lib.reflect.Reflect;
|
||||
import fr.pandacube.lib.util.Log;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -18,18 +14,26 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Abstract class that holds the logic of a specific command to be registered in {@link BungeeBrigadierDispatcher} and
|
||||
* BungeeCord command API.
|
||||
*/
|
||||
public abstract class BungeeBrigadierCommand extends BrigadierCommand<CommandSender> {
|
||||
|
||||
/**
|
||||
* The command dispatcher.
|
||||
*/
|
||||
protected BungeeBrigadierDispatcher dispatcher;
|
||||
|
||||
|
||||
/**
|
||||
* Instanciate this command isntance.
|
||||
* @param d the dispatcher in which to register this command.
|
||||
*/
|
||||
public BungeeBrigadierCommand(BungeeBrigadierDispatcher d) {
|
||||
if (d == null) {
|
||||
throw new IllegalStateException("BungeeBrigadierDispatcher not provided.");
|
||||
@@ -62,12 +66,14 @@ public abstract class BungeeBrigadierCommand extends BrigadierCommand<CommandSen
|
||||
.redirect(commandNode)
|
||||
.build()
|
||||
);
|
||||
|
||||
ProxyServer.getInstance().getPluginManager().registerCommand(dispatcher.plugin, new CommandRelay(alias));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private class CommandRelay extends Command implements TabExecutor {
|
||||
private final String alias;
|
||||
public CommandRelay(String alias) {
|
||||
@@ -117,9 +123,11 @@ public abstract class BungeeBrigadierCommand extends BrigadierCommand<CommandSen
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Wraps the provided {@link SuggestionsSupplier} into a Brigadier’s {@link SuggestionProvider}.
|
||||
* @param suggestions the suggestions to wrap.
|
||||
* @return a {@link SuggestionProvider} generating the suggestions from the provided {@link SuggestionsSupplier}.
|
||||
*/
|
||||
protected SuggestionProvider<CommandSender> wrapSuggestions(SuggestionsSupplier<CommandSender> suggestions) {
|
||||
return wrapSuggestions(suggestions, Function.identity());
|
||||
}
|
||||
|
@@ -1,21 +1,7 @@
|
||||
package fr.pandacube.lib.bungee.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
import com.mojang.brigadier.context.SuggestionContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import fr.pandacube.lib.chat.Chat;
|
||||
import fr.pandacube.lib.commands.BrigadierCommand;
|
||||
import fr.pandacube.lib.commands.BrigadierDispatcher;
|
||||
import fr.pandacube.lib.commands.BrigadierSuggestionsUtil;
|
||||
import fr.pandacube.lib.util.Log;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -25,11 +11,10 @@ import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Implementation of {@link BrigadierDispatcher} that integrates the commands into BungeeCord API, so the players and
|
||||
* the console can actually execute them.
|
||||
*/
|
||||
public class BungeeBrigadierDispatcher extends BrigadierDispatcher<CommandSender> implements Listener {
|
||||
|
||||
|
||||
@@ -37,15 +22,20 @@ public class BungeeBrigadierDispatcher extends BrigadierDispatcher<CommandSender
|
||||
|
||||
/* package */ final Plugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new instance of {@link BungeeBrigadierDispatcher}.
|
||||
* @param pl the plugin that creates this dispatcher.
|
||||
*/
|
||||
public BungeeBrigadierDispatcher(Plugin pl) {
|
||||
plugin = pl;
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called when a player sends a chat message. Used to gets the typed command and execute it.
|
||||
* @param event the event.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChat(ChatEvent event) {
|
||||
if (!event.getMessage().startsWith("/"))
|
||||
|
Reference in New Issue
Block a user