. + improve build system
This commit is contained in:
parent
00eb51595d
commit
e09ae6cc18
10 changed files with 117 additions and 107 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
As of v2.0.2, a command for getting/setting coins of a player could look like this:
|
As of v2.2.0, a command for getting/setting coins of a player could look like this:
|
||||||
```java
|
```java
|
||||||
public class CoinsCommand {
|
public class CoinsCommand {
|
||||||
|
|
||||||
|
|
|
||||||
65
build.gradle.kts
Normal file
65
build.gradle.kts
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "de.kentoj.scrow"
|
||||||
|
version = "0.2"
|
||||||
|
|
||||||
|
fun RepositoryHandler.scrowRepo() = 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subprojects {
|
||||||
|
apply(plugin = "java")
|
||||||
|
apply(plugin = "maven-publish")
|
||||||
|
apply(plugin = "io.freefair.lombok")
|
||||||
|
|
||||||
|
java {
|
||||||
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<Javadoc>().configureEach {
|
||||||
|
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:all,-missing", "-quiet")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {
|
||||||
|
name = "spigotmc-repo"
|
||||||
|
}
|
||||||
|
scrowRepo()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
||||||
|
implementation("org.jetbrains:annotations:26.0.2-1")
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions.configure<PublishingExtension> {
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("KenCommandAPI") {
|
||||||
|
groupId = rootProject.group.toString()
|
||||||
|
version = rootProject.version.toString()
|
||||||
|
artifactId = project.name
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
scrowRepo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,56 +4,12 @@ val scrowToken = providers.gradleProperty("scrowMavenToken")
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("java-library")
|
id("java-library")
|
||||||
id("maven-publish")
|
|
||||||
id("io.freefair.lombok") version "9.2.0"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "de.kentoj"
|
group = "de.kentoj"
|
||||||
version = "2.0.2"
|
version = "2.2.0"
|
||||||
|
|
||||||
fun scrowRepo(handler: RepositoryHandler) = handler.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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {
|
|
||||||
name = "spigotmc-repo"
|
|
||||||
}
|
|
||||||
scrowRepo(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
api(project(":kencommandapi-core"))
|
||||||
implementation("org.jetbrains:annotations:26.0.2-1")
|
compileOnly("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
api("de.kentoj:kencommandapi-core:2.0.2")
|
|
||||||
|
|
||||||
api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
|
||||||
implementation("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
create<MavenPublication>("KenCommandAPIBukkit") {
|
|
||||||
groupId = project.group.toString()
|
|
||||||
artifactId = "kencommandapi-bukkit"
|
|
||||||
version = project.version.toString()
|
|
||||||
from(components["java"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositories {
|
|
||||||
scrowRepo(this)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package de.kentoj.kencommandapi;
|
package de.kentoj.kencommandapi;
|
||||||
|
|
||||||
|
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||||
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
||||||
|
|
@ -20,6 +21,12 @@ public class BukkitKenCommandApi extends AbstractKenCommandApi<CommandSender, Bu
|
||||||
return new BukkitCommandContext(sender, parsedArguments);
|
return new BukkitCommandContext(sender, parsedArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendErrorMessage(CommandSender sender, CommandException ex) {
|
||||||
|
var cause = (ex.getCause() != null) ? ": " + ex.getCause().getMessage() : "";
|
||||||
|
sender.sendMessage("§c" + ex.getMessage() + cause);
|
||||||
|
}
|
||||||
|
|
||||||
public void register(CommandNode<CommandSender, BukkitCommandContext> rootNode) {
|
public void register(CommandNode<CommandSender, BukkitCommandContext> rootNode) {
|
||||||
try {
|
try {
|
||||||
Field field = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
Field field = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package de.kentoj.kencommandapi.type;
|
package de.kentoj.kencommandapi.type;
|
||||||
|
|
||||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
|
|
@ -22,15 +22,15 @@ public class OfflinePlayerArgumentType implements ArgumentType<CommandSender, Bu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OfflinePlayer parseInput(String string) {
|
public OfflinePlayer parseInput(String string) {
|
||||||
OfflinePlayer player = Bukkit.getPlayer(string);
|
OfflinePlayer player = Bukkit.getPlayerExact(string);
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
try {
|
try {
|
||||||
player = Bukkit.getOfflinePlayer(UUID.fromString(string));
|
player = Bukkit.getOfflinePlayer(UUID.fromString(string));
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
throw new RuntimeException("Not a UUID or online player -- " + string);
|
throw new CommandException("Not a UUID or online player -- " + string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!player.hasPlayedBefore()) throw new RuntimeException("Unknown player -- " + string);
|
if (!player.hasPlayedBefore() && !player.isOnline()) throw new CommandException("Unknown player -- " + string);
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package de.kentoj.kencommandapi.type;
|
||||||
|
|
||||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||||
|
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
|
|
@ -22,7 +23,7 @@ public class PlayerArgumentType implements ArgumentType<CommandSender, BukkitCom
|
||||||
@Override
|
@Override
|
||||||
public Player parseInput(String string) {
|
public Player parseInput(String string) {
|
||||||
var player = Bukkit.getPlayer(string);
|
var player = Bukkit.getPlayer(string);
|
||||||
if (player == null) throw new RuntimeException("Player not online -- " + string);
|
if (player == null) throw new CommandException("Player not online -- " + string);
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
package de.kentoj.kencommandapi;
|
||||||
|
|
||||||
|
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||||
import de.kentoj.kencommandapi.api.structure.argument.types.IntegerArgumentType;
|
import de.kentoj.kencommandapi.api.structure.argument.types.IntegerArgumentType;
|
||||||
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
||||||
|
|
@ -28,6 +29,11 @@ public class Main {
|
||||||
public BasicCommandContext createContext(PrintStream sender, Map<String, ParsedArgument<PrintStream, BasicCommandContext, ?>> parsedArguments) {
|
public BasicCommandContext createContext(PrintStream sender, Map<String, ParsedArgument<PrintStream, BasicCommandContext, ?>> parsedArguments) {
|
||||||
return new BasicCommandContext(sender, parsedArguments);
|
return new BasicCommandContext(sender, parsedArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendErrorMessage(PrintStream printStream, CommandException ex) {
|
||||||
|
System.err.println(ex.getMessage());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var root = api.createNode("coins");
|
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.KenCommandApi;
|
||||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
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.processing.ParsedArgument;
|
||||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
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 S createContext(T sender, Map<String, ParsedArgument<T, S, ?>> parsedArguments);
|
||||||
|
|
||||||
|
public abstract void sendErrorMessage(T t, CommandException exception);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandNode<T, S> createNode(String... name) {
|
public CommandNode<T, S> createNode(String... name) {
|
||||||
return new CommandNodeImpl<>(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) {
|
public void invoke(CommandNode<T, S> node, T sender, String[] args) {
|
||||||
var iter = Arrays.stream(args).iterator();
|
var iter = Arrays.stream(args).iterator();
|
||||||
|
|
||||||
|
try {
|
||||||
var executableLiteral = processLiterals(node, iter);
|
var executableLiteral = processLiterals(node, iter);
|
||||||
var parsedArguments = parseArguments(executableLiteral, iter);
|
var parsedArguments = parseArguments(executableLiteral, iter);
|
||||||
assert executableLiteral.getExecutor() != null;
|
assert executableLiteral.getExecutor() != null;
|
||||||
executableLiteral.getExecutor().execute(createContext(sender, parsedArguments));
|
executableLiteral.getExecutor().execute(createContext(sender, parsedArguments));
|
||||||
|
} catch (CommandException ex) {
|
||||||
|
sendErrorMessage(sender, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandNode<T, S> processLiterals(CommandNode<T, S> commandNode, Iterator<String> iter) {
|
private CommandNode<T, S> processLiterals(CommandNode<T, S> commandNode, Iterator<String> iter) {
|
||||||
if (!iter.hasNext()) {
|
if (!iter.hasNext()) {
|
||||||
// literals/arguments are optional if the node itself is executable
|
// 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;
|
return commandNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +62,7 @@ public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> i
|
||||||
final var arg = iter.next();
|
final var arg = iter.next();
|
||||||
final var literal = commandNode.getLiteral(arg);
|
final var literal = commandNode.getLiteral(arg);
|
||||||
if (literal == null) {
|
if (literal == null) {
|
||||||
throw new RuntimeException("Invalid literal: " + arg);
|
throw new CommandException("Invalid literal: " + arg);
|
||||||
}
|
}
|
||||||
return processLiterals(literal, iter);
|
return processLiterals(literal, iter);
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +75,7 @@ public abstract class AbstractKenCommandApi<T, S extends CommandContext<T, ?>> i
|
||||||
|
|
||||||
if (!iter.hasNext()) {
|
if (!iter.hasNext()) {
|
||||||
var defaultValue = arg.getDefaultValue();
|
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));
|
parsedArguments.put(arg.getId(), new ParsedArgumentImpl<>(defaultValue, arg));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue