♻️ Reformat + Update .editorconfig
This commit is contained in:
parent
8bdec87a74
commit
2aac3980d5
169 changed files with 4261 additions and 2448 deletions
|
|
@ -61,8 +61,10 @@ public final class BukkitBrigadierMapper<C> {
|
|||
* @param commandManager The {@link BukkitCommandManager} to use for mapping
|
||||
* @param brigadierManager The {@link CloudBrigadierManager} to use for mapping
|
||||
*/
|
||||
public BukkitBrigadierMapper(final @NonNull BukkitCommandManager<C> commandManager,
|
||||
final @NonNull CloudBrigadierManager brigadierManager) {
|
||||
public BukkitBrigadierMapper(
|
||||
final @NonNull BukkitCommandManager<C> commandManager,
|
||||
final @NonNull CloudBrigadierManager brigadierManager
|
||||
) {
|
||||
this.commandManager = commandManager;
|
||||
this.brigadierManager = brigadierManager;
|
||||
|
||||
|
|
@ -90,8 +92,8 @@ public final class BukkitBrigadierMapper<C> {
|
|||
this.mapComplexNMS(MultiplePlayerSelector.class, this.getEntitySelectorArgument(false, true));
|
||||
} catch (final Exception e) {
|
||||
this.commandManager.getOwningPlugin()
|
||||
.getLogger()
|
||||
.log(Level.WARNING, "Failed to map Bukkit types to NMS argument types", e);
|
||||
.getLogger()
|
||||
.log(Level.WARNING, "Failed to map Bukkit types to NMS argument types", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,8 +102,10 @@ public final class BukkitBrigadierMapper<C> {
|
|||
* @param playersOnly Whether the selector is for players only (true), or for all entities (false)
|
||||
* @return The NMS ArgumentType
|
||||
*/
|
||||
private Supplier<ArgumentType<?>> getEntitySelectorArgument(final boolean single,
|
||||
final boolean playersOnly) {
|
||||
private Supplier<ArgumentType<?>> getEntitySelectorArgument(
|
||||
final boolean single,
|
||||
final boolean playersOnly
|
||||
) {
|
||||
return () -> {
|
||||
try {
|
||||
final Constructor<?> constructor = this.getNMSArgument("Entity").getDeclaredConstructors()[0];
|
||||
|
|
@ -132,8 +136,10 @@ public final class BukkitBrigadierMapper<C> {
|
|||
* @param type Type to map
|
||||
* @param constructor Constructor that construct the NMS argument type
|
||||
*/
|
||||
public void mapSimpleNMS(final @NonNull Class<?> type,
|
||||
final @NonNull Constructor<?> constructor) {
|
||||
public void mapSimpleNMS(
|
||||
final @NonNull Class<?> type,
|
||||
final @NonNull Constructor<?> constructor
|
||||
) {
|
||||
try {
|
||||
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, () -> {
|
||||
try {
|
||||
|
|
@ -145,9 +151,11 @@ public final class BukkitBrigadierMapper<C> {
|
|||
});
|
||||
} catch (final Exception e) {
|
||||
this.commandManager.getOwningPlugin()
|
||||
.getLogger()
|
||||
.warning(String.format("Failed to map '%s' to a Mojang serializable argument type",
|
||||
type.getCanonicalName()));
|
||||
.getLogger()
|
||||
.warning(String.format(
|
||||
"Failed to map '%s' to a Mojang serializable argument type",
|
||||
type.getCanonicalName()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,15 +165,20 @@ public final class BukkitBrigadierMapper<C> {
|
|||
* @param type Type to map
|
||||
* @param argumentTypeSupplier Supplier of the NMS argument type
|
||||
*/
|
||||
public void mapComplexNMS(final @NonNull Class<?> type,
|
||||
final @NonNull Supplier<ArgumentType<?>> argumentTypeSupplier) {
|
||||
public void mapComplexNMS(
|
||||
final @NonNull Class<?> type,
|
||||
final @NonNull Supplier<ArgumentType<?>> argumentTypeSupplier
|
||||
) {
|
||||
try {
|
||||
this.brigadierManager.registerDefaultArgumentTypeSupplier(type, argumentTypeSupplier);
|
||||
} catch (final Exception e) {
|
||||
this.commandManager.getOwningPlugin()
|
||||
.getLogger()
|
||||
.warning(String.format("Failed to map '%s' to a Mojang serializable argument type",
|
||||
type.getCanonicalName()));
|
||||
.getLogger()
|
||||
.warning(String.format(
|
||||
"Failed to map '%s' to a Mojang serializable argument type",
|
||||
type.getCanonicalName()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,83 +51,91 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
|||
private final Command<C> cloudCommand;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
BukkitCommand(final @NonNull String label,
|
||||
final @NonNull List<@NonNull String> aliases,
|
||||
final @NonNull Command<C> cloudCommand,
|
||||
final @NonNull CommandArgument<C, ?> command,
|
||||
final @NonNull BukkitCommandManager<C> manager) {
|
||||
super(label,
|
||||
cloudCommand.getCommandMeta().getOrDefault("description", ""),
|
||||
"",
|
||||
aliases);
|
||||
BukkitCommand(
|
||||
final @NonNull String label,
|
||||
final @NonNull List<@NonNull String> aliases,
|
||||
final @NonNull Command<C> cloudCommand,
|
||||
final @NonNull CommandArgument<C, ?> command,
|
||||
final @NonNull BukkitCommandManager<C> manager
|
||||
) {
|
||||
super(
|
||||
label,
|
||||
cloudCommand.getCommandMeta().getOrDefault("description", ""),
|
||||
"",
|
||||
aliases
|
||||
);
|
||||
this.command = command;
|
||||
this.manager = manager;
|
||||
this.cloudCommand = cloudCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final @NonNull CommandSender commandSender,
|
||||
final @NonNull String s,
|
||||
final @NonNull String @NonNull [] strings) {
|
||||
public boolean execute(
|
||||
final @NonNull CommandSender commandSender,
|
||||
final @NonNull String s,
|
||||
final @NonNull String @NonNull [] strings
|
||||
) {
|
||||
/* Join input */
|
||||
final StringBuilder builder = new StringBuilder(this.command.getName());
|
||||
for (final String string : strings) {
|
||||
builder.append(" ").append(string);
|
||||
}
|
||||
final C sender = this.manager.getCommandSenderMapper().apply(commandSender);
|
||||
this.manager.executeCommand(sender,
|
||||
builder.toString())
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof CompletionException) {
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
final Throwable finalThrowable = throwable;
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidSyntaxException.class,
|
||||
(InvalidSyntaxException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
ChatColor.RED + "Invalid Command Syntax. "
|
||||
+ "Correct command syntax is: "
|
||||
+ ChatColor.GRAY + "/"
|
||||
+ ((InvalidSyntaxException) finalThrowable)
|
||||
.getCorrectSyntax())
|
||||
);
|
||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidCommandSenderException.class,
|
||||
(InvalidCommandSenderException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
ChatColor.RED + finalThrowable.getMessage())
|
||||
);
|
||||
} else if (throwable instanceof NoPermissionException) {
|
||||
this.manager.handleException(sender,
|
||||
NoPermissionException.class,
|
||||
(NoPermissionException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_NO_PERMS)
|
||||
);
|
||||
} else if (throwable instanceof NoSuchCommandException) {
|
||||
this.manager.handleException(sender,
|
||||
NoSuchCommandException.class,
|
||||
(NoSuchCommandException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND)
|
||||
);
|
||||
} else if (throwable instanceof ArgumentParseException) {
|
||||
this.manager.handleException(sender,
|
||||
ArgumentParseException.class,
|
||||
(ArgumentParseException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
ChatColor.RED + "Invalid Command Argument: "
|
||||
+ ChatColor.GRAY + finalThrowable.getCause()
|
||||
.getMessage())
|
||||
);
|
||||
} else {
|
||||
commandSender.sendMessage(throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
this.manager.executeCommand(
|
||||
sender,
|
||||
builder.toString()
|
||||
)
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof CompletionException) {
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
}));
|
||||
final Throwable finalThrowable = throwable;
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidSyntaxException.class,
|
||||
(InvalidSyntaxException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
ChatColor.RED + "Invalid Command Syntax. "
|
||||
+ "Correct command syntax is: "
|
||||
+ ChatColor.GRAY + "/"
|
||||
+ ((InvalidSyntaxException) finalThrowable)
|
||||
.getCorrectSyntax())
|
||||
);
|
||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidCommandSenderException.class,
|
||||
(InvalidCommandSenderException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
ChatColor.RED + finalThrowable.getMessage())
|
||||
);
|
||||
} else if (throwable instanceof NoPermissionException) {
|
||||
this.manager.handleException(sender,
|
||||
NoPermissionException.class,
|
||||
(NoPermissionException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_NO_PERMS)
|
||||
);
|
||||
} else if (throwable instanceof NoSuchCommandException) {
|
||||
this.manager.handleException(sender,
|
||||
NoSuchCommandException.class,
|
||||
(NoSuchCommandException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND)
|
||||
);
|
||||
} else if (throwable instanceof ArgumentParseException) {
|
||||
this.manager.handleException(sender,
|
||||
ArgumentParseException.class,
|
||||
(ArgumentParseException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
ChatColor.RED + "Invalid Command Argument: "
|
||||
+ ChatColor.GRAY + finalThrowable.getCause()
|
||||
.getMessage())
|
||||
);
|
||||
} else {
|
||||
commandSender.sendMessage(throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -137,16 +145,20 @@ final class BukkitCommand<C> extends org.bukkit.command.Command implements Plugi
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(final @NonNull CommandSender sender,
|
||||
final @NonNull String alias,
|
||||
final @NonNull String @NonNull [] args)
|
||||
public List<String> tabComplete(
|
||||
final @NonNull CommandSender sender,
|
||||
final @NonNull String alias,
|
||||
final @NonNull String @NonNull [] args
|
||||
)
|
||||
throws IllegalArgumentException {
|
||||
final StringBuilder builder = new StringBuilder(this.command.getName());
|
||||
for (final String string : args) {
|
||||
builder.append(" ").append(string);
|
||||
}
|
||||
return this.manager.suggest(this.manager.getCommandSenderMapper().apply(sender),
|
||||
builder.toString());
|
||||
return this.manager.suggest(
|
||||
this.manager.getCommandSenderMapper().apply(sender),
|
||||
builder.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -89,11 +89,13 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
|||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||
* @throws Exception If the construction of the manager fails
|
||||
*/
|
||||
public BukkitCommandManager(final @NonNull Plugin owningPlugin,
|
||||
final @NonNull Function<@NonNull CommandTree<C>,
|
||||
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
|
||||
final @NonNull Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper)
|
||||
public BukkitCommandManager(
|
||||
final @NonNull Plugin owningPlugin,
|
||||
final @NonNull Function<@NonNull CommandTree<C>,
|
||||
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
|
||||
final @NonNull Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper
|
||||
)
|
||||
throws Exception {
|
||||
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler<>());
|
||||
((BukkitPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||
|
|
@ -108,14 +110,16 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
|||
int version = -1;
|
||||
try {
|
||||
final Matcher matcher = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)")
|
||||
.matcher(Bukkit.getVersion());
|
||||
.matcher(Bukkit.getVersion());
|
||||
if (matcher.find()) {
|
||||
version = Integer.parseInt(matcher.toMatchResult().group(2),
|
||||
VERSION_RADIX);
|
||||
version = Integer.parseInt(
|
||||
matcher.toMatchResult().group(2),
|
||||
VERSION_RADIX
|
||||
);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
this.owningPlugin.getLogger().severe("Failed to determine Minecraft version "
|
||||
+ "for cloud Bukkit capability detection");
|
||||
+ "for cloud Bukkit capability detection");
|
||||
}
|
||||
this.minecraftVersion = version;
|
||||
|
||||
|
|
@ -132,13 +136,17 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
|||
|
||||
/* Register Bukkit Parsers */
|
||||
this.getParserRegistry().registerParserSupplier(TypeToken.get(World.class), params -> new WorldArgument.WorldParser<>());
|
||||
this.getParserRegistry().registerParserSupplier(TypeToken.get(Material.class),
|
||||
params -> new MaterialArgument.MaterialParser<>());
|
||||
this.getParserRegistry().registerParserSupplier(
|
||||
TypeToken.get(Material.class),
|
||||
params -> new MaterialArgument.MaterialParser<>()
|
||||
);
|
||||
this.getParserRegistry()
|
||||
.registerParserSupplier(TypeToken.get(Player.class), params -> new PlayerArgument.PlayerParser<>());
|
||||
.registerParserSupplier(TypeToken.get(Player.class), params -> new PlayerArgument.PlayerParser<>());
|
||||
this.getParserRegistry()
|
||||
.registerParserSupplier(TypeToken.get(OfflinePlayer.class),
|
||||
params -> new OfflinePlayerArgument.OfflinePlayerParser<>());
|
||||
.registerParserSupplier(
|
||||
TypeToken.get(OfflinePlayer.class),
|
||||
params -> new OfflinePlayerArgument.OfflinePlayerParser<>()
|
||||
);
|
||||
/* Register Entity Selector Parsers */
|
||||
this.getParserRegistry().registerParserSupplier(TypeToken.get(SingleEntitySelector.class), parserParameters ->
|
||||
new SingleEntitySelectorArgument.SingleEntitySelectorParser<>());
|
||||
|
|
@ -195,18 +203,20 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
|||
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
||||
}
|
||||
|
||||
protected final void setSplitAliases(final boolean value) {
|
||||
this.splitAliases = value;
|
||||
}
|
||||
|
||||
protected final boolean getSplitAliases() {
|
||||
return this.splitAliases;
|
||||
}
|
||||
|
||||
protected final void setSplitAliases(final boolean value) {
|
||||
this.splitAliases = value;
|
||||
}
|
||||
|
||||
protected final void checkBrigadierCompatibility() throws BrigadierFailureException {
|
||||
if (!this.queryCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
throw new BrigadierFailureException(BrigadierFailureReason.VERSION_TOO_LOW,
|
||||
new IllegalArgumentException("Version: " + this.minecraftVersion));
|
||||
throw new BrigadierFailureException(
|
||||
BrigadierFailureReason.VERSION_TOO_LOW,
|
||||
new IllegalArgumentException("Version: " + this.minecraftVersion)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -229,21 +239,27 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
|||
if (this.paper) {
|
||||
if (this.minecraftVersion >= ASYNC_TAB_MINIMUM_VERSION) {
|
||||
if (this.minecraftVersion >= PAPER_BRIGADIER_VERSION) {
|
||||
return EnumSet.of(CloudBukkitCapabilities.NATIVE_BRIGADIER,
|
||||
CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION,
|
||||
CloudBukkitCapabilities.BRIGADIER);
|
||||
return EnumSet.of(
|
||||
CloudBukkitCapabilities.NATIVE_BRIGADIER,
|
||||
CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION,
|
||||
CloudBukkitCapabilities.BRIGADIER
|
||||
);
|
||||
} else if (this.minecraftVersion >= BRIGADIER_MINIMUM_VERSION) {
|
||||
return EnumSet.of(CloudBukkitCapabilities.COMMODORE_BRIGADIER,
|
||||
CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION,
|
||||
CloudBukkitCapabilities.BRIGADIER);
|
||||
return EnumSet.of(
|
||||
CloudBukkitCapabilities.COMMODORE_BRIGADIER,
|
||||
CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION,
|
||||
CloudBukkitCapabilities.BRIGADIER
|
||||
);
|
||||
} else {
|
||||
return EnumSet.of(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.minecraftVersion >= BRIGADIER_MINIMUM_VERSION) {
|
||||
return EnumSet.of(CloudBukkitCapabilities.COMMODORE_BRIGADIER,
|
||||
CloudBukkitCapabilities.BRIGADIER);
|
||||
return EnumSet.of(
|
||||
CloudBukkitCapabilities.COMMODORE_BRIGADIER,
|
||||
CloudBukkitCapabilities.BRIGADIER
|
||||
);
|
||||
}
|
||||
}
|
||||
return EnumSet.noneOf(CloudBukkitCapabilities.class);
|
||||
|
|
@ -320,9 +336,11 @@ public class BukkitCommandManager<C> extends CommandManager<C> {
|
|||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return String.format("Could not initialize Brigadier mappings. Reason: %s (%s)",
|
||||
this.reason.name().toLowerCase().replace("_", " "),
|
||||
this.getCause() == null ? "" : this.getCause().getMessage());
|
||||
return String.format(
|
||||
"Could not initialize Brigadier mappings. Reason: %s (%s)",
|
||||
this.reason.name().toLowerCase().replace("_", " "),
|
||||
this.getCause() == null ? "" : this.getCause().getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,4 +41,5 @@ final class BukkitPlayerSender extends BukkitCommandSender {
|
|||
public @NonNull Player asPlayer() {
|
||||
return (Player) this.getInternalSender();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
|
||||
final String label;
|
||||
final String prefixedLabel = String.format("%s:%s", this.bukkitCommandManager.getOwningPlugin().getName(),
|
||||
commandArgument.getName()).toLowerCase();
|
||||
commandArgument.getName()
|
||||
).toLowerCase();
|
||||
if (!(this.bukkitCommandManager.getCommandRegistrationHandler() instanceof CloudCommodoreManager)
|
||||
&& bukkitCommands.containsKey(commandArgument.getName())) {
|
||||
label = prefixedLabel;
|
||||
|
|
@ -87,8 +88,7 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
label = commandArgument.getName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<String> aliases = new ArrayList<>(((StaticArgument<C>) commandArgument).getAlternativeAliases());
|
||||
@SuppressWarnings("unchecked") final List<String> aliases = new ArrayList<>(((StaticArgument<C>) commandArgument).getAlternativeAliases());
|
||||
|
||||
if (!label.contains(":")) {
|
||||
aliases.add(prefixedLabel);
|
||||
|
|
@ -99,11 +99,14 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
(this.bukkitCommandManager.getSplitAliases() ? Collections.<String>emptyList() : aliases),
|
||||
(Command<C>) command,
|
||||
(CommandArgument<C, ?>) commandArgument,
|
||||
this.bukkitCommandManager);
|
||||
this.bukkitCommandManager
|
||||
);
|
||||
this.registeredCommands.put(commandArgument, bukkitCommand);
|
||||
this.commandMap.register(label,
|
||||
this.bukkitCommandManager.getOwningPlugin().getName().toLowerCase(),
|
||||
bukkitCommand);
|
||||
this.commandMap.register(
|
||||
label,
|
||||
this.bukkitCommandManager.getOwningPlugin().getName().toLowerCase(),
|
||||
bukkitCommand
|
||||
);
|
||||
this.registerExternal(label, command, bukkitCommand);
|
||||
this.recognizedAliases.add(label);
|
||||
|
||||
|
|
@ -115,10 +118,12 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
Collections.emptyList(),
|
||||
(Command<C>) command,
|
||||
(CommandArgument<C, ?>) commandArgument,
|
||||
this.bukkitCommandManager);
|
||||
this.bukkitCommandManager
|
||||
);
|
||||
this.commandMap.register(alias, this.bukkitCommandManager.getOwningPlugin()
|
||||
.getName().toLowerCase(),
|
||||
bukkitCommand);
|
||||
.getName().toLowerCase(),
|
||||
bukkitCommand
|
||||
);
|
||||
this.registerExternal(alias, command, aliasCommand);
|
||||
this.recognizedAliases.add(alias);
|
||||
}
|
||||
|
|
@ -138,9 +143,11 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
return this.recognizedAliases.contains(alias);
|
||||
}
|
||||
|
||||
protected void registerExternal(final @NonNull String label,
|
||||
final @NonNull Command<?> command,
|
||||
final @NonNull BukkitCommand<C> bukkitCommand) {
|
||||
protected void registerExternal(
|
||||
final @NonNull String label,
|
||||
final @NonNull Command<?> command,
|
||||
final @NonNull BukkitCommand<C> bukkitCommand
|
||||
) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ final class BukkitSynchronizer implements TaskSynchronizer {
|
|||
|
||||
@Override
|
||||
public <I> CompletableFuture<Void> runSynchronous(final @NonNull I input, final @NonNull TaskConsumer<I> consumer) {
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
this.plugin.getServer().getScheduler().runTask(this.plugin, () -> {
|
||||
consumer.accept(input);
|
||||
future.complete(null);
|
||||
});
|
||||
return future;
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
this.plugin.getServer().getScheduler().runTask(this.plugin, () -> {
|
||||
consumer.accept(input);
|
||||
future.complete(null);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,5 +27,8 @@ package cloud.commandframework.bukkit;
|
|||
* Capabilities for the Bukkit module
|
||||
*/
|
||||
public enum CloudBukkitCapabilities {
|
||||
BRIGADIER, COMMODORE_BRIGADIER, NATIVE_BRIGADIER, ASYNCHRONOUS_COMPLETION
|
||||
BRIGADIER,
|
||||
COMMODORE_BRIGADIER,
|
||||
NATIVE_BRIGADIER,
|
||||
ASYNCHRONOUS_COMPLETION
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
|||
throws BukkitCommandManager.BrigadierFailureException {
|
||||
if (!CommodoreProvider.isSupported()) {
|
||||
throw new BukkitCommandManager.BrigadierFailureException(BukkitCommandManager
|
||||
.BrigadierFailureReason.COMMODORE_NOT_PRESENT);
|
||||
.BrigadierFailureReason.COMMODORE_NOT_PRESENT);
|
||||
}
|
||||
this.commandManager = commandManager;
|
||||
this.commodore = CommodoreProvider.getCommodore(commandManager.getOwningPlugin());
|
||||
|
|
@ -59,21 +59,27 @@ class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerExternal(final @NonNull String label,
|
||||
final @NonNull Command<?> command,
|
||||
final @NonNull BukkitCommand<C> bukkitCommand) {
|
||||
protected void registerExternal(
|
||||
final @NonNull String label,
|
||||
final @NonNull Command<?> command,
|
||||
final @NonNull BukkitCommand<C> bukkitCommand
|
||||
) {
|
||||
this.registerWithCommodore(label, command);
|
||||
this.registerWithCommodore(String.format("%s:%s", bukkitCommand.getPlugin().getName(), label).toLowerCase(), command);
|
||||
}
|
||||
|
||||
private void registerWithCommodore(final @NonNull String label,
|
||||
final @NonNull Command<?> command) {
|
||||
private void registerWithCommodore(
|
||||
final @NonNull String label,
|
||||
final @NonNull Command<?> command
|
||||
) {
|
||||
final com.mojang.brigadier.Command<?> cmd = o -> 1;
|
||||
final LiteralCommandNode<?> literalCommandNode = this.brigadierManager
|
||||
.<Object>createLiteralCommandNode(label, command, (o, p) -> {
|
||||
final CommandSender sender = this.commodore.getBukkitSender(o);
|
||||
return this.commandManager.hasPermission(this.commandManager.getCommandSenderMapper().apply(sender),
|
||||
(CommandPermission) p);
|
||||
return this.commandManager.hasPermission(
|
||||
this.commandManager.getCommandSenderMapper().apply(sender),
|
||||
(CommandPermission) p
|
||||
);
|
||||
}, false, cmd);
|
||||
final CommandNode existingNode = this.commodore.getDispatcher().findNode(Collections.singletonList(label));
|
||||
if (existingNode != null) {
|
||||
|
|
|
|||
|
|
@ -43,8 +43,10 @@ public abstract class EntitySelector {
|
|||
* @param selector The input string used to create this selector
|
||||
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public EntitySelector(final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities) {
|
||||
public EntitySelector(
|
||||
final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities
|
||||
) {
|
||||
this.selector = selector;
|
||||
this.entities = entities;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,10 @@ public class MultipleEntitySelector extends EntitySelector {
|
|||
* @param selector The input string used to create this selector
|
||||
* @param entities The List of Bukkit {@link Entity}s to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public MultipleEntitySelector(final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities) {
|
||||
public MultipleEntitySelector(
|
||||
final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities
|
||||
) {
|
||||
super(selector, entities);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,10 @@ public class MultiplePlayerSelector extends MultipleEntitySelector {
|
|||
* @param selector The input string used to create this selector
|
||||
* @param entities The List of Bukkit {@link Entity}s to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public MultiplePlayerSelector(final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities) {
|
||||
public MultiplePlayerSelector(
|
||||
final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities
|
||||
) {
|
||||
super(selector, entities);
|
||||
entities.forEach(e -> {
|
||||
if (e.getType() != EntityType.PLAYER) {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,10 @@ public final class SingleEntitySelector extends MultipleEntitySelector {
|
|||
* @param selector The input string used to create this selector
|
||||
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public SingleEntitySelector(final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities) {
|
||||
public SingleEntitySelector(
|
||||
final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities
|
||||
) {
|
||||
super(selector, entities);
|
||||
if (entities.size() > 1) {
|
||||
throw new IllegalArgumentException("More than 1 entity selected in single entity selector.");
|
||||
|
|
|
|||
|
|
@ -37,8 +37,10 @@ public final class SinglePlayerSelector extends MultiplePlayerSelector {
|
|||
* @param selector The input string used to create this selector
|
||||
* @param entities The List of Bukkit {@link Entity entities} to construct the {@link EntitySelector} from
|
||||
*/
|
||||
public SinglePlayerSelector(final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities) {
|
||||
public SinglePlayerSelector(
|
||||
final @NonNull String selector,
|
||||
final @NonNull List<@NonNull Entity> entities
|
||||
) {
|
||||
super(selector, entities);
|
||||
if (getPlayers().size() > 1) {
|
||||
throw new IllegalArgumentException("More than 1 player selected in single player selector.");
|
||||
|
|
|
|||
|
|
@ -44,11 +44,13 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
public class MaterialArgument<C> extends CommandArgument<C, Material> {
|
||||
|
||||
protected MaterialArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||
protected MaterialArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new MaterialParser<>(), defaultValue, Material.class, suggestionsProvider);
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +95,10 @@ public class MaterialArgument<C> extends CommandArgument<C, Material> {
|
|||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, Material> optional(final @NonNull String name,
|
||||
final @NonNull Material material) {
|
||||
public static <C> @NonNull CommandArgument<C, Material> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull Material material
|
||||
) {
|
||||
return MaterialArgument.<C>newBuilder(name).asOptionalWithDefault(material.name().toLowerCase()).build();
|
||||
}
|
||||
|
||||
|
|
@ -110,8 +114,10 @@ public class MaterialArgument<C> extends CommandArgument<C, Material> {
|
|||
public static final class MaterialParser<C> implements ArgumentParser<C, Material> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<Material> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<Material> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
|
|
@ -154,8 +160,9 @@ public class MaterialArgument<C> extends CommandArgument<C, Material> {
|
|||
@Override
|
||||
public String getMessage() {
|
||||
return EnumSet.allOf(Material.class).stream().map(Material::name).map(String::toLowerCase)
|
||||
.collect(Collectors.joining(", "));
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,11 +49,13 @@ import java.util.function.BiFunction;
|
|||
@SuppressWarnings("unused")
|
||||
public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePlayer> {
|
||||
|
||||
private OfflinePlayerArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||
private OfflinePlayerArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new OfflinePlayerParser<>(), defaultValue, OfflinePlayer.class, suggestionsProvider);
|
||||
}
|
||||
|
||||
|
|
@ -98,8 +100,10 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
|||
* @param <C> Command sender type
|
||||
* @return Created component
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, OfflinePlayer> optional(final @NonNull String name,
|
||||
final @NonNull String defaultPlayer) {
|
||||
public static <C> @NonNull CommandArgument<C, OfflinePlayer> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultPlayer
|
||||
) {
|
||||
return OfflinePlayerArgument.<C>newBuilder(name).asOptionalWithDefault(defaultPlayer).build();
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +122,8 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
|||
@Override
|
||||
public @NonNull OfflinePlayerArgument<C> build() {
|
||||
return new OfflinePlayerArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(),
|
||||
this.getSuggestionsProvider());
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -127,8 +132,10 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
|||
public static final class OfflinePlayerParser<C> implements ArgumentParser<C, OfflinePlayer> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<OfflinePlayer> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<OfflinePlayer> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
|
|
@ -146,8 +153,10 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input) {
|
||||
public @NonNull List<@NonNull String> suggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input
|
||||
) {
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
|
@ -156,6 +165,7 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -188,5 +198,7 @@ public final class OfflinePlayerArgument<C> extends CommandArgument<C, OfflinePl
|
|||
public String getMessage() {
|
||||
return String.format("No player found for input '%s'.", input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,11 +45,13 @@ import java.util.function.BiFunction;
|
|||
@SuppressWarnings("unused")
|
||||
public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
||||
|
||||
private PlayerArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||
private PlayerArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new PlayerParser<>(), defaultValue, Player.class, suggestionsProvider);
|
||||
}
|
||||
|
||||
|
|
@ -94,8 +96,10 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
|||
* @param <C> Command sender type
|
||||
* @return Created component
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, Player> optional(final @NonNull String name,
|
||||
final @NonNull String defaultPlayer) {
|
||||
public static <C> @NonNull CommandArgument<C, Player> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultPlayer
|
||||
) {
|
||||
return PlayerArgument.<C>newBuilder(name).asOptionalWithDefault(defaultPlayer).build();
|
||||
}
|
||||
|
||||
|
|
@ -122,8 +126,10 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
|||
public static final class PlayerParser<C> implements ArgumentParser<C, Player> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<Player> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<Player> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
|
|
@ -141,8 +147,10 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input) {
|
||||
public @NonNull List<@NonNull String> suggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input
|
||||
) {
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
|
@ -151,6 +159,7 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -183,5 +192,7 @@ public final class PlayerArgument<C> extends CommandArgument<C, Player> {
|
|||
public String getMessage() {
|
||||
return String.format("No player found for input '%s'.", input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,10 +44,12 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
public class WorldArgument<C> extends CommandArgument<C, World> {
|
||||
|
||||
protected WorldArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
||||
protected WorldArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new WorldParser<>(), defaultValue, World.class, suggestionsProvider);
|
||||
}
|
||||
|
||||
|
|
@ -92,8 +94,10 @@ public class WorldArgument<C> extends CommandArgument<C, World> {
|
|||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, World> optional(final @NonNull String name,
|
||||
final @NonNull String defaultValue) {
|
||||
public static <C> @NonNull CommandArgument<C, World> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue
|
||||
) {
|
||||
return WorldArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
|
||||
}
|
||||
|
||||
|
|
@ -108,14 +112,17 @@ public class WorldArgument<C> extends CommandArgument<C, World> {
|
|||
public @NonNull CommandArgument<C, World> build() {
|
||||
return new WorldArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static final class WorldParser<C> implements ArgumentParser<C, World> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<World> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<World> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
|
|
@ -164,6 +171,7 @@ public class WorldArgument<C> extends CommandArgument<C, World> {
|
|||
public String getMessage() {
|
||||
return String.format("'%s' is not a valid Minecraft world", this.input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,13 +41,16 @@ import java.util.function.BiFunction;
|
|||
|
||||
public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C, MultipleEntitySelector> {
|
||||
|
||||
private MultipleEntitySelectorArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||
private MultipleEntitySelectorArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new MultipleEntitySelectorParser<>(), defaultValue, MultipleEntitySelector.class,
|
||||
suggestionsProvider);
|
||||
suggestionsProvider
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -91,8 +94,10 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, MultipleEntitySelector> optional(final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector) {
|
||||
public static <C> @NonNull CommandArgument<C, MultipleEntitySelector> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector
|
||||
) {
|
||||
return MultipleEntitySelectorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultEntitySelector).build();
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +116,8 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
@Override
|
||||
public @NonNull MultipleEntitySelectorArgument<C> build() {
|
||||
return new MultipleEntitySelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(),
|
||||
this.getSuggestionsProvider());
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -120,8 +126,10 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
public static final class MultipleEntitySelectorParser<C> implements ArgumentParser<C, MultipleEntitySelector> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<MultipleEntitySelector> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<MultipleEntitySelector> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
if (!commandContext.<Set<CloudBukkitCapabilities>>get("CloudBukkitCapabilities").contains(
|
||||
CloudBukkitCapabilities.BRIGADIER)) {
|
||||
return ArgumentParseResult.failure(
|
||||
|
|
@ -142,6 +150,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
|
||||
return ArgumentParseResult.success(new MultipleEntitySelector(input, entities));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,13 +45,16 @@ import java.util.function.BiFunction;
|
|||
|
||||
public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C, MultiplePlayerSelector> {
|
||||
|
||||
private MultiplePlayerSelectorArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||
private MultiplePlayerSelectorArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new MultiplePlayerSelectorParser<>(), defaultValue, MultiplePlayerSelector.class,
|
||||
suggestionsProvider);
|
||||
suggestionsProvider
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -95,8 +98,10 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, MultiplePlayerSelector> optional(final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector) {
|
||||
public static <C> @NonNull CommandArgument<C, MultiplePlayerSelector> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector
|
||||
) {
|
||||
return MultiplePlayerSelectorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultEntitySelector).build();
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +120,8 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
@Override
|
||||
public @NonNull MultiplePlayerSelectorArgument<C> build() {
|
||||
return new MultiplePlayerSelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(),
|
||||
this.getSuggestionsProvider());
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -124,8 +130,10 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
public static final class MultiplePlayerSelectorParser<C> implements ArgumentParser<C, MultiplePlayerSelector> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<MultiplePlayerSelector> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<MultiplePlayerSelector> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
|
|
@ -160,8 +168,10 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input) {
|
||||
public @NonNull List<@NonNull String> suggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input
|
||||
) {
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
|
@ -170,6 +180,7 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,4 +54,5 @@ public final class SelectorParseException extends IllegalArgumentException {
|
|||
public String getMessage() {
|
||||
return String.format("Selector '%s' is malformed.", input);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,11 +41,13 @@ import java.util.function.BiFunction;
|
|||
|
||||
public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, SingleEntitySelector> {
|
||||
|
||||
private SingleEntitySelectorArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||
private SingleEntitySelectorArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new SingleEntitySelectorParser<>(), defaultValue, SingleEntitySelector.class, suggestionsProvider);
|
||||
}
|
||||
|
||||
|
|
@ -90,8 +92,10 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, SingleEntitySelector> optional(final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector) {
|
||||
public static <C> @NonNull CommandArgument<C, SingleEntitySelector> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector
|
||||
) {
|
||||
return SingleEntitySelectorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultEntitySelector).build();
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +114,8 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
@Override
|
||||
public @NonNull SingleEntitySelectorArgument<C> build() {
|
||||
return new SingleEntitySelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(),
|
||||
this.getSuggestionsProvider());
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -119,8 +124,10 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
public static final class SingleEntitySelectorParser<C> implements ArgumentParser<C, SingleEntitySelector> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<SingleEntitySelector> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<SingleEntitySelector> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
if (!commandContext.<Set<CloudBukkitCapabilities>>get("CloudBukkitCapabilities").contains(
|
||||
CloudBukkitCapabilities.BRIGADIER)) {
|
||||
return ArgumentParseResult.failure(
|
||||
|
|
@ -146,6 +153,7 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
|
||||
return ArgumentParseResult.success(new SingleEntitySelector(input, entities));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,11 +45,13 @@ import java.util.function.BiFunction;
|
|||
|
||||
public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, SinglePlayerSelector> {
|
||||
|
||||
private SinglePlayerSelectorArgument(final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider) {
|
||||
private SinglePlayerSelectorArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultValue,
|
||||
final @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||
@NonNull List<@NonNull String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new SinglePlayerSelectorParser<>(), defaultValue, SinglePlayerSelector.class, suggestionsProvider);
|
||||
}
|
||||
|
||||
|
|
@ -94,8 +96,10 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull CommandArgument<C, SinglePlayerSelector> optional(final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector) {
|
||||
public static <C> @NonNull CommandArgument<C, SinglePlayerSelector> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull String defaultEntitySelector
|
||||
) {
|
||||
return SinglePlayerSelectorArgument.<C>newBuilder(name).asOptionalWithDefault(defaultEntitySelector).build();
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +118,8 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
@Override
|
||||
public @NonNull SinglePlayerSelectorArgument<C> build() {
|
||||
return new SinglePlayerSelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(),
|
||||
this.getSuggestionsProvider());
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -123,8 +128,10 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
public static final class SinglePlayerSelectorParser<C> implements ArgumentParser<C, SinglePlayerSelector> {
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<SinglePlayerSelector> parse(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue) {
|
||||
public @NonNull ArgumentParseResult<SinglePlayerSelector> parse(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
|
|
@ -163,8 +170,10 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<@NonNull String> suggestions(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input) {
|
||||
public @NonNull List<@NonNull String> suggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input
|
||||
) {
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
|
@ -173,6 +182,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue