Add Bungee implementation
This commit is contained in:
parent
04a6919c6a
commit
1a85251fc6
29 changed files with 420 additions and 57 deletions
|
|
@ -52,7 +52,7 @@ import java.util.function.Predicate;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parser that parses class instances {@link Command commands}
|
* Parser that parses class instances {@link com.intellectualsites.commands.Command commands}
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package com.intellectualsites.commands.arguments.standard;
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package com.intellectualsites.commands.arguments.standard;
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package com.intellectualsites.commands.arguments.standard;
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package com.intellectualsites.commands.arguments.standard;
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package com.intellectualsites.commands.arguments.standard;
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ package com.intellectualsites.commands.brigadier;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import com.intellectualsites.commands.Command;
|
||||||
import com.intellectualsites.commands.CommandManager;
|
import com.intellectualsites.commands.CommandManager;
|
||||||
import com.intellectualsites.commands.CommandTree;
|
import com.intellectualsites.commands.CommandTree;
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
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.IntegerArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
||||||
import com.mojang.brigadier.LiteralMessage;
|
import com.mojang.brigadier.LiteralMessage;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
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.ArgumentBuilder;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
|
@ -65,7 +66,7 @@ import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager used to map cloud {@link com.intellectualsites.commands.Command}
|
* Manager used to map cloud {@link Command}
|
||||||
* <p>
|
* <p>
|
||||||
* The structure of this class is largely inspired by
|
* 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">
|
* <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, ?>,
|
private final Map<Class<?>, Function<? extends CommandArgument<C, ?>,
|
||||||
? extends ArgumentType<?>>> mappers;
|
? extends ArgumentType<?>>> mappers;
|
||||||
private final Map<Class<?>, Supplier<ArgumentType<?>>> defaultArgumentTypeSuppliers;
|
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;
|
private final CommandManager<C, ?> commandManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,7 +90,7 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
* @param dummyContextProvider Provider of dummy context for completions
|
* @param dummyContextProvider Provider of dummy context for completions
|
||||||
*/
|
*/
|
||||||
public CloudBrigadierManager(@Nonnull final CommandManager<C, ?> commandManager,
|
public CloudBrigadierManager(@Nonnull final CommandManager<C, ?> commandManager,
|
||||||
@Nonnull final Supplier<com.intellectualsites.commands.context.CommandContext<C>>
|
@Nonnull final Supplier<CommandContext<C>>
|
||||||
dummyContextProvider) {
|
dummyContextProvider) {
|
||||||
this.mappers = Maps.newHashMap();
|
this.mappers = Maps.newHashMap();
|
||||||
this.defaultArgumentTypeSuppliers = 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,
|
private CompletableFuture<Suggestions> buildSuggestions(@Nonnull final CommandArgument<C, ?> argument,
|
||||||
@Nonnull final CommandContext<S> s,
|
@Nonnull final CommandContext<S> s,
|
||||||
@Nonnull final SuggestionsBuilder builder) {
|
@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 LinkedList<String> inputQueue = new LinkedList<>(Collections.singletonList(builder.getInput()));
|
||||||
final CommandPreprocessingContext<C> commandPreprocessingContext =
|
final CommandPreprocessingContext<C> commandPreprocessingContext =
|
||||||
new CommandPreprocessingContext<>(commandContext, inputQueue);
|
new CommandPreprocessingContext<>(commandContext, inputQueue);
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,11 @@ import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.FloatArgument;
|
import com.intellectualsites.commands.arguments.standard.FloatArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
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.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.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,9 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// 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.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.StaticArgument;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.exceptions.ArgumentParseException;
|
import com.intellectualsites.commands.exceptions.ArgumentParseException;
|
||||||
|
|
@ -36,9 +37,7 @@ import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
final class BukkitCommand<C> extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
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 CommandArgument<C, ?> command;
|
||||||
private final BukkitCommandManager<C> bukkitCommandManager;
|
private final BukkitCommandManager<C> bukkitCommandManager;
|
||||||
private final com.intellectualsites.commands.Command<C, BukkitCommandMeta> cloudCommand;
|
private final Command<C, BukkitCommandMeta> cloudCommand;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@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 CommandArgument<C, ?> command,
|
||||||
@Nonnull final BukkitCommandManager<C> bukkitCommandManager) {
|
@Nonnull final BukkitCommandManager<C> bukkitCommandManager) {
|
||||||
super(command.getName(),
|
super(command.getName(),
|
||||||
|
|
@ -88,7 +87,7 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
||||||
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND);
|
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND);
|
||||||
} else if (throwable instanceof ArgumentParseException) {
|
} else if (throwable instanceof ArgumentParseException) {
|
||||||
commandSender.sendMessage(ChatColor.RED + "Invalid Command Argument: "
|
commandSender.sendMessage(ChatColor.RED + "Invalid Command Argument: "
|
||||||
+ ChatColor.GRAY + throwable.getCause().getMessage());
|
+ ChatColor.GRAY + throwable.getCause().getMessage());
|
||||||
} else {
|
} else {
|
||||||
commandSender.sendMessage(throwable.getMessage());
|
commandSender.sendMessage(throwable.getMessage());
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
|
|
@ -124,25 +123,4 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
||||||
return this.cloudCommand.getCommandPermission();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -21,12 +21,14 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.bukkit;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
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.execution.CommandExecutionCoordinator;
|
||||||
import com.intellectualsites.commands.parsers.MaterialArgument;
|
|
||||||
import com.intellectualsites.commands.parsers.WorldArgument;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
@ -97,8 +99,13 @@ public class BukkitCommandManager<C>
|
||||||
return BukkitCommandMetaBuilder.builder().withDescription("").build();
|
return BukkitCommandMetaBuilder.builder().withDescription("").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command sender mapper
|
||||||
|
*
|
||||||
|
* @return Command sender mapper
|
||||||
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
final Function<CommandSender, C> getCommandSenderMapper() {
|
public final Function<CommandSender, C> getCommandSenderMapper() {
|
||||||
return this.commandSenderMapper;
|
return this.commandSenderMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.bukkit;
|
||||||
|
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.bukkit;
|
||||||
|
|
||||||
import com.intellectualsites.commands.meta.CommandMeta;
|
import com.intellectualsites.commands.meta.CommandMeta;
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.bukkit;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.bukkit;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.bukkit;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -21,8 +21,9 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// 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.CommandArgument;
|
||||||
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -25,4 +25,4 @@
|
||||||
/**
|
/**
|
||||||
* cloud implementation for Bukkit 1.8-1.16
|
* cloud implementation for Bukkit 1.8-1.16
|
||||||
*/
|
*/
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.bukkit;
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.parsers;
|
package com.intellectualsites.commands.bukkit.parsers;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.parsers;
|
package com.intellectualsites.commands.bukkit.parsers;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
|
|
@ -25,4 +25,4 @@
|
||||||
/**
|
/**
|
||||||
* Bukkit specific command arguments
|
* Bukkit specific command arguments
|
||||||
*/
|
*/
|
||||||
package com.intellectualsites.commands.parsers;
|
package com.intellectualsites.commands.bukkit.parsers;
|
||||||
60
cloud-minecraft/cloud-bungee/pom.xml
Normal file
60
cloud-minecraft/cloud-bungee/pom.xml
Normal 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>
|
||||||
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -21,12 +21,14 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.paper;
|
||||||
|
|
||||||
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||||
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
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.brigadier.CloudBrigadierManager;
|
||||||
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -21,8 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// 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 com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
@ -25,4 +25,4 @@
|
||||||
/**
|
/**
|
||||||
* Paper specific implementation that extends the Bukkit implementation
|
* Paper specific implementation that extends the Bukkit implementation
|
||||||
*/
|
*/
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands.paper;
|
||||||
1
pom.xml
1
pom.xml
|
|
@ -17,6 +17,7 @@
|
||||||
<module>cloud-minecraft/cloud-paper</module>
|
<module>cloud-minecraft/cloud-paper</module>
|
||||||
<module>cloud-minecraft/cloud-brigadier</module>
|
<module>cloud-minecraft/cloud-brigadier</module>
|
||||||
<module>cloud-annotations</module>
|
<module>cloud-annotations</module>
|
||||||
|
<module>cloud-minecraft/cloud-bungee</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<inceptionYear>2020</inceptionYear>
|
<inceptionYear>2020</inceptionYear>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue