. + improve build system
This commit is contained in:
parent
00eb51595d
commit
e09ae6cc18
10 changed files with 117 additions and 107 deletions
|
|
@ -1,47 +0,0 @@
|
|||
val scrowToken = providers.gradleProperty("scrowMavenToken")
|
||||
.orElse(providers.environmentVariable("SCROW_MAVEN_TOKEN")).get()
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
id("maven-publish")
|
||||
id("io.freefair.lombok") version "9.2.0"
|
||||
}
|
||||
|
||||
group = "de.kentoj"
|
||||
version = "2.0.2"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
||||
implementation("org.jetbrains:annotations:26.0.2-1")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("KenCommandAPI") {
|
||||
groupId = project.group.toString()
|
||||
artifactId = "kencommandapi-core"
|
||||
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 $scrowToken"
|
||||
}
|
||||
|
||||
authentication {
|
||||
create<HttpHeaderAuthentication>("header")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package de.kentoj.kencommandapi;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.types.IntegerArgumentType;
|
||||
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
||||
|
|
@ -28,6 +29,11 @@ public class Main {
|
|||
public BasicCommandContext createContext(PrintStream sender, Map<String, ParsedArgument<PrintStream, BasicCommandContext, ?>> parsedArguments) {
|
||||
return new BasicCommandContext(sender, parsedArguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendErrorMessage(PrintStream printStream, CommandException ex) {
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
var root = api.createNode("coins");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package de.kentoj.kencommandapi.api.processing;
|
||||
|
||||
public class CommandException extends RuntimeException {
|
||||
public CommandException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CommandException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CommandException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package de.kentoj.kencommandapi.impl;
|
|||
|
||||
import de.kentoj.kencommandapi.api.KenCommandApi;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
|
|
@ -21,6 +22,8 @@ public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> i
|
|||
|
||||
public abstract S createContext(T sender, Map<String, ParsedArgument<T, S, ?>> parsedArguments);
|
||||
|
||||
public abstract void sendErrorMessage(T t, CommandException exception);
|
||||
|
||||
@Override
|
||||
public CommandNode<T, S> createNode(String... name) {
|
||||
return new CommandNodeImpl<>(name);
|
||||
|
|
@ -35,16 +38,20 @@ public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> i
|
|||
public void invoke(CommandNode<T, S> node, T sender, String[] args) {
|
||||
var iter = Arrays.stream(args).iterator();
|
||||
|
||||
var executableLiteral = processLiterals(node, iter);
|
||||
var parsedArguments = parseArguments(executableLiteral, iter);
|
||||
assert executableLiteral.getExecutor() != null;
|
||||
executableLiteral.getExecutor().execute(createContext(sender, parsedArguments));
|
||||
try {
|
||||
var executableLiteral = processLiterals(node, iter);
|
||||
var parsedArguments = parseArguments(executableLiteral, iter);
|
||||
assert executableLiteral.getExecutor() != null;
|
||||
executableLiteral.getExecutor().execute(createContext(sender, parsedArguments));
|
||||
} catch (CommandException ex) {
|
||||
sendErrorMessage(sender, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private CommandNode<T, S> processLiterals(CommandNode<T, S> commandNode, Iterator<String> iter) {
|
||||
if (!iter.hasNext()) {
|
||||
// literals/arguments are optional if the node itself is executable
|
||||
if (commandNode.getExecutor() == null) throw new RuntimeException("no literal given but required");
|
||||
if (commandNode.getExecutor() == null) throw new CommandException("no literal given but required");
|
||||
return commandNode;
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +62,7 @@ public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> i
|
|||
final var arg = iter.next();
|
||||
final var literal = commandNode.getLiteral(arg);
|
||||
if (literal == null) {
|
||||
throw new RuntimeException("Invalid literal: " + arg);
|
||||
throw new CommandException("Invalid literal: " + arg);
|
||||
}
|
||||
return processLiterals(literal, iter);
|
||||
}
|
||||
|
|
@ -68,7 +75,7 @@ public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> i
|
|||
|
||||
if (!iter.hasNext()) {
|
||||
var defaultValue = arg.getDefaultValue();
|
||||
if (defaultValue == null) throw new RuntimeException("no argument given but required");
|
||||
if (defaultValue == null) throw new CommandException("no argument given but required");
|
||||
parsedArguments.put(arg.getId(), new ParsedArgumentImpl<>(defaultValue, arg));
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue