Add Bungee implementation

This commit is contained in:
Alexander Söderberg 2020-09-19 00:21:27 +02:00
parent 04a6919c6a
commit 1a85251fc6
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
29 changed files with 420 additions and 57 deletions

View file

@ -25,6 +25,7 @@ package com.intellectualsites.commands.brigadier;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import com.intellectualsites.commands.Command;
import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.CommandTree;
import com.intellectualsites.commands.arguments.CommandArgument;
@ -36,6 +37,7 @@ import com.intellectualsites.commands.arguments.standard.FloatArgument;
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
import com.intellectualsites.commands.arguments.standard.ShortArgument;
import com.intellectualsites.commands.arguments.standard.StringArgument;
import com.intellectualsites.commands.context.CommandContext;
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.arguments.ArgumentType;
@ -47,7 +49,6 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
@ -65,7 +66,7 @@ import java.util.function.Function;
import java.util.function.Supplier;
/**
* Manager used to map cloud {@link com.intellectualsites.commands.Command}
* Manager used to map cloud {@link Command}
* <p>
* The structure of this class is largely inspired by
* <a href="https://github.com/aikar/commands/blob/master/brigadier/src/main/java/co.aikar.commands/ACFBrigadierManager.java">
@ -79,7 +80,7 @@ public final class CloudBrigadierManager<C, S> {
private final Map<Class<?>, Function<? extends CommandArgument<C, ?>,
? extends ArgumentType<?>>> mappers;
private final Map<Class<?>, Supplier<ArgumentType<?>>> defaultArgumentTypeSuppliers;
private final Supplier<com.intellectualsites.commands.context.CommandContext<C>> dummyContextProvider;
private final Supplier<CommandContext<C>> dummyContextProvider;
private final CommandManager<C, ?> commandManager;
/**
@ -89,7 +90,7 @@ public final class CloudBrigadierManager<C, S> {
* @param dummyContextProvider Provider of dummy context for completions
*/
public CloudBrigadierManager(@Nonnull final CommandManager<C, ?> commandManager,
@Nonnull final Supplier<com.intellectualsites.commands.context.CommandContext<C>>
@Nonnull final Supplier<CommandContext<C>>
dummyContextProvider) {
this.mappers = Maps.newHashMap();
this.defaultArgumentTypeSuppliers = Maps.newHashMap();
@ -298,7 +299,7 @@ public final class CloudBrigadierManager<C, S> {
private CompletableFuture<Suggestions> buildSuggestions(@Nonnull final CommandArgument<C, ?> argument,
@Nonnull final CommandContext<S> s,
@Nonnull final SuggestionsBuilder builder) {
final com.intellectualsites.commands.context.CommandContext<C> commandContext = this.dummyContextProvider.get();
final CommandContext<C> commandContext = this.dummyContextProvider.get();
final LinkedList<String> inputQueue = new LinkedList<>(Collections.singletonList(builder.getInput()));
final CommandPreprocessingContext<C> commandPreprocessingContext =
new CommandPreprocessingContext<>(commandContext, inputQueue);

View file

@ -37,8 +37,11 @@ import com.intellectualsites.commands.arguments.standard.EnumArgument;
import com.intellectualsites.commands.arguments.standard.FloatArgument;
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
import com.intellectualsites.commands.arguments.standard.StringArgument;
import com.intellectualsites.commands.bukkit.BukkitCommandMeta;
import com.intellectualsites.commands.bukkit.BukkitCommandMetaBuilder;
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
import com.intellectualsites.commands.parsers.WorldArgument;
import com.intellectualsites.commands.paper.PaperCommandManager;
import com.intellectualsites.commands.bukkit.parsers.WorldArgument;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;

View file

@ -21,8 +21,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import com.intellectualsites.commands.Command;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.arguments.StaticArgument;
import com.intellectualsites.commands.exceptions.ArgumentParseException;
@ -36,9 +37,7 @@ import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.plugin.Plugin;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Consumer;
final class BukkitCommand<C> extends org.bukkit.command.Command implements PluginIdentifiableCommand {
@ -49,10 +48,10 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
private final CommandArgument<C, ?> command;
private final BukkitCommandManager<C> bukkitCommandManager;
private final com.intellectualsites.commands.Command<C, BukkitCommandMeta> cloudCommand;
private final Command<C, BukkitCommandMeta> cloudCommand;
@SuppressWarnings("unchecked")
BukkitCommand(@Nonnull final com.intellectualsites.commands.Command<C, BukkitCommandMeta> cloudCommand,
BukkitCommand(@Nonnull final Command<C, BukkitCommandMeta> cloudCommand,
@Nonnull final CommandArgument<C, ?> command,
@Nonnull final BukkitCommandManager<C> bukkitCommandManager) {
super(command.getName(),
@ -88,7 +87,7 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND);
} else if (throwable instanceof ArgumentParseException) {
commandSender.sendMessage(ChatColor.RED + "Invalid Command Argument: "
+ ChatColor.GRAY + throwable.getCause().getMessage());
+ ChatColor.GRAY + throwable.getCause().getMessage());
} else {
commandSender.sendMessage(throwable.getMessage());
throwable.printStackTrace();
@ -124,25 +123,4 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
return this.cloudCommand.getCommandPermission();
}
@Nullable
private <E extends Throwable> E captureException(@Nonnull final Class<E> clazz, @Nullable final Throwable throwable) {
if (throwable == null) {
return null;
}
if (clazz.equals(throwable.getClass())) {
//noinspection unchecked
return (E) throwable;
}
return captureException(clazz, throwable.getCause());
}
private <E extends Throwable> boolean handleException(@Nullable final E throwable,
@Nonnull final Consumer<E> consumer) {
if (throwable == null) {
return false;
}
consumer.accept(throwable);
return true;
}
}

View file

@ -21,12 +21,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import com.google.common.reflect.TypeToken;
import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.CommandTree;
import com.intellectualsites.commands.bukkit.parsers.MaterialArgument;
import com.intellectualsites.commands.bukkit.parsers.WorldArgument;
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
import com.intellectualsites.commands.parsers.MaterialArgument;
import com.intellectualsites.commands.parsers.WorldArgument;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
@ -97,8 +99,13 @@ public class BukkitCommandManager<C>
return BukkitCommandMetaBuilder.builder().withDescription("").build();
}
/**
* Get the command sender mapper
*
* @return Command sender mapper
*/
@Nonnull
final Function<CommandSender, C> getCommandSenderMapper() {
public final Function<CommandSender, C> getCommandSenderMapper() {
return this.commandSenderMapper;
}

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import com.intellectualsites.commands.meta.SimpleCommandMeta;

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import com.intellectualsites.commands.meta.CommandMeta;

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import org.bukkit.entity.Player;

View file

@ -21,8 +21,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;
import com.intellectualsites.commands.Command;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
import org.bukkit.Bukkit;

View file

@ -25,4 +25,4 @@
/**
* cloud implementation for Bukkit 1.8-1.16
*/
package com.intellectualsites.commands;
package com.intellectualsites.commands.bukkit;

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands.parsers;
package com.intellectualsites.commands.bukkit.parsers;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;

View file

@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands.parsers;
package com.intellectualsites.commands.bukkit.parsers;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;

View file

@ -25,4 +25,4 @@
/**
* Bukkit specific command arguments
*/
package com.intellectualsites.commands.parsers;
package com.intellectualsites.commands.bukkit.parsers;

View file

@ -0,0 +1,60 @@
<?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-bungee</artifactId>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.intellectualsites</groupId>
<artifactId>cloud-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,122 @@
//
// 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.bungee;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.arguments.StaticArgument;
import com.intellectualsites.commands.exceptions.ArgumentParseException;
import com.intellectualsites.commands.exceptions.InvalidCommandSenderException;
import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
import com.intellectualsites.commands.exceptions.NoPermissionException;
import com.intellectualsites.commands.exceptions.NoSuchCommandException;
import com.intellectualsites.commands.meta.SimpleCommandMeta;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import javax.annotation.Nonnull;
public final class BungeeCommand<C> extends Command implements TabExecutor {
private static final String MESSAGE_NO_PERMS =
"I'm sorry, but you do not have permission to perform this command. "
+ "Please contact the server administrators if you believe that this is in error.";
private static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command. Type \"/help\" for help.";
private final BungeeCommandManager<C> bungeeCommandManager;
private final CommandArgument<C, ?> command;
private final com.intellectualsites.commands.Command<C, SimpleCommandMeta> cloudCommand;
@SuppressWarnings("unchecked")
BungeeCommand(@Nonnull final com.intellectualsites.commands.Command<C, SimpleCommandMeta> cloudCommand,
@Nonnull final CommandArgument<C, ?> command,
@Nonnull final BungeeCommandManager<C> bungeeCommandManager) {
super(command.getName(),
cloudCommand.getCommandPermission(),
((StaticArgument<C>) command).getAlternativeAliases().toArray(new String[0]));
this.command = command;
this.bungeeCommandManager = bungeeCommandManager;
this.cloudCommand = cloudCommand;
}
@Override
public void execute(final CommandSender commandSender, final String[] strings) {
/* Join input */
final StringBuilder builder = new StringBuilder(this.command.getName());
for (final String string : strings) {
builder.append(" ").append(string);
}
this.bungeeCommandManager.executeCommand(this.bungeeCommandManager.getCommandSenderMapper().apply(commandSender),
builder.toString())
.whenComplete(((commandResult, throwable) -> {
if (throwable != null) {
if (throwable instanceof InvalidSyntaxException) {
commandSender.sendMessage(
new ComponentBuilder("Invalid Command Syntax. Correct command syntax is: ")
.color(ChatColor.RED)
.append("/")
.color(ChatColor.GRAY)
.append(((InvalidSyntaxException) throwable).getCorrectSyntax())
.color(ChatColor.GRAY)
.create()
);
} else if (throwable instanceof InvalidCommandSenderException) {
commandSender.sendMessage(new ComponentBuilder(throwable.getMessage())
.color(ChatColor.RED)
.create());
} else if (throwable instanceof NoPermissionException) {
commandSender.sendMessage(new ComponentBuilder(MESSAGE_NO_PERMS)
.color(ChatColor.WHITE)
.create());
} else if (throwable instanceof NoSuchCommandException) {
commandSender.sendMessage(new ComponentBuilder(MESSAGE_UNKNOWN_COMMAND)
.color(ChatColor.WHITE)
.create());
} else if (throwable instanceof ArgumentParseException) {
commandSender.sendMessage(new ComponentBuilder("Invalid Command Argument: ")
.color(ChatColor.GRAY)
.append(throwable.getCause().getMessage())
.create());
} else {
commandSender.sendMessage(new ComponentBuilder(throwable.getMessage()).create());
throwable.printStackTrace();
}
}
}));
}
@Override
public Iterable<String> onTabComplete(final CommandSender sender,
final String[] args) {
final StringBuilder builder = new StringBuilder(this.command.getName());
for (final String string : args) {
builder.append(" ").append(string);
}
return this.bungeeCommandManager.suggest(this.bungeeCommandManager.getCommandSenderMapper().apply(sender),
builder.toString());
}
}

View file

@ -0,0 +1,91 @@
//
// 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.bungee;
import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.CommandTree;
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
import com.intellectualsites.commands.meta.SimpleCommandMeta;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Plugin;
import javax.annotation.Nonnull;
import java.util.function.Function;
public class BungeeCommandManager<C> extends CommandManager<C, SimpleCommandMeta> {
private final Plugin owningPlugin;
private final Function<CommandSender, C> commandSenderMapper;
private final Function<C, CommandSender> backwardsCommandSenderMapper;
/**
* Construct a new Bukkit command manager
*
* @param owningPlugin Plugin that is constructing the manager
* @param commandExecutionCoordinator Coordinator provider
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
* @throws Exception If the construction of the manager fails
*/
public BungeeCommandManager(@Nonnull final Plugin owningPlugin,
@Nonnull final Function<CommandTree<C, SimpleCommandMeta>,
CommandExecutionCoordinator<C, SimpleCommandMeta>> commandExecutionCoordinator,
@Nonnull final Function<CommandSender, C> commandSenderMapper,
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper)
throws Exception {
super(commandExecutionCoordinator, new BungeePluginRegistrationHandler<>());
((BungeePluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
this.owningPlugin = owningPlugin;
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 SimpleCommandMeta createDefaultCommandMeta() {
return SimpleCommandMeta.empty();
}
@Nonnull
final Function<CommandSender, C> getCommandSenderMapper() {
return this.commandSenderMapper;
}
/**
* Get the owning plugin
*
* @return Owning plugin
*/
@Nonnull
public Plugin getOwningPlugin() {
return this.owningPlugin;
}
}

View file

@ -0,0 +1,66 @@
//
// 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.bungee;
import com.intellectualsites.commands.Command;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
import com.intellectualsites.commands.meta.SimpleCommandMeta;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
final class BungeePluginRegistrationHandler<C> implements
CommandRegistrationHandler<SimpleCommandMeta> {
private final Map<CommandArgument<?, ?>, net.md_5.bungee.api.plugin.Command> registeredCommands = new HashMap<>();
private BungeeCommandManager<C> bungeeCommandManager;
BungeePluginRegistrationHandler() {
}
void initialize(@Nonnull final BungeeCommandManager<C> bungeeCommandManager) {
this.bungeeCommandManager = bungeeCommandManager;
}
@Override
public boolean registerCommand(@Nonnull final Command<?, SimpleCommandMeta> command) {
/* We only care about the root command argument */
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
if (this.registeredCommands.containsKey(commandArgument)) {
return false;
}
@SuppressWarnings("unchecked") final BungeeCommand<C> bungeeCommand = new BungeeCommand<>(
(Command<C, SimpleCommandMeta>) command,
(CommandArgument<C, ?>) commandArgument,
this.bungeeCommandManager);
this.registeredCommands.put(commandArgument, bungeeCommand);
this.bungeeCommandManager.getOwningPlugin().getProxy().getPluginManager()
.registerCommand(this.bungeeCommandManager.getOwningPlugin(), bungeeCommand);
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.
//
/**
* BungeeCord implementation of cloud
*/
package com.intellectualsites.commands.bungee;

View file

@ -21,12 +21,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.paper;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.bukkit.BukkitCommandMeta;
import com.intellectualsites.commands.CommandTree;
import com.intellectualsites.commands.brigadier.CloudBrigadierManager;
import com.intellectualsites.commands.arguments.CommandArgument;
import com.intellectualsites.commands.context.CommandContext;
import com.mojang.brigadier.arguments.ArgumentType;
import org.bukkit.Bukkit;

View file

@ -21,8 +21,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package com.intellectualsites.commands;
package com.intellectualsites.commands.paper;
import com.intellectualsites.commands.bukkit.BukkitCommandManager;
import com.intellectualsites.commands.bukkit.BukkitCommandMeta;
import com.intellectualsites.commands.CommandTree;
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

View file

@ -25,4 +25,4 @@
/**
* Paper specific implementation that extends the Bukkit implementation
*/
package com.intellectualsites.commands;
package com.intellectualsites.commands.paper;