forked from public-mirrors/Uniform
refactor: redo layout, registration structure
parent
712949d4f7
commit
8f4e952337
@ -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
|
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/example-plugin" />
|
||||
<option value="$PROJECT_DIR$/paper" />
|
||||
<option value="$PROJECT_DIR$/velocity" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -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 <will27528@gmail.com>
|
||||
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 <https://www.gnu.org/licenses/>.
|
@ -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.
|
@ -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()
|
||||
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 {
|
||||
url = "https://libraries.minecraft.net/"
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi("com.mojang:brigadier:1.1.8")
|
||||
compileOnlyApi("org.jetbrains:annotations:24.0.0")
|
||||
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')
|
||||
}
|
@ -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'
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.william278.uniform;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CommandExecutor<S> {
|
||||
|
||||
void execute(@NotNull CommandContext<S> context);
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<S>(@Nullable Predicate<S> condition, @NotNull CommandExecutor<S> executor, @NotNull List<CommandElement<S>> elements) {
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.william278.uniform;
|
||||
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<S>(@NotNull Node<S> root) {
|
||||
|
||||
|
||||
static <S> @NotNull Graph<S> create(@NotNull Command<S> command) {
|
||||
return new Graph<>(Node.command(command));
|
||||
}
|
||||
|
||||
static <S> @NotNull CommandElement<S> commandToElement(@NotNull Command<S> command) {
|
||||
return new LiteralElement<>(command.getName());
|
||||
}
|
||||
|
||||
@NotNull LiteralCommandNode<S> build() {
|
||||
CommandNode<S> node = this.root.build();
|
||||
if (!(node instanceof LiteralCommandNode<S> literalNode)) {
|
||||
throw new IllegalStateException("Root node is somehow not a literal node. This should be impossible.");
|
||||
}
|
||||
return literalNode;
|
||||
}
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<S>(@NotNull CommandElement<S> element, @Nullable Execution<S> execution, @NotNull List<Node<S>> children) {
|
||||
|
||||
static <S> @NotNull Node<S> command(@NotNull Command<S> command) {
|
||||
return ConversionNode.fromCommand(command).toNode();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
CommandNode<S> build() {
|
||||
ArgumentBuilder<S, ?> builder = this.element.toBuilder();
|
||||
if (this.execution != null) this.execution.addToBuilder(builder);
|
||||
|
||||
for (Node<S> child : this.children) {
|
||||
builder.then(child.build());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<S, T>(@NotNull String name, @NotNull ArgumentType<T> type,
|
||||
@Nullable SuggestionProvider<S> suggestionProvider) implements CommandElement<S> {
|
||||
|
||||
@Override
|
||||
public @NotNull ArgumentBuilder<S, ?> toBuilder() {
|
||||
var builder = RequiredArgumentBuilder.<S, T>argument(this.name, this.type);
|
||||
if (this.suggestionProvider != null) builder.suggests(this.suggestionProvider);
|
||||
return builder;
|
||||
}
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.william278.uniform.element;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CommandElement<S> {
|
||||
|
||||
@NotNull ArgumentBuilder<S, ?> toBuilder();
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<S>(@NotNull String name) implements CommandElement<S> {
|
||||
|
||||
@Override
|
||||
public @NotNull ArgumentBuilder<S, ?> toBuilder() {
|
||||
return LiteralArgumentBuilder.literal(this.name);
|
||||
}
|
||||
}
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
name: ExamplePlugin
|
||||
name: UniformExample
|
||||
version: 1.0
|
||||
api-version: "1.20"
|
||||
main: me.tofaa.Main
|
||||
main: net.william278.uniform.UniformExample
|
@ -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.
|
Binary file not shown.
@ -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
|
||||
|
@ -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'
|
||||
}
|
@ -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<PaperCommand> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<PaperCommand> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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'
|
||||
)
|
@ -1,9 +0,0 @@
|
||||
package me.tofaa.brigadierwrapper;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CommandExecutor<S> {
|
||||
|
||||
void execute(@NotNull CommandContext<S> context);
|
||||
}
|
@ -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<S>(@Nullable Predicate<S> condition, @NotNull CommandExecutor<S> executor, @NotNull List<CommandElement<S>> elements) {
|
||||
}
|
@ -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<S>(@NotNull Node<S> root) {
|
||||
|
||||
|
||||
static <S> @NotNull Graph<S> create(@NotNull Command<S> command) {
|
||||
return new Graph<>(Node.command(command));
|
||||
}
|
||||
|
||||
static <S> @NotNull CommandElement<S> commandToElement(@NotNull Command<S> command) {
|
||||
return new LiteralElement<>(command.getName());
|
||||
}
|
||||
|
||||
@NotNull LiteralCommandNode<S> build() {
|
||||
CommandNode<S> node = this.root.build();
|
||||
if (!(node instanceof LiteralCommandNode<S> literalNode)) {
|
||||
throw new IllegalStateException("Root node is somehow not a literal node. This should be impossible.");
|
||||
}
|
||||
return literalNode;
|
||||
}
|
||||
}
|
@ -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<S>(@NotNull CommandElement<S> element, @Nullable Execution<S> execution, @NotNull List<Node<S>> children) {
|
||||
|
||||
static <S> @NotNull Node<S> command(@NotNull Command<S> command) {
|
||||
return ConversionNode.fromCommand(command).toNode();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
CommandNode<S> build() {
|
||||
ArgumentBuilder<S, ?> builder = this.element.toBuilder();
|
||||
if (this.execution != null) this.execution.addToBuilder(builder);
|
||||
|
||||
for (Node<S> child : this.children) {
|
||||
builder.then(child.build());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
@ -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<S, T>(@NotNull String name, @NotNull ArgumentType<T> type,
|
||||
@Nullable SuggestionProvider<S> suggestionProvider) implements CommandElement<S> {
|
||||
|
||||
@Override
|
||||
public @NotNull ArgumentBuilder<S, ?> toBuilder() {
|
||||
var builder = RequiredArgumentBuilder.<S, T>argument(this.name, this.type);
|
||||
if (this.suggestionProvider != null) builder.suggests(this.suggestionProvider);
|
||||
return builder;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package me.tofaa.brigadierwrapper.element;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CommandElement<S> {
|
||||
|
||||
@NotNull ArgumentBuilder<S, ?> toBuilder();
|
||||
}
|
@ -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<S>(@NotNull String name) implements CommandElement<S> {
|
||||
|
||||
@Override
|
||||
public @NotNull ArgumentBuilder<S, ?> toBuilder() {
|
||||
return LiteralArgumentBuilder.literal(this.name);
|
||||
}
|
||||
}
|
@ -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'
|
||||
}
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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 <will27528@gmail.com>
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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())));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue