.
This commit is contained in:
parent
179f94085f
commit
3345595146
52 changed files with 95 additions and 905 deletions
|
|
@ -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<HttpHeaderAuthentication>("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<MavenPublication>("CoreBukkitApi") {
|
||||
create<MavenPublication>("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<HttpHeaderAuthentication>("header")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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<CommandSender, CommandContext<CommandSender>> 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<CommandSender, CommandContext<CommandSender>> commandManager) {
|
||||
ScrowAPI.commandManager = commandManager;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.scrow.bukkit.services.email;
|
||||
package de.kentoj.scrow.bukkit.email;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.scrow.bukkit.services.email;
|
||||
package de.kentoj.scrow.bukkit.email;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.scrow.bukkit.services.friends;
|
||||
package de.kentoj.scrow.bukkit.friends;
|
||||
|
||||
public class FriendRequestUsageException extends RuntimeException {
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
<T> CommandArgument<T> argument(String name, ArgumentType<T> type, Function<CommandContext, T> defaultValueFun);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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 <T> CommandArgument<T> argument0(String name, ArgumentType<T> type, Function<CommandContext, T> defaultValueFun) {
|
||||
return factory.argument(name, type, defaultValueFun);
|
||||
}
|
||||
|
||||
public static <T> CommandArgument<T> argument1(String name, ArgumentType<T> type, T defaultValue) {
|
||||
return factory.argument(name, type, __ -> defaultValue);
|
||||
}
|
||||
|
||||
public static <T> CommandArgument<T> argument0(String name, ArgumentType<T> type) {
|
||||
return factory.argument(name, type, __ -> null);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setFactory(CommandFactory factory) {
|
||||
Commands.factory = factory;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> suggest(CommandContext context);
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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> {
|
||||
|
||||
T getValue();
|
||||
|
||||
CommandArgument<T> getArgument();
|
||||
|
||||
/**
|
||||
* @return null if the default value for the type was used
|
||||
*/
|
||||
@Nullable String getRawInput();
|
||||
}
|
||||
|
|
@ -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
|
||||
*/
|
||||
<T> ArgumentData<T> getArgData(String name);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T getArgData(CommandArgument<T> arg) {
|
||||
return (T) getArgData(arg.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T getArg(String name) {
|
||||
return (T) getArgData(name).getValue();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T> T getArg(CommandArgument<T> arg) {
|
||||
return (T) getArgData(arg.getName()).getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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<T> {
|
||||
|
||||
String getName();
|
||||
|
||||
ArgumentType<T> 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();
|
||||
}
|
||||
|
|
@ -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<Literal> 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);
|
||||
|
||||
<T> void addArgument(CommandArgument<T> argument);
|
||||
|
||||
List<CommandArgument<?>> getArguments();
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.literal;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface RootLiteral extends Literal {
|
||||
|
||||
Set<String> getAliases();
|
||||
|
||||
void setAliases(Set<String> aliases);
|
||||
|
||||
void addAliases(String... aliases);
|
||||
}
|
||||
|
|
@ -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> {
|
||||
|
||||
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<String> getDefaultSuggestions(CommandContext ctx);
|
||||
}
|
||||
|
|
@ -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> 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<String> getDefaultSuggestions(CommandContext ctx) {
|
||||
return Set.of();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -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> 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<String> getDefaultSuggestions(CommandContext ctx) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toSet());
|
||||
}
|
||||
};
|
||||
|
||||
private static final ArgumentType<OfflinePlayer> 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<String> 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> player() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public static ArgumentType<OfflinePlayer> offlinePlayer() {
|
||||
return offlinePlayer;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue