Add Velocity module

This commit is contained in:
Alexander Söderberg 2020-09-19 15:50:44 +02:00
parent ccd0e8ae0e
commit f1d4e7865d
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
17 changed files with 566 additions and 22 deletions

View file

@ -38,7 +38,7 @@ Once the core functionality is present, the framework will offer implementation
- Create a Discord implementation (JDA)
- Create a Java CLI implementation (JLine3)
## nomenclature
- **sender**: someone who is able to produce input
- **argument**: an argument is something that can be parsed from a string
@ -47,7 +47,17 @@ Once the core functionality is present, the framework will offer implementation
- **static argument**: a string literal
- **command**: a command is a chain of arguments and a handler that acts on the parsed arguments
- **command tree**: structure that contains all commands and is used to parse input into arguments
## modules
- **cloud-core**: Core module containing most of the cloud API, and shared implementations
- **cloud-annotations**: Annotation processing code that allows you to use annotated methods rather than builders
- **cloud-jline**: W.I.P JLine3 implementation of cloud
- **cloud-minecraft/cloud-brigadier**: Brigadier mappings for cloud
- **cloud-minecraft/cloud-bukkit**: Bukkit 1.8.8+ implementation of cloud
- **cloud-minecraft/cloud-paper**: Module that extends cloud-bukkit to add special support for Paper 1.8.8+
- **cloud-minecraft/cloud-bungee**: BungeeCord 1.8.8+ implementation of Cloud
- **cloud-minecraft/cloud-velocity**: Velocity v1.1.0 implementation of cloud
## links
- Discord: https://discord.gg/KxkjDVg

View file

@ -55,7 +55,6 @@ import java.util.regex.Pattern;
* Parser that parses class instances {@link com.intellectualsites.commands.Command commands}
*
* @param <C> Command sender type
* @param <M> Command meta type
*/
public final class AnnotationParser<C> {

View file

@ -38,7 +38,7 @@ import java.util.concurrent.CompletionException;
class AnnotationParserTest {
private static CommandManager<TestCommandSender> manager;
private static AnnotationParser<TestCommandSender, SimpleCommandMeta> annotationParser;
private static AnnotationParser<TestCommandSender> annotationParser;
@BeforeAll
static void setup() {

View file

@ -447,10 +447,8 @@ public final class CommandTree<C> {
chain = chain.subList(1, chain.size());
// Go through all nodes from the tail upwards until a collision occurs
for (final Node<CommandArgument<C, ?>> commandArgumentNode : chain) {
if (commandArgumentNode.nodeMeta.containsKey("permission") && !commandArgumentNode.nodeMeta.get("permission")
.equalsIgnoreCase(
node.nodeMeta
.get("permission"))) {
if (commandArgumentNode.nodeMeta.containsKey("permission")
&& !commandArgumentNode.nodeMeta.get("permission").equalsIgnoreCase(node.nodeMeta.get("permission"))) {
commandArgumentNode.nodeMeta.put("permission", "");
} else {
commandArgumentNode.nodeMeta.put("permission", node.nodeMeta.get("permission"));

View file

@ -148,9 +148,8 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
if (producer == null) {
/* Give enums special treatment */
if (actualType.isSubtypeOf(Enum.class)) {
@SuppressWarnings("all") final EnumArgument.EnumParser enumArgument = new EnumArgument.EnumParser((Class<Enum>)
actualType
.getRawType());
@SuppressWarnings("all") final EnumArgument.EnumParser enumArgument
= new EnumArgument.EnumParser((Class<Enum>) actualType.getRawType());
// noinspection all
return Optional.of(enumArgument);
}

View file

@ -239,6 +239,33 @@ public final class CloudBrigadierManager<C, S> {
return new Pair<>(StringArgumentType.string(), false);
}
/**
* Create a new literal command node
*
* @param cloudCommand Cloud command instance
* @param permissionChecker Permission checker
* @param executor Command executor
* @return Literal command node
*/
public LiteralCommandNode<S> createLiteralCommandNode(@Nonnull final Command<C> cloudCommand,
@Nonnull final BiPredicate<S, String> permissionChecker,
@Nonnull final com.mojang.brigadier.Command<S> executor) {
final CommandTree.Node<CommandArgument<C, ?>> node = this.commandManager
.getCommandTree().getNamedNode(cloudCommand.getArguments().get(0).getName());
final SuggestionProvider<S> provider = (context, builder) -> this.buildSuggestions(node.getValue(), context, builder);
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder
.<S>literal(cloudCommand.getArguments().get(0).getName())
.requires(sender -> permissionChecker.test(sender, node.getNodeMeta().getOrDefault("permission", "")));
if (node.isLeaf() && node.getValue() != null) {
literalArgumentBuilder.executes(executor);
}
final LiteralCommandNode<S> constructedRoot = literalArgumentBuilder.build();
for (final CommandTree.Node<CommandArgument<C, ?>> child : node.getChildren()) {
constructedRoot.addChild(this.constructCommandNode(child, permissionChecker, executor, provider).build());
}
return constructedRoot;
}
/**
* Create a literal command from Brigadier command info, and a cloud command instance
*
@ -297,7 +324,7 @@ public final class CloudBrigadierManager<C, S> {
@Nonnull
private CompletableFuture<Suggestions> buildSuggestions(@Nonnull final CommandArgument<C, ?> argument,
@Nonnull final CommandContext<S> s,
@Nonnull final com.mojang.brigadier.context.CommandContext<S> s,
@Nonnull final SuggestionsBuilder builder) {
final CommandContext<C> commandContext = this.dummyContextProvider.get();
final LinkedList<String> inputQueue = new LinkedList<>(Collections.singletonList(builder.getInput()));
@ -313,10 +340,7 @@ public final class CloudBrigadierManager<C, S> {
command = command.substring(1);
}
final List<String> suggestions = this.commandManager.suggest(commandContext.getSender(), command);
/*argument.getParser().suggestions(commandContext, builder.getInput());*/
for (final String suggestion : suggestions) {
System.out.printf("- %s\n", suggestion);
}
/*
System.out.println("Filtering out with: " + builder.getInput());
final CommandSuggestionProcessor<C> processor = this.commandManager.getCommandSuggestionProcessor();

View file

@ -105,7 +105,7 @@ public final class BukkitTest extends JavaPlugin {
.<CommandSender>newBuilder("perc")
.withMin(PERC_MIN).withMax(PERC_MAX).build())
.handler(context -> {
((Player) context.getSender()).sendMessage(String.format(
context.getSender().sendMessage(String.format(
"Kenny sux %d%%",
context.<Integer>get("perc").orElse(PERC_MIN)
));

View file

@ -76,9 +76,9 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
if (throwable != null) {
if (throwable instanceof InvalidSyntaxException) {
commandSender.sendMessage(ChatColor.RED + "Invalid Command Syntax. "
+ "Correct command syntax is: "
+ ChatColor.GRAY + "/"
+ ((InvalidSyntaxException) throwable).getCorrectSyntax());
+ "Correct command syntax is: "
+ ChatColor.GRAY + "/"
+ ((InvalidSyntaxException) throwable).getCorrectSyntax());
} else if (throwable instanceof InvalidCommandSenderException) {
commandSender.sendMessage(ChatColor.RED + throwable.getMessage());
} else if (throwable instanceof NoPermissionException) {

View file

@ -50,6 +50,7 @@
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.8-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.intellectualsites</groupId>

View file

@ -40,7 +40,7 @@ public class BungeeCommandManager<C> extends CommandManager<C> {
private final Function<C, CommandSender> backwardsCommandSenderMapper;
/**
* Construct a new Bukkit command manager
* Construct a new Bungee command manager
*
* @param owningPlugin Plugin that is constructing the manager
* @param commandExecutionCoordinator Coordinator provider

View file

@ -0,0 +1,214 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ MIT License
~
~ Copyright (c) 2020 Alexander Söderberg
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloud</artifactId>
<groupId>com.intellectualsites</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-velocity-test</artifactId>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>filter-src</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
<dependencies>
<dependency>
<groupId>net.trajano.wagon</groupId>
<artifactId>wagon-git</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>@{project.version}</tagNameFormat>
<scmCommentPrefix xml:space="preserve">[RELEASE] </scmCommentPrefix>
<goals>install deploy site-deploy
</goals> <!-- install is here to fix javadoc generation in multi-module projects -->
<releaseProfiles>release</releaseProfiles>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</reporting>
<repositories>
<repository>
<id>velocitypowered-repo</id>
<url>https://repo.velocitypowered.com/snapshots/</url>
</repository>
<repository>
<id>minecraft-libraries</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>spongepowered-repo</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.intellectualsites</groupId>
<artifactId>cloud-velocity</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,28 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
/**
* Velocity test plugin
*/
package com.intellectualsites.cloudvelocitytest;

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ MIT License
~
~ Copyright (c) 2020 Alexander Söderberg
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloud</artifactId>
<groupId>com.intellectualsites</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-velocity</artifactId>
<repositories>
<repository>
<id>velocity-snapshosts</id>
<url>https://repo.velocitypowered.com/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.intellectualsites</groupId>
<artifactId>cloud-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.intellectualsites</groupId>
<artifactId>cloud-brigadier</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,89 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands.velocity;
import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.CommandTree;
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
import com.intellectualsites.commands.meta.CommandMeta;
import com.intellectualsites.commands.meta.SimpleCommandMeta;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.ProxyServer;
import javax.annotation.Nonnull;
import java.util.function.Function;
/**
* {@link CommandManager} implementation for Velocity
*
* @param <C> Command sender type
*/
public class VelocityCommandManager<C> extends CommandManager<C> {
private final ProxyServer proxyServer;
private final Function<CommandSource, C> commandSenderMapper;
private final Function<C, CommandSource> backwardsCommandSenderMapper;
/**
* Create a new command manager instance
*
* @param proxyServer ProxyServer instance
* @param commandExecutionCoordinator Coordinator provider
* @param commandSenderMapper Function that maps {@link CommandSource} to the command sender type
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSource}
*/
public VelocityCommandManager(
@Nonnull final ProxyServer proxyServer,
@Nonnull final Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
@Nonnull final Function<CommandSource, C> commandSenderMapper,
@Nonnull final Function<C, CommandSource> backwardsCommandSenderMapper) {
super(commandExecutionCoordinator, new VelocityPluginRegistrationHandler<>());
((VelocityPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
this.proxyServer = proxyServer;
this.commandSenderMapper = commandSenderMapper;
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
}
@Override
public final boolean hasPermission(@Nonnull final C sender, @Nonnull final String permission) {
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
}
@Nonnull
@Override
public final CommandMeta createDefaultCommandMeta() {
return SimpleCommandMeta.empty();
}
@Nonnull
final ProxyServer getProxyServer() {
return this.proxyServer;
}
@Nonnull
final Function<CommandSource, C> getCommandSenderMapper() {
return this.commandSenderMapper;
}
}

View file

@ -0,0 +1,86 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands.velocity;
import com.intellectualsites.commands.Command;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.arguments.StaticArgument;
import com.intellectualsites.commands.brigadier.CloudBrigadierManager;
import com.intellectualsites.commands.context.CommandContext;
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.CommandSource;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
final class VelocityPluginRegistrationHandler<C> implements CommandRegistrationHandler {
private final Map<CommandArgument<?, ?>, BrigadierCommand> registeredCommands = new HashMap<>();
private CloudBrigadierManager<C, CommandSource> brigadierManager;
private VelocityCommandManager<C> velocityCommandManager;
void initialize(@Nonnull final VelocityCommandManager<C> velocityCommandManager) {
this.velocityCommandManager = velocityCommandManager;
this.brigadierManager = new CloudBrigadierManager<>(velocityCommandManager,
() -> new CommandContext<>(
velocityCommandManager.getCommandSenderMapper()
.apply(velocityCommandManager.getProxyServer()
.getConsoleCommandSource()))
);
}
@Override
public boolean registerCommand(@Nonnull final Command<?> command) {
final CommandArgument<?, ?> argument = command.getArguments().get(0);
if (this.registeredCommands.containsKey(argument)) {
return false;
}
final List<String> aliases = ((StaticArgument<C>) argument).getAlternativeAliases();
final BrigadierCommand brigadierCommand = new BrigadierCommand(
this.brigadierManager.createLiteralCommandNode((Command<C>) command,
(c, p) -> this.velocityCommandManager.hasPermission(
this.velocityCommandManager.getCommandSenderMapper()
.apply(c), p),
commandContext -> {
final CommandSource source = commandContext.getSource();
final String input = commandContext.getInput();
this.velocityCommandManager.executeCommand(
this.velocityCommandManager.getCommandSenderMapper()
.apply(source), input);
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
})
);
final CommandMeta commandMeta = this.velocityCommandManager.getProxyServer().getCommandManager()
.metaBuilder(brigadierCommand)
.aliases(aliases.toArray(new String[0])).build();
this.velocityCommandManager.getProxyServer().getCommandManager().register(commandMeta, brigadierCommand);
this.registeredCommands.put(argument, brigadierCommand);
return true;
}
}

View file

@ -0,0 +1,28 @@
//
// MIT License
//
// Copyright (c) 2020 Alexander Söderberg
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
/**
* Velocity implementation of cloud
*/
package com.intellectualsites.commands.velocity;

View file

@ -11,13 +11,15 @@
<module>cloud-jline</module>
<module>cloud-core</module>
<module>cloud-pipeline</module>
<module>cloud-annotations</module>
<!-- REMOVE THIS -->
<module>cloud-minecraft/cloud-bukkit-test</module>
<module>cloud-minecraft/cloud-velocity-test</module>
<module>cloud-minecraft/cloud-bukkit</module>
<module>cloud-minecraft/cloud-paper</module>
<module>cloud-minecraft/cloud-brigadier</module>
<module>cloud-annotations</module>
<module>cloud-minecraft/cloud-bungee</module>
<module>cloud-minecraft/cloud-velocity</module>
</modules>
<packaging>pom</packaging>
<inceptionYear>2020</inceptionYear>