forked from public-mirrors/Uniform
add
parent
9b464fd06d
commit
712949d4f7
@ -1,21 +1,42 @@
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
# Avoid ignore Gradle wrappper properties
|
||||
!gradle-wrapper.properties
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
# Eclipse Gradle plugin generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
### Mac OS ###
|
||||
.DS_Store
|
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -0,0 +1,20 @@
|
||||
<?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>
|
@ -0,0 +1,10 @@
|
||||
<?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>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group = 'me.tofaa'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = "https://libraries.minecraft.net/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi("com.mojang:brigadier:1.1.8")
|
||||
compileOnlyApi("org.jetbrains:annotations:24.0.0")
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":paper"))
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
|
||||
tasks {
|
||||
runServer {
|
||||
minecraftVersion("1.20.4")
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
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"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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,4 @@
|
||||
name: ExamplePlugin
|
||||
version: 1.0
|
||||
api-version: "1.20"
|
||||
main: me.tofaa.Main
|
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
#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
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# 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
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
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"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
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.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
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.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="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
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group = 'me.tofaa'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = "https://repo.papermc.io/repository/maven-public/"
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
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,59 @@
|
||||
package me.tofaa.brigadierwrapper.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 org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class PaperCommand extends Command<BukkitBrigadierCommandSource> {
|
||||
|
||||
public PaperCommand(@NotNull String name, @NotNull String... aliases) {
|
||||
super(name, aliases);
|
||||
}
|
||||
|
||||
protected static ArgumentElement<BukkitBrigadierCommandSource, Material> materialArg(String name) {
|
||||
return new ArgumentElement<>(name, reader -> {
|
||||
String materialName = reader.readString();
|
||||
Material material = Material.matchMaterial(materialName);
|
||||
if (material == null) {
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||
}
|
||||
return material;
|
||||
}, (context, builder) -> {
|
||||
for (Material material : Material.values()) {
|
||||
builder.suggest(material.name());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
});
|
||||
}
|
||||
|
||||
protected static ArgumentElement<BukkitBrigadierCommandSource, Collection<? extends Player>> playerArg(String name) {
|
||||
return new ArgumentElement<>(name, reader -> {
|
||||
String playerName = reader.readString();
|
||||
if (playerName.equals("@a")) {
|
||||
return Bukkit.getOnlinePlayers();
|
||||
}
|
||||
var player = Bukkit.getPlayer(playerName);
|
||||
if (player == null) {
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||
}
|
||||
return List.of(player);
|
||||
}, (context, builder) -> {
|
||||
builder.suggest("@a");
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
builder.suggest(player.getName());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
rootProject.name = 'BrigadierWrapper'
|
||||
include 'paper'
|
||||
include 'velocity'
|
||||
include 'example-plugin'
|
||||
|
@ -0,0 +1,133 @@
|
||||
package me.tofaa.brigadierwrapper;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class Command<S> {
|
||||
|
||||
private final String name;
|
||||
private final String[] aliases;
|
||||
|
||||
private @Nullable Predicate<S> condition;
|
||||
private @Nullable CommandExecutor<S> defaultExecutor;
|
||||
|
||||
private final List<CommandSyntax<S>> syntaxes = new ArrayList<>();
|
||||
private final List<Command<S>> subCommands = new ArrayList<>();
|
||||
|
||||
public Command(@NotNull String name, @NotNull String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
public Command(@NotNull String name) {
|
||||
this(name, new String[0]);
|
||||
}
|
||||
|
||||
protected final void setCondition(@NotNull Predicate<S> condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
protected final void setDefaultExecutor(@NotNull CommandExecutor<S> executor) {
|
||||
this.defaultExecutor = executor;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final void addConditionalSyntax(@Nullable Predicate<S> condition, @NotNull CommandExecutor<S> executor,
|
||||
@NotNull CommandElement<S>... elements) {
|
||||
var syntax = new CommandSyntax<>(condition, executor, List.of(elements));
|
||||
this.syntaxes.add(syntax);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final void addSyntax(@NotNull CommandExecutor<S> executor, @NotNull CommandElement<S>... elements) {
|
||||
this.addConditionalSyntax(null, executor, elements);
|
||||
}
|
||||
|
||||
protected final void addSubCommand(@NotNull Command<S> command) {
|
||||
this.subCommands.add(command);
|
||||
}
|
||||
|
||||
public final @NotNull LiteralCommandNode<S> build() {
|
||||
return Graph.create(this).build();
|
||||
}
|
||||
|
||||
public final @NotNull String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public final @NotNull String[] getAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
final @Nullable Predicate<S> getCondition() {
|
||||
return this.condition;
|
||||
}
|
||||
|
||||
final @Nullable CommandExecutor<S> getDefaultExecutor() {
|
||||
return this.defaultExecutor;
|
||||
}
|
||||
|
||||
final @NotNull Collection<CommandSyntax<S>> getSyntaxes() {
|
||||
return this.syntaxes;
|
||||
}
|
||||
|
||||
final @NotNull Collection<Command<S>> getSubCommands() {
|
||||
return this.subCommands;
|
||||
}
|
||||
|
||||
protected static <S> @NotNull LiteralElement<S> literalArg(@NotNull String name) {
|
||||
return new LiteralElement<>(name);
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, String> stringArg(@NotNull String name) {
|
||||
return argument(name, StringArgumentType.string());
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, Integer> integerArg(@NotNull String name) {
|
||||
return argument(name, IntegerArgumentType.integer());
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, Integer> integerArg(@NotNull String name, int min) {
|
||||
return argument(name, IntegerArgumentType.integer(min));
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, Integer> integerArg(@NotNull String name, int min, int max) {
|
||||
return argument(name, IntegerArgumentType.integer(min, max));
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, Float> floatArg(@NotNull String name) {
|
||||
return argument(name, FloatArgumentType.floatArg());
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, Float> floatArg(@NotNull String name, float min) {
|
||||
return argument(name, FloatArgumentType.floatArg(min));
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, Float> floatArg(@NotNull String name, float min, float max) {
|
||||
return argument(name, FloatArgumentType.floatArg(min, max));
|
||||
}
|
||||
|
||||
protected static <S> @NotNull ArgumentElement<S, Boolean> booleanArg(@NotNull String name) {
|
||||
return argument(name, BoolArgumentType.bool());
|
||||
}
|
||||
|
||||
protected static <S, T> @NotNull ArgumentElement<S, T> argument(@NotNull String name, @NotNull ArgumentType<T> type, @Nullable SuggestionProvider<S> suggestionProvider) {
|
||||
return new ArgumentElement<>(name, type, suggestionProvider);
|
||||
}
|
||||
|
||||
protected static <S, T> @NotNull ArgumentElement<S, T> argument(@NotNull String name, @NotNull ArgumentType<T> type) {
|
||||
return argument(name, type, null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
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);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
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) {
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package me.tofaa.brigadierwrapper;
|
||||
|
||||
import me.tofaa.brigadierwrapper.element.CommandElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static me.tofaa.brigadierwrapper.Graph.commandToElement;
|
||||
|
||||
record ConversionNode<S>(@NotNull CommandElement<S> element, @Nullable Execution<S> execution,
|
||||
@NotNull Map<CommandElement<S>, ConversionNode<S>> nextMap) {
|
||||
|
||||
static <S> @NotNull ConversionNode<S> fromCommand(@NotNull Command<S> command) {
|
||||
ConversionNode<S> root = new ConversionNode<>(commandToElement(command), Execution.fromCommand(command));
|
||||
|
||||
for (CommandSyntax<S> syntax : command.getSyntaxes()) {
|
||||
ConversionNode<S> syntaxNode = root;
|
||||
|
||||
for (CommandElement<S> element : syntax.elements()) {
|
||||
boolean last = element == syntax.elements().get(syntax.elements().size() - 1);
|
||||
syntaxNode = syntaxNode.nextMap.computeIfAbsent(element, e -> {
|
||||
Execution<S> execution = last ? Execution.fromSyntax(syntax) : null;
|
||||
return new ConversionNode<>(e, execution);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (Command<S> subCommand : command.getSubCommands()) {
|
||||
root.nextMap.put(commandToElement(subCommand), fromCommand(subCommand));
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
ConversionNode(@NotNull CommandElement<S> element, @Nullable Execution<S> execution) {
|
||||
this(element, execution, new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
Node<S> toNode() {
|
||||
@SuppressWarnings("unchecked") // this is fine - we only put Node<S> in to this array
|
||||
Node<S>[] nodes = (Node<S>[]) new Node<?>[this.nextMap.size()];
|
||||
|
||||
int i = 0;
|
||||
for (ConversionNode<S> entry : this.nextMap.values()) {
|
||||
nodes[i++] = entry.toNode();
|
||||
}
|
||||
|
||||
return new Node<>(this.element, this.execution, List.of(nodes));
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package me.tofaa.brigadierwrapper;
|
||||
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
record Execution<S>(@NotNull Predicate<S> predicate, @Nullable CommandExecutor<S> defaultExecutor, @Nullable CommandExecutor<S> executor,
|
||||
@Nullable Predicate<S> condition) implements Predicate<S> {
|
||||
|
||||
private static final Executor CACHED_EXECUTOR = Executors.newCachedThreadPool();
|
||||
|
||||
|
||||
static <S> @NotNull Execution<S> fromCommand(@NotNull Command<S> command) {
|
||||
CommandExecutor<S> defaultExecutor = command.getDefaultExecutor();
|
||||
Predicate<S> defaultCondition = command.getCondition();
|
||||
|
||||
CommandExecutor<S> executor = defaultExecutor;
|
||||
Predicate<S> condition = defaultCondition;
|
||||
for (CommandSyntax<S> syntax : command.getSyntaxes()) {
|
||||
if (!syntax.elements().isEmpty()) continue;
|
||||
executor = syntax.executor();
|
||||
condition = syntax.condition();
|
||||
break;
|
||||
}
|
||||
|
||||
return new Execution<>(source -> defaultCondition == null || defaultCondition.test(source), defaultExecutor, executor, condition);
|
||||
}
|
||||
|
||||
static <S> @NotNull Execution<S> fromSyntax(@NotNull CommandSyntax<S> syntax) {
|
||||
CommandExecutor<S> executor = syntax.executor();
|
||||
Predicate<S> condition = syntax.condition();
|
||||
return new Execution<>(source -> condition == null || condition.test(source), null, executor, condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(@NotNull S source) {
|
||||
return this.predicate.test(source);
|
||||
}
|
||||
|
||||
void addToBuilder(@NotNull ArgumentBuilder<S, ?> builder) {
|
||||
if (this.condition != null) builder.requires(this.condition);
|
||||
if (this.executor != null) {
|
||||
builder.executes(convertExecutor(this.executor));
|
||||
} else if (this.defaultExecutor != null) {
|
||||
builder.executes(convertExecutor(this.defaultExecutor));
|
||||
}
|
||||
}
|
||||
|
||||
private static <S> com.mojang.brigadier.@NotNull Command<S> convertExecutor(@NotNull CommandExecutor<S> executor) {
|
||||
return context -> {
|
||||
CACHED_EXECUTOR.execute(() -> executor.execute(context));
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package me.tofaa.brigadierwrapper.element;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CommandElement<S> {
|
||||
|
||||
@NotNull ArgumentBuilder<S, ?> toBuilder();
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group = 'me.tofaa'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = "https://repo.papermc.io/repository/maven-public/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
api(project(":"))
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
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,61 @@
|
||||
package me.tofaa.brigadierwrapper.velocity;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class VelocityCommand extends Command<CommandSource> {
|
||||
|
||||
public VelocityCommand(@NotNull String name, @NotNull String... aliases) {
|
||||
super(name, aliases);
|
||||
}
|
||||
|
||||
protected static ArgumentElement<CommandSource, RegisteredServer> serverArg(ProxyServer server, String name, SuggestionProvider<CommandSource> suggestionProvider) {
|
||||
ArgumentType<RegisteredServer> argumentType = reader -> {
|
||||
String s = reader.readUnquotedString();
|
||||
RegisteredServer server1 = server.getServer(s).orElse(null);
|
||||
if (server1 == null) {
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||
}
|
||||
return server1;
|
||||
};
|
||||
return new ArgumentElement<>(name, argumentType, suggestionProvider);
|
||||
}
|
||||
|
||||
protected static ArgumentElement<CommandSource, RegisteredServer> serverArg(ProxyServer server, String name) {
|
||||
return serverArg(server, name, (context, builder) -> {
|
||||
for (RegisteredServer server1 : server.getAllServers()) {
|
||||
builder.suggest(server1.getServerInfo().getName());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
});
|
||||
}
|
||||
|
||||
protected static ArgumentElement<CommandSource, CommandSource> sourceArg(ProxyServer server, String name, SuggestionProvider<CommandSource> suggestionProvider) {
|
||||
ArgumentType<CommandSource> argumentType = reader -> {
|
||||
String s = reader.readUnquotedString();
|
||||
CommandSource source = server.getPlayer(s).orElse(null);
|
||||
if (source == null) {
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
|
||||
}
|
||||
return source;
|
||||
};
|
||||
return new ArgumentElement<>(name, argumentType, suggestionProvider);
|
||||
}
|
||||
|
||||
protected static ArgumentElement<CommandSource, CommandSource> sourceArg(ProxyServer server, String name) {
|
||||
return sourceArg(server, name, (context, builder) -> {
|
||||
for (Player source : server.getAllPlayers()) {
|
||||
builder.suggest(source.getUsername());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue