Functionality Update

Numerous changes;
Features that may be removed:
SubCommand system
This commit is contained in:
Paldiu 2022-02-05 22:05:33 -06:00
parent 83bd9dfced
commit 8569cf1510
46 changed files with 568 additions and 138 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

Binary file not shown.

View File

@ -0,0 +1,2 @@
#Sat Feb 05 19:33:20 CST 2022
gradle.version=7.2

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

12
.idea/compiler.xml generated
View File

@ -1,16 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="SimplexCL" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="SimplexCL" target="1.17" />
</bytecodeTargetLevel>
<bytecodeTargetLevel target="17" />
</component>
</project>

17
.idea/gradle.xml generated Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -26,5 +26,15 @@
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven3" />
<option name="name" value="maven3" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenLocal" />
<option name="name" value="MavenLocal" />
<option name="url" value="file:/$MAVEN_REPOSITORY$/" />
</remote-repository>
</component>
</project>

8
.idea/misc.xml generated
View File

@ -5,13 +5,7 @@
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
</list>
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/SimplexCL.iml" filepath="$PROJECT_DIR$/SimplexCL.iml" />
</modules>
</component>
</project>

13
.idea/modules/SimplexCL.main.iml generated Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

48
build.gradle Normal file
View File

@ -0,0 +1,48 @@
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
id 'java'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
tasks {
build {
dependsOn(shadowJar)
}
}
repositories {
mavenLocal()
maven {
url = uri('https://papermc.io/repo/repository/maven-public/')
}
maven {
url = uri('https://oss.sonatype.org/content/groups/public/')
}
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
mavenCentral()
}
dependencies {
shadow 'org.reflections:reflections:0.10.2'
compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT'
}
group = 'io.github.simplex'
version = '1.0.0'
description = 'SimplexCL'
java.sourceCompatibility = JavaVersion.VERSION_17
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

View File

@ -0,0 +1,8 @@
name: SimplexCL
version: '${project.version}'
main: io.github.simplex.SimplexCL
api-version: 1.18
prefix: CommandLoader
authors: [ SimplexDevelopment ]
description: A Command Loader for Paper
website: https://simplexdev.app

Binary file not shown.

View File

@ -0,0 +1,2 @@
Manifest-Version: 1.0

View File

@ -0,0 +1,4 @@
Manifest-Version: 1.0
Class-Path: reflections-0.10.2.jar javassist-3.28.0-GA.jar jsr305-3.0.2.
jar slf4j-api-1.7.32.jar

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

234
gradlew vendored Normal file
View File

@ -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" "$@"

89
gradlew.bat vendored Normal file
View File

@ -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

5
settings.gradle Normal file
View File

@ -0,0 +1,5 @@
/*
* This file was generated by the Gradle 'init' task.
*/
rootProject.name = 'SimplexCL'

View File

@ -1,26 +1,29 @@
package io.github.simplex;
import io.github.simplex.api.ICommand;
import io.github.simplex.api.annotations.Permission;
import io.github.simplex.api.annotations.SubCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.util.RGBLike;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.plugin.Plugin;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class CommandBase extends Permissible implements ICommand {
private final Plugin plugin;
public CommandBase(Plugin plugin, String permission, String permissionMessage) {
super(permission, permissionMessage);
this.plugin = plugin;
public CommandBase(String permission, String permissionMessage, boolean allowConsole) {
super(permission, permissionMessage, allowConsole);
}
public CommandBase(Plugin plugin, String permission) {
this(plugin, permission, "You do not have permission to use this command.");
public CommandBase(String permission, String permissionMessage) {
this(permission, permissionMessage, true);
}
@Override
@ -32,7 +35,21 @@ public abstract class CommandBase extends Permissible implements ICommand {
.color(TextColor.color(255, 3, 62)));
return true;
}
execute();
if (!(sender instanceof Player) && !allowConsole()) {
sender.sendMessage(Component.empty().content("This command may only be run in game."));
}
execute(sender, args, allowConsole());
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return new ArrayList<>();
}
public TextComponent msg(String text) {
return Component.empty().content(text);
}
}

View File

@ -2,68 +2,44 @@ package io.github.simplex;
import io.github.simplex.api.annotations.*;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
import org.bukkit.plugin.Plugin;
import org.reflections.Reflections;
import java.lang.annotation.AnnotationTypeMismatchException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Set;
public class CommandLoader {
public class CommandLoader<T extends CommandBase> {
private final Plugin plugin;
public CommandLoader(Plugin plugin) {
this.plugin = plugin;
}
public Plugin getPlugin() {
return plugin;
}
public void registerCommands(Class<CommandBase> target) {
public void registerCommands(Class<T> target) {
Reflections reflections = new Reflections(target);
if (target.getDeclaredAnnotation(Info.class) != null) {
Set<Class<?>> classSet = reflections.getTypesAnnotatedWith(Info.class);
classSet.forEach(cmd -> {
Info info = cmd.getDeclaredAnnotation(Info.class);
try {
CommandBase base = (CommandBase) cmd.getConstructor(Plugin.class, String.class, String.class).newInstance(plugin, info.permission(), info.permissionMessage());
DummyCommand dummy = new DummyCommand(base, info.name(), info.description(), info.usage(), Arrays.asList(info.aliases().split(",")));
Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
CommandMap commandMap = (CommandMap) f.get(Bukkit.getServer());
commandMap.register(info.name(), dummy);
} catch (NoSuchMethodException
| InvocationTargetException
| IllegalAccessException
| InstantiationException
| NoSuchFieldException e) {
plugin.getLogger().severe(e.getMessage() + "\n\n\n" + e.getCause());
}
});
} else if (target.getDeclaredAnnotation(Name.class) != null) {
Set<Class<?>> classSet = reflections.getTypesAnnotatedWith(Name.class);
classSet.forEach(cmd -> {
Name name = cmd.getDeclaredAnnotation(Name.class);
Description description = cmd.getDeclaredAnnotation(Description.class);
Usage usage = cmd.getDeclaredAnnotation(Usage.class);
Aliases aliases = cmd.getDeclaredAnnotation(Aliases.class);
Permission permission = cmd.getDeclaredAnnotation(Permission.class);
try {
CommandBase base = (CommandBase) cmd.getConstructor(Plugin.class, String.class, String.class).newInstance(plugin, permission.permission(), permission.permissionMessage());
DummyCommand dummy = new DummyCommand(base, name.name(), description.description(), usage.usage(), Arrays.asList(aliases.aliases().split(",")));
Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
CommandMap commandMap = (CommandMap) f.get(Bukkit.getServer());
commandMap.register(name.name(), dummy);
CommandBase base = (CommandBase) cmd.getConstructor(String.class,
String.class,
Boolean.class)
.newInstance(permission.permission(),
permission.permissionMessage(),
permission.allowConsole());
DummyCommand dummy = new DummyCommand(plugin,
base,
info.name(),
info.description(),
info.usage(),
Arrays.asList(info.aliases().split(",")));
Bukkit.getCommandMap().register(info.name(), "SimplexCL", dummy);
} catch (NoSuchMethodException
| InvocationTargetException
| IllegalAccessException
| InstantiationException
| NoSuchFieldException e) {
| InstantiationException e) {
plugin.getLogger().severe(e.getMessage() + "\n\n\n" + e.getCause());
}
});

View File

@ -1,15 +1,18 @@
package io.github.simplex;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class DummyCommand extends BukkitCommand {
public final class DummyCommand extends Command implements PluginIdentifiableCommand {
private final CommandBase base;
private final Plugin plugin;
protected DummyCommand(@NotNull CommandBase base, @NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases) {
DummyCommand(@NotNull Plugin plugin, @NotNull CommandBase base, @NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases) {
super(name, description, usageMessage, aliases);
this.setName(name);
this.setDescription(description);
@ -17,6 +20,7 @@ public class DummyCommand extends BukkitCommand {
this.setAliases(aliases);
this.setPermission(base.getPermission());
this.base = base;
this.plugin = plugin;
}
@Override
@ -24,4 +28,9 @@ public class DummyCommand extends BukkitCommand {
base.onCommand(sender, this, commandLabel, args);
return true;
}
@Override
public @NotNull Plugin getPlugin() {
return plugin;
}
}

View File

@ -5,14 +5,12 @@ import org.bukkit.command.CommandSender;
public abstract class Permissible {
private final String permission;
private final String permissionMessage;
private final boolean allowConsole;
public Permissible(String permission, String permissionMessage) {
public Permissible(String permission, String permissionMessage, boolean allowConsole) {
this.permission = permission;
this.permissionMessage = permissionMessage;
}
public Permissible(String permission) {
this(permission, "You do not have permission to use this command.");
this.allowConsole = allowConsole;
}
public String getPermission() {
@ -26,4 +24,8 @@ public abstract class Permissible {
public boolean hasPermission(CommandSender sender) {
return sender.hasPermission(getPermission());
}
public boolean allowConsole() {
return allowConsole;
}
}

View File

@ -0,0 +1,15 @@
package io.github.simplex;
/*
* This class is intended to be used as a nested class inside your main command class.
* For example:
*/
public abstract class SubCommandBase extends CommandBase {
public SubCommandBase(String permission, String permissionMessage, boolean allowConsole) {
super(permission, permissionMessage, allowConsole);
}
public SubCommandBase(String permission, String permissionMessage) {
this(permission, permissionMessage, true);
}
}

View File

@ -1,8 +1,9 @@
package io.github.simplex.api;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
public interface ICommand extends CommandExecutor, TabCompleter {
boolean execute();
void execute(CommandSender sender, String[] args, boolean allowConsole);
}

View File

@ -1,12 +0,0 @@
package io.github.simplex.api.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Aliases {
String aliases();
}

View File

@ -1,12 +0,0 @@
package io.github.simplex.api.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Description {
String description();
}

View File

@ -11,7 +11,5 @@ public @interface Info {
String name();
String description();
String usage();
String permission();
String aliases() default "";
String permissionMessage() default "You do not have permission to use this command.";
}

View File

@ -1,12 +0,0 @@
package io.github.simplex.api.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Name {
String name();
}

View File

@ -10,4 +10,5 @@ import java.lang.annotation.Target;
public @interface Permission {
String permission();
String permissionMessage() default "You do not have permission to use this command!";
boolean allowConsole() default true;
}

View File

@ -5,7 +5,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SubCommand {
String name();
}

View File

@ -1,12 +0,0 @@
package io.github.simplex.api.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Usage {
String usage();
}

View File

@ -0,0 +1,39 @@
package io.github.simplex.impl;
import io.github.simplex.CommandBase;
import io.github.simplex.SubCommandBase;
import io.github.simplex.api.annotations.Info;
import io.github.simplex.api.annotations.Permission;
import io.github.simplex.api.annotations.SubCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.CommandSender;
@Info(name = "example", description = "An example command implementation to see how this works.", usage = "/example [info]", aliases = "ex, impl")
@Permission(permission = "simplexcl.example", permissionMessage = "You cannot use this command!")
public final class ExampleCommand extends CommandBase {
public ExampleCommand(String permission, String permissionMessage, boolean allowConsole) {
super(permission, permissionMessage, allowConsole);
}
@Override
public void execute(CommandSender sender, String[] args, boolean allowConsole) {
}
@SubCommand(name = "info")
@Permission(permission = "simplexcl.example.info")
public class InfoSubCommand extends SubCommandBase {
public InfoSubCommand(String permission, String permissionMessage, boolean allowConsole) {
super(permission, permissionMessage, allowConsole);
}
@Override
public void execute(CommandSender sender, String[] args, boolean allowConsole) {
TextComponent message = Component.empty();
message = message.append(msg("SimplexCL was created by SimplexDevelopment!"))
.append(msg("https://github.com/SimplexDevelopment/"));
sender.sendMessage(message);
}
}
}