Add Velocity module
This commit is contained in:
parent
ccd0e8ae0e
commit
f1d4e7865d
17 changed files with 566 additions and 22 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
));
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
214
cloud-minecraft/cloud-velocity-test/pom.xml
Normal file
214
cloud-minecraft/cloud-velocity-test/pom.xml
Normal 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>
|
||||
|
|
@ -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;
|
||||
66
cloud-minecraft/cloud-velocity/pom.xml
Normal file
66
cloud-minecraft/cloud-velocity/pom.xml
Normal 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>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue