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

fabric, take 3 or something #223

Merged
merged 40 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
21a292e
fabric: Begin work on commands manager for platform
zml2008 Nov 25, 2020
b699242
fabric: Use stateful command manager
zml2008 Dec 16, 2020
36b0499
fabric: Add registration environment meta
zml2008 Jan 1, 2021
d27f497
brigadier: Add support for wrapped parsers
zml2008 Jan 3, 2021
69aca60
fabric: Begin adding support for some wrapped vanilla arguments
zml2008 Jan 3, 2021
4f82b86
core: Add a way to map the output of argument parsers
zml2008 Jan 4, 2021
cf66869
fabric: Split out server-specific command manager to allow for client…
zml2008 Jan 4, 2021
8d89915
fabric: Add builders for many of the basic argument types
zml2008 Jan 4, 2021
e808904
brigadier: Allow specifying a custom brigadier suggestions provider
zml2008 Jan 5, 2021
19701b5
fabric: Fully implement a registry entry argument type
zml2008 Jan 5, 2021
846e1e4
More parser work
zml2008 Jan 8, 2021
781761a
brigadier: Unwrap mapped argument parsers
zml2008 Jan 10, 2021
50da96c
fabric: work
zml2008 Jan 12, 2021
81fb37a
bump MC version
zml2008 Jan 16, 2021
6ba5551
fabric: More work
zml2008 Jan 16, 2021
ba949c4
license headers
zml2008 Jan 31, 2021
4d172f3
fabric: update loom to 0.6-SNAPSHOT
jpenilla Feb 3, 2021
abc86a1
fabric: check permissions using fabric-permissions-api
jpenilla Feb 4, 2021
569ecdf
fabric: register forwards mapper with the BrigadierManager
jpenilla Feb 6, 2021
72ad112
fabric: only strip the starting '/' from input when it is actually there
jpenilla Feb 6, 2021
8735c7d
fabric: use Velocity's workaround for https://github.com/Mojang/briga…
jpenilla Feb 7, 2021
b57f3bd
fix brigadier suggestions with the '/execute' command, fix running cl…
jpenilla Feb 7, 2021
6dd93ff
fabric: Implement FabricClientCommandManager
jpenilla Mar 10, 2021
d5e47ae
brigadier: Fix MappedArgumentParsers always mapping to string
jpenilla Mar 11, 2021
1b49450
fabric: Implement entity/player selector argument types
jpenilla Mar 11, 2021
24a7ff3
fabric: Remove unfinished argument types, add some javadoc, fix check…
jpenilla Mar 11, 2021
526b415
fabric: Add a couple more commands to the test mod
jpenilla Mar 11, 2021
7d5ce9d
fabric: minor formatting/javadoc fixes
jpenilla Mar 12, 2021
7bfc061
fabric: javadoc cleanup
jpenilla Mar 12, 2021
e01092f
brigadier: add `@since` tags
jpenilla Mar 12, 2021
0b768c7
fabric: add more nullability annotations
jpenilla Mar 12, 2021
89eaec1
fabric: implement location argument types
jpenilla Mar 13, 2021
d00e92c
fabric: fix javadoc on `@Center` annotation, add myself to fabric.mod…
jpenilla Mar 13, 2021
e602f95
fabric: use interfaces for entity selectors
jpenilla Mar 13, 2021
81dc3b5
fabric: add some pre-built predicate permissions for the client comma…
jpenilla Mar 13, 2021
80a07fd
fabric: add missing since tags
jpenilla Mar 13, 2021
bf689c8
fabric: fix checkstyle issues
jpenilla Mar 13, 2021
97bd549
fabric: remove redundant `@Unique`
jpenilla Mar 16, 2021
25bee05
Remove todos
jpenilla Mar 19, 2021
b2900c1
Remove Dokka linking that didn't work anyways
jpenilla Mar 20, 2021
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
7 changes: 7 additions & 0 deletions .checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="(?:(?:Member|Method)Name|DesignForExtension|Javadoc.*)" files=".*[\\/]mixin[\\/].*"/>
</suppressions>
6 changes: 3 additions & 3 deletions .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@

<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
default="checkstyle-suppressions.xml"/>
<property name="optional" value="true"/>
<property name="file" value="${config_loc}/checkstyle-suppressions.xml"/>
<property name="optional" value="false"/>
</module>

<!-- Checks that a package-info.java file exists for each package. -->
Expand All @@ -101,6 +100,7 @@
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="140"/>
<property name="ignorePattern" value="^ *\* "/> <!-- Ignore long JavaDoc lines (i.e. a link) -->
</module>

<!-- Checks for whitespace -->
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,7 @@ gradle-app.setting
**/build/

# End of https://www.toptal.com/developers/gitignore/api/git,java,eclipse,jetbrains+all,gradle

### Fabric Loom run files ###

/run/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The code is based on a (W.I.P) paper that can be found [here](https://github.com
- **cloud-minecraft/cloud-bungee**: BungeeCord 1.8.8+ implementation of Cloud
- **cloud-minecraft/cloud-velocity**: Velocity v1.1.0 implementation of cloud
- **cloud-minecraft/cloud-cloudburst**: Cloudburst v1.0.0+ implementation of cloud
- **cloud-minecraft/cloud-fabric**: Fabric implementation of Cloud
- **cloud-minecraft/cloud-minecraft-extras**: Opinionated Extra Features for cloud-minecraft
- **cloud-discord/cloud-jda**: JDA v4.2.0_209+ implementation of cloud
- **cloud-discord/cloud-javacord**: Javacord v3.1.1+ implementation of cloud
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ object Versions {
const val spongeApi7 = "7.3.0"
const val jetbrainsAnnotations = "20.1.0"
const val guava = "21.0-jre"
const val fabricLoader = "0.11.1"
const val fabricMc = "1.16.5"
const val fabricYarn = "1"
const val fabricApi = "0.31.0+1.16"

// IRC DEPENDENCIES
const val pircbotx = "83a4c22e80"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,98 @@ protected final boolean isRequired() {
return this.defaultDescription;
}

protected final @NonNull TypeToken<T> getValueType() {
return this.valueType;
}

}

/**
* A variant of builders designed for subclassing, that returns a self type .
*
* @param <C> sender type
* @param <T> argument value type
* @param <B> the subclass type
* @since 1.5.0
*/
public abstract static class TypedBuilder<C, T, B extends Builder<C, T>> extends Builder<C, T> {

protected TypedBuilder(
final @NonNull TypeToken<T> valueType,
final @NonNull String name
) {
super(valueType, name);
}

protected TypedBuilder(
final @NonNull Class<T> valueType,
final @NonNull String name
) {
super(valueType, name);
}

@SuppressWarnings("unchecked")
protected final B self() {
return (B) this;
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull B manager(final @NonNull CommandManager<C> manager) {
super.manager(manager);
return this.self();
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull B asRequired() {
super.asRequired();
return this.self();
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull B asOptional() {
super.asOptional();
return this.self();
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull B asOptionalWithDefault(final @NonNull String defaultValue) {
super.asOptionalWithDefault(defaultValue);
return this.self();
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull B withParser(final @NonNull ArgumentParser<@NonNull C, @NonNull T> parser) {
super.withParser(parser);
return this.self();
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull Builder<@NonNull C, @NonNull T> withSuggestionsProvider(
final @NonNull BiFunction<@NonNull CommandContext<C>,
@NonNull String, @NonNull List<String>> suggestionsProvider
) {
super.withSuggestionsProvider(suggestionsProvider);
return this.self();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Optional;
import java.util.function.Function;

/**
* Result of the parsing done by a {@link ArgumentParser}
Expand Down Expand Up @@ -66,13 +67,42 @@ private ArgumentParseResult() {
*/
public abstract @NonNull Optional<T> getParsedValue();

/**
* If this result is successful, transform the output value.
*
* @param mapper the transformation
* @param <U> the result type
* @return a new result if successful, otherwise a failure
* @since 1.5.0
*/
public abstract <U> @NonNull ArgumentParseResult<U> mapParsedValue(Function<T, U> mapper);

/**
* If this result is successful, transform the output value, returning another parse result.
*
* @param mapper the transformation
* @param <U> the result type
* @return a new result if successful, otherwise a failure
* @since 1.5.0
*/
public abstract <U> @NonNull ArgumentParseResult<U> flatMapParsedValue(Function<T, ArgumentParseResult<U>> mapper);

/**
* Get the failure reason, if it exists
*
* @return Optional containing the failure reason
*/
public abstract @NonNull Optional<Throwable> getFailure();

/**
* If this result is a failure, transform the exception.
*
* @param mapper the exception transformation
* @return if this is a failure, a transformed result, otherwise this
* @since 1.5.0
*/
public abstract @NonNull ArgumentParseResult<T> mapFailure(Function<Throwable, Throwable> mapper);


private static final class ParseSuccess<T> extends ArgumentParseResult<T> {

Expand All @@ -90,13 +120,27 @@ private ParseSuccess(final @NonNull T value) {
return Optional.of(this.value);
}

@Override
public @NonNull <U> ArgumentParseResult<U> mapParsedValue(final Function<T, U> mapper) {
return new ParseSuccess<>(mapper.apply(this.value));
}

@Override
public @NonNull <U> ArgumentParseResult<U> flatMapParsedValue(final Function<T, ArgumentParseResult<U>> mapper) {
return mapper.apply(this.value);
}

@Override
public @NonNull Optional<Throwable> getFailure() {
return Optional.empty();
}

}
@Override
public @NonNull ArgumentParseResult<T> mapFailure(final Function<Throwable, Throwable> mapper) {
return this;
}

}

private static final class ParseFailure<T> extends ArgumentParseResult<T> {

Expand All @@ -114,11 +158,27 @@ private ParseFailure(final @NonNull Throwable failure) {
return Optional.empty();
}

@Override
@SuppressWarnings("unchecked")
public @NonNull <U> ArgumentParseResult<U> mapParsedValue(final Function<T, U> mapper) {
return (ArgumentParseResult<U>) this;
}

@Override
@SuppressWarnings("unchecked")
public @NonNull <U> ArgumentParseResult<U> flatMapParsedValue(final Function<T, ArgumentParseResult<U>> mapper) {
return (ArgumentParseResult<U>) this;
}

@Override
public @NonNull Optional<Throwable> getFailure() {
return Optional.of(this.failure);
}

@Override
public @NonNull ArgumentParseResult<T> mapFailure(final Function<Throwable, Throwable> mapper) {
return new ParseFailure<>(mapper.apply(this.failure));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.function.BiFunction;

import static java.util.Objects.requireNonNull;

/**
* Parser that parses strings into values of a specific type
Expand Down Expand Up @@ -89,6 +92,18 @@ public interface ArgumentParser<C, T> {
return Collections.emptyList();
}

/**
* Create a derived argument parser preserving all properties of this parser, but converting the output type.
*
* @param mapper the mapper to apply
* @param <O> the result type
* @return a derived parser.
* @since 1.5.0
*/
default <O> @NonNull ArgumentParser<C, O> map(final BiFunction<CommandContext<C>, T, ArgumentParseResult<O>> mapper) {
return new MappedArgumentParser<>(this, requireNonNull(mapper, "mapper"));
}

/**
* Check whether or not this argument parser is context free. A context free
* parser will not use the provided command context, and so supports impromptu parsing
Expand Down
Loading