diff --git a/.gitignore b/.gitignore index b63da45..c14df57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,18 @@ -.gradle +### Build/run paths ### build/ +run/ +target/ + +### Gradle ### +.gradle !gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ ### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ +.idea/ +out/ *.iws *.iml *.ipr -out/ !**/src/main/**/out/ !**/src/test/**/out/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index ff72d26..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index fae6c8e..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/HEADER b/HEADER new file mode 100644 index 0000000..53b6610 --- /dev/null +++ b/HEADER @@ -0,0 +1,18 @@ +This file is part of Uniform, licensed under the GNU General Public License v3.0. + + Copyright (c) Tofaa2 + Copyright (c) William278 + Copyright (c) contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . \ No newline at end of file diff --git a/README.md b/README.md index f3e84af..d0b190b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# BrigadierWrapper -A brigadier wrapper for paper and velocity inspired by emortalmcs command system +# Uniform +A cross-platform wrapper for making Brigadier commands, based on BrigadierWrapper by Tofaa2, itself inspired by emortalmcs command system. \ No newline at end of file diff --git a/build.gradle b/build.gradle index bf3184c..44ccb2f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,178 @@ +import org.apache.tools.ant.filters.ReplaceTokens + plugins { + id 'org.cadixdev.licenser' version '0.6.1' apply false + id 'io.github.goooler.shadow' version '8.1.7' + id 'org.ajoberstar.grgit' version '5.2.2' + id 'maven-publish' id 'java' - id 'java-library' } -group = 'me.tofaa' -version = '1.0-SNAPSHOT' +group 'net.william278' +version "$ext.library_version${versionMetadata()}" +description "$ext.library_description" +defaultTasks 'licenseFormat', 'build' -repositories { - mavenCentral() - maven { - url = "https://libraries.minecraft.net/" +publishing { + repositories { + if (System.getenv("RELEASES_MAVEN_USERNAME") != null) { + maven { + name = "william278-releases" + url = "https://repo.william278.net/releases" + credentials { + username = System.getenv("RELEASES_MAVEN_USERNAME") + password = System.getenv("RELEASES_MAVEN_PASSWORD") + } + authentication { + basic(BasicAuthentication) + } + } + } + if (System.getenv("SNAPSHOTS_MAVEN_USERNAME") != null) { + maven { + name = "william278-snapshots" + url = "https://repo.william278.net/snapshots" + credentials { + username = System.getenv("SNAPSHOTS_MAVEN_USERNAME") + password = System.getenv("SNAPSHOTS_MAVEN_PASSWORD") + } + authentication { + basic(BasicAuthentication) + } + } + } } } -dependencies { - compileOnlyApi("com.mojang:brigadier:1.1.8") - compileOnlyApi("org.jetbrains:annotations:24.0.0") +allprojects { + apply plugin: 'io.github.goooler.shadow' + apply plugin: 'org.cadixdev.licenser' + apply plugin: 'java' + + compileJava.options.encoding = 'UTF-8' + compileJava.options.release.set 17 + javadoc.options.encoding = 'UTF-8' + javadoc.options.addStringOption('Xdoclint:none', '-quiet') + + repositories { + mavenLocal() + mavenCentral() + maven { url 'https://repo.papermc.io/repository/maven-public/' } + maven { url 'https://libraries.minecraft.net/' } + } + + dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.2' + } + + test { + useJUnitPlatform() + } + + license { + header = rootProject.file('HEADER') + include '**/*.java' + newLine = true + } + + processResources { + filesMatching(['**/*.json', '**/*.yml']) { + filter ReplaceTokens as Class, beginToken: '${', endToken: '}', + tokens: rootProject.ext.properties + } + } +} + +subprojects { + version rootProject.version + archivesBaseName = "${rootProject.name}-${project.name.capitalize()}" + + jar { + from '../LICENSE' + } + + shadowJar { + destinationDirectory.set(file("$rootDir/target")) + archiveClassifier.set('') + } + + // Don't include example plugin in publishing + if (['example-plugin'].contains(project.name)) return; + + // API publishing + java { + withSourcesJar() + withJavadocJar() + } + sourcesJar { + destinationDirectory.set(file("$rootDir/target")) + } + javadocJar { + destinationDirectory.set(file("$rootDir/target")) + } + shadowJar.dependsOn(sourcesJar, javadocJar) + + publishing { + if (['common'].contains(project.name)) { + publications { + mavenJavaCommon(MavenPublication) { + groupId = 'net.william278.uniform' + artifactId = 'uniform-common' + version = "$rootProject.version" + artifact shadowJar + artifact sourcesJar + artifact javadocJar + } + } + } + + if (['paper'].contains(project.name)) { + publications { + mavenJavaBukkit(MavenPublication) { + groupId = 'net.william278.uniform' + artifactId = 'uniform-paper' + version = "$rootProject.version" + artifact shadowJar + artifact sourcesJar + artifact javadocJar + } + } + } + + if (['velocity'].contains(project.name)) { + publications { + mavenJavaBukkit(MavenPublication) { + groupId = 'net.william278.uniform' + artifactId = 'uniform-velocity' + version = "$rootProject.version" + artifact shadowJar + artifact sourcesJar + artifact javadocJar + } + } + } + + } + + jar.dependsOn shadowJar + clean.delete "$rootDir/target" } + +logger.lifecycle("Building Uniform ${version} by William278") + +@SuppressWarnings('GrMethodMayBeStatic') +def versionMetadata() { + // Get if there is a tag for this commit + def tag = grgit.tag.list().find { it.commit.id == grgit.head().id } + if (tag != null) { + return '' + } + + // Otherwise, get the last commit hash and if it's a clean head + if (grgit == null) { + return '-' + System.getenv("GITHUB_RUN_NUMBER") ? 'build.' + System.getenv("GITHUB_RUN_NUMBER") : 'unknown' + } + return '-' + grgit.head().abbreviatedId + (grgit.status().clean ? '' : '-indev') +} \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..2dc6337 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,13 @@ +plugins { + id 'java-library' + id 'maven-publish' +} + +dependencies { + compileOnlyApi 'com.mojang:brigadier:1.1.8' + + compileOnly 'org.jetbrains:annotations:24.1.0' + compileOnly 'org.projectlombok:lombok:1.18.32' + + annotationProcessor 'org.projectlombok:lombok:1.18.32' +} \ No newline at end of file diff --git a/src/main/java/me/tofaa/brigadierwrapper/Command.java b/common/src/main/java/net/william278/uniform/Command.java similarity index 77% rename from src/main/java/me/tofaa/brigadierwrapper/Command.java rename to common/src/main/java/net/william278/uniform/Command.java index 7eb0f22..c5acdf6 100644 --- a/src/main/java/me/tofaa/brigadierwrapper/Command.java +++ b/common/src/main/java/net/william278/uniform/Command.java @@ -1,11 +1,32 @@ -package me.tofaa.brigadierwrapper; +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; import com.mojang.brigadier.arguments.*; import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.tree.LiteralCommandNode; -import me.tofaa.brigadierwrapper.element.ArgumentElement; -import me.tofaa.brigadierwrapper.element.CommandElement; -import me.tofaa.brigadierwrapper.element.LiteralElement; +import net.william278.uniform.element.ArgumentElement; +import net.william278.uniform.element.CommandElement; +import net.william278.uniform.element.LiteralElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,6 +35,7 @@ import java.util.Collection; import java.util.List; import java.util.function.Predicate; +@SuppressWarnings("unused") public abstract class Command { private final String name; @@ -122,7 +144,8 @@ public abstract class Command { return argument(name, BoolArgumentType.bool()); } - protected static @NotNull ArgumentElement argument(@NotNull String name, @NotNull ArgumentType type, @Nullable SuggestionProvider suggestionProvider) { + protected static @NotNull ArgumentElement argument(@NotNull String name, @NotNull ArgumentType type, + @Nullable SuggestionProvider suggestionProvider) { return new ArgumentElement<>(name, type, suggestionProvider); } diff --git a/common/src/main/java/net/william278/uniform/CommandExecutor.java b/common/src/main/java/net/william278/uniform/CommandExecutor.java new file mode 100644 index 0000000..1d1e34b --- /dev/null +++ b/common/src/main/java/net/william278/uniform/CommandExecutor.java @@ -0,0 +1,30 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; + +import com.mojang.brigadier.context.CommandContext; +import org.jetbrains.annotations.NotNull; + +public interface CommandExecutor { + + void execute(@NotNull CommandContext context); +} diff --git a/common/src/main/java/net/william278/uniform/CommandSyntax.java b/common/src/main/java/net/william278/uniform/CommandSyntax.java new file mode 100644 index 0000000..d919a70 --- /dev/null +++ b/common/src/main/java/net/william278/uniform/CommandSyntax.java @@ -0,0 +1,32 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; + +import net.william278.uniform.element.CommandElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Predicate; + +public record CommandSyntax(@Nullable Predicate condition, @NotNull CommandExecutor executor, @NotNull List> elements) { +} diff --git a/src/main/java/me/tofaa/brigadierwrapper/ConversionNode.java b/common/src/main/java/net/william278/uniform/ConversionNode.java similarity index 61% rename from src/main/java/me/tofaa/brigadierwrapper/ConversionNode.java rename to common/src/main/java/net/william278/uniform/ConversionNode.java index aed4a3a..ac992f6 100644 --- a/src/main/java/me/tofaa/brigadierwrapper/ConversionNode.java +++ b/common/src/main/java/net/william278/uniform/ConversionNode.java @@ -1,6 +1,27 @@ -package me.tofaa.brigadierwrapper; +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -import me.tofaa.brigadierwrapper.element.CommandElement; +package net.william278.uniform; + +import net.william278.uniform.element.CommandElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -8,10 +29,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import static me.tofaa.brigadierwrapper.Graph.commandToElement; +import static net.william278.uniform.Graph.commandToElement; record ConversionNode(@NotNull CommandElement element, @Nullable Execution execution, - @NotNull Map, ConversionNode> nextMap) { + @NotNull Map, ConversionNode> nextMap) { static @NotNull ConversionNode fromCommand(@NotNull Command command) { ConversionNode root = new ConversionNode<>(commandToElement(command), Execution.fromCommand(command)); diff --git a/src/main/java/me/tofaa/brigadierwrapper/Execution.java b/common/src/main/java/net/william278/uniform/Execution.java similarity index 72% rename from src/main/java/me/tofaa/brigadierwrapper/Execution.java rename to common/src/main/java/net/william278/uniform/Execution.java index 2529f94..3821f33 100644 --- a/src/main/java/me/tofaa/brigadierwrapper/Execution.java +++ b/common/src/main/java/net/william278/uniform/Execution.java @@ -1,4 +1,25 @@ -package me.tofaa.brigadierwrapper; +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; import com.mojang.brigadier.builder.ArgumentBuilder; diff --git a/common/src/main/java/net/william278/uniform/Graph.java b/common/src/main/java/net/william278/uniform/Graph.java new file mode 100644 index 0000000..b5cb8ce --- /dev/null +++ b/common/src/main/java/net/william278/uniform/Graph.java @@ -0,0 +1,48 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; + +import com.mojang.brigadier.tree.CommandNode; +import com.mojang.brigadier.tree.LiteralCommandNode; +import net.william278.uniform.element.CommandElement; +import net.william278.uniform.element.LiteralElement; +import org.jetbrains.annotations.NotNull; + +record Graph(@NotNull Node root) { + + + static @NotNull Graph create(@NotNull Command command) { + return new Graph<>(Node.command(command)); + } + + static @NotNull CommandElement commandToElement(@NotNull Command command) { + return new LiteralElement<>(command.getName()); + } + + @NotNull LiteralCommandNode build() { + CommandNode node = this.root.build(); + if (!(node instanceof LiteralCommandNode literalNode)) { + throw new IllegalStateException("Root node is somehow not a literal node. This should be impossible."); + } + return literalNode; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/william278/uniform/Node.java b/common/src/main/java/net/william278/uniform/Node.java new file mode 100644 index 0000000..ca0d1ae --- /dev/null +++ b/common/src/main/java/net/william278/uniform/Node.java @@ -0,0 +1,49 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.tree.CommandNode; +import net.william278.uniform.element.CommandElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +record Node(@NotNull CommandElement element, @Nullable Execution execution, @NotNull List> children) { + + static @NotNull Node command(@NotNull Command command) { + return ConversionNode.fromCommand(command).toNode(); + } + + @NotNull + CommandNode build() { + ArgumentBuilder builder = this.element.toBuilder(); + if (this.execution != null) this.execution.addToBuilder(builder); + + for (Node child : this.children) { + builder.then(child.build()); + } + + return builder.build(); + } +} \ No newline at end of file diff --git a/common/src/main/java/net/william278/uniform/element/ArgumentElement.java b/common/src/main/java/net/william278/uniform/element/ArgumentElement.java new file mode 100644 index 0000000..a371a39 --- /dev/null +++ b/common/src/main/java/net/william278/uniform/element/ArgumentElement.java @@ -0,0 +1,41 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.element; + + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public record ArgumentElement(@NotNull String name, @NotNull ArgumentType type, + @Nullable SuggestionProvider suggestionProvider) implements CommandElement { + + @Override + public @NotNull ArgumentBuilder toBuilder() { + var builder = RequiredArgumentBuilder.argument(this.name, this.type); + if (this.suggestionProvider != null) builder.suggests(this.suggestionProvider); + return builder; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/william278/uniform/element/CommandElement.java b/common/src/main/java/net/william278/uniform/element/CommandElement.java new file mode 100644 index 0000000..0284888 --- /dev/null +++ b/common/src/main/java/net/william278/uniform/element/CommandElement.java @@ -0,0 +1,30 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.element; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import org.jetbrains.annotations.NotNull; + +public interface CommandElement { + + @NotNull ArgumentBuilder toBuilder(); +} \ No newline at end of file diff --git a/common/src/main/java/net/william278/uniform/element/LiteralElement.java b/common/src/main/java/net/william278/uniform/element/LiteralElement.java new file mode 100644 index 0000000..b99ce24 --- /dev/null +++ b/common/src/main/java/net/william278/uniform/element/LiteralElement.java @@ -0,0 +1,34 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.element; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import org.jetbrains.annotations.NotNull; + +public record LiteralElement(@NotNull String name) implements CommandElement { + + @Override + public @NotNull ArgumentBuilder toBuilder() { + return LiteralArgumentBuilder.literal(this.name); + } +} \ No newline at end of file diff --git a/example-plugin/build.gradle b/example-plugin/build.gradle index 9fe78be..24058ad 100644 --- a/example-plugin/build.gradle +++ b/example-plugin/build.gradle @@ -1,24 +1,13 @@ plugins { id 'java' - id 'xyz.jpenilla.run-paper' version '2.2.2' - id 'com.github.johnrengelman.shadow' version '7.0.0' -} - -group = 'me.tofaa' -version = '1.0-SNAPSHOT' - -repositories { - mavenCentral() - maven { - url = "https://repo.papermc.io/repository/maven-public/" - } + id 'xyz.jpenilla.run-paper' version '2.3.0' } dependencies { implementation(project(":paper")) - compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") -} + compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT' +} tasks { runServer { diff --git a/example-plugin/src/main/java/me/tofaa/ExampleCommand.java b/example-plugin/src/main/java/me/tofaa/ExampleCommand.java deleted file mode 100644 index 665f5c0..0000000 --- a/example-plugin/src/main/java/me/tofaa/ExampleCommand.java +++ /dev/null @@ -1,17 +0,0 @@ -package me.tofaa; - -import me.tofaa.brigadierwrapper.paper.PaperCommand; -import net.kyori.adventure.text.minimessage.MiniMessage; - -public class ExampleCommand extends PaperCommand { - - public ExampleCommand() { - super("example", "silly-command"); - addSyntax((context) -> { - context.getSource().getBukkitSender().sendMessage("Woah!!!!"); - String arg = context.getArgument("message", String.class); - context.getSource().getBukkitSender().sendMessage(MiniMessage.miniMessage().deserialize(arg)); - }, stringArg("message")); - } - -} diff --git a/example-plugin/src/main/java/me/tofaa/Main.java b/example-plugin/src/main/java/me/tofaa/Main.java deleted file mode 100644 index 805a2d6..0000000 --- a/example-plugin/src/main/java/me/tofaa/Main.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.tofaa; - -import me.tofaa.brigadierwrapper.paper.PaperBrigadierWrapper; -import org.bukkit.plugin.java.JavaPlugin; - -public class Main extends JavaPlugin { - - - @Override - public void onEnable() { - PaperBrigadierWrapper.init(this); - PaperBrigadierWrapper.register(new ExampleCommand()); - } -} \ No newline at end of file diff --git a/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java b/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java new file mode 100644 index 0000000..695437d --- /dev/null +++ b/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java @@ -0,0 +1,38 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; + +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.william278.uniform.paper.PaperCommand; + +public class ExampleCommand extends PaperCommand { + + public ExampleCommand() { + super("example", "silly-command"); + addSyntax((context) -> { + context.getSource().getBukkitSender().sendMessage("Woah!!!!"); + String arg = context.getArgument("message", String.class); + context.getSource().getBukkitSender().sendMessage(MiniMessage.miniMessage().deserialize(arg)); + }, stringArg("message")); + } + +} diff --git a/example-plugin/src/main/java/net/william278/uniform/UniformExample.java b/example-plugin/src/main/java/net/william278/uniform/UniformExample.java new file mode 100644 index 0000000..503fbe6 --- /dev/null +++ b/example-plugin/src/main/java/net/william278/uniform/UniformExample.java @@ -0,0 +1,35 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform; + +import net.william278.uniform.paper.PaperUniform; +import org.bukkit.plugin.java.JavaPlugin; + +@SuppressWarnings("unused") +public class UniformExample extends JavaPlugin { + + @Override + public void onEnable() { + PaperUniform.getInstance(this).register(new ExampleCommand()); + } + +} \ No newline at end of file diff --git a/example-plugin/src/main/resources/plugin.yml b/example-plugin/src/main/resources/plugin.yml index 06f0457..c4956ec 100644 --- a/example-plugin/src/main/resources/plugin.yml +++ b/example-plugin/src/main/resources/plugin.yml @@ -1,4 +1,4 @@ -name: ExamplePlugin +name: UniformExample version: 1.0 api-version: "1.20" -main: me.tofaa.Main \ No newline at end of file +main: net.william278.uniform.UniformExample \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..301469a --- /dev/null +++ b/gradle.properties @@ -0,0 +1,8 @@ +javaVersion=17 + +org.gradle.jvmargs='-Dfile.encoding=UTF-8' +org.gradle.daemon=true + +library_version=1.0 +library_archive=uniform +library_description=Cross-platform wrapper for making Brigadier commands, based on BrigadierWrapper by Tofaa2, itself inspired by emortalmcs command system. \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..d64cd49 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 57ec304..a441313 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Tue May 07 18:37:10 AZT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..1aa94a4 100644 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/paper/build.gradle b/paper/build.gradle index a2d29bb..ac4ea25 100644 --- a/paper/build.gradle +++ b/paper/build.gradle @@ -1,20 +1,15 @@ plugins { - id 'java' id 'java-library' + id 'maven-publish' } -group = 'me.tofaa' -version = '1.0-SNAPSHOT' +dependencies { + api project(path: ':common') -repositories { - mavenCentral() - maven { - url = "https://repo.papermc.io/repository/maven-public/" - } -} + compileOnlyApi 'io.papermc.paper:paper-mojangapi:1.20.4-R0.1-SNAPSHOT' -dependencies { - api(project(":")) - compileOnlyApi("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") - compileOnlyApi("io.papermc.paper:paper-mojangapi:1.20.4-R0.1-SNAPSHOT") + compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT' + compileOnly 'org.projectlombok:lombok:1.18.32' + + annotationProcessor 'org.projectlombok:lombok:1.18.32' } \ No newline at end of file diff --git a/paper/src/main/java/me/tofaa/brigadierwrapper/paper/PaperBrigadierWrapper.java b/paper/src/main/java/me/tofaa/brigadierwrapper/paper/PaperBrigadierWrapper.java deleted file mode 100644 index acd7885..0000000 --- a/paper/src/main/java/me/tofaa/brigadierwrapper/paper/PaperBrigadierWrapper.java +++ /dev/null @@ -1,38 +0,0 @@ -package me.tofaa.brigadierwrapper.paper; - -import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public final class PaperBrigadierWrapper { - - private PaperBrigadierWrapper() {} - - private static final Set COMMANDS = new HashSet<>(); - - public static void register(PaperCommand... commands) { - Collections.addAll(COMMANDS, commands); - } - - public static void init( - @NotNull JavaPlugin plugin - ) { - Bukkit.getServer().getPluginManager().registerEvents(new Listener() { - @EventHandler - public void onCmd(CommandRegisteredEvent event) { - for (PaperCommand command : COMMANDS) { - event.getRoot().addChild(command.build()); - COMMANDS.remove(command); - } - } - }, plugin); - } - -} diff --git a/paper/src/main/java/me/tofaa/brigadierwrapper/paper/PaperCommand.java b/paper/src/main/java/net/william278/uniform/paper/PaperCommand.java similarity index 66% rename from paper/src/main/java/me/tofaa/brigadierwrapper/paper/PaperCommand.java rename to paper/src/main/java/net/william278/uniform/paper/PaperCommand.java index f9590ee..6f2e340 100644 --- a/paper/src/main/java/me/tofaa/brigadierwrapper/paper/PaperCommand.java +++ b/paper/src/main/java/net/william278/uniform/paper/PaperCommand.java @@ -1,11 +1,30 @@ -package me.tofaa.brigadierwrapper.paper; +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.paper; import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import me.tofaa.brigadierwrapper.Command; -import me.tofaa.brigadierwrapper.element.ArgumentElement; +import net.william278.uniform.Command; +import net.william278.uniform.element.ArgumentElement; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -14,6 +33,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.List; +@SuppressWarnings("unused") public class PaperCommand extends Command { public PaperCommand(@NotNull String name, @NotNull String... aliases) { diff --git a/paper/src/main/java/net/william278/uniform/paper/PaperUniform.java b/paper/src/main/java/net/william278/uniform/paper/PaperUniform.java new file mode 100644 index 0000000..67e2476 --- /dev/null +++ b/paper/src/main/java/net/william278/uniform/paper/PaperUniform.java @@ -0,0 +1,81 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.paper; + +import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent; +import com.google.common.collect.Sets; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.Set; + +/** + * A class for registering commands with the Paper server's command manager + * + * @since 1.0 + */ +@SuppressWarnings("UnstableApiUsage") +public final class PaperUniform implements Listener { + + private static PaperUniform INSTANCE; + + private final Set commands = Sets.newHashSet(); + + private PaperUniform(@NotNull JavaPlugin plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + @SuppressWarnings({"rawtypes", "unchecked"}) + private void onCommandRegistered(@NotNull CommandRegisteredEvent event) { + for (PaperCommand command : commands) { + event.getRoot().addChild(command.build()); + commands.remove(command); + } + } + + /** + * Get the PaperUniform instance for registering commands + * + * @param plugin The plugin instance + * @return The PaperUniform instance + * @since 1.0 + */ + @NotNull + public static PaperUniform getInstance(@NotNull JavaPlugin plugin) { + return INSTANCE != null ? INSTANCE : (INSTANCE = new PaperUniform(plugin)); + } + + /** + * Register a command to be added to the server's command manager + * + * @param commands The commands to register + * @since 1.0 + */ + public void register(@NotNull PaperCommand... commands) { + Collections.addAll(this.commands, commands); + } + +} diff --git a/settings.gradle b/settings.gradle index dc6e8bd..c5ab759 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,14 @@ -rootProject.name = 'BrigadierWrapper' -include 'paper' -include 'velocity' -include 'example-plugin' +pluginManagement { + repositories { + gradlePluginPortal() + } +} +rootProject.name = 'Uniform' +include( + 'common', + 'paper', + 'velocity', + + 'example-plugin' +) \ No newline at end of file diff --git a/src/main/java/me/tofaa/brigadierwrapper/CommandExecutor.java b/src/main/java/me/tofaa/brigadierwrapper/CommandExecutor.java deleted file mode 100644 index 46d879f..0000000 --- a/src/main/java/me/tofaa/brigadierwrapper/CommandExecutor.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.tofaa.brigadierwrapper; - -import com.mojang.brigadier.context.CommandContext; -import org.jetbrains.annotations.NotNull; - -public interface CommandExecutor { - - void execute(@NotNull CommandContext context); -} diff --git a/src/main/java/me/tofaa/brigadierwrapper/CommandSyntax.java b/src/main/java/me/tofaa/brigadierwrapper/CommandSyntax.java deleted file mode 100644 index 1319b2a..0000000 --- a/src/main/java/me/tofaa/brigadierwrapper/CommandSyntax.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.tofaa.brigadierwrapper; - -import me.tofaa.brigadierwrapper.element.CommandElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.function.Predicate; - -public record CommandSyntax(@Nullable Predicate condition, @NotNull CommandExecutor executor, @NotNull List> elements) { -} diff --git a/src/main/java/me/tofaa/brigadierwrapper/Graph.java b/src/main/java/me/tofaa/brigadierwrapper/Graph.java deleted file mode 100644 index a1cdd28..0000000 --- a/src/main/java/me/tofaa/brigadierwrapper/Graph.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.tofaa.brigadierwrapper; - -import com.mojang.brigadier.tree.CommandNode; -import com.mojang.brigadier.tree.LiteralCommandNode; -import me.tofaa.brigadierwrapper.element.CommandElement; -import me.tofaa.brigadierwrapper.element.LiteralElement; -import org.jetbrains.annotations.NotNull; - -record Graph(@NotNull Node root) { - - - static @NotNull Graph create(@NotNull Command command) { - return new Graph<>(Node.command(command)); - } - - static @NotNull CommandElement commandToElement(@NotNull Command command) { - return new LiteralElement<>(command.getName()); - } - - @NotNull LiteralCommandNode build() { - CommandNode node = this.root.build(); - if (!(node instanceof LiteralCommandNode literalNode)) { - throw new IllegalStateException("Root node is somehow not a literal node. This should be impossible."); - } - return literalNode; - } -} \ No newline at end of file diff --git a/src/main/java/me/tofaa/brigadierwrapper/Node.java b/src/main/java/me/tofaa/brigadierwrapper/Node.java deleted file mode 100644 index fcf1557..0000000 --- a/src/main/java/me/tofaa/brigadierwrapper/Node.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.tofaa.brigadierwrapper; - -import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.tree.CommandNode; -import me.tofaa.brigadierwrapper.element.CommandElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -record Node(@NotNull CommandElement element, @Nullable Execution execution, @NotNull List> children) { - - static @NotNull Node command(@NotNull Command command) { - return ConversionNode.fromCommand(command).toNode(); - } - - @NotNull - CommandNode build() { - ArgumentBuilder builder = this.element.toBuilder(); - if (this.execution != null) this.execution.addToBuilder(builder); - - for (Node child : this.children) { - builder.then(child.build()); - } - - return builder.build(); - } -} \ No newline at end of file diff --git a/src/main/java/me/tofaa/brigadierwrapper/element/ArgumentElement.java b/src/main/java/me/tofaa/brigadierwrapper/element/ArgumentElement.java deleted file mode 100644 index 0832003..0000000 --- a/src/main/java/me/tofaa/brigadierwrapper/element/ArgumentElement.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.tofaa.brigadierwrapper.element; - - -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public record ArgumentElement(@NotNull String name, @NotNull ArgumentType type, - @Nullable SuggestionProvider suggestionProvider) implements CommandElement { - - @Override - public @NotNull ArgumentBuilder toBuilder() { - var builder = RequiredArgumentBuilder.argument(this.name, this.type); - if (this.suggestionProvider != null) builder.suggests(this.suggestionProvider); - return builder; - } -} \ No newline at end of file diff --git a/src/main/java/me/tofaa/brigadierwrapper/element/CommandElement.java b/src/main/java/me/tofaa/brigadierwrapper/element/CommandElement.java deleted file mode 100644 index cfddefb..0000000 --- a/src/main/java/me/tofaa/brigadierwrapper/element/CommandElement.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.tofaa.brigadierwrapper.element; - -import com.mojang.brigadier.builder.ArgumentBuilder; -import org.jetbrains.annotations.NotNull; - -public interface CommandElement { - - @NotNull ArgumentBuilder toBuilder(); -} \ No newline at end of file diff --git a/src/main/java/me/tofaa/brigadierwrapper/element/LiteralElement.java b/src/main/java/me/tofaa/brigadierwrapper/element/LiteralElement.java deleted file mode 100644 index 89f8ae2..0000000 --- a/src/main/java/me/tofaa/brigadierwrapper/element/LiteralElement.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.tofaa.brigadierwrapper.element; - -import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import org.jetbrains.annotations.NotNull; - -public record LiteralElement(@NotNull String name) implements CommandElement { - - @Override - public @NotNull ArgumentBuilder toBuilder() { - return LiteralArgumentBuilder.literal(this.name); - } -} \ No newline at end of file diff --git a/velocity/build.gradle b/velocity/build.gradle index 7fe6275..040860e 100644 --- a/velocity/build.gradle +++ b/velocity/build.gradle @@ -1,19 +1,13 @@ plugins { - id 'java' id 'java-library' + id 'maven-publish' } -group = 'me.tofaa' -version = '1.0-SNAPSHOT' +dependencies { + api project(path: ':common') -repositories { - mavenCentral() - maven { - url = "https://repo.papermc.io/repository/maven-public/" - } -} + compileOnly 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT' + compileOnly 'org.projectlombok:lombok:1.18.32' -dependencies { - compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT") - api(project(":")) -} + annotationProcessor 'org.projectlombok:lombok:1.18.32' +} \ No newline at end of file diff --git a/velocity/src/main/java/me/tofaa/brigadierwrapper/velocity/VelocityBrigadierWrapper.java b/velocity/src/main/java/me/tofaa/brigadierwrapper/velocity/VelocityBrigadierWrapper.java deleted file mode 100644 index 58a8e1d..0000000 --- a/velocity/src/main/java/me/tofaa/brigadierwrapper/velocity/VelocityBrigadierWrapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.tofaa.brigadierwrapper.velocity; - -import com.velocitypowered.api.command.BrigadierCommand; -import com.velocitypowered.api.proxy.ProxyServer; - -public final class VelocityBrigadierWrapper { - - private VelocityBrigadierWrapper() {} - - public static void registerCommands( - ProxyServer server, - VelocityCommand... commands - ) { - for (VelocityCommand command : commands) { - server.getCommandManager().register(new BrigadierCommand(command.build())); - } - } - -} diff --git a/velocity/src/main/java/me/tofaa/brigadierwrapper/velocity/VelocityCommand.java b/velocity/src/main/java/net/william278/uniform/velocity/VelocityCommand.java similarity index 63% rename from velocity/src/main/java/me/tofaa/brigadierwrapper/velocity/VelocityCommand.java rename to velocity/src/main/java/net/william278/uniform/velocity/VelocityCommand.java index 9da8c25..28e071b 100644 --- a/velocity/src/main/java/me/tofaa/brigadierwrapper/velocity/VelocityCommand.java +++ b/velocity/src/main/java/net/william278/uniform/velocity/VelocityCommand.java @@ -1,4 +1,25 @@ -package me.tofaa.brigadierwrapper.velocity; +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.velocity; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -7,17 +28,19 @@ import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.server.RegisteredServer; -import me.tofaa.brigadierwrapper.Command; -import me.tofaa.brigadierwrapper.element.ArgumentElement; +import net.william278.uniform.Command; +import net.william278.uniform.element.ArgumentElement; import org.jetbrains.annotations.NotNull; +@SuppressWarnings("unused") public class VelocityCommand extends Command { public VelocityCommand(@NotNull String name, @NotNull String... aliases) { super(name, aliases); } - protected static ArgumentElement serverArg(ProxyServer server, String name, SuggestionProvider suggestionProvider) { + protected static ArgumentElement serverArg(ProxyServer server, String name, + SuggestionProvider suggestionProvider) { ArgumentType argumentType = reader -> { String s = reader.readUnquotedString(); RegisteredServer server1 = server.getServer(s).orElse(null); @@ -38,7 +61,8 @@ public class VelocityCommand extends Command { }); } - protected static ArgumentElement sourceArg(ProxyServer server, String name, SuggestionProvider suggestionProvider) { + protected static ArgumentElement sourceArg(ProxyServer server, String name, + SuggestionProvider suggestionProvider) { ArgumentType argumentType = reader -> { String s = reader.readUnquotedString(); CommandSource source = server.getPlayer(s).orElse(null); @@ -58,4 +82,5 @@ public class VelocityCommand extends Command { return builder.buildFuture(); }); } + } diff --git a/velocity/src/main/java/net/william278/uniform/velocity/VelocityUniform.java b/velocity/src/main/java/net/william278/uniform/velocity/VelocityUniform.java new file mode 100644 index 0000000..4a1578d --- /dev/null +++ b/velocity/src/main/java/net/william278/uniform/velocity/VelocityUniform.java @@ -0,0 +1,68 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.velocity; + +import com.velocitypowered.api.command.BrigadierCommand; +import com.velocitypowered.api.proxy.ProxyServer; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; + +/** + * A class for registering commands with the Velocity server's command manager + * + * @since 1.0 + */ +@SuppressWarnings("unused") +public final class VelocityUniform { + + private static VelocityUniform INSTANCE; + + private final ProxyServer server; + + private VelocityUniform(@NotNull ProxyServer server) { + this.server = server; + } + + /** + * Get the VelocityUniform instance for registering commands + * + * @param server The server instance + * @return The VelocityUniform instance + * @since 1.0 + */ + @NotNull + public static VelocityUniform getInstance(@NotNull ProxyServer server) { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VelocityUniform(server)); + } + + /** + * Register one or more commands with the server's command manager + * + * @param commands The commands to register + * @since 1.0 + */ + public void register(@NotNull VelocityCommand... commands) { + Arrays.stream(commands).forEach(cmd -> server.getCommandManager().register(new BrigadierCommand(cmd.build()))); + } + +}