diff --git a/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOffPlayer.java b/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOffPlayer.java
index 717de5a..f2280d1 100644
--- a/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOffPlayer.java
+++ b/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOffPlayer.java
@@ -5,6 +5,9 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import fr.pandacube.lib.players.standalone.AbstractOffPlayer;
+/**
+ * Represents any player on a Bungeecord proxy, either offline or online.
+ */
public interface BungeeOffPlayer extends AbstractOffPlayer {
/*
@@ -12,8 +15,8 @@ public interface BungeeOffPlayer extends AbstractOffPlayer {
*/
/**
- * @return l'instance Bungee du joueur en ligne, ou null si il n'est pas en
- * ligne
+ * Returns the {@link ProxiedPlayer} instance of this player, or null if not available (offline).
+ * @return the {@link ProxiedPlayer} instance of this player, or null if not available (offline).
*/
default ProxiedPlayer getBungeeProxiedPlayer() {
return ProxyServer.getInstance().getPlayer(getUniqueId());
diff --git a/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOnlinePlayer.java b/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOnlinePlayer.java
index edb66bd..f34f65e 100644
--- a/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOnlinePlayer.java
+++ b/pandalib-bungee-players/src/main/java/fr/pandacube/lib/bungee/players/BungeeOnlinePlayer.java
@@ -23,6 +23,9 @@ import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.util.MinecraftVersion;
+/**
+ * Represents any online player on a Bungeecord proxy.
+ */
public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlayer {
/*
@@ -41,24 +44,24 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
return getServer().getInfo().getName();
}
+ /**
+ * Returns the server on which the player is.
+ * @return the server on which the player is.
+ */
default Server getServer() {
return getBungeeProxiedPlayer().getServer();
}
+ /**
+ * Gets the minecraft version of this player’s client.
+ * @return the minecraft version of this player’s client.
+ */
default MinecraftVersion getMinecraftVersion() {
return MinecraftVersion.getVersion(getBungeeProxiedPlayer().getPendingConnection().getVersion());
}
- /*
- * Related class instances
- */
-
- @Override
- ProxiedPlayer getBungeeProxiedPlayer();
-
-
@@ -95,11 +98,17 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
@Override
default void sendMessage(Component message, Identified sender) {
- getBungeeProxiedPlayer().sendMessage(sender.identity().uuid(), Chat.toBungee(message));
+ getBungeeProxiedPlayer().sendMessage(sender == null ? null : sender.identity().uuid(), Chat.toBungee(message));
}
+ /**
+ * Display the provided message in the player’s chat, if they allows to display CHAT messages.
+ * @param message the message to send.
+ * @param sender the player causing the send of this message. Client side filtering may occur. May be null if we
+ * don’t want client filtering, but still consider the message as CHAT message.
+ */
default void sendMessage(ComponentLike message, ProxiedPlayer sender) {
- getBungeeProxiedPlayer().sendMessage(sender.getUniqueId(), Chat.toBungee(message.asComponent()));
+ getBungeeProxiedPlayer().sendMessage(sender == null ? null : sender.getUniqueId(), Chat.toBungee(message.asComponent()));
}
@Override
@@ -134,9 +143,17 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
return new BungeeClientOptions(this);
}
+ /**
+ * Provides various configuration values of the Minecraft client.
+ */
class BungeeClientOptions implements AbstractOnlinePlayer.ClientOptions {
private final BungeeOnlinePlayer op;
+
+ /**
+ * Create a new instance of {@link BungeeClientOptions}.
+ * @param op the {@link BungeeOnlinePlayer} instance.
+ */
public BungeeClientOptions(BungeeOnlinePlayer op) {
this.op = op;
}
@@ -155,6 +172,10 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
return op.getBungeeProxiedPlayer().hasChatColors();
}
+ /**
+ * Gets the chat visibility configuration.
+ * @return the chat visibility configuration.
+ */
public ChatMode getChatMode() {
return op.getBungeeProxiedPlayer().getChatMode();
}
@@ -185,6 +206,10 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
return op.getBungeeProxiedPlayer().getViewDistance();
}
+ /**
+ * Gets the player’s main hand.
+ * @return the player’s main hand.
+ */
public MainHand getMainHand() {
return op.getBungeeProxiedPlayer().getMainHand();
}
@@ -211,6 +236,10 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, AbstractOnlinePlaye
return settings != null && settings.isAllowServerListing();
}
+ /**
+ * Gets the player’s skin configuration.
+ * @return the player’s skin configuration.
+ */
public SkinConfiguration getSkinParts() {
return op.getBungeeProxiedPlayer().getSkinParts();
}
diff --git a/pandalib-paper-commands/pom.xml b/pandalib-paper-commands/pom.xml
index 4711358..d1fe212 100644
--- a/pandalib-paper-commands/pom.xml
+++ b/pandalib-paper-commands/pom.xml
@@ -54,6 +54,13 @@
${project.version}
+
+ fr.pandacube.lib
+ pandalib-paper-permissions
+ ${project.version}
+ provided
+
+
io.papermc.paper
diff --git a/pandalib-paper-commands/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java b/pandalib-paper-commands/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java
index 63dcf03..6bd378a 100644
--- a/pandalib-paper-commands/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java
+++ b/pandalib-paper-commands/src/main/java/fr/pandacube/lib/paper/commands/PaperBrigadierCommand.java
@@ -2,12 +2,9 @@ package fr.pandacube.lib.paper.commands;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
-import com.mojang.brigadier.context.ParsedCommandNode;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
-import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
@@ -15,7 +12,7 @@ import com.mojang.brigadier.tree.RootCommandNode;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.commands.BrigadierCommand;
import fr.pandacube.lib.commands.SuggestionsSupplier;
-import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftNamespacedKey;
+import fr.pandacube.lib.paper.permissions.PandalibPaperPermissions;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftVector;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.VanillaCommandWrapper;
@@ -25,18 +22,14 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.ComponentArgume
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Coordinates;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.EntityArgument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.EntitySelector;
-import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.GameProfileArgument;
-import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.ResourceLocationArgument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Vec3Argument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.BlockPos;
-import fr.pandacube.lib.paper.reflect.wrapper.minecraft.resources.ResourceLocation;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerPlayer;
import fr.pandacube.lib.paper.reflect.wrapper.paper.PaperAdventure;
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.util.Log;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
-import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
@@ -55,200 +48,283 @@ import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.function.Function;
import java.util.function.Predicate;
+/**
+ * Abstract class to hold a command to be integrated into a Paper server vanilla command dispatcher.
+ */
public abstract class PaperBrigadierCommand extends BrigadierCommand implements Listener {
- protected static final Commands vanillaCommandDispatcher;
- private static final CommandDispatcher nmsDispatcher;
-
- static {
- vanillaCommandDispatcher = ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class)
- .getServer()
- .vanillaCommandDispatcher();
- nmsDispatcher = vanillaCommandDispatcher.dispatcher();
- }
+ private static final Commands vanillaCommandDispatcher;
+ private static final CommandDispatcher nmsDispatcher;
+
+ static {
+ vanillaCommandDispatcher = ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class)
+ .getServer()
+ .vanillaCommandDispatcher();
+ nmsDispatcher = vanillaCommandDispatcher.dispatcher();
+ }
+
+ /**
+ * Removes a plugin command that overrides a vanilla command, so the vanilla command functionnalities are fully
+ * restored (so, not only the usage, but also the suggestions and the command structure sent to the client).
+ * @param name the name of the command to restore.
+ */
+ public static void restoreVanillaCommand(String name) {
+ CommandMap bukkitCmdMap = Bukkit.getCommandMap();
+ Command bukkitCommand = bukkitCmdMap.getCommand(name);
+ if (bukkitCommand != null) {
+ if (VanillaCommandWrapper.REFLECT.get().isInstance(bukkitCommand)) {
+ Log.info("Command /" + name + " is already a vanilla command.");
+ return;
+ }
+ Log.info("Removing Bukkit command /" + name + " (" + getCommandIdentity(bukkitCommand) + ")");
+ bukkitCmdMap.getKnownCommands().remove(name.toLowerCase(java.util.Locale.ENGLISH));
+ bukkitCommand.unregister(bukkitCmdMap);
+
+ LiteralCommandNode node = (LiteralCommandNode) getRootNode().getChild(name);
+ Command newCommand = new VanillaCommandWrapper(vanillaCommandDispatcher, node).__getRuntimeInstance();
+ bukkitCmdMap.getKnownCommands().put(name.toLowerCase(), newCommand);
+ newCommand.register(bukkitCmdMap);
+ }
+ }
- public static CommandDispatcher getNMSDispatcher() {
- return nmsDispatcher;
- }
+ /**
+ * Returns the vanilla instance of the Brigadier dispatcher.
+ * @return the vanilla instance of the Brigadier dispatcher.
+ */
+ public static CommandDispatcher getNMSDispatcher() {
+ return nmsDispatcher;
+ }
- protected static RootCommandNode getRootNode() {
- return nmsDispatcher.getRoot();
- }
-
- protected Plugin plugin;
-
- protected LiteralCommandNode commandNode;
-
- private Set allAliases;
-
- public PaperBrigadierCommand(Plugin pl) {
- plugin = pl;
- commandNode = buildCommand().build();
- postBuildCommand(commandNode);
- register();
- Bukkit.getPluginManager().registerEvents(this, plugin);
- }
-
+ /**
+ * Returns the root command node of the Brigadier dispatcher.
+ * @return the root command node of the Brigadier dispatcher.
+ */
+ protected static RootCommandNode getRootNode() {
+ return nmsDispatcher.getRoot();
+ }
-
-
- private void register() {
-
- String[] aliases = getAliases();
- if (aliases == null)
- aliases = new String[0];
-
- String pluginName = plugin.getName().toLowerCase();
-
- allAliases = new HashSet<>();
- registerNode(commandNode, false);
- registerAlias(pluginName + ":" + commandNode.getLiteral(), true);
-
- for (String alias : aliases) {
- registerAlias(alias, false);
- registerAlias(pluginName + ":" + alias, true);
- }
- }
-
-
- private void registerAlias(String alias, boolean prefixed) {
- LiteralCommandNode node = literal(alias)
- .requires(commandNode.getRequirement())
- .executes(commandNode.getCommand())
- .redirect(commandNode)
- .build();
- registerNode(node, prefixed);
- }
-
-
- private void registerNode(LiteralCommandNode node, boolean prefixed) {
- RootCommandNode root = getRootNode();
- String name = node.getLiteral();
- //boolean isAlias = node.getRedirect() == commandNode;
- boolean forceRegistration = true;//prefixed || !isAlias;
-
- // nmsDispatcher integration and conflit resolution
- boolean nmsRegister = false, nmsRegistered = false;
- CommandNode nmsConflited = root.getChild(name);
- if (nmsConflited != null) {
-
- if (isFromThisCommand(nmsConflited)) {
- // this command is already registered in NMS
- // don’t need to register again
- nmsRegistered = true;
- }
- else if (forceRegistration) {
- nmsRegister = true;
- Log.info("Overwriting Brigadier command /" + name);
- }
- else {
- Log.severe("/" + name + " already in NMS Brigadier instance."
- + " Wont replace it because registration is not forced.");
- }
- }
- else {
- nmsRegister = true;
- }
-
- if (nmsRegister) {
- @SuppressWarnings("unchecked")
- var rCommandNode = ReflectWrapper.wrapTyped(root, fr.pandacube.lib.paper.reflect.wrapper.brigadier.CommandNode.class);
- rCommandNode.removeCommand(name);
- root.addChild(node);
- nmsRegistered = true;
- }
-
- if (!nmsRegistered) {
- return;
- }
-
- allAliases.add(name);
-
- // bukkit dispatcher conflict resolution
- boolean bukkitRegister = false;
- CommandMap bukkitCmdMap = Bukkit.getCommandMap();
- Command bukkitConflicted = bukkitCmdMap.getCommand(name);
- if (bukkitConflicted != null) {
- if (isFromThisCommand(bukkitConflicted)) {
- // nothing to do, already good
- }
- else if (forceRegistration) {
- bukkitRegister = true;
- Log.info("Overwriting Bukkit command /" + name
- + " (" + getCommandIdentity(bukkitConflicted) + ")");
- }
- else {
- Log.severe("/" + name + " already in Bukkit"
- + " dispatcher (" + getCommandIdentity(bukkitConflicted)
- + "). Wont replace it because registration is not forced.");
- }
- }
- else {
- bukkitRegister = true;
- }
-
- if (bukkitRegister) {
- bukkitCmdMap.getKnownCommands().remove(name.toLowerCase());
- if (bukkitConflicted != null)
- bukkitConflicted.unregister(bukkitCmdMap);
- Command newCommand = new VanillaCommandWrapper(vanillaCommandDispatcher, node).__getRuntimeInstance();
- bukkitCmdMap.getKnownCommands().put(name.toLowerCase(), newCommand);
- newCommand.register(bukkitCmdMap);
- }
-
- }
-
- private boolean isFromThisCommand(CommandNode node) {
- return node == commandNode || node.getRedirect() == commandNode;
- }
- private boolean isFromThisCommand(Command bukkitCmd) {
- if (VanillaCommandWrapper.REFLECT.get().isInstance(bukkitCmd)) {
- return isFromThisCommand(ReflectWrapper.wrapTyped((BukkitCommand) bukkitCmd, VanillaCommandWrapper.class).vanillaCommand());
- }
- return false;
- }
-
- protected static String getCommandIdentity(Command bukkitCmd) {
- if (bukkitCmd instanceof PluginCommand cmd) {
- return "Bukkit command: /" + cmd.getName() + " from plugin " + cmd.getPlugin().getName();
- }
- else if (VanillaCommandWrapper.REFLECT.get().isInstance(bukkitCmd)) {
- return "Vanilla command: /" + bukkitCmd.getName();
- }
- else
- return bukkitCmd.getClass().getName() + ": /" + bukkitCmd.getName();
- }
-
-
-
-
- @EventHandler
- public void onPlayerCommandSend(PlayerCommandSendEvent event) {
- event.getCommands().removeAll(allAliases.stream().map(s -> "minecraft:" + s).toList());
- }
-
-
- @EventHandler
- public void onServerLoad(ServerLoadEvent event) {
- register();
- }
-
-
- /**
- * The permission that should be tested instead of "minecraft.command.cmdName".
- */
- protected abstract String getTargetPermission();
+
+
+
+
+
+ private final Plugin plugin;
+
+ /**
+ * The command node of this command.
+ */
+ protected final LiteralCommandNode commandNode;
+
+ private final RegistrationPolicy registrationPolicy;
+
+ private Set registeredAliases;
+
+ /**
+ * Instanciate this command isntance.
+ *
+ * @param pl the plugin instance.
+ * @param regPolicy the registration policy for this command.
+ */
+ public PaperBrigadierCommand(Plugin pl, RegistrationPolicy regPolicy) {
+ plugin = pl;
+ registrationPolicy = regPolicy;
+ commandNode = buildCommand().build();
+ postBuildCommand(commandNode);
+ register();
+ Bukkit.getPluginManager().registerEvents(this, plugin);
+ try {
+ PandalibPaperPermissions.addPermissionMapping("minecraft.command." + commandNode.getLiteral().toLowerCase(), getTargetPermission().toLowerCase());
+ } catch (NoClassDefFoundError ignored) { }
+ }
+
+ /**
+ * Instanciate this command isntance with a registration policy of {@link RegistrationPolicy#ONLY_BASE_COMMAND}.
+ * @param pl the plugin instance.
+ */
+ public PaperBrigadierCommand(Plugin pl) {
+ this(pl, RegistrationPolicy.ONLY_BASE_COMMAND);
+ }
+
+
+
+
+ private void register() {
+
+ String[] aliases = getAliases();
+ if (aliases == null)
+ aliases = new String[0];
+
+ String pluginName = plugin.getName().toLowerCase();
+
+ registeredAliases = new HashSet<>();
+ registerNode(commandNode, false);
+ registerAlias(pluginName + ":" + commandNode.getLiteral(), true);
+
+ for (String alias : aliases) {
+ registerAlias(alias, false);
+ registerAlias(pluginName + ":" + alias, true);
+ }
+ }
+
+
+ private void registerAlias(String alias, boolean prefixed) {
+ LiteralCommandNode node = literal(alias)
+ .requires(commandNode.getRequirement())
+ .executes(commandNode.getCommand())
+ .redirect(commandNode)
+ .build();
+ registerNode(node, prefixed);
+ }
+
+
+ private void registerNode(LiteralCommandNode node, boolean prefixed) {
+ RootCommandNode root = getRootNode();
+ String name = node.getLiteral();
+ boolean isAlias = node.getRedirect() == commandNode;
+ boolean forceRegistration = switch (registrationPolicy) {
+ case NONE -> false;
+ case ONLY_BASE_COMMAND -> prefixed || !isAlias;
+ case ALL -> true;
+ };
+
+ // nmsDispatcher integration and conflit resolution
+ boolean nmsRegister = false, nmsRegistered = false;
+ CommandNode nmsConflited = root.getChild(name);
+ if (nmsConflited != null) {
+
+ if (isFromThisCommand(nmsConflited)) {
+ // this command is already registered in NMS. Don’t need to register again
+ nmsRegistered = true;
+ }
+ else if (forceRegistration) {
+ nmsRegister = true;
+ Log.info("Overwriting Brigadier command /" + name);
+ }
+ else {
+ Log.severe("/" + name + " already in NMS Brigadier instance."
+ + " Wont replace it because registration is not forced.");
+ }
+ }
+ else {
+ nmsRegister = true;
+ }
+
+ if (nmsRegister) {
+ @SuppressWarnings("unchecked")
+ var rCommandNode = ReflectWrapper.wrapTyped(root, fr.pandacube.lib.paper.reflect.wrapper.brigadier.CommandNode.class);
+ rCommandNode.removeCommand(name);
+ root.addChild(node);
+ nmsRegistered = true;
+ }
+
+ if (!nmsRegistered) {
+ return;
+ }
+
+ registeredAliases.add(name);
+
+ // bukkit dispatcher conflict resolution
+ boolean bukkitRegister = false;
+ CommandMap bukkitCmdMap = Bukkit.getCommandMap();
+ Command bukkitConflicted = bukkitCmdMap.getCommand(name);
+ if (bukkitConflicted != null) {
+ if (!isFromThisCommand(bukkitConflicted)) {
+ if (forceRegistration) {
+ bukkitRegister = true;
+ Log.info("Overwriting Bukkit command /" + name
+ + " (" + getCommandIdentity(bukkitConflicted) + ")");
+ }
+ else {
+ Log.severe("/" + name + " already in Bukkit"
+ + " dispatcher (" + getCommandIdentity(bukkitConflicted)
+ + "). Wont replace it because registration is not forced.");
+ }
+ }
+ }
+ else {
+ bukkitRegister = true;
+ }
+
+ if (bukkitRegister) {
+ bukkitCmdMap.getKnownCommands().remove(name.toLowerCase());
+ if (bukkitConflicted != null)
+ bukkitConflicted.unregister(bukkitCmdMap);
+
+ Command newCommand = new VanillaCommandWrapper(vanillaCommandDispatcher, node).__getRuntimeInstance();
+ bukkitCmdMap.getKnownCommands().put(name.toLowerCase(), newCommand);
+ newCommand.register(bukkitCmdMap);
+ }
+
+ }
+
+ private boolean isFromThisCommand(CommandNode node) {
+ return node == commandNode || node.getRedirect() == commandNode;
+ }
+
+ private boolean isFromThisCommand(Command bukkitCmd) {
+ if (VanillaCommandWrapper.REFLECT.get().isInstance(bukkitCmd)) {
+ return isFromThisCommand(ReflectWrapper.wrapTyped((BukkitCommand) bukkitCmd, VanillaCommandWrapper.class).vanillaCommand());
+ }
+ return false;
+ }
+
+ private static String getCommandIdentity(Command bukkitCmd) {
+ if (bukkitCmd instanceof PluginCommand cmd) {
+ return "Bukkit command: /" + cmd.getName() + " from plugin " + cmd.getPlugin().getName();
+ }
+ else if (VanillaCommandWrapper.REFLECT.get().isInstance(bukkitCmd)) {
+ return "Vanilla command: /" + bukkitCmd.getName();
+ }
+ else
+ return bukkitCmd.getClass().getName() + ": /" + bukkitCmd.getName();
+ }
+
+
+ /**
+ * Player command sender event handler.
+ * @param event the event.
+ */
+ @EventHandler
+ public void onPlayerCommandSend(PlayerCommandSendEvent event) {
+ event.getCommands().removeAll(registeredAliases.stream().map(s -> "minecraft:" + s).toList());
+ }
+
+
+ /**
+ * Server load event handler.
+ * @param event the event.
+ */
+ @EventHandler
+ public void onServerLoad(ServerLoadEvent event) {
+ register();
+ }
+
+
+
+
+
+
+
+
+
+
+
+ /**
+ * Returns the permission that should be tested instead of "minecraft.command.cmdName". The conversion from the
+ * minecraft prefixed permission node to the returned node is done by the {@code pandalib-paper-permissions} if it
+ * is present in the classpath during runtime.
+ * @return the permission that should be tested instead of "minecraft.command.cmdName".
+ */
+ protected abstract String getTargetPermission();
@@ -263,198 +339,304 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand hasPermission(String permission) {
- return wrapper -> getCommandSender(wrapper).hasPermission(permission);
- }
-
-
- public boolean isConsole(CommandSender sender) {
- return sender instanceof ConsoleCommandSender;
- }
- public boolean isPlayer(CommandSender sender) {
- return sender instanceof Player;
- }
-
-
-
-
- public static CommandSender getCommandSender(CommandContext context) {
- return getCommandSender(context.getSource());
- }
- public static CommandSender getCommandSender(BukkitBrigadierCommandSource wrapper) {
- return wrapper.getBukkitSender();
- }
- public static BukkitBrigadierCommandSource getBrigadierCommandSource(CommandSender sender) {
- return VanillaCommandWrapper.getListener(sender);
- }
-
-
-
-
-
-
-
-
-
-
-
+ public boolean isConsole(BukkitBrigadierCommandSource wrapper) {
+ return isConsole(getCommandSender(wrapper));
+ }
+ public boolean isPlayer(BukkitBrigadierCommandSource wrapper) {
+ return isPlayer(getCommandSender(wrapper));
+ }
+ public Predicate hasPermission(String permission) {
+ return wrapper -> getCommandSender(wrapper).hasPermission(permission);
+ }
- public static final SuggestionsSupplier TAB_WORLDS = (s, ti, token, a) -> SuggestionsSupplier.collectFilteredStream(Bukkit.getWorlds().stream().map(World::getName), token);
-
-
-
- protected SuggestionProvider wrapSuggestions(SuggestionsSupplier suggestions) {
- return wrapSuggestions(suggestions, PaperBrigadierCommand::getCommandSender);
- }
-
-
-
-
- protected static com.mojang.brigadier.Command wrapCommand(com.mojang.brigadier.Command cmd) {
- return context -> {
- try {
- return cmd.run(context);
- } catch(CommandSyntaxException e) {
- throw e;
- } catch (Throwable t) {
- Log.severe(t);
- getCommandSender(context).sendMessage(Chat.failureText("Error while using the command: " + t));
- return 0;
- }
- };
- }
-
-
-
-
-
-
-
-
- /*
- * Minecraft argument type
- */
-
-
- public static ArgumentType