diff --git a/build.gradle.kts b/build.gradle.kts index 41dd70c..3657f77 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,6 @@ +val scrowToken = providers.gradleProperty("scrowMavenToken") + .orElse(providers.environmentVariable("SCROW_MAVEN_TOKEN")).get() + plugins { id("java") id("io.freefair.lombok") version "9.2.0" apply false @@ -19,6 +22,18 @@ subprojects { maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") { name = "spigotmc-repo" } + maven { + name = "scrow" + url = uri("http://forge.kentoj.de/api/packages/scrow/maven") + isAllowInsecureProtocol = true + credentials(HttpHeaderCredentials::class) { + name = "Authorization" + value = "token $scrowToken" + } + authentication { + create("header") + } + } } dependencies { @@ -26,7 +41,7 @@ subprojects { implementation("org.jetbrains:annotations:26.0.2-1") // https://projectreactor.io/docs/core/release/reference/gettingStarted.html - implementation(platform("io.projectreactor:reactor-bom:2025.0.3")) + implementation(platform("io.projectreactor:reactor-bom:2025.0.3")) implementation("io.projectreactor:reactor-core") // https://mvnrepository.com/artifact/com.google.guava/guava diff --git a/core-bukkit-api/build.gradle.kts b/core-bukkit-api/build.gradle.kts index 56c737d..24048c8 100644 --- a/core-bukkit-api/build.gradle.kts +++ b/core-bukkit-api/build.gradle.kts @@ -1,4 +1,5 @@ -import org.gradle.internal.declarativedsl.dom.mutation.valueFromString +val scrowToken = providers.gradleProperty("scrowMavenToken") + .orElse(providers.environmentVariable("SCROW_MAVEN_TOKEN")) plugins { id("java") @@ -11,6 +12,20 @@ version = "1.0-SNAPSHOT" repositories { mavenCentral() + maven { + name = "scrow" + url = uri("http://forge.kentoj.de/api/packages/scrow/maven") + isAllowInsecureProtocol = true + + credentials(HttpHeaderCredentials::class) { + name = "Authorization" + value = "token $scrowToken" + } + + authentication { + create("header") + } + } } dependencies { @@ -20,33 +35,19 @@ dependencies { api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT") api("net.kyori:adventure-platform-bukkit:4.4.1") + + api("de.kentoj:kencommandapi-core:1.0.0") } publishing { publications { - create("CoreBukkitApi") { + create("ScrowBukkitApi") { groupId = project.group.toString() artifactId = project.name version = project.version.toString() from(components["java"]) } } - repositories { - maven { - name = "scrow" - url = uri("http://forge.kentoj.de/api/packages/scrow/maven") - isAllowInsecureProtocol = true - - credentials(HttpHeaderCredentials::class) { - name = "Authorization" - value = "token a967694822eed6e97b1b20e8737733ef1400fa1f" - } - - authentication { - create("header") - } - } - } } tasks.test { diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/EconomyService.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/EconomyService.java similarity index 95% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/EconomyService.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/EconomyService.java index 4f57459..b74ac16 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/EconomyService.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/EconomyService.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services; +package de.kentoj.scrow.bukkit; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Mono; diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java index 721e7f5..ffd8a59 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java @@ -1,12 +1,15 @@ package de.kentoj.scrow.bukkit; import com.mongodb.reactivestreams.client.MongoDatabase; -import de.kentoj.scrow.bukkit.services.EconomyService; -import de.kentoj.scrow.bukkit.services.command.CommandManager; -import de.kentoj.scrow.bukkit.services.friends.FriendsService; +import de.kentoj.kencommandapi.api.KenCommandApi; +import de.kentoj.kencommandapi.api.processing.CommandContext; +import de.kentoj.kencommandapi.api.structure.node.CommandNode; +import de.kentoj.scrow.bukkit.friends.FriendsService; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; +import org.bukkit.command.CommandSender; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import reactor.core.scheduler.Scheduler; @@ -17,7 +20,7 @@ public class ScrowAPI { @Getter private static @Nullable MongoDatabase database; @Getter - private static CommandManager commandManager; + private static KenCommandApi> commandManager; @Getter private static Scheduler minecraftScheduler; @Getter @@ -36,7 +39,7 @@ public class ScrowAPI { } @ApiStatus.Internal - public static void setCommandManager(CommandManager commandManager) { + public static void setCommandManager(KenCommandApi> commandManager) { ScrowAPI.commandManager = commandManager; } diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/Email.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/Email.java similarity index 86% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/Email.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/Email.java index e5797c2..1b5ac62 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/Email.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/Email.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services.email; +package de.kentoj.scrow.bukkit.email; import org.jetbrains.annotations.Nullable; diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/EmailDraft.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/EmailDraft.java similarity index 91% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/EmailDraft.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/EmailDraft.java index 5cbb0bd..cfcf406 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/EmailDraft.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/EmailDraft.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services.email; +package de.kentoj.scrow.bukkit.email; import org.jetbrains.annotations.Nullable; diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/EmailService.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/EmailService.java similarity index 92% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/EmailService.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/EmailService.java index f609a47..7778116 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/email/EmailService.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/email/EmailService.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services.email; +package de.kentoj.scrow.bukkit.email; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Flux; diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendRequest.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendRequest.java similarity index 75% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendRequest.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendRequest.java index 644de2f..58e250f 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendRequest.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendRequest.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services.friends; +package de.kentoj.scrow.bukkit.friends; import java.time.Instant; import java.util.UUID; diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendRequestUsageException.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendRequestUsageException.java similarity index 84% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendRequestUsageException.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendRequestUsageException.java index f4637df..7d08abc 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendRequestUsageException.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendRequestUsageException.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services.friends; +package de.kentoj.scrow.bukkit.friends; public class FriendRequestUsageException extends RuntimeException { diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendsService.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendsService.java similarity index 95% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendsService.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendsService.java index f2f114b..ce13313 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/FriendsService.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/FriendsService.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services.friends; +package de.kentoj.scrow.bukkit.friends; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Flux; diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/Friendship.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/Friendship.java similarity index 87% rename from core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/Friendship.java rename to core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/Friendship.java index b22eafa..be4cf13 100644 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/friends/Friendship.java +++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/Friendship.java @@ -1,4 +1,4 @@ -package de.kentoj.scrow.bukkit.services.friends; +package de.kentoj.scrow.bukkit.friends; import de.kentoj.scrow.bukkit.util.pair.Tuple2; diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/CommandFactory.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/CommandFactory.java deleted file mode 100644 index e584c14..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/CommandFactory.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command; - -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import de.kentoj.scrow.bukkit.services.command.literal.Literal; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import de.kentoj.scrow.bukkit.services.command.type.ArgumentType; - -import java.util.function.Function; - -public interface CommandFactory { - - Literal literal(String name); - - RootLiteral root(String name); - - CommandArgument argument(String name, ArgumentType type, Function defaultValueFun); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/CommandManager.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/CommandManager.java deleted file mode 100644 index ca3db96..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/CommandManager.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command; - -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import org.bukkit.plugin.Plugin; - -public interface CommandManager { - - void register(RootLiteral rootLiteral, Plugin plugin); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/Commands.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/Commands.java deleted file mode 100644 index f190a5c..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/Commands.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command; - -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import de.kentoj.scrow.bukkit.services.command.literal.Literal; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import de.kentoj.scrow.bukkit.services.command.type.ArgumentType; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.jetbrains.annotations.ApiStatus; - -import java.util.function.Function; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class Commands { - - private static CommandFactory factory; - - public static Literal literal(String name) { - return factory.literal(name); - } - - public static RootLiteral root(String name) { - return factory.root(name); - } - - public static CommandArgument argument0(String name, ArgumentType type, Function defaultValueFun) { - return factory.argument(name, type, defaultValueFun); - } - - public static CommandArgument argument1(String name, ArgumentType type, T defaultValue) { - return factory.argument(name, type, __ -> defaultValue); - } - - public static CommandArgument argument0(String name, ArgumentType type) { - return factory.argument(name, type, __ -> null); - } - - @ApiStatus.Internal - public static void setFactory(CommandFactory factory) { - Commands.factory = factory; - } -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/SuggestionProvider.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/SuggestionProvider.java deleted file mode 100644 index 6df8520..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/SuggestionProvider.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command; - -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; - -import java.util.Set; - -public interface SuggestionProvider { - - Set suggest(CommandContext context); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/exception/CommandInvocationException.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/exception/CommandInvocationException.java deleted file mode 100644 index e28fe57..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/exception/CommandInvocationException.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.exception; - -/** - * When a command has a syntax issue. - * {@code CommandSyntaxException::getMessage} should return a user-friendly message explaining the issue. - */ -public class CommandInvocationException extends RuntimeException { - - /** - * @param message user-friendly message - */ - public CommandInvocationException(String message) { - super(message); - } - - /** - * @param message user-friendly message - */ - public CommandInvocationException(String message, Throwable throwable) { - super(message + ": " + throwable.getMessage()); - } -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/ArgumentData.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/ArgumentData.java deleted file mode 100644 index 5469835..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/ArgumentData.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.execution; - -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import org.jetbrains.annotations.Nullable; - -public interface ArgumentData { - - T getValue(); - - CommandArgument getArgument(); - - /** - * @return null if the default value for the type was used - */ - @Nullable String getRawInput(); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/CommandContext.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/CommandContext.java deleted file mode 100644 index d08b962..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/CommandContext.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.execution; - -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public interface CommandContext { - - CommandSender getSender(); - - Player getSenderPlayer(); - - Entity getSenderEntity(); - - /** - * @return Object that is parsed from the raw argument - * @throws CommandInvocationException if no value given and no default value supplied - */ - ArgumentData getArgData(String name); - - @SuppressWarnings("unchecked") - default T getArgData(CommandArgument arg) { - return (T) getArgData(arg.getName()); - } - - @SuppressWarnings("unchecked") - default T getArg(String name) { - return (T) getArgData(name).getValue(); - } - - @SuppressWarnings("unchecked") - default T getArg(CommandArgument arg) { - return (T) getArgData(arg.getName()).getValue(); - } -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/CommandExecutor.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/CommandExecutor.java deleted file mode 100644 index f3700c7..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/execution/CommandExecutor.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.execution; - -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; - -public interface CommandExecutor { - - void execute(CommandContext ctx) throws CommandInvocationException; -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/ArgumentReader.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/ArgumentReader.java deleted file mode 100644 index d927492..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/ArgumentReader.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.literal; - -public interface ArgumentReader { - - boolean isEOF(); - - String readWord(); - - String readQuotedWord(); - - int getCursor(); - - void setCursor(int cursor); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/CommandArgument.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/CommandArgument.java deleted file mode 100644 index adad226..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/CommandArgument.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.literal; - -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.SuggestionProvider; -import de.kentoj.scrow.bukkit.services.command.type.ArgumentType; -import org.jetbrains.annotations.Nullable; - -public interface CommandArgument { - - String getName(); - - ArgumentType getType(); - - @Nullable T getDefaultValue(CommandContext ctx); - - void setSuggestionProvider(@Nullable SuggestionProvider suggestionProvider); - - /** - * @return the explicitly set SuggestionProvider or the suggestions for the type if unset/null - */ - SuggestionProvider getSuggestionProvider(); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/Literal.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/Literal.java deleted file mode 100644 index adbd51a..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/Literal.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.literal; - -import de.kentoj.scrow.bukkit.services.command.execution.CommandExecutor; -import org.bukkit.permissions.Permission; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Set; - -public interface Literal { - - /** - * String with no spaces! - */ - void setName(String name); - - /** - * String with no spaces! - */ - String getName(); - - void addLiteral(Literal node); - - @Nullable Literal getLiteral(String rawArg); - - Set getLiterals(); - - boolean hasLiteral(); - - void setExecutor(@Nullable CommandExecutor executor); - - @Nullable CommandExecutor getExecutor(); - - void setDescription(@Nullable String description); - - @Nullable String getDescription(); - - Permission getRequiredPermission(); - - void setRequiredPermission(Permission permission); - - void addArgument(CommandArgument argument); - - List> getArguments(); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/RootLiteral.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/RootLiteral.java deleted file mode 100644 index 61beca9..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/literal/RootLiteral.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.literal; - -import java.util.Set; - -public interface RootLiteral extends Literal { - - Set getAliases(); - - void setAliases(Set aliases); - - void addAliases(String... aliases); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/ArgumentType.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/ArgumentType.java deleted file mode 100644 index f5bd226..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/ArgumentType.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.type; - -import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; - -import java.util.Set; - -public interface ArgumentType { - - T parseInput(String rawInput); - - String readRawInput(ArgumentReader reader); - - /** - * @throws CommandInvocationException if the given value may not be used - */ - void checkValue(CommandContext ctx, T value, String rawInput) throws CommandInvocationException; - - Set getDefaultSuggestions(CommandContext ctx); -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/NumberArgumentType.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/NumberArgumentType.java deleted file mode 100644 index bebc540..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/NumberArgumentType.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.type; - -import com.google.common.base.Preconditions; -import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Set; - -// TODO add livingEntity - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class NumberArgumentType { - - public static ArgumentType integer(int min, int max) { - Preconditions.checkArgument(min < max, "min is greater than max"); - - return new ArgumentType<>() { - @Override - public Integer parseInput(String rawInput) { - try { - return Integer.parseInt(rawInput); - } catch (NumberFormatException ex) { - throw new CommandInvocationException("Invalid number -- " + rawInput); - } - } - - @Override - public String readRawInput(ArgumentReader reader) { - return reader.readWord(); - } - - @Override - public void checkValue(CommandContext ctx, Integer value, String rawInput) throws CommandInvocationException { - if (value < min) throw new CommandInvocationException("Value too small -- " + value); - if (value > max) throw new CommandInvocationException("Value too large -- " + value); - } - - @Override - public Set getDefaultSuggestions(CommandContext ctx) { - return Set.of(); - } - }; - } -} diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/PlayerArgumentType.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/PlayerArgumentType.java deleted file mode 100644 index be19e5d..0000000 --- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/services/command/type/PlayerArgumentType.java +++ /dev/null @@ -1,89 +0,0 @@ -package de.kentoj.scrow.bukkit.services.command.type; - -import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -// TODO add livingEntity - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlayerArgumentType { - - private static final ArgumentType player = new ArgumentType<>() { - - @Override - public Player parseInput(String rawInput) { - if (rawInput.length() == 36) { - var uuid = UUID.fromString(rawInput); - return Bukkit.getPlayer(uuid); - } else { - return Bukkit.getPlayerExact(rawInput); - } - } - - @Override - public String readRawInput(ArgumentReader reader) { - return reader.readWord(); - } - - @Override - public void checkValue(CommandContext ctx, Player value, String rawInput) throws CommandInvocationException { - if (value == null) throw new CommandInvocationException("Player is not online -- " + rawInput); - } - - @Override - public Set getDefaultSuggestions(CommandContext ctx) { - return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toSet()); - } - }; - - private static final ArgumentType offlinePlayer = new ArgumentType<>() { - - @Override - public OfflinePlayer parseInput(String rawInput) { - OfflinePlayer player; - - player = Bukkit.getPlayerExact(rawInput); - if (player == null) { - try { - player = Bukkit.getOfflinePlayer(UUID.fromString(rawInput)); - } catch (IllegalArgumentException ex) { - throw new CommandInvocationException("Not a UUID or name of an online player -- " + rawInput); - } - } - return player; - } - - @Override - public String readRawInput(ArgumentReader reader) { - return reader.readWord(); - } - - @Override - public Set getDefaultSuggestions(CommandContext ctx) { - return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toSet()); - } - - @Override - public void checkValue(CommandContext ctx, OfflinePlayer value, String rawInput) throws CommandInvocationException { - if (!value.hasPlayedBefore()) throw new CommandInvocationException("Player has never played before -- " + rawInput); - } - }; - - public static ArgumentType player() { - return player; - } - - public static ArgumentType offlinePlayer() { - return offlinePlayer; - } -} diff --git a/core-bukkit-impl/build.gradle.kts b/core-bukkit-impl/build.gradle.kts index c609bba..04e7941 100644 --- a/core-bukkit-impl/build.gradle.kts +++ b/core-bukkit-impl/build.gradle.kts @@ -18,8 +18,11 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher") - implementation(project(":core-bukkit-api")) implementation(kotlin("stdlib-jdk8")) + implementation(project(":core-bukkit-api")) + + implementation("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT") + implementation("de.kentoj:kencommandapi-bukkit:1.0.0") } tasks { diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java index 439bccc..c6a3d1b 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java @@ -1,5 +1,6 @@ package de.kentoj.scrow.bukkit; +import de.kentoj.kencommandapi.BukkitKenCommandApi; import de.kentoj.scrow.bukkit.economy.CoinsCommand; import de.kentoj.scrow.bukkit.friends.command.FriendCommand; import org.bukkit.plugin.java.JavaPlugin; @@ -14,6 +15,7 @@ public class CoreImplPlugin extends JavaPlugin { ScrowAPISurface.initScrowAPI(this, false); { + BukkitKenCommandApi kenCommandApi = new BukkitKenCommandApi(); ScrowAPI.getCommandManager().register(new CoinsCommand().create(), this); ScrowAPI.getCommandManager().register(new FriendCommand().create(), this); } diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java index d11e4ae..943616b 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java @@ -4,11 +4,12 @@ import com.mongodb.ConnectionString; import com.mongodb.MongoClientSettings; import com.mongodb.reactivestreams.client.MongoClient; import com.mongodb.reactivestreams.client.MongoClients; +import de.kentoj.kencommandapi.BukkitKenCommandApi; import de.kentoj.scrow.bukkit.cmds2.CommandFactoryImpl; import de.kentoj.scrow.bukkit.cmds2.bukkit.BukkitCommandManager; import de.kentoj.scrow.bukkit.economy.InMemoryEconomyService; import de.kentoj.scrow.bukkit.economy.MongoEconomyService; -import de.kentoj.scrow.bukkit.services.command.Commands; +import de.kentoj.scrow.bukkit.command.Commands; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.bson.UuidRepresentation; @@ -47,9 +48,10 @@ public class ScrowAPISurface { ScrowAPI.getDatabase() != null ? new MongoEconomyService(ScrowAPI.getDatabase()) : new InMemoryEconomyService() ); + + ScrowAPI.setCommandManager(new BukkitKenCommandApi()); + // TODO friends service - Commands.setFactory(new CommandFactoryImpl()); - ScrowAPI.setCommandManager(new BukkitCommandManager()); } public static void destroyScrowAPI() { diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandArgumentImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandArgumentImpl.java deleted file mode 100644 index 91dab4e..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandArgumentImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2; - -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.SuggestionProvider; -import de.kentoj.scrow.bukkit.services.command.type.ArgumentType; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import org.jetbrains.annotations.Nullable; - -import java.util.function.Function; - -@Getter -@RequiredArgsConstructor -public class CommandArgumentImpl implements CommandArgument { - - private final String name; - private final ArgumentType type; - private final Function defaultValueFun; - @Setter - private @Nullable SuggestionProvider suggestionProvider; - - @Override - public @Nullable T getDefaultValue(CommandContext ctx) { - return defaultValueFun.apply(ctx); - } - - public SuggestionProvider getSuggestionProvider() { - if (suggestionProvider == null) - return type::getDefaultSuggestions; - return suggestionProvider; - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandContextImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandContextImpl.java deleted file mode 100644 index f4377db..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandContextImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2; - -import com.google.common.base.Preconditions; -import de.kentoj.scrow.bukkit.services.command.execution.ArgumentData; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.util.Map; - -@RequiredArgsConstructor -public class CommandContextImpl implements CommandContext { - - @Getter - private final CommandSender sender; - private final Map> arguments; - - @SuppressWarnings("unchecked") - public ArgumentData getArgData(String name) { - final var data = (ArgumentData) arguments.get(name); - Preconditions.checkState(data != null, "no data for '" + name + "'-argument"); - return data; - } - - @Override - public Player getSenderPlayer() { - if (!(sender instanceof Player)) throw new CommandInvocationException("This command can only be used by players"); - return (Player) sender; - } - - @Override - public Entity getSenderEntity() { - if (!(sender instanceof Entity)) throw new CommandInvocationException("This command can only be used by entities"); - return (Entity) sender; - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandFactoryImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandFactoryImpl.java deleted file mode 100644 index c14d6a2..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/CommandFactoryImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2; - -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.CommandFactory; -import de.kentoj.scrow.bukkit.services.command.literal.Literal; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import de.kentoj.scrow.bukkit.services.command.type.ArgumentType; - -import java.util.function.Function; - -public class CommandFactoryImpl implements CommandFactory { - - @Override - public Literal literal(String name) { - return new LiteralImpl(name); - } - - @Override - public RootLiteral root(String name) { - return new RootLiteralImpl(name); - } - - @Override - public CommandArgument argument(String name, ArgumentType type, Function defaultValueFun) { - return new CommandArgumentImpl<>(name, type, defaultValueFun); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/LiteralImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/LiteralImpl.java deleted file mode 100644 index d8fa877..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/LiteralImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2; - -import de.kentoj.scrow.bukkit.services.command.execution.CommandExecutor; -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import de.kentoj.scrow.bukkit.services.command.literal.Literal; -import lombok.Getter; -import lombok.Setter; -import org.bukkit.Bukkit; -import org.bukkit.permissions.Permission; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -@Getter -public class LiteralImpl implements Literal { - - @Setter - private String name; - - @Setter - private @Nullable Permission requiredPermission = null; - @Setter - private @Nullable String description = null; - @Setter - private @Nullable CommandExecutor executor = null; - private final List> arguments = new ArrayList<>(); - private final Map literals = new HashMap<>(); - - public LiteralImpl(String name) { - this.name = name; - } - - @Override - public void addLiteral(Literal node) { - if (literals.containsKey(node.getName())) { - Bukkit.getLogger().warning("Literal " + node.getName() + " is overwritten by literal with same name"); - } - literals.put(node.getName(), node); - } - - @Override - public @Nullable Literal getLiteral(String name) { - return literals.get(name); - } - - @Override - public boolean hasLiteral() { - return !literals.isEmpty(); - } - - @Override - public Set getLiterals() { - return new HashSet<>(literals.values()); - } - - @Override - public void addArgument(CommandArgument argument) { - arguments.add(argument); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/RootLiteralImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/RootLiteralImpl.java deleted file mode 100644 index b4b0b71..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/RootLiteralImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2; - -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import lombok.Getter; -import lombok.Setter; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class RootLiteralImpl extends LiteralImpl implements RootLiteral { - - @Getter - @Setter - private Set aliases = new HashSet<>(); - - public RootLiteralImpl(String name) { - super(name); - } - - @Override - public void addAliases(String... aliases) { - this.aliases.addAll(List.of(aliases)); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitCommand.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitCommand.java deleted file mode 100644 index 54bc851..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2.bukkit; - -import de.kentoj.scrow.bukkit.cmds2.parsing.ArgumentReaderImpl; -import de.kentoj.scrow.bukkit.cmds2.parsing.CommandProcessor; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -public class BukkitCommand extends Command { - - private final RootLiteral rootLiteral; - - public BukkitCommand(RootLiteral rootLiteral) { - super(rootLiteral.getName()); - this.rootLiteral = rootLiteral; - - if (rootLiteral.getDescription() != null) { - super.setDescription(rootLiteral.getDescription()); - } - if (rootLiteral.getAliases() != null) { - super.setAliases(rootLiteral.getAliases().stream().toList()); - } - // TODO usage string? - } - - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) { - try { - new CommandProcessor(sender, new ArgumentReaderImpl(args)).execute(rootLiteral); - } catch (CommandInvocationException syntaxException) { - sender.sendMessage(ChatColor.RED + syntaxException.getMessage()); - } - return true; - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitCommandManager.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitCommandManager.java deleted file mode 100644 index b330320..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitCommandManager.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2.bukkit; - -import de.kentoj.scrow.bukkit.services.command.CommandManager; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandMap; -import org.bukkit.plugin.Plugin; - -public class BukkitCommandManager implements CommandManager { - - private final CommandMap commandMap; - - public BukkitCommandManager() { - try { - var field = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap"); - field.setAccessible(true); - commandMap = (CommandMap) field.get(Bukkit.getPluginManager()); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - @Override - public void register(RootLiteral rootLiteral, Plugin plugin) { - var bukkitCommand = new BukkitCommand(rootLiteral); - commandMap.register(plugin.getName(), bukkitCommand); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitTabCompleter.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitTabCompleter.java deleted file mode 100644 index 06b5cda..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/bukkit/BukkitTabCompleter.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2.bukkit; - -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import lombok.RequiredArgsConstructor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -@RequiredArgsConstructor -public class BukkitTabCompleter implements TabCompleter { - - private final RootLiteral rootLiteral; - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - - return List.of(); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/ArgumentDataImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/ArgumentDataImpl.java deleted file mode 100644 index 7609256..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/ArgumentDataImpl.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2.parsing; - -import de.kentoj.scrow.bukkit.services.command.execution.ArgumentData; -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import lombok.Value; -import org.jetbrains.annotations.Nullable; - -@Value -public class ArgumentDataImpl implements ArgumentData { - T value; - CommandArgument argument; - @Nullable String rawInput; -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/ArgumentReaderImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/ArgumentReaderImpl.java deleted file mode 100644 index 8eed79c..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/ArgumentReaderImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2.parsing; - -import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader; -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; - -import java.nio.CharBuffer; - -public class ArgumentReaderImpl implements ArgumentReader { - - private final CharBuffer buf; - - public ArgumentReaderImpl(String string) { - buf = CharBuffer.wrap(string); - } - - public ArgumentReaderImpl(String[] args) { - this(String.join(" ", args)); - } - - @Override - public boolean isEOF() { - return buf.position() >= buf.limit(); - } - - @Override - public String readWord() { - final var str = new StringBuilder(); - while (true) { - if (buf.position() >= buf.limit()) break; - final char c = buf.get(); - if (c == ' ') break; - str.append(c); - } - return str.toString(); - } - - @Override - public String readQuotedWord() { - final var str = new StringBuilder(); - var quoting = false; - while (true) { - if (buf.position() >= buf.limit()) break; - final char c = buf.get(); - if (c == '"') quoting = !quoting; - if (c == ' ' && !quoting) break; - str.append(c); - } - - if (quoting) throw new CommandInvocationException("Missing matching \" to terminate quote"); - return str.toString(); - } - - @Override - public int getCursor() { - return buf.position(); - } - - @Override - public void setCursor(int cursor) { - buf.position(cursor); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/CommandProcessor.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/CommandProcessor.java deleted file mode 100644 index cca2e1e..0000000 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/cmds2/parsing/CommandProcessor.java +++ /dev/null @@ -1,76 +0,0 @@ -package de.kentoj.scrow.bukkit.cmds2.parsing; - -import de.kentoj.scrow.bukkit.cmds2.CommandContextImpl; -import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException; -import de.kentoj.scrow.bukkit.services.command.execution.ArgumentData; -import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader; -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import de.kentoj.scrow.bukkit.services.command.literal.Literal; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import lombok.RequiredArgsConstructor; -import org.bukkit.command.CommandSender; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -@RequiredArgsConstructor -public class CommandProcessor { - - private final Map> arguments = new HashMap<>(); - - private final CommandSender sender; - private final ArgumentReader argumentReader; - - public void execute(RootLiteral rootLiteral) { - Literal literal = rootLiteral; - do { - processArguments(literal); - - if (argumentReader.isEOF()) { - if (literal.getExecutor() == null) { - throw new CommandInvocationException("Incomplete command -- literal expected"); - } - literal.getExecutor().execute(new CommandContextImpl(sender, arguments)); - return; - } - - final var literalName = argumentReader.readWord(); - final var nextLiteral = literal.getLiteral(literalName); - if (nextLiteral == null) { - final String validLiterals = literal.getLiterals().stream().map(Literal::getName).collect(Collectors.joining(", ")); - throw new CommandInvocationException("Unknown literal -- " + literalName + - "\nValid literals: " + validLiterals); - } - literal = nextLiteral; - - final boolean hasSenderPermission = literal.getRequiredPermission() == null || sender.hasPermission(literal.getRequiredPermission()); - if (!hasSenderPermission) throw new CommandInvocationException("No permission"); - } while (literal.hasLiteral()); - - processArguments(literal); - - if (literal.getExecutor() == null) throw new CommandInvocationException("Incomplete command."); - literal.getExecutor().execute(new CommandContextImpl(sender, arguments)); - } - - private void processArguments(Literal node) { - node.getArguments().forEach(arg -> { - var parsed = parseArgument(arg); - arguments.put(arg.getName(), parsed); - }); - } - - private ArgumentData parseArgument(CommandArgument argument) { - if (argumentReader.isEOF()) { - final var defaultValue = argument.getDefaultValue(new CommandContextImpl(sender, arguments)); - if (defaultValue == null) throw new CommandInvocationException("Missing argument -- " + argument.getName()); - return new ArgumentDataImpl<>(defaultValue, argument, null); - } - - final var rawInput = argument.getType().readRawInput(argumentReader); - final T value = argument.getType().parseInput(rawInput); - argument.getType().checkValue(new CommandContextImpl(sender, arguments), value, rawInput); - return new ArgumentDataImpl<>(value, argument, rawInput); - } -} diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/CoinsCommand.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/CoinsCommand.java index 0c1ebc6..130eb08 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/CoinsCommand.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/CoinsCommand.java @@ -1,30 +1,41 @@ package de.kentoj.scrow.bukkit.economy; +import de.kentoj.kencommandapi.BukkitKenCommandApi; +import de.kentoj.kencommandapi.api.processing.CommandContext; +import de.kentoj.kencommandapi.api.structure.argument.types.IntegerArgumentType; +import de.kentoj.kencommandapi.api.structure.node.CommandNode; import de.kentoj.scrow.bukkit.ScrowAPI; -import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.Commands; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; -import de.kentoj.scrow.bukkit.services.command.type.NumberArgumentType; -import de.kentoj.scrow.bukkit.services.command.type.PlayerArgumentType; +import de.kentoj.scrow.bukkit.command.Commands; +import de.kentoj.scrow.bukkit.command.execution.CommandContext; +import de.kentoj.scrow.bukkit.command.literal.CommandArgument; +import de.kentoj.scrow.bukkit.command.literal.RootLiteral; +import de.kentoj.scrow.bukkit.command.type.NumberArgumentType; +import de.kentoj.scrow.bukkit.command.type.PlayerArgumentType; +import lombok.var; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; import reactor.core.scheduler.Schedulers; import java.util.logging.Level; public class CoinsCommand { - private final RootLiteral rootCommand; private final CommandArgument playerArg; private final CommandArgument amountArg; + public void create() { + var rootCommand = ScrowAPI.getCommandManager().createNode("coins"); + + var playerArg = ScrowAPI.getCommandManager().createArgument("player", ) + } + /* /coins steve /coins steve set 0 /coins steve get */ - public CoinsCommand() { + public CoinsCommand(BukkitKenCommandApi commandManager) { playerArg = Commands.argument0("player", PlayerArgumentType.offlinePlayer(), CommandContext::getSenderPlayer); amountArg = Commands.argument0("amount", NumberArgumentType.integer(0, Integer.MAX_VALUE)); @@ -45,10 +56,6 @@ public class CoinsCommand { } } - public RootLiteral create() { - return rootCommand; - } - private void getCoins(CommandContext ctx) { final var player = ctx.getArg(playerArg); diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/InMemoryEconomyService.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/InMemoryEconomyService.java index 372813b..f9207af 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/InMemoryEconomyService.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/InMemoryEconomyService.java @@ -1,7 +1,7 @@ package de.kentoj.scrow.bukkit.economy; import com.google.common.base.Preconditions; -import de.kentoj.scrow.bukkit.services.EconomyService; +import de.kentoj.scrow.bukkit.EconomyService; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Mono; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/MongoEconomyService.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/MongoEconomyService.java index 96c80ad..96d2534 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/MongoEconomyService.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/MongoEconomyService.java @@ -6,9 +6,8 @@ import com.mongodb.client.model.UpdateOptions; import com.mongodb.client.model.Updates; import com.mongodb.reactivestreams.client.MongoCollection; import com.mongodb.reactivestreams.client.MongoDatabase; -import de.kentoj.scrow.bukkit.services.EconomyService; +import de.kentoj.scrow.bukkit.EconomyService; import org.bson.Document; -import org.bson.types.ObjectId; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Mono; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java index 6e64a3b..a28eacc 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendCommand.java @@ -1,12 +1,10 @@ package de.kentoj.scrow.bukkit.friends.command; -import de.kentoj.scrow.bukkit.services.command.Commands; -import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral; +import de.kentoj.scrow.bukkit.command.Commands; +import de.kentoj.scrow.bukkit.command.literal.RootLiteral; public class FriendCommand { - private final RootLiteral rootLiteral; - public FriendCommand() { rootLiteral = Commands.root("friend"); rootLiteral.addAliases("f", "friends"); diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java index b1857f2..246eceb 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendListLiteral.java @@ -1,9 +1,9 @@ package de.kentoj.scrow.bukkit.friends.command; import de.kentoj.scrow.bukkit.ScrowAPI; -import de.kentoj.scrow.bukkit.services.command.Commands; -import de.kentoj.scrow.bukkit.services.command.execution.CommandContext; -import de.kentoj.scrow.bukkit.services.command.literal.Literal; +import de.kentoj.scrow.bukkit.command.Commands; +import de.kentoj.scrow.bukkit.command.execution.CommandContext; +import de.kentoj.scrow.bukkit.command.literal.Literal; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import reactor.core.scheduler.Schedulers; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/BsonFriendship.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/BsonFriendship.java index 6527c02..1dbaf7b 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/BsonFriendship.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/BsonFriendship.java @@ -1,7 +1,7 @@ package de.kentoj.scrow.bukkit.friends.friendship; import com.google.common.base.Preconditions; -import de.kentoj.scrow.bukkit.services.friends.Friendship; +import de.kentoj.scrow.bukkit.friends.Friendship; import de.kentoj.scrow.bukkit.util.pair.Tuple2; import lombok.Value; import org.bson.codecs.pojo.annotations.BsonCreator; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/FriendshipRepository.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/FriendshipRepository.java index 7f7a2d4..516a0e7 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/FriendshipRepository.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/FriendshipRepository.java @@ -1,6 +1,6 @@ package de.kentoj.scrow.bukkit.friends.friendship; -import de.kentoj.scrow.bukkit.services.friends.Friendship; +import de.kentoj.scrow.bukkit.friends.Friendship; import de.kentoj.scrow.bukkit.util.pair.Tuple2; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Flux; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipRepository.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipRepository.java index c97c93f..075d87b 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipRepository.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/MongoFriendshipRepository.java @@ -7,7 +7,7 @@ import com.mongodb.client.model.IndexOptions; import com.mongodb.client.model.Indexes; import com.mongodb.reactivestreams.client.MongoCollection; import com.mongodb.reactivestreams.client.MongoDatabase; -import de.kentoj.scrow.bukkit.services.friends.Friendship; +import de.kentoj.scrow.bukkit.friends.Friendship; import de.kentoj.scrow.bukkit.util.pair.Tuple2; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Flux; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/BsonFriendRequest.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/BsonFriendRequest.java index 371a6fb..e99e4ed 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/BsonFriendRequest.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/BsonFriendRequest.java @@ -1,7 +1,7 @@ package de.kentoj.scrow.bukkit.friends.request; import com.google.common.base.Preconditions; -import de.kentoj.scrow.bukkit.services.friends.FriendRequest; +import de.kentoj.scrow.bukkit.friends.FriendRequest; import lombok.Value; import org.bson.codecs.pojo.annotations.BsonCreator; import org.bson.codecs.pojo.annotations.BsonProperty; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/FriendRequestRepository.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/FriendRequestRepository.java index f44e230..2302b33 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/FriendRequestRepository.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/FriendRequestRepository.java @@ -1,6 +1,6 @@ package de.kentoj.scrow.bukkit.friends.request; -import de.kentoj.scrow.bukkit.services.friends.FriendRequest; +import de.kentoj.scrow.bukkit.friends.FriendRequest; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/MongoFriendRequestRepository.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/MongoFriendRequestRepository.java index 1ac0dc5..9f14cc9 100644 --- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/MongoFriendRequestRepository.java +++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/MongoFriendRequestRepository.java @@ -7,7 +7,7 @@ import com.mongodb.client.model.IndexOptions; import com.mongodb.client.model.Indexes; import com.mongodb.reactivestreams.client.MongoCollection; import com.mongodb.reactivestreams.client.MongoDatabase; -import de.kentoj.scrow.bukkit.services.friends.FriendRequest; +import de.kentoj.scrow.bukkit.friends.FriendRequest; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/core-bukkit-impl/src/main/resources/plugin.yml b/core-bukkit-impl/src/main/resources/plugin.yml index a580ed7..d405e8f 100644 --- a/core-bukkit-impl/src/main/resources/plugin.yml +++ b/core-bukkit-impl/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: "CoreBukkit" version: "1.0" main: "de.kentoj.scrow.bukkit.CoreImplPlugin" -api-version: "1.1" +api-version: "1.21" author: "Kento2 " \ No newline at end of file