BAZEL + some code
This commit is contained in:
parent
dd25337ed6
commit
4db84feb43
44 changed files with 627 additions and 389 deletions
4
.bazelrc
Normal file
4
.bazelrc
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
build --java_language_version=25
|
||||
build --java_runtime_version=25
|
||||
build --tool_java_language_version=25
|
||||
build --tool_java_runtime_version=25
|
||||
13
.gitignore
vendored
13
.gitignore
vendored
|
|
@ -1,9 +1,10 @@
|
|||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
.kotlin
|
||||
/.idea/inspectionProfiles
|
||||
/MODULE.bazel.lock
|
||||
/.bazelbsp
|
||||
/bazel-bin
|
||||
/bazel-out
|
||||
/bazel-KenCommandAPI
|
||||
/bazel-testlogs
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
|
|
|
|||
2
.idea/bazelVersionCache.xml
generated
2
.idea/bazelVersionCache.xml
generated
|
|
@ -6,7 +6,7 @@
|
|||
<fork_state>
|
||||
<option name="name" value="bazelbuild" />
|
||||
<option name="version" value="9.2.0" />
|
||||
<option name="lastUpdated" value="1785569158664" />
|
||||
<option name="lastUpdated" value="1785684742087" />
|
||||
</fork_state>
|
||||
</entry>
|
||||
</forks>
|
||||
|
|
|
|||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" />
|
||||
</project>
|
||||
143
.idea/workspace.xml
generated
143
.idea/workspace.xml
generated
|
|
@ -9,7 +9,7 @@
|
|||
</component>
|
||||
<component name="BazelProjectProperties">
|
||||
<option name="bazelProject" value="true" />
|
||||
<option name="defaultJdkName" value="KenCommandAPI-jdk-b0cea" />
|
||||
<option name="defaultJdkName" value="KenCommandAPI-jdk-e101e" />
|
||||
<option name="initialized" value="true" />
|
||||
<option name="rootDirUrl" value="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
|
|
@ -37,20 +37,49 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="6414223f-1761-4683-97f5-9dab59d6c44a" name="Changes" comment="use version catalog">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/bazelVersionCache.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/runConfigurations.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/third_party/BUILD" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
|
||||
<list default="true" id="6414223f-1761-4683-97f5-9dab59d6c44a" name="Changes" comment="BAZEL">
|
||||
<change afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/ArgumentRequirement.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/CommandArgumentImpl.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/CommandArgumentSpec.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/CommandArgumentSpecBuilder.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/CommandArgumentSpecImpl.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/literal/LiteralBuilder.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/CommandContextImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/bazelVersionCache.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/bazelVersionCache.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/TODO" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/gradle/libs.versions.toml" beforeDir="false" afterPath="$PROJECT_DIR$/third_party/libs.versions.toml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/gradle/wrapper/gradle-wrapper.jar" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/gradle/wrapper/gradle-wrapper.properties" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/gradlew" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/gradlew.bat" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-bukkit/BUILD" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-bukkit/BUILD" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/BukkitKenCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/BukkitKenCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/CommandAPI.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/CommandAPI.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/TabCompleteListener.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/TabCompleteListener.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/suggestionprovider/PlayerSuggestionProvider.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/suggestionprovider/PlayerSuggestionProvider.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/type/OfflinePlayerArgumentType.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/type/OfflinePlayerArgumentType.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/type/PlayerArgumentType.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-bukkit/src/main/java/de/kentoj/kencommandapi/type/PlayerArgumentType.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/BUILD" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/BUILD" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/CommandHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/CommandHandler.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/ArgumentType.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/ArgumentType.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/CommandArgument.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/CommandArgument.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/types/IntegerArgumentType.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/types/IntegerArgumentType.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/types/StringArgumentType.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/argument/types/StringArgumentType.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/invocation/CommandContext.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/invocation/CommandContext.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/invocation/ParsedArgument.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/literal/Literal.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/literal/Literal.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/literal/RootLiteral.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/platform/PlainMessageStyle.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/platform/PlainMessageStyle.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/suggestion/NoSuggestionProvider.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/suggestion/NoSuggestionProvider.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/suggestion/SuggestionProvider.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/suggestion/SuggestionProvider.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/CommandArgumentImpl.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/LiteralImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/api/literal/LiteralImpl.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/ParsedArgumentImpl.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/RootLiteralImpl.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/parser/InvocationCommandParser.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/parser/InvocationCommandParser.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/parser/SuggestionCommandParser.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/main/java/de/kentoj/kencommandapi/internal/parser/SuggestionCommandParser.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-core/src/test/java/de/kentoj/kencommandapi/api/parser/SuggestionCommandParserTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-core/src/test/java/de/kentoj/kencommandapi/api/parser/SuggestionCommandParserTest.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-velocity/src/main/java/de/kentoj/kencommandapi/CommandAPI.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-velocity/src/main/java/de/kentoj/kencommandapi/CommandAPI.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/kencommandapi-velocity/src/main/java/de/kentoj/kencommandapi/VelocityCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/kencommandapi-velocity/src/main/java/de/kentoj/kencommandapi/VelocityCommand.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/third_party/BUILD" beforeDir="false" afterPath="$PROJECT_DIR$/third_party/BUILD" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -145,45 +174,45 @@
|
|||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Gradle./home/a/src/kento2/KenCommandAPI/kencommandapi-core [:kencommandapi-core:de.kentoj.kencommandapi.Main.main()].executor": "Run",
|
||||
"Gradle./home/a/src/kento2/KenCommandAPI/kencommandapi-core [build].executor": "Run",
|
||||
"Gradle./home/a/src/kento2/KenCommandAPI/kencommandapi-core [publish].executor": "Run",
|
||||
"Gradle.CommandParserTest.checkArgumentExpected.executor": "Run",
|
||||
"Gradle.Download Sources.executor": "Run",
|
||||
"Gradle.KenCommandAPI [:de.kencommand.Main.main()].executor": "Run",
|
||||
"Gradle.KenCommandAPI [assemble].executor": "Run",
|
||||
"Gradle.KenCommandAPI [buildEnvironment].executor": "Run",
|
||||
"Gradle.KenCommandAPI [build].executor": "Run",
|
||||
"Gradle.KenCommandAPI [clean test].executor": "Run",
|
||||
"Gradle.KenCommandAPI [clean].executor": "Run",
|
||||
"Gradle.KenCommandAPI [javadoc].executor": "Run",
|
||||
"Gradle.KenCommandAPI [publishAllPublicationsToScrowRepository].executor": "Run",
|
||||
"Gradle.KenCommandAPI [publish].executor": "Run",
|
||||
"Gradle.KenCommandAPI [test].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [build].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [generatePomFileForKenCommandAPIBukkitPublication].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [publishAllPublicationsToScrowRepository].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [publish].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-velocity [publish].executor": "Run",
|
||||
"Gradle.kencommandapi-core [build].executor": "Run",
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"bazel.project.detector.is.bazel.project": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "/home/a/src/scrow/KenCommandAPI/gradle",
|
||||
"project.structure.last.edited": "Modules",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.6268199",
|
||||
"remote.dev.show.docker.config.missing.jdk.notification": "false",
|
||||
"settings.editor.selected.configurable": "preferences.pluginManager"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Gradle./home/a/src/kento2/KenCommandAPI/kencommandapi-core [:kencommandapi-core:de.kentoj.kencommandapi.Main.main()].executor": "Run",
|
||||
"Gradle./home/a/src/kento2/KenCommandAPI/kencommandapi-core [build].executor": "Run",
|
||||
"Gradle./home/a/src/kento2/KenCommandAPI/kencommandapi-core [publish].executor": "Run",
|
||||
"Gradle.CommandParserTest.checkArgumentExpected.executor": "Run",
|
||||
"Gradle.Download Sources.executor": "Run",
|
||||
"Gradle.KenCommandAPI [:de.kencommand.Main.main()].executor": "Run",
|
||||
"Gradle.KenCommandAPI [assemble].executor": "Run",
|
||||
"Gradle.KenCommandAPI [buildEnvironment].executor": "Run",
|
||||
"Gradle.KenCommandAPI [build].executor": "Run",
|
||||
"Gradle.KenCommandAPI [clean test].executor": "Run",
|
||||
"Gradle.KenCommandAPI [clean].executor": "Run",
|
||||
"Gradle.KenCommandAPI [javadoc].executor": "Run",
|
||||
"Gradle.KenCommandAPI [publishAllPublicationsToScrowRepository].executor": "Run",
|
||||
"Gradle.KenCommandAPI [publish].executor": "Run",
|
||||
"Gradle.KenCommandAPI [test].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [build].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [generatePomFileForKenCommandAPIBukkitPublication].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [publishAllPublicationsToScrowRepository].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-bukkit [publish].executor": "Run",
|
||||
"Gradle.KenCommandAPI:kencommandapi-velocity [publish].executor": "Run",
|
||||
"Gradle.kencommandapi-core [build].executor": "Run",
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"bazel.project.detector.is.bazel.project": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "/home/a/src/scrow/KenCommandAPI/gradle",
|
||||
"project.structure.last.edited": "Modules",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.6268199",
|
||||
"remote.dev.show.docker.config.missing.jdk.notification": "false",
|
||||
"settings.editor.selected.configurable": "preferences.pluginManager"
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CreateClassDialog.RecentsKey">
|
||||
<recent name="de.kentoj.kencommandapi.api" />
|
||||
|
|
@ -200,8 +229,13 @@
|
|||
<recent name="$PROJECT_DIR$/src/main/java/de/kencommand/api" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/third_party" />
|
||||
<recent name="$PROJECT_DIR$" />
|
||||
<recent name="$PROJECT_DIR$/kencommandapi-core" />
|
||||
</key>
|
||||
<key name="ExtractSuperBase.RECENT_KEYS">
|
||||
<recent name="de.kentoj.kencommandapi.api.invocation" />
|
||||
</key>
|
||||
<key name="CopyClassDialog.RECENTS_KEY">
|
||||
<recent name="de.kentoj.kencommandapi.api.parser2" />
|
||||
<recent name="de.kentoj.kencommandapi.api.invocation" />
|
||||
|
|
@ -220,13 +254,13 @@
|
|||
<command value="bazel build //:kencommandapi-core" />
|
||||
<command value="bazel build //:core" />
|
||||
<command value="bazel build //kencommandapi-core:core" />
|
||||
<command value="bazel clean" />
|
||||
<command value="bazel build //kencommandapi-core:core --sandbox_debug " />
|
||||
<command value="bazel build //kencommandapi-core:core " />
|
||||
<command value="bazel build //kencommandapi-bukkit:bukkit" />
|
||||
<command value="bazel build //kencommandapi-bukkit:bukkit --verbose_failures+" />
|
||||
<command value="bazel build //kencommandapi-bukkit:bukkit --verbose_failures" />
|
||||
<command value="bazel build //kencommandapi-core:core --nojava_header_compilation" />
|
||||
<command value="bazel build //kencommandapi-bukkit:bukkit" />
|
||||
<command value="bazel clean" />
|
||||
<command value="bazel build //kencommandapi-bukkit:bukkit --nojava_header_compilation" />
|
||||
</option>
|
||||
</component>
|
||||
|
|
@ -621,6 +655,7 @@
|
|||
<MESSAGE value="add TODO" />
|
||||
<MESSAGE value="." />
|
||||
<MESSAGE value="use version catalog" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="use version catalog" />
|
||||
<MESSAGE value="BAZEL" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="BAZEL" />
|
||||
</component>
|
||||
</project>
|
||||
83
README.md
83
README.md
|
|
@ -1,2 +1,81 @@
|
|||
example usage:
|
||||
http://forge.kentoj.de/scrow/core/src/commit/a55d985773t425e099fe9650cc1a705ceb2ece00/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/command/economy
|
||||
## Limitations & Bugs
|
||||
|
||||
- argument's can't require specific permissions.
|
||||
- errors are always formatted using the RootLiteral's MessageStyle
|
||||
|
||||
## Design
|
||||
|
||||
Commands are trees of Literals.
|
||||
Literals can have arguments.
|
||||
Literals can also have Executors.
|
||||
|
||||
arguments can be optional by giving them a default value.
|
||||
arguments can have suggestions.
|
||||
|
||||
`/feed <user>`:
|
||||
- feed is the root literal
|
||||
- `<user>` is an argument: it's value is a User Object
|
||||
|
||||
To allow the use of `/feed` without giving a user's name, i.e. to make the argument optional, we need to assign the
|
||||
user-argument a default value.
|
||||
|
||||
## An example command
|
||||
|
||||
Let's say we want to make a command that allows seeing how many coins another User has.
|
||||
If we don't specify a user, it should instead show the coins the sender has.
|
||||
|
||||
## As a tree
|
||||
|
||||
Visualized as a tree, we have a Node/Literal `coins` with an alias `balance` with an optional argument called `user`.
|
||||
To make an argument optional, it must have a default value.
|
||||
|
||||
```text
|
||||
literal:coins/balance
|
||||
- has argument:user
|
||||
- has executor:getCoins
|
||||
```
|
||||
|
||||
## As code
|
||||
```java
|
||||
/**
|
||||
* Show the amount coins a user has.
|
||||
* If no user is given, it should show the amount the sender of the command has.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class CoinsCommand {
|
||||
|
||||
@Getter
|
||||
private final Literal<User> rootLiteral;
|
||||
private final CommandArgumentSpec<User, User> userArg;
|
||||
|
||||
public CoinsCommand() {
|
||||
userArg = CommandArgumentSpec.builder("user", new UserArgumentType<User>())
|
||||
.withRequirement(p -> !p.hasPermission("economy.immune.getcoins"),
|
||||
"you can't see that player's balance")
|
||||
.withDefaultValue(CommandContext::getSender)
|
||||
.build();
|
||||
rootLiteral = Literal.<User>builder("coins", "balance")
|
||||
.withStyle(MessageStyle.PLAIN)
|
||||
.withPermission("economy.command.coins")
|
||||
.withArgument(userArg)
|
||||
.withSyncExecutor(this::getCoins)
|
||||
.build();
|
||||
}
|
||||
|
||||
private Result<Object, String> getCoins(CommandContext<User> ctx) {
|
||||
var player = ctx.getArg(userArg);
|
||||
ctx.getSender().sendMessage(player.getName() + " has " + player.getCoins() + " coins");
|
||||
return Results.success(new Object());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If we wanted to report an error, we could do for example `return Results.failure("That user doesn't exist")`.
|
||||
However, if we have a smart UserArgumentType, it automatically makes sure that the user exists.
|
||||
Additionally, we can also a Requirement in the CommandArgumentSpec.
|
||||
|
||||
The registration of the command is platform-dependant. Typically, a class called CommandAPI can be used.
|
||||
```java
|
||||
CommandAPI api = new CommandAPI();
|
||||
register(new CoinsCommand().getRootLiteral());
|
||||
```
|
||||
|
|
@ -6,9 +6,12 @@ java_library(
|
|||
srcs = glob(["src/main/**/*.java"]),
|
||||
deps = [
|
||||
"//kencommandapi-core:core",
|
||||
artifact("org.jetbrains:annotations"),
|
||||
artifact("org.projectlombok:lombok"),
|
||||
artifact("org.jetbrains:annotations"),
|
||||
artifact("io.papermc.paper:paper-api:[26.2.build,)"),
|
||||
],
|
||||
exports = [
|
||||
"//kencommandapi-core:core",
|
||||
],
|
||||
plugins = [ "//third_party:lombok_plugin" ],
|
||||
)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.kencommandapi;
|
||||
|
||||
import de.kentoj.kencommandapi.api.CommandHandler;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -11,12 +11,12 @@ import java.util.stream.Stream;
|
|||
|
||||
public class BukkitKenCommand extends Command {
|
||||
|
||||
private final RootLiteral<CommandSender> rootNode;
|
||||
private final Literal<CommandSender> rootNode;
|
||||
private final CommandHandler<CommandSender> commandHandler;
|
||||
|
||||
protected BukkitKenCommand(
|
||||
CommandHandler<CommandSender> commandHandler,
|
||||
RootLiteral<CommandSender> rootLiteral
|
||||
Literal<CommandSender> rootLiteral
|
||||
) {
|
||||
super(rootLiteral.getNames()[0]);
|
||||
this.commandHandler = commandHandler;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.kencommandapi;
|
||||
|
||||
import de.kentoj.kencommandapi.api.CommandHandler;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
|
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
public class CommandAPI {
|
||||
|
||||
private final CommandHandler<CommandSender> commandHandler;
|
||||
private final List<RootLiteral<CommandSender>> registeredNodes = new ArrayList<>();
|
||||
private final List<Literal<CommandSender>> registeredNodes = new ArrayList<>();
|
||||
private final SimpleCommandMap commandMap;
|
||||
|
||||
public CommandAPI(Plugin plugin) {
|
||||
|
|
@ -32,7 +32,7 @@ public class CommandAPI {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable RootLiteral<CommandSender> getRegistered(String name) {
|
||||
@Nullable Literal<CommandSender> getRegistered(String name) {
|
||||
for (var node : registeredNodes) {
|
||||
for (String nodeName : node.getNames()) {
|
||||
if (nodeName.equals(name)) return node;
|
||||
|
|
@ -41,7 +41,7 @@ public class CommandAPI {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void register(RootLiteral<CommandSender> rootNode) {
|
||||
public void register(Literal<CommandSender> rootNode) {
|
||||
registeredNodes.add(rootNode);
|
||||
commandMap.register(rootNode.getNames()[0], new BukkitKenCommand(commandHandler, rootNode));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ public class TabCompleteListener implements Listener {
|
|||
if (l >= 0)
|
||||
label = label.substring(l+1);
|
||||
}
|
||||
var rootNode = commandAPI.getRegistered(label);
|
||||
if (rootNode == null) return;
|
||||
var literal = commandAPI.getRegistered(label);
|
||||
if (literal == null) return;
|
||||
ev.setHandled(true);
|
||||
ev.setCompletions(commandHandler.getSuggestions(rootNode, ev.getSender(), Arrays.copyOfRange(args, 1, args.length), ev.getBuffer().endsWith(" ")));
|
||||
ev.setCompletions(commandHandler.getSuggestions(literal, ev.getSender(), Arrays.copyOfRange(args, 1, args.length), ev.getBuffer().endsWith(" ")));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerSuggestionProvider implements SuggestionProvider<CommandSender> {
|
||||
public class PlayerSuggestionProvider<T> implements SuggestionProvider<T> {
|
||||
@Override
|
||||
public List<String> suggest(CommandSender __) {
|
||||
public List<String> suggest(T __) {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.toList();
|
||||
|
|
|
|||
|
|
@ -12,15 +12,12 @@ import org.bukkit.command.CommandSender;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class OfflinePlayerArgumentType implements ArgumentType<CommandSender, OfflinePlayer> {
|
||||
|
||||
@Getter(lazy = true)
|
||||
private static final OfflinePlayerArgumentType instance = new OfflinePlayerArgumentType();
|
||||
@NoArgsConstructor
|
||||
public class OfflinePlayerArgumentType<T> implements ArgumentType<T, OfflinePlayer> {
|
||||
|
||||
// TODO make work with player names on offline players
|
||||
@Override
|
||||
public OfflinePlayer parseInput(String string) {
|
||||
public OfflinePlayer parseInputUnchecked(String string) {
|
||||
OfflinePlayer player = Bukkit.getPlayerExact(string);
|
||||
if (player == null) {
|
||||
try {
|
||||
|
|
@ -34,7 +31,7 @@ public class OfflinePlayerArgumentType implements ArgumentType<CommandSender, Of
|
|||
}
|
||||
|
||||
@Override
|
||||
public SuggestionProvider<CommandSender> defaultSuggestionProvider() {
|
||||
return new PlayerSuggestionProvider();
|
||||
public SuggestionProvider<T> getDefaultSuggestionProvider() {
|
||||
return new PlayerSuggestionProvider<>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,28 +3,22 @@ package de.kentoj.kencommandapi.type;
|
|||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.suggestionprovider.PlayerSuggestionProvider;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class PlayerArgumentType implements ArgumentType<CommandSender, Player> {
|
||||
|
||||
@Getter(lazy = true)
|
||||
private static final PlayerArgumentType instance = new PlayerArgumentType();
|
||||
@NoArgsConstructor
|
||||
public class PlayerArgumentType<T> implements ArgumentType<T, Player> {
|
||||
|
||||
@Override
|
||||
public Player parseInput(String string) {
|
||||
public Player parseInputUnchecked(String string) {
|
||||
var player = Bukkit.getPlayer(string);
|
||||
if (player == null) throw new IllegalArgumentException("player not online");
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestionProvider<CommandSender> defaultSuggestionProvider() {
|
||||
return new PlayerSuggestionProvider();
|
||||
public SuggestionProvider<T> getDefaultSuggestionProvider() {
|
||||
return new PlayerSuggestionProvider<>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@ java_library(
|
|||
srcs = glob(["src/main/**/*.java"]),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
artifact("org.projectlombok:lombok"),
|
||||
artifact("com.leakyabstractions:result-api"),
|
||||
artifact("com.leakyabstractions:result"),
|
||||
artifact("org.jetbrains:annotations"),
|
||||
artifact("com.google.guava:guava"),
|
||||
artifact("org.slf4j:slf4j-api"),
|
||||
artifact("net.kyori:adventure-api"),
|
||||
artifact("org.projectlombok:lombok"),
|
||||
],
|
||||
plugins = [ "//third_party:lombok_plugin" ],
|
||||
)
|
||||
)
|
||||
load("@rules_java//toolchains:default_java_toolchain.bzl", "default_java_toolchain")
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
package de.kentoj.kencommandapi.api;
|
||||
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.platform.HasPermissionMethod;
|
||||
import de.kentoj.kencommandapi.api.platform.SendMessageMethod;
|
||||
import de.kentoj.kencommandapi.internal.parser.CommandParseHelper;
|
||||
import de.kentoj.kencommandapi.internal.parser.InvocationCommandParser;
|
||||
import de.kentoj.kencommandapi.internal.parser.SuggestionCommandParser;
|
||||
import de.kentoj.kencommandapi.api.platform.HasPermissionMethod;
|
||||
import de.kentoj.kencommandapi.api.platform.SendMessageMethod;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -28,23 +27,25 @@ public class CommandHandler<T> {
|
|||
suggestionParser = new SuggestionCommandParser<>(parseHelper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("CodeBlock2Expr")
|
||||
public void invoke(RootLiteral<T> rootLiteral, T sender, Stream<String> args) {
|
||||
public void invoke(Literal<T> rootLiteral, T sender, Stream<String> args) {
|
||||
// FIXME uses rootLiteral's message style
|
||||
invocationParser.parse(rootLiteral, sender, args.toList().iterator())
|
||||
.ifSuccessOrElse(data -> {
|
||||
var ctx = new CommandContext<>(sender, data.getArguments());
|
||||
data.getExecutor().execute(ctx).whenComplete((result, ex) -> {
|
||||
if (ex != null)
|
||||
sendMessageMethod.send(sender, rootLiteral.getMessageStyle().exception(ex));
|
||||
result.ifFailure(err ->
|
||||
sendMessageMethod.send(sender, rootLiteral.getMessageStyle().err(err)));
|
||||
});
|
||||
}, err -> {
|
||||
sendMessageMethod.send(sender, rootLiteral.getMessageStyle().err(err));
|
||||
.ifSuccessOrElse(data -> exec(rootLiteral, data),
|
||||
err -> sendMessageMethod.send(sender, rootLiteral.getMessageStyle().err(err)));
|
||||
}
|
||||
|
||||
private void exec(Literal<T> rootLiteral, InvocationCommandParser<T>.ExecutionData data) {
|
||||
var sender = data.getContext().getSender();
|
||||
data.getExecutor().execute(data.getContext())
|
||||
.whenComplete((result, ex) -> {
|
||||
if (ex != null)
|
||||
sendMessageMethod.send(sender, rootLiteral.getMessageStyle().exception(ex));
|
||||
result.ifFailure(err ->
|
||||
sendMessageMethod.send(sender, rootLiteral.getMessageStyle().err(err)));
|
||||
});
|
||||
}
|
||||
|
||||
public List<String> getSuggestions(RootLiteral<T> rootNode, T sender, String[] args, boolean trailingSpace) {
|
||||
public List<String> getSuggestions(Literal<T> rootNode, T sender, String[] args, boolean trailingSpace) {
|
||||
return suggestionParser.suggest(rootNode, sender, Arrays.stream(args).iterator(), trailingSpace);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @param <V> type of the parsed argument value
|
||||
*/
|
||||
@Value
|
||||
public class ArgumentRequirement<V> {
|
||||
Predicate<V> predicate;
|
||||
String message;
|
||||
}
|
||||
|
|
@ -2,14 +2,24 @@ package de.kentoj.kencommandapi.api.argument;
|
|||
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface ArgumentType<T, V> {
|
||||
|
||||
/**
|
||||
* parses the given input and returns it.
|
||||
* Unlike {@link CommandArgumentSpec#parseInput(String)}, this does not check any additional requirements.
|
||||
*
|
||||
* @throws IllegalArgumentException if string invalid
|
||||
* @see CommandArgumentSpec#parseInput(String)
|
||||
* @see CommandArgumentSpecBuilder#addRequirement(Predicate, String)
|
||||
*/
|
||||
V parseInput(String string);
|
||||
V parseInputUnchecked(String input) throws IllegalArgumentException;
|
||||
|
||||
SuggestionProvider<T> defaultSuggestionProvider();
|
||||
/**
|
||||
* @see CommandArgumentSpec#getSuggestionProvider()
|
||||
*/
|
||||
SuggestionProvider<T> getDefaultSuggestionProvider();
|
||||
|
||||
/**
|
||||
* @return whether this argument is greedy. Greedy arguments consume all remaining input instead of a single word.
|
||||
|
|
|
|||
|
|
@ -1,30 +1,8 @@
|
|||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.internal.CommandArgumentImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface CommandArgument<T, V> {
|
||||
|
||||
static <T, V> CommandArgument<T, V> arg(String id, ArgumentType<T, V> type) {
|
||||
return new CommandArgumentImpl<>(id, type);
|
||||
}
|
||||
V getValue();
|
||||
|
||||
String getId();
|
||||
|
||||
ArgumentType<T, V> getType();
|
||||
|
||||
void setDefaultValueProvider(@Nullable Function<T, V> defaultValueProvider);
|
||||
|
||||
@Nullable Function<T, V> getDefaultValueProvider();
|
||||
|
||||
void setSuggestionProvider(@Nullable SuggestionProvider<T> suggestionProvider);
|
||||
|
||||
/**
|
||||
* @return the explicitly set SuggestionProvider or the default suggestions for the type if unset/null
|
||||
*/
|
||||
@NotNull SuggestionProvider<T> getSuggestionProvider();
|
||||
CommandArgumentSpec<T, V> getArgument();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class CommandArgumentImpl<T, V> implements CommandArgument<T, V> {
|
||||
V value;
|
||||
CommandArgumentSpec<T, V> argument;
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public sealed interface CommandArgumentSpec<T, V> permits CommandArgumentSpecImpl {
|
||||
|
||||
static <T, V> CommandArgumentSpecBuilder<T, V> builder(String id, ArgumentType<T, V> type) {
|
||||
return new CommandArgumentSpecBuilder<>(id, type);
|
||||
}
|
||||
|
||||
String getId();
|
||||
|
||||
ArgumentType<T, V> getType();
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException if string invalid or if a requirement is not met
|
||||
*/
|
||||
V parseInput(String rawInput);
|
||||
|
||||
@Nullable Function<CommandContext<T>, V> getDefaultValueProvider();
|
||||
|
||||
/**
|
||||
* @return the explicitly set SuggestionProvider or the default suggestions for the type if unset/null
|
||||
*/
|
||||
/* explicit @NotNull to avoid confusion */
|
||||
@NotNull SuggestionProvider<T> getSuggestionProvider();
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @param <T> type of the command sender
|
||||
* @param <V> type of the value
|
||||
*/
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
public class CommandArgumentSpecBuilder<T, V> {
|
||||
|
||||
private final String id;
|
||||
private final ArgumentType<T, V> type;
|
||||
|
||||
private @Nullable Function<CommandContext<T>, V> defaultValueProvider;
|
||||
private @Nullable SuggestionProvider<T> suggestionProvider;
|
||||
|
||||
private final List<ArgumentRequirement<V>> requirements = new ArrayList<>();
|
||||
|
||||
public CommandArgumentSpecBuilder<T, V> withRequirement(Predicate<V> predicate, String message) {
|
||||
requirements.add(new ArgumentRequirement<>(predicate, message));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandArgumentSpecBuilder<T, V> withDefaultValue(@Nullable Function<CommandContext<T>, V> defaultValueProvider) {
|
||||
this.defaultValueProvider = defaultValueProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandArgumentSpecBuilder<T, V> withSuggestionProvider(@Nullable SuggestionProvider<T> suggestionProvider) {
|
||||
this.suggestionProvider = suggestionProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandArgumentSpec<T, V> build() {
|
||||
return new CommandArgumentSpecImpl<>(id, type, requirements, defaultValueProvider, suggestionProvider);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package de.kentoj.kencommandapi.api.argument;
|
||||
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public final class CommandArgumentSpecImpl<T, V> implements CommandArgumentSpec<T, V> {
|
||||
@Getter
|
||||
private final String id;
|
||||
@Getter
|
||||
private final ArgumentType<T, V> type;
|
||||
private final List<ArgumentRequirement<V>> requirements;
|
||||
private final Function<CommandContext<T>, V> defaultValueProvider;
|
||||
private final @Nullable SuggestionProvider<T> suggestionProvider;
|
||||
|
||||
@Override
|
||||
public V parseInput(String rawInput) {
|
||||
var parsed = type.parseInputUnchecked(rawInput);
|
||||
for (var requirement : requirements) {
|
||||
if (!requirement.getPredicate().test(parsed))
|
||||
throw new IllegalArgumentException(requirement.getMessage());
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Function<CommandContext<T>, V> getDefaultValueProvider() {
|
||||
return defaultValueProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SuggestionProvider<T> getSuggestionProvider() {
|
||||
return suggestionProvider != null ? suggestionProvider : type.getDefaultSuggestionProvider();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,17 +2,16 @@ package de.kentoj.kencommandapi.api.argument.types;
|
|||
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.suggestion.NoSuggestionProvider;
|
||||
|
||||
public class IntegerArgumentType<T> implements ArgumentType<T, Integer> {
|
||||
|
||||
@Override
|
||||
public Integer parseInput(String string) {
|
||||
public Integer parseInputUnchecked(String string) {
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestionProvider<T> defaultSuggestionProvider() {
|
||||
return new NoSuggestionProvider<>();
|
||||
public SuggestionProvider<T> getDefaultSuggestionProvider() {
|
||||
return SuggestionProvider.none();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package de.kentoj.kencommandapi.api.argument.types;
|
|||
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.api.suggestion.NoSuggestionProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
|
|
@ -15,13 +14,13 @@ public class StringArgumentType<T> implements ArgumentType<T, String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String parseInput(String string) {
|
||||
public String parseInputUnchecked(String string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuggestionProvider<T> defaultSuggestionProvider() {
|
||||
return new NoSuggestionProvider<>();
|
||||
public SuggestionProvider<T> getDefaultSuggestionProvider() {
|
||||
return SuggestionProvider.none();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,37 +1,37 @@
|
|||
package de.kentoj.kencommandapi.api.invocation;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class CommandContext<T> {
|
||||
@Getter
|
||||
private final T sender;
|
||||
@Getter
|
||||
private final Map<String, ParsedArgument<T, ?>> parsedArguments;
|
||||
public interface CommandContext<T> {
|
||||
|
||||
public <V> ParsedArgument<T, V> getParsedArgument(String name) {
|
||||
try {
|
||||
//noinspection unchecked
|
||||
return (ParsedArgument<T, V>) parsedArguments.get(name);
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException("requested argument with wrong type", e);
|
||||
}
|
||||
}
|
||||
T getSender();
|
||||
|
||||
<V> CommandArgument<T, V> getParsedArgument(String id);
|
||||
|
||||
/**
|
||||
* @return the value of the argument with the specified id
|
||||
* @param <V> the type of the value of the argument with the specified id
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> V getArg(String name) {
|
||||
return (V) getParsedArgument(name).getValue();
|
||||
default <V> V getArg(String id) {
|
||||
return (V) getParsedArgument(id).getValue();
|
||||
}
|
||||
|
||||
public <V> V getArg(CommandArgument<T, V> arg) {
|
||||
/**
|
||||
* @param arg the argument whose value to return
|
||||
* @return the value of the argument
|
||||
* @param <V> the type of the value of the argument
|
||||
*/
|
||||
default <V> V getArg(CommandArgumentSpec<T, V> arg) {
|
||||
return getArg(arg.getId());
|
||||
}
|
||||
|
||||
public <V> ParsedArgument<T, V> getParsedArgument(CommandArgument<T, V> arg) {
|
||||
default <V> CommandArgument<T, V> getParsedArgument(CommandArgumentSpec<T, V> arg) {
|
||||
return getParsedArgument(arg.getId());
|
||||
}
|
||||
|
||||
Map<String, CommandArgument<T, ?>> getParsedArguments();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
package de.kentoj.kencommandapi.api.invocation;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
|
||||
public interface ParsedArgument<T, V> {
|
||||
|
||||
V getValue();
|
||||
|
||||
CommandArgument<T, V> getArgument();
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package de.kentoj.kencommandapi.api.literal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.internal.LiteralImpl;
|
||||
import de.kentoj.kencommandapi.internal.RootLiteralImpl;
|
||||
import de.kentoj.kencommandapi.api.invocation.SyncCommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -12,51 +11,26 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
public interface Literal<T> {
|
||||
static <T> Literal<T> literal(String... name) {
|
||||
return new LiteralImpl<>(name);
|
||||
}
|
||||
|
||||
static <T> RootLiteral<T> rootLiteral(MessageStyle messageStyle, String...name) {
|
||||
return new RootLiteralImpl<>(messageStyle, name);
|
||||
static <T> LiteralBuilder<T> builder(String... name) {
|
||||
return new LiteralBuilder<>(name);
|
||||
}
|
||||
|
||||
@NotNull String[] getNames();
|
||||
|
||||
void setDescription(@Nullable String description);
|
||||
|
||||
/**
|
||||
* @return what the literal does
|
||||
*/
|
||||
@Nullable String getDescription();
|
||||
|
||||
/*
|
||||
* arguments
|
||||
*/
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException if there is already an argument with the same id
|
||||
* @throws IllegalStateException if a greedy argument was added to the literal previously
|
||||
*/
|
||||
<V> void addArgument(CommandArgument<T, V> argument);
|
||||
|
||||
List<CommandArgument<T, ?>> getArguments();
|
||||
|
||||
/*
|
||||
* literals
|
||||
*/
|
||||
|
||||
void setExecutor(@Nullable CommandExecutor<T> executor);
|
||||
List<CommandArgumentSpec<T, ?>> getArguments();
|
||||
|
||||
@Nullable CommandExecutor<T> getExecutor();
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException if there is already a literal with the same name
|
||||
* @throws IllegalStateException if a greedy argument was added to the literal previously
|
||||
*/
|
||||
void addLiteral(@NotNull Literal<T> literal);
|
||||
|
||||
@Nullable Literal<T> getLiteral(@NotNull String name);
|
||||
|
||||
@NotNull Set<Literal<T>> getLiterals();
|
||||
@NotNull List<Literal<T>> getLiterals();
|
||||
|
||||
@Nullable String getPermission();
|
||||
|
||||
void setPermission(@Nullable String permission);
|
||||
MessageStyle getMessageStyle();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,100 @@
|
|||
package de.kentoj.kencommandapi.api.literal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.invocation.SyncCommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
public final class LiteralBuilder<T> {
|
||||
|
||||
private final String[] names;
|
||||
private @Nullable String description;
|
||||
private @Nullable CommandExecutor<T> executor;
|
||||
private @Nullable String permission;
|
||||
private @Nullable MessageStyle messageStyle;
|
||||
private final List<CommandArgumentSpec<T, ?>> arguments = new ArrayList<>();
|
||||
private final List<Literal<T>> literals = new ArrayList<>();
|
||||
|
||||
LiteralBuilder(String... names) {
|
||||
checkArgument(names.length > 0, "at least one name is required");
|
||||
this.names = names;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description what the literal does
|
||||
*/
|
||||
public LiteralBuilder<T> withDescription(@Nullable String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiteralBuilder<T> withExecutor(@Nullable CommandExecutor<T> executor) {
|
||||
this.executor = executor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiteralBuilder<T> withSyncExecutor(@Nullable SyncCommandExecutor<T> executor) {
|
||||
return withExecutor(executor);
|
||||
}
|
||||
|
||||
public LiteralBuilder<T> withPermission(@Nullable String permission) {
|
||||
this.permission = permission;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiteralBuilder<T> withStyle(MessageStyle messageStyle) {
|
||||
this.messageStyle = messageStyle;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException if there is already an argument with the same id
|
||||
* @throws IllegalStateException if a greedy argument was added to the literal previously
|
||||
*/
|
||||
public LiteralBuilder<T> withArgument(CommandArgumentSpec<T, ?> argument) {
|
||||
checkArgument(!hasGreedyArg(), "cannot add an argument after a greedy argument");
|
||||
if (arguments.stream().anyMatch(arg -> arg.getId().equals(argument.getId())))
|
||||
throw new IllegalArgumentException("cannot add multiple arguments with the same id");
|
||||
|
||||
this.arguments.add(argument);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalArgumentException if there is already a literal with the same name
|
||||
* @throws IllegalStateException if a greedy argument was added to the literal previously
|
||||
*/
|
||||
public LiteralBuilder<T> withLiteral(Literal<T> literal) {
|
||||
checkArgument(!hasGreedyArg(), "cannot add a literal after a greedy argument");
|
||||
for (String name : literal.getNames())
|
||||
for (var l : literals)
|
||||
if (l.getLiteral(name) != null)
|
||||
throw new IllegalArgumentException("literal with same name already exists");
|
||||
|
||||
this.literals.add(literal);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Literal<T> build() {
|
||||
return new LiteralImpl<>(
|
||||
names,
|
||||
literals,
|
||||
arguments,
|
||||
executor,
|
||||
permission,
|
||||
messageStyle == null ? MessageStyle.PLAIN : messageStyle
|
||||
);
|
||||
}
|
||||
|
||||
private boolean hasGreedyArg() {
|
||||
if (arguments.isEmpty()) return false;
|
||||
var arg = arguments.getLast();
|
||||
return arg != null && arg.getType().isGreedy();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package de.kentoj.kencommandapi.api.literal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
public class LiteralImpl<T> implements Literal<T> {
|
||||
private final String[] names;
|
||||
private final List<Literal<T>> literals;
|
||||
private final List<CommandArgumentSpec<T, ?>> arguments;
|
||||
private final CommandExecutor<T> executor;
|
||||
/**
|
||||
* what the literal does
|
||||
*/
|
||||
private String description;
|
||||
private final @Nullable String permission;
|
||||
private final MessageStyle messageStyle;
|
||||
|
||||
@Override
|
||||
public @Nullable Literal<T> getLiteral(@NotNull String name) {
|
||||
for (Literal<T> literal : literals) {
|
||||
for (var literalName : literal.getNames()) {
|
||||
if (literalName.equalsIgnoreCase(name))
|
||||
return literal;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package de.kentoj.kencommandapi.api.literal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
|
||||
public interface RootLiteral<T> extends Literal<T> {
|
||||
|
||||
MessageStyle getMessageStyle();
|
||||
|
||||
void setMessageStyle(MessageStyle messageStyle);
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
package de.kentoj.kencommandapi.api.platform;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class PlainMessageStyle implements MessageStyle {
|
||||
@NoArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class PlainMessageStyle implements MessageStyle {
|
||||
@Override
|
||||
public Component ok(Component msg) {
|
||||
return msg;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
package de.kentoj.kencommandapi.api.suggestion;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class NoSuggestionProvider<T> implements SuggestionProvider<T> {
|
||||
@NoArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class NoSuggestionProvider<T> implements SuggestionProvider<T> {
|
||||
|
||||
@Override
|
||||
public List<String> suggest(T __) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package de.kentoj.kencommandapi.api.suggestion;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface SuggestionProvider<T> {
|
||||
|
||||
static <T> SuggestionProvider<T> none() {
|
||||
return new NoSuggestionProvider<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an unfiltered(no permission checks or filtering by input) list of strings that may be used for the argument/literal
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
package de.kentoj.kencommandapi.internal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class CommandArgumentImpl<T, V> implements CommandArgument<T, V> {
|
||||
|
||||
@Getter
|
||||
private final String id;
|
||||
@Getter
|
||||
private final ArgumentType<T, V> type;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private @Nullable Function<T, V> defaultValueProvider = null;
|
||||
@Setter
|
||||
private @Nullable SuggestionProvider<T> suggestionProvider;
|
||||
|
||||
@Override
|
||||
public @NotNull SuggestionProvider<T> getSuggestionProvider() {
|
||||
if (suggestionProvider == null)
|
||||
return getType().defaultSuggestionProvider();
|
||||
return this.suggestionProvider;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package de.kentoj.kencommandapi.internal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class CommandContextImpl<T> implements CommandContext<T> {
|
||||
@Getter
|
||||
private final T sender;
|
||||
@Getter
|
||||
private final Map<String, CommandArgument<T, ?>> parsedArguments;
|
||||
|
||||
@Override
|
||||
public <V> CommandArgument<T, V> getParsedArgument(String id) {
|
||||
try {
|
||||
//noinspection unchecked
|
||||
return (CommandArgument<T, V>) parsedArguments.get(id);
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException("requested argument with wrong type", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
package de.kentoj.kencommandapi.internal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandExecutor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class LiteralImpl<T> implements Literal<T> {
|
||||
|
||||
@Getter
|
||||
private final String[] names;
|
||||
@Getter
|
||||
private final Set<Literal<T>> literals = new HashSet<>();
|
||||
@Getter
|
||||
private final List<CommandArgument<T, ?>> arguments = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private @Nullable CommandExecutor<T> executor;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String description;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private @Nullable String permission = null;
|
||||
|
||||
public LiteralImpl(String[] names) {
|
||||
if (names.length == 0) throw new IllegalArgumentException("at least one name is required");
|
||||
this.names = names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLiteral(@NotNull Literal<T> literal) {
|
||||
if (isGreedy()) throw new IllegalStateException("can't add literal to a node with a greedy argument");
|
||||
for (String name : literal.getNames())
|
||||
if (getLiteral(name) != null)
|
||||
throw new IllegalArgumentException("literal with same name already exists");
|
||||
literals.add(literal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Literal<T> getLiteral(@NotNull String name) {
|
||||
for (var literal : literals)
|
||||
for (String literalName : literal.getNames())
|
||||
if (literalName.equalsIgnoreCase(name)) return literal;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> void addArgument(CommandArgument<T, V> argument) {
|
||||
if (isGreedy()) throw new IllegalStateException("can't add literal to a node with a greedy argument");
|
||||
if (arguments.stream().anyMatch(arg -> arg.getId().equals(argument.getId())))
|
||||
throw new IllegalArgumentException("argument with same identifier is already added");
|
||||
arguments.add(argument);
|
||||
}
|
||||
|
||||
private boolean isGreedy() {
|
||||
if (arguments.isEmpty()) return false;
|
||||
var arg = arguments.getLast();
|
||||
return arg != null && arg.getType().isGreedy();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package de.kentoj.kencommandapi.internal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.invocation.ParsedArgument;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class ParsedArgumentImpl<T, V> implements ParsedArgument<T, V> {
|
||||
V value;
|
||||
CommandArgument<T, V> argument;
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package de.kentoj.kencommandapi.internal;
|
||||
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class RootLiteralImpl<T> extends LiteralImpl<T> implements RootLiteral<T> {
|
||||
@Setter
|
||||
@Getter
|
||||
private MessageStyle messageStyle;
|
||||
|
||||
public RootLiteralImpl(MessageStyle messageStyle, String[] names) {
|
||||
super(names);
|
||||
this.messageStyle = messageStyle;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,12 +2,13 @@ package de.kentoj.kencommandapi.internal.parser;
|
|||
|
||||
import com.leakyabstractions.result.api.Result;
|
||||
import com.leakyabstractions.result.core.Results;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.invocation.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.invocation.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.internal.ParsedArgumentImpl;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgumentImpl;
|
||||
import de.kentoj.kencommandapi.internal.CommandContextImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Value;
|
||||
|
||||
|
|
@ -20,17 +21,17 @@ public class InvocationCommandParser<T> {
|
|||
private final CommandParseHelper<T> helper;
|
||||
|
||||
public Result<ExecutionData, String> parse(
|
||||
RootLiteral<T> rootLiteral,
|
||||
Literal<T> rootLiteral,
|
||||
T sender,
|
||||
Iterator<String> tokenIter
|
||||
) {
|
||||
Literal<T> currentLiteral = rootLiteral;
|
||||
Map<String, ParsedArgument<T, ?>> parsedArguments = new HashMap<>();
|
||||
var ctx = new CommandContextImpl<>(sender, new HashMap<>());
|
||||
|
||||
while (true) {
|
||||
{
|
||||
var result = processArguments(currentLiteral, sender, tokenIter)
|
||||
.ifSuccess(parsedArguments::putAll);
|
||||
var result = processArguments(currentLiteral, ctx, tokenIter)
|
||||
.ifSuccess(ctx.getParsedArguments()::putAll);
|
||||
if (result.hasFailure())
|
||||
return result.mapSuccess(__ -> null);
|
||||
}
|
||||
|
|
@ -49,35 +50,35 @@ public class InvocationCommandParser<T> {
|
|||
currentLiteral = nextLiteral;
|
||||
}
|
||||
|
||||
return Results.success(new ExecutionData(currentLiteral.getExecutor(), parsedArguments));
|
||||
return Results.success(new ExecutionData(currentLiteral.getExecutor(), ctx));
|
||||
}
|
||||
|
||||
private Result<Map<String, ParsedArgument<T, ?>>, String> processArguments(
|
||||
private Result<Map<String, CommandArgument<T, ?>>, String> processArguments(
|
||||
Literal<T> literal,
|
||||
T sender,
|
||||
CommandContext<T> ctx,
|
||||
Iterator<String> tokenIter
|
||||
) {
|
||||
Map<String, ParsedArgument<T, ?>> parsedArguments = new HashMap<>();
|
||||
Map<String, CommandArgument<T, ?>> parsedArguments = new HashMap<>();
|
||||
|
||||
for (var _argument : literal.getArguments()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
var argument = ((CommandArgument<T, Object>) _argument);
|
||||
var argument = ((CommandArgumentSpec<T, Object>) _argument);
|
||||
|
||||
Object value;
|
||||
if (!tokenIter.hasNext()) {
|
||||
if (argument.getDefaultValueProvider() == null)
|
||||
return Results.failure("Argument expected: " + argument.getId());
|
||||
value = argument.getDefaultValueProvider().apply(sender);
|
||||
value = argument.getDefaultValueProvider().apply(ctx);
|
||||
} else {
|
||||
var input = helper.parseInput(tokenIter, argument.getType().isGreedy());
|
||||
try {
|
||||
value = argument.getType().parseInput(input);
|
||||
value = argument.parseInput(input);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return Results.failure("Illegal argument '" + input + "' for " + argument.getId() + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
parsedArguments.put(argument.getId(), new ParsedArgumentImpl<>(value, argument));
|
||||
parsedArguments.put(argument.getId(), new CommandArgumentImpl<>(value, argument));
|
||||
}
|
||||
|
||||
return Results.success(parsedArguments);
|
||||
|
|
@ -86,6 +87,6 @@ public class InvocationCommandParser<T> {
|
|||
@Value
|
||||
public class ExecutionData {
|
||||
CommandExecutor<T> executor;
|
||||
Map<String, ParsedArgument<T, ?>> arguments;
|
||||
CommandContext<T> context;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package de.kentoj.kencommandapi.internal.parser;
|
||||
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -16,7 +15,7 @@ public class SuggestionCommandParser<T> {
|
|||
private final CommandParseHelper<T> helper;
|
||||
|
||||
public List<String> suggest(
|
||||
RootLiteral<T> rootLiteral,
|
||||
Literal<T> rootLiteral,
|
||||
T sender,
|
||||
Iterator<String> tokenIter,
|
||||
boolean suggestNext
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package de.kentoj.kencommandapi.api.parser;
|
|||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.argument.types.StringArgumentType;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import de.kentoj.kencommandapi.api.platform.MessageStyle;
|
||||
import de.kentoj.kencommandapi.internal.parser.SuggestionCommandParser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
public class SuggestionCommandParserTest {
|
||||
|
||||
private final SuggestionCommandParser<Object> suggestionParser;
|
||||
private final RootLiteral<Object> rootLiteral;
|
||||
private final Literal<Object> rootLiteral;
|
||||
|
||||
public SuggestionCommandParserTest() {
|
||||
rootLiteral = Literal.rootLiteral(MessageStyle.PLAIN, "someRootNode");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package de.kentoj.kencommandapi;
|
|||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.kentoj.kencommandapi.api.CommandHandler;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -15,7 +15,7 @@ public class CommandAPI {
|
|||
private final CommandHandler<CommandSource> commandHandler =
|
||||
new CommandHandler<>(CommandSource::sendMessage, CommandSource::hasPermission);
|
||||
|
||||
public void register(RootLiteral<CommandSource> rootNode) {
|
||||
public void register(Literal<CommandSource> rootNode) {
|
||||
var cm = server.getCommandManager();
|
||||
var meta = cm.metaBuilder(rootNode.getNames()[0])
|
||||
.aliases(Arrays.copyOfRange(rootNode.getNames(), 1, rootNode.getNames().length))
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package de.kentoj.kencommandapi;
|
|||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.RawCommand;
|
||||
import de.kentoj.kencommandapi.api.CommandHandler;
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
import de.kentoj.kencommandapi.api.literal.Literal;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
public class VelocityCommand implements RawCommand {
|
||||
|
||||
private final CommandHandler<CommandSource> commandHandler;
|
||||
private final RootLiteral<CommandSource> rootNode;
|
||||
private final Literal<CommandSource> rootNode;
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
|
|
|
|||
1
third_party/BUILD
vendored
1
third_party/BUILD
vendored
|
|
@ -4,5 +4,4 @@ java_plugin(
|
|||
visibility = ["//visibility:public"],
|
||||
deps = ["@maven//:org_projectlombok_lombok"],
|
||||
processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
|
||||
generates_api = True,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue