8000 Release/9.7.0 by JorelAli · Pull Request #618 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Release/9.7.0 #618

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

Merged
merged 64 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b38936a
Set version to 9.6.2-SNAPSHOT
JorelAli Oct 28, 2024
558f09c
Create `commandapi-bukkit-test-toolkit`
willkroboth Jul 4, 2024
1816bff
Add `MockCommandAPIPlugin` for testing with `commandapi-bukkit-plugin`
willkroboth Jul 5, 2024
9ad579f
Add `assertCommandSucceeds` and `assertCommandFails` methods to Comma…
willkroboth Jul 5, 2024
8ed2acf
Add `assertCommandRunsWithArguments` methods to CommandAPITestUtilities
willkroboth Jul 9, 2024
d2fa55e
Implement testing IntegerRangeArgument NMS independently
willkroboth Jul 9, 2024
b86eb60
Fix CommandAPIHandler javadoc error that breaks full build
willkroboth Jul 9, 2024
be330ca
Add `assertCommandSuggests` methods to CommandAPITestUtilities
willkroboth Jul 10, 2024
7178477
Add `assertCommandFailsWithArguments` methods
willkroboth Jul 10, 2024
dafa99a
Improve coverage report by using Supplier<String> in CommandAPITestUt…
willkroboth Jul 10, 2024
83e5133
Add example argument and suggestion tests
willkroboth Jul 10, 2024
363c247
Add EntitySelectorArgument, PlayerArgument, and OfflinePlayerArgument…
willkroboth Jul 13, 2024
874770b
Implement ArgumentType suggestions for test toolkit
willkroboth Jul 16, 2024
2824ed8
Refactor Parser building syntax
willkroboth Jul 17, 2024
421fa57
Add README files for the test toolkit example projects
willkroboth Jul 17, 2024
4b67594
Add javadocs for important test toolkit methods and classes
willkroboth Jul 18, 2024
2ab0c17
Add docs for the test toolkit
willkroboth Jul 19, 2024
3b92c11
Fix trailing space (markdown lint)
willkroboth Jul 19, 2024
7b5750a
Add manual update notes to `update.sh`
willkroboth Jul 22, 2024
6b5f791
Allow developers to load custom MockCommandAPIBukkit instances in the…
willkroboth Aug 24, 2024
3b74499
Use translation keys instead of literal messages
willkroboth Sep 23, 2024
c8264e3
Update note about unimplemented methods in test_intro.md
willkroboth Sep 23, 2024
764f72e
Update MockBukkit-v1.21 to match paper updates
willkroboth Sep 23, 2024
5b286a3
Add javadocs to ArgumentUtilities and parser package
willkroboth Oct 6, 2024
87406f3
Update dependencies to 1.21
willkroboth Oct 16, 2024
40e8f87
Add @n to suggestions
willkroboth Oct 16, 2024
e9003b5
Add braces to inlined if-statements
willkroboth Oct 16, 2024
d2a8f88
Update documented dependency versions and mention gradle dependencies
willkroboth Oct 16, 2024
461f9f9
Fix markdownlint errors in test_setup.md
willkroboth Oct 16, 2024
ba8d578
Update MockBukkit to fix Paper 1.21 api update
willkroboth Oct 22, 2024
ac84d75
Rework `Parser` definition
willkroboth Oct 25, 2024
0bb04fa
Fix test-toolkit dependencies
willkroboth Oct 26, 2024
8688a08
Code review
willkroboth Oct 26, 2024
cf61f14
Update test toolkit versions to 9.6.2-SNAPSHOT manually
willkroboth Oct 28, 2024
e000a4b
Add new 9.6.0 NMS methods to MockCommandAPIBukkit
willkroboth Oct 28, 2024
c53e451
Merge pull request #575 from JorelAli/dev/simple-test-suite
willkroboth Oct 28, 2024
b27fc71
complete #529
MC-XiaoHei Nov 13, 2024
a47d939
format, docs, and fix tests
MC-XiaoHei Nov 15, 2024
1582991
format
MC-XiaoHei Nov 15, 2024
ab330ee
use const for more readable
MC-XiaoHei Nov 15, 2024
2c9b081
Update commandapi-core/src/main/java/dev/jorel/commandapi/AbstractArg…
MC-XiaoHei Nov 18, 2024
fd2eca8
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 18, 2024
90e6045
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 18, 2024
994653c
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 18, 2024
d0dd2c8
add thenNested() list ver, implement array ver with list ver
MC-XiaoHei Nov 18, 2024
0203144
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 19, 2024
3a8a6f2
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 19, 2024
59572b2
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 19, 2024
a31e859
implement nested { } with list ver thenNested() method
MC-XiaoHei Nov 19, 2024
54d3e36
Update commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/…
MC-XiaoHei Nov 19, 2024
8771911
fix indentation
MC-XiaoHei Nov 20, 2024
50fa068
fix indentation
MC-XiaoHei Nov 20, 2024
27b9360
Merge pull request #613 from MC-XiaoHei/dev/dev
JorelAli Nov 20, 2024
082bee7
Initial work for 1. 8000 21.4 support
DerEchtePilz Dec 3, 2024
ed915a3
Adds support for new Trail particle in 1.21.4
JorelAli Dec 3, 2024
0cb559a
Adds documentation for Trail particle and adds thenNested to the docu…
JorelAli Dec 3, 2024
362b8e6
Add 1.21.4 to the issue template
DerEchtePilz Dec 3, 2024
32319cf
Add test toolkit to 9.7.0 documentation changelog
willkroboth Dec 4, 2024
6017fd0
Set version to 9.7.0
JorelAli Dec 4, 2024
28cc2f5
Adds 9.7.0 documentation
JorelAli Dec 4, 2024
e79fb6e
Update homepage to point to 9.7.0
JorelAli Dec 4, 2024
aea0a3e
Generate 9.7.0 JavaDocs
JorelAli Dec 4, 2024
2e3adc2
Update documentation wiki.vg links to point to the MinecraftWiki wiki…
JorelAli Dec 4, 2024
7fe69b7
Merge branch 'master' into release/9.7.0
JorelAli Dec 4, 2024
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
Prev Previous commit
Next Next commit
Use translation keys instead of literal messages
Updated test toolkit's MockBukkit version to include MockBukkit/MockBukkit#1077, which allows accessing Minecraft Language codes.

Moved utilities for creating mock argument parsers into ArgumentUtilities class.

Made example project build script run maven tests, so the tests in the `automated-tests` and `automated-tests-shaded` example projects are run by GitHub Actions.
  • Loading branch information
willkroboth committed Oct 28, 2024
commit 3b7449960a65c49f0b9dd315cb440d7ae2972bc3
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<!-- Compatibility with MockBukkit API -->
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.9.0</version>
<artifactId>MockBukkit-v1.21</artifactId>
<version>3.120.4</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -89,10 +89,12 @@
</dependency>

<!-- Run our own tests with JUnit API -->
<!-- Note: This version matches the artifactId `junit-jupiter` dependency transitively inherited
from `MockBukkit-v1.21`. If it doesn't match, the tests might fail with class not found errors. -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import dev.jorel.commandapi.wrappers.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.*;
import org.bukkit.advancement.Advancement;
Expand Down Expand Up @@ -128,7 +130,7 @@ public MockCommandSource getBrigadierSourceFromCommandSender(AbstractCommandSend
return new MockCommandSource(sender.getSource());
}

// Logging
// Miscellaneous methods
/**
* A global toggle for whether the default logger returned by {@link #getLogger()} should print messages to the
* console. This is {@code false} by default, so not messages will appear. If you don't provide your own logger
Expand All @@ -144,6 +146,14 @@ public CommandAPILogger getLogger() {
CommandAPILogger.bindToMethods(msg -> {}, msg -> {}, msg -> {}, (msg, ex) -> {});
}

@Override
public Message generateMessageFromJson(String json) {
Component component = GsonComponentSerializer.gson().deserialize(json);
String text = PlainTextComponentSerializer.plainText().serialize(component);

return () -> text;
}

// Arguments
@Override
public ArgumentType<?> _ArgumentEntity(ArgumentSubType subType) {
Expand Down Expand Up @@ -645,9 +655,4 @@ public HelpTopic generateHelpTopic(String commandName, String shortDescription,
publi 10000 c Map<String, HelpTopic> getHelpMap() {
throw new UnimplementedMethodException();
}

@Override
public Message generateMessageFromJson(String json) {
throw new UnimplementedMethodException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package dev.jorel.commandapi.arguments;

import com.mojang.brigadier.Message;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import dev.jorel.commandapi.BukkitTooltip;
import dev.jorel.commandapi.arguments.parser.Parser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;

import java.util.function.Function;

/**
* Utilities for creating mock argument parsers
*/
public class ArgumentUtilities {
private ArgumentUtilities() {
}

// Translatable messages
public static Message translatedMessage(String key) {
return BukkitTooltip.messageFromAdventureComponent(Component.translatable(key));
}


public static Message translatedMessage(String key, Object... args) {
TextComponent[] argsComponents = new TextComponent[args.length];
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
String text = arg.toString();
argsComponents[i] = Component.text(text);
}
return BukkitTooltip.messageFromAdventureComponent(Component.translatable(key, argsComponents));
}

// Parser utilities
public static final CommandSyntaxException NEXT_BRANCH = new SimpleCommandExceptionType(
() -> "This branch did not match"
).create();


public static Parser.Literal assertCanRead(Function<StringReader, CommandSyntaxException> exception) {
return reader -> {
if (!reader.canRead()) throw exception.apply(reader);
};
}

public static Parser.Literal literal(String literal) {
return reader -> {
if (reader.canRead(literal.length())) {
int start = reader.getCursor();
int end = start + literal.length();

if (reader.getString().substring(start, end).equals(literal)) {
reader.setCursor(end);
return;
}
}
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.literalIncorrect().createWithContext(reader, literal);
};
}

public static Parser.Argument<String> readUntilWithoutEscapeCharacter(char terminator) {
return reader -> {
int start = reader.getCursor();
while (reader.canRead() && reader.peek() != terminator) {
reader.skip();
}
return reader.getString().substring(start, reader.getCursor());
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public static EntitySelectorArgumentType player() {

// ArgumentType implementation
public static final SimpleCommandExceptionType ERROR_NOT_SINGLE_ENTITY = new SimpleCommandExceptionType(
() -> "Only one entity is allowed, but the provided selector allows more than one"
ArgumentUtilities.translatedMessage("argument.entity.toomany")
);
public static final SimpleCommandExceptionType ERROR_NOT_SINGLE_PLAYER = new SimpleCommandExceptionType(
() -> "Only one player is allowed, but the provided selector allows more than one"
ArgumentUtilities.translatedMessage("argument.player.toomany")
);
public static final SimpleCommandExceptionType ERROR_ONLY_PLAYERS_ALLOWED = new SimpleCommandExceptionType(
() -> "Only players may be affected by this command, but the provided selector includes entities"
ArgumentUtilities.translatedMessage("argument.player.entities")
);
public static final SimpleCommandExceptionType NO_ENTITIES_FOUND = new SimpleCommandExceptionType(
() -> "No entity was found"
ArgumentUtilities.translatedMessage("argument.entity.notfound.entity")
);
public static final SimpleCommandExceptionType NO_PLAYERS_FOUND = new SimpleCommandExceptionType(
() -> "No player was found"
ArgumentUtilities.translatedMessage("argument.entity.notfound.player")
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
public class EntitySelectorParser {
// Errors
public static final SimpleCommandExceptionType ERROR_INVALID_NAME_OR_UUID = new SimpleCommandExceptionType(
() -> "Invalid name or UUID"
ArgumentUtilities.translatedMessage("argument.entity.invalid")
);
public static final DynamicCommandExceptionType ERROR_UNKNOWN_SELECTOR_TYPE = new DynamicCommandExceptionType(
object -> {
String message = "Unknown selector type '%s'".formatted(object);
return () -> message;
}
object -> ArgumentUtilities.translatedMessage("argument.entity.selector.unknown", object)
);
public static final SimpleCommandExceptionType ERROR_MISSING_SELECTOR_TYPE = new SimpleCommandExceptionType(
() -> "Missing selector type"
ArgumentUtilities.translatedMessage("argument.entity.selector.missing")
);

// State for building a selector
Expand All @@ -52,7 +49,7 @@ private EntitySelector build() {

// Parsing
private static final Parser.Literal isSelectorStart = reader -> {
if (!(reader.canRead() && reader.peek() == '@')) throw Parser.NEXT_BRANCH;
if (!(reader.canRead() && reader.peek() == '@')) throw ArgumentUtilities.NEXT_BRANCH;
};

private static Parser.Literal parseSelector(ParameterGetter<EntitySelectorParser> selectorBuilderGetter) {
Expand Down Expand Up @@ -108,7 +105,7 @@ private static Parser.Literal parseSelector(ParameterGetter<EntitySelectorParser
}

private static final Parser.Literal isSelectorOptionsStart = reader -> {
if (!(reader.canRead() && reader.peek() == '[')) throw Parser.NEXT_BRANCH;
if (!(reader.canRead() && reader.peek() == '[')) throw ArgumentUtilities.NEXT_BRANCH;
};

private static Parser.Literal parseSelectorOptions(ParameterGetter<EntitySelectorParser> selectorBuilderGetter) {
Expand Down Expand Up @@ -164,11 +161,11 @@ private static Parser.Argument<EntitySelector> conclude(ParameterGetter<EntitySe
});
};
private static final SuggestionProvider suggestSelector = (context, builder) -> {
builder.suggest("@p", () -> "Nearest player");
builder.suggest("@a", () -> "All players");
builder.suggest("@r", () -> "Random player");
builder.suggest("@s", () -> "Current entity");
builder.suggest("@e", () -> "All entities");
builder.suggest("@p", ArgumentUtilities.translatedMessage("argument.entity.selector.nearestPlayer"));
builder.suggest("@a", ArgumentUtilities.translatedMessage("argument.entity.selector.allPlayers"));
builder.suggest("@r", ArgumentUtilities.translatedMessage("argument.entity.selector.randomPlayer"));
builder.suggest("@s", ArgumentUtilities.translatedMessage("argument.entity.selector.self"));
builder.suggest("@e", ArgumentUtilities.translatedMessage("argument.entity.selector.allEntities"));
};
private static final SuggestionProvider suggestNameOrSelector = (context, builder) -> {
suggestSelector.addSuggestions(context, builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ private IntegerRangeArgumentType() {
// but MockBukkit doesn't seem to currently support that: https://github.com/MockBukkit/MockBukkit/issues/1040.
// For now, just grabbing the literal strings from https://gist.github.com/sppmacd/82af47c83b225d4ffd33bb0c27b0d932.
public static final SimpleCommandExceptionType EMPTY_INPUT = new SimpleCommandExceptionType(
() -> "Expected value or range of values"
ArgumentUtilities.translatedMessage("argument.range.empty")
);
public static final SimpleCommandExceptionType RANGE_SWAPPED = new SimpleCommandExceptionType(
() -> "Min cannot be bigger than max"
ArgumentUtilities.translatedMessage("argument.range.swapped")
);

private static final Parser.Argument<Integer> READ_INT_BEFORE_RANGE = reader -> {
Expand Down Expand Up @@ -58,11 +58,11 @@ private IntegerRangeArgumentType() {
private static final Predicate<CommandSyntaxException> THROW_INVALID_INT_EXCEPTIONS = exception ->
exception.getType().equals(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidInt());

private static final Parser<IntegerRange> PARSER = Parser
private static final Parser<IntegerRange> PARSER = ArgumentUtilities
.assertCanRead(EMPTY_INPUT::createWithContext)
.alwaysThrowException()
.continueWith(
Parser.tryParse(Parser.literal("..")
Parser.tryParse(ArgumentUtilities.literal("..")
.neverThrowException()
// Input ..
.continueWith(
Expand Down Expand Up @@ -98,7 +98,7 @@ private IntegerRangeArgumentType() {
})
// Input low
.continueWith(getLow ->
Parser.tryParse(Parser.literal("..")
Parser.tryParse(ArgumentUtilities.literal("..")
.neverThrowException()
// Input low..
.continueWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public interface Result {
}

public static final SimpleCommandExceptionType ERROR_UNKNOWN_PLAYER = new SimpleCommandExceptionType(
() -> "That player does not exist"
ArgumentUtilities.translatedMessage("argument.player.unknown")
);

private static final Parser.Literal isSelectorStart = reader -> {
if (!(reader.canRead() && reader.peek() == '@')) throw Parser.NEXT_BRANCH;
if (!(reader.canRead() && reader.peek() == '@')) throw ArgumentUtilities.NEXT_BRANCH;
};

private static final Parser<Result> PARSER = Parser
Expand Down Expand Up @@ -64,7 +64,7 @@ public interface Result {
}
))
)
).then(Parser.readUntilWithoutEscapeCharacter(' ')
).then(ArgumentUtilities.readUntilWithoutEscapeCharacter(' ')
.alwaysThrowException()
.continueWith(nameGetter -> Parser.parse(
reader -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;

Expand Down Expand Up @@ -353,42 +352,4 @@ public Parser<T> then(Parser<T> parser) {
};
}
}

//////////////////////////////////
// Common parsers and utilities //
//////////////////////////////////
CommandSyntaxException NEXT_BRANCH = new SimpleCommandExceptionType(
() -> "This branch did not match"
).create();

static Literal assertCanRead(Function<StringReader, CommandSyntaxException> exception) {
return reader -> {
if (!reader.canRead()) throw exception.apply(reader);
};
}

static Literal literal(String literal) {
return reader -> {
if (reader.canRead(literal.length())) {
int start = reader.getCursor();
int end = start + literal.length();

if (reader.getString().substring(start, end).equals(literal)) {
reader.setCursor(end);
return;
}
}
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.literalIncorrect().createWithContext(reader, literal);
};
}

static Argument<String> readUntilWithoutEscapeCharacter(char terminator) {
return reader -> {
int start = reader.getCursor();
while (reader.canRead() && reader.peek() != terminator) {
reader.skip();
}
return reader.getString().substring(start, reader.getCursor());
};
}
}
2 changes: 1 addition & 1 deletion examples/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ echo "Building Maven examples"
for folder in $(find $PWD -name "pom.xml" -print0 | xargs -0 dirname); do
if [[ ! $folder =~ "maven-shaded-tests" ]]; then
# The parentheses are required to only change the directory for the command so the second find $PWD does not break
(cd "$folder" && mvn clean package)
(cd "$folder" && mvn clean verify)
fi
done

Expand Down
0