Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.8.4 #467

Merged
merged 8 commits into from
Sep 9, 2023
Merged

1.8.4 #467

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.8.4]

### Fixed
- Core: Flags not tab-completing unless string is empty ([#460](https://github.com/Incendo/cloud/pull/460))
- Core: Parser registry not properly resolving `TypeToken`s ([#454](https://github.com/Incendo/cloud/pull/454))
- Fabric: Pottery pattern registry overriding default string parser for annotations
- Fabric: Log cause of CommandExecutionException in fabric's default exception handler ([#466](https://github.com/Incendo/cloud/pull/466))

### Changed
- Core: Improved string parser supplier argument checking
- Bukkit/Paper: Improve docs around Brigadier support

## [1.8.3]

### Changed
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Snapshot builds of Cloud are available through the [Sonatype OSS Snapshot reposi
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-PLATFORM</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</dependency>
<!--
~ Optional: Allows you to use annotated methods
Expand All @@ -124,7 +124,7 @@ Snapshot builds of Cloud are available through the [Sonatype OSS Snapshot reposi
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-annotations</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</dependency>
```

Expand Down Expand Up @@ -185,7 +185,7 @@ repositories {

```kotlin
dependencies {
implementation("cloud.commandframework", "cloud-PLATFORM", "1.8.3")
implementation("cloud.commandframework", "cloud-PLATFORM", "1.8.4")
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import cloud.commandframework.permission.CommandPermission;
import cloud.commandframework.permission.OrPermission;
import cloud.commandframework.types.tuples.Pair;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -613,10 +612,6 @@ private CommandTree(final @NonNull CommandManager<C> commandManager) {
if (!lastFlag.isPresent()) {
commandContext.remove(FlagArgument.FLAG_META_KEY);
}
} else if (GenericTypeReflector.erase(child.getValue().getValueType().getType()).isArray()) {
while (commandQueue.size() > 1) {
commandQueue.remove();
}
} else if (commandQueue.size() <= child.getValue().getParser().getRequestedArgumentCount()) {
for (int i = 0; i < child.getValue().getParser().getRequestedArgumentCount() - 1
&& commandQueue.size() > 1; i++) {
Expand All @@ -636,7 +631,7 @@ private CommandTree(final @NonNull CommandManager<C> commandManager) {
} else if (child.getValue() instanceof CompoundArgument) {
return this.directSuggestions(commandContext, child, ((LinkedList<String>) commandQueue).getLast());
}
} else if (commandQueue.size() == 1 && commandQueue.peek().isEmpty()) {
} else if (commandQueue.size() == 1) {
return this.directSuggestions(commandContext, child, commandQueue.peek());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
import cloud.commandframework.arguments.standard.StringArrayArgument;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.context.CommandContext;
import io.leangen.geantyref.AnnotatedTypeMap;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedType;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -85,7 +87,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
};

private final Map<String, Function<ParserParameters, ArgumentParser<C, ?>>> namedParsers = new HashMap<>();
private final Map<TypeToken<?>, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new HashMap<>();
private final Map<AnnotatedType, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new AnnotatedTypeMap<>();
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
annotationMappers = new HashMap<>();
private final Map<String, BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<String>>>
Expand Down Expand Up @@ -152,16 +154,21 @@ public StandardParserRegistry() {
final boolean greedy = options.get(StandardParameters.GREEDY, false);
final boolean greedyFlagAware = options.get(StandardParameters.FLAG_YIELDING, false);
final boolean quoted = options.get(StandardParameters.QUOTED, false);
if (greedy && quoted) {
if (greedyFlagAware && quoted) {
throw new IllegalArgumentException(
"Don't know whether to create GREEDY_FLAG_YIELDING or QUOTED StringArgument.StringParser, both specified."
);
} else if (greedy && quoted) {
throw new IllegalArgumentException(
"Don't know whether to create GREEDY or QUOTED StringArgument.StringParser, both specified."
);
}
final StringArgument.StringMode stringMode;
if (greedy) {
stringMode = StringArgument.StringMode.GREEDY;
} else if (greedyFlagAware) {
// allow @Greedy and @FlagYielding to both be true, give flag yielding priority
if (greedyFlagAware) {
stringMode = StringArgument.StringMode.GREEDY_FLAG_YIELDING;
} else if (greedy) {
stringMode = StringArgument.StringMode.GREEDY;
} else if (quoted) {
stringMode = StringArgument.StringMode.QUOTED;
} else {
Expand Down Expand Up @@ -190,7 +197,7 @@ public <T> void registerParserSupplier(
final @NonNull Function<@NonNull ParserParameters,
@NonNull ArgumentParser<C, ?>> supplier
) {
this.parserSuppliers.put(type, supplier);
this.parserSuppliers.put(type.getAnnotatedType(), supplier);
}

@Override
Expand Down Expand Up @@ -243,7 +250,7 @@ public <A extends Annotation, T> void registerAnnotationMapper(
} else {
actualType = type;
}
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType);
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType.getAnnotatedType());
if (producer == null) {
/* Give enums special treatment */
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//
package cloud.commandframework;

import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.compound.ArgumentTriplet;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.standard.BooleanArgument;
Expand All @@ -37,8 +38,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Ignore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static cloud.commandframework.util.TestUtils.createManager;
Expand Down Expand Up @@ -635,6 +638,41 @@ void testFlagYieldingStringArrayWithLiberalFlagArgument() {
assertThat(suggestions6).isEmpty();
}

@Test
void testTextFlagCompletion() {
// Arrange
final CommandManager<TestCommandSender> manager = createManager();
manager.setSetting(CommandManager.ManagerSettings.LIBERAL_FLAG_PARSING, true);
manager.command(
manager.commandBuilder("command")
.flag(manager.flagBuilder("flag").withAliases("f")
.withArgument(EnumArgument.of(TestEnum.class, "test")).build())
.flag(manager.flagBuilder("flog").build())
);

// Act
final List<String> suggestions1 = suggest(manager, "command ");
final List<String> suggestions2 = suggest(manager, "command --");
final List<String> suggestions3 = suggest(manager, "command --f");
final List<String> suggestions4 = suggest(manager, "command --fla");
final List<String> suggestions5 = suggest(manager, "command -f");
final List<String> suggestions6 = suggest(manager, "command -");

final List<String> suggestions7 = suggest(manager, "command -f ");
final List<String> suggestions8 = suggest(manager, "command -f b");

// Assert
assertThat(suggestions1).containsExactly("--flag", "--flog", "-f");
assertThat(suggestions2).containsExactly("--flag", "--flog");
assertThat(suggestions3).containsExactly("--flag", "--flog");
assertThat(suggestions4).containsExactly("--flag");
assertThat(suggestions5).containsExactly("-f");
assertThat(suggestions6).containsExactly("--flag", "--flog", "-f");
assertThat(suggestions7).containsExactly("foo", "bar");
assertThat(suggestions8).containsExactly("bar");
}


private List<String> suggest(CommandManager<TestCommandSender> manager, String command) {
return manager.suggest(new TestCommandSender(), command);
}
Expand Down
22 changes: 11 additions & 11 deletions cloud-minecraft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ mappings will be available.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-bukkit</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-bukkit:1.8.3'
implementation 'cloud.commandframework:cloud-bukkit:1.8.4'
}
```

Expand Down Expand Up @@ -93,14 +93,14 @@ mappings are available even without commodore present.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-paper</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-paper:1.8.3'
implementation 'cloud.commandframework:cloud-paper:1.8.4'
}
```

Expand All @@ -118,14 +118,14 @@ BungeeCord mappings for cloud.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-bungee</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-bungee:1.8.3'
implementation 'cloud.commandframework:cloud-bungee:1.8.4'
}
```

Expand All @@ -150,14 +150,14 @@ cloud mappings for Velocity 1.1.0.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-velocity</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-velocity:1.8.3'
implementation 'cloud.commandframework:cloud-velocity:1.8.4'
}
```

Expand All @@ -181,14 +181,14 @@ cloud mappings for CloudBurst 1.0.0-SNAPSHOT.
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-cloudburst</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</dependency>
```

**gradle**:
```groovy
dependencies {
implementation 'cloud.commandframework:cloud-velocity:1.8.3'
implementation 'cloud.commandframework:cloud-velocity:1.8.4'
}
```

Expand Down Expand Up @@ -217,7 +217,7 @@ the latest release of cloud.
**gradle**:
```groovy
dependencies {
modImplementation 'cloud.commandframework:cloud-fabric:1.8.3'
modImplementation 'cloud.commandframework:cloud-fabric:1.8.4'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ public final boolean queryCapability(final @NonNull CloudBukkitCapabilities capa
}

/**
* Attempt to register the Brigadier mapper, and return it.
* Attempts to enable Brigadier command registration through Commodore.
*
* <p>Callers should check for {@link CloudBukkitCapabilities#COMMODORE_BRIGADIER} first
* to avoid exceptions.</p>
*
* @throws BrigadierFailureException If Brigadier isn't
* supported by the platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,36 @@
* Capabilities for the Bukkit module
*/
public enum CloudBukkitCapabilities implements CloudCapability {
/**
* Whether Brigadier is present in the current environment. Certain parser types require this, and are able to work
* even if a capability for Brigadier command registration is not present (as long as this capability is present).
*/
BRIGADIER(CraftBukkitReflection.classExists("com.mojang.brigadier.tree.CommandNode")
&& CraftBukkitReflection.findOBCClass("command.BukkitCommandWrapper") != null),

/**
* Whether support for native Brigadier command registration is available
* through the Paper API ({@code PaperCommandManager#registerBrigadier} from {@code cloud-paper}).
*/
NATIVE_BRIGADIER(CraftBukkitReflection.classExists(
"com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent")),

/**
* Whether support for Brigadier command registration is available through Commodore
* ({@link BukkitCommandManager#registerBrigadier}).
*
* <p><b>Note:</b> As of 1.19.2, Commodore simply delegates to the same Paper API as cloud is capable of using directly,
* doing nothing on non-Paper Bukkit implementations. As such, this capability will not be present in 1.19.2+ environments.
* Users should prefer using {@code PaperCommandManager} from {@code cloud-paper} and checking for
* {@link #NATIVE_BRIGADIER}.</p>
*/
COMMODORE_BRIGADIER(BRIGADIER.capable()
&& !NATIVE_BRIGADIER.capable()
&& !CraftBukkitReflection.classExists("org.bukkit.entity.Warden")),

/**
* Whether asynchronous command completions are supported through the Paper API.
*/
ASYNCHRONOUS_COMPLETION(CraftBukkitReflection.classExists(
"com.destroystokyo.paper.event.server.AsyncTabCompleteEvent"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private void registerRegistryEntryMappings() {
* Eventually, these could be resolved by using ParserParameters in some way? */
seenClasses.add(ResourceLocation.class);
seenClasses.add(Codec.class);
seenClasses.add(String.class); // avoid pottery pattern registry overriding default string parser
for (final Field field : Registries.class.getDeclaredFields()) {
if ((field.getModifiers() & MOD_PUBLIC_STATIC_FINAL) != MOD_PUBLIC_STATIC_FINAL) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void handleThrowable(final @NonNull S source, final @NonNull C sender, f
LOGGER.warn(
"Error occurred while executing command for user {}:",
this.getName.apply(source),
throwable
throwable.getCause()
);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,16 @@ public PaperCommandManager(
}

/**
* Register Brigadier mappings using the native paper events
* Attempts to enable Brigadier command registration through the Paper API, falling
* back to {@link BukkitCommandManager#registerBrigadier()} if that fails.
*
* <p>Callers should check for {@link CloudBukkitCapabilities#NATIVE_BRIGADIER} first
* to avoid exceptions.</p>
*
* <p>A check for {@link CloudBukkitCapabilities#NATIVE_BRIGADIER} {@code ||} {@link CloudBukkitCapabilities#COMMODORE_BRIGADIER}
* may also be appropriate for some use cases (because of the fallback behavior), but not most, as Commodore does not offer
* any functionality on modern
* versions (see the documentation for {@link CloudBukkitCapabilities#COMMODORE_BRIGADIER}).</p>
*
* @throws BrigadierFailureException Exception thrown if the mappings cannot be registered
*/
Expand Down
4 changes: 0 additions & 4 deletions examples/example-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ dependencies {
implementation(project(":cloud-annotations"))
implementation(project(":cloud-minecraft-extras"))
/* Extras */
implementation(libs.commodore) {
isTransitive = false
}
implementation(libs.adventurePlatformBukkit)
/* Bukkit */
compileOnly(libs.bukkit)
Expand All @@ -25,7 +22,6 @@ dependencies {
tasks {
shadowJar {
relocate("net.kyori", "cloud.commandframework.example.kyori")
relocate("me.lucko", "cloud.commandframework.example.lucko")
relocate("io.leangen.geantyref", "cloud.commandframework.example.geantyref")
}
assemble {
Expand Down
Loading