mirror of
https://github.com/SimplexDevelopment/SimplexCL.git
synced 2024-11-14 14:33:34 +00:00
Minor Update
This commit is contained in:
parent
8569cf1510
commit
355d04d9ba
@ -1,55 +0,0 @@
|
||||
package io.github.simplex;
|
||||
|
||||
import io.github.simplex.api.ICommand;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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 {
|
||||
public CommandBase(String permission, String permissionMessage, boolean allowConsole) {
|
||||
super(permission, permissionMessage, allowConsole);
|
||||
}
|
||||
|
||||
public CommandBase(String permission, String permissionMessage) {
|
||||
this(permission, permissionMessage, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String lbl, String[] args) {
|
||||
if (!hasPermission(sender)) {
|
||||
sender.sendMessage(Component
|
||||
.empty()
|
||||
.content(getPermissionMessage())
|
||||
.color(TextColor.color(255, 3, 62)));
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,14 +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.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Permission {
|
||||
String permission();
|
||||
String permissionMessage() default "You do not have permission to use this command!";
|
||||
boolean allowConsole() default true;
|
||||
}
|
@ -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;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface SubCommand {
|
||||
String name();
|
||||
}
|
107
src/main/java/io/github/simplex/cl/CommandBase.java
Normal file
107
src/main/java/io/github/simplex/cl/CommandBase.java
Normal file
@ -0,0 +1,107 @@
|
||||
package io.github.simplex.cl;
|
||||
|
||||
import io.github.simplex.api.ICommand;
|
||||
import io.github.simplex.api.SubCommand;
|
||||
import io.github.simplex.msgutils.AdvancedColors;
|
||||
import io.github.simplex.msgutils.BasicColors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class CommandBase extends Permissible implements ICommand {
|
||||
public CommandBase(String permission, String permissionMessage, boolean allowConsole) {
|
||||
super(permission, permissionMessage, allowConsole);
|
||||
}
|
||||
|
||||
public CommandBase(String permission, String permissionMessage) {
|
||||
this(permission, permissionMessage, true);
|
||||
}
|
||||
|
||||
public CommandBase(String permission, boolean allowConsole) {
|
||||
this(permission, "You do not have permission to use this command!", allowConsole);
|
||||
}
|
||||
|
||||
public CommandBase(String permission) {
|
||||
this(permission, "You do not have permission to use this command!", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String lbl, String[] args) {
|
||||
if (!hasPermission(sender)) {
|
||||
sender.sendMessage(msg(getPermissionMessage(), BasicColors.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player) && !allowConsole()) {
|
||||
sender.sendMessage(msg("This command can 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);
|
||||
}
|
||||
|
||||
public TextComponent msg(String text, BasicColors color) {
|
||||
return Component.empty().content(text).color(color.getColor());
|
||||
}
|
||||
|
||||
public TextComponent msg(String text, AdvancedColors color) {
|
||||
return Component.empty().content(text).color(color.getColor());
|
||||
}
|
||||
|
||||
public void subCommand(String name, String[] args, SubCommand command) {
|
||||
if (args[0].equalsIgnoreCase(name)) {
|
||||
command.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public Player getPlayer(String name) {
|
||||
return Bukkit.getServer().getPlayer(name);
|
||||
}
|
||||
|
||||
public Player getPlayer(UUID uuid) {
|
||||
return Bukkit.getServer().getPlayer(uuid);
|
||||
}
|
||||
|
||||
public List<? extends Player> getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers().stream().toList();
|
||||
}
|
||||
|
||||
public void broadcast(String text) {
|
||||
Bukkit.getServer().broadcast(msg(text));
|
||||
}
|
||||
|
||||
public void broadcast(String text, BasicColors color) {
|
||||
Bukkit.getServer().broadcast(msg(text, color));
|
||||
}
|
||||
|
||||
public void broadcast(String text, AdvancedColors color) {
|
||||
Bukkit.getServer().broadcast(msg(text, color));
|
||||
}
|
||||
|
||||
public void enablePlugin(Plugin plugin) {
|
||||
Bukkit.getServer().getPluginManager().enablePlugin(plugin);
|
||||
}
|
||||
|
||||
public void disablePlugin(Plugin plugin) {
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
}
|
@ -1,34 +1,29 @@
|
||||
package io.github.simplex;
|
||||
package io.github.simplex.cl;
|
||||
|
||||
import io.github.simplex.api.annotations.*;
|
||||
import io.github.simplex.cl.api.annotations.Info;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandLoader<T extends CommandBase> {
|
||||
public class CommandLoader {
|
||||
private final Plugin plugin;
|
||||
|
||||
public CommandLoader(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void registerCommands(Class<T> target) {
|
||||
Reflections reflections = new Reflections(target);
|
||||
if (target.getDeclaredAnnotation(Info.class) != null) {
|
||||
public <T extends CommandBase> void registerCommands(Class<T> commandRoot) {
|
||||
Reflections reflections = new Reflections(commandRoot);
|
||||
if (commandRoot.getDeclaredAnnotation(Info.class) != null) {
|
||||
Set<Class<?>> classSet = reflections.getTypesAnnotatedWith(Info.class);
|
||||
classSet.forEach(cmd -> {
|
||||
Info info = cmd.getDeclaredAnnotation(Info.class);
|
||||
Permission permission = cmd.getDeclaredAnnotation(Permission.class);
|
||||
try {
|
||||
CommandBase base = (CommandBase) cmd.getConstructor(String.class,
|
||||
String.class,
|
||||
Boolean.class)
|
||||
.newInstance(permission.permission(),
|
||||
permission.permissionMessage(),
|
||||
permission.allowConsole());
|
||||
CommandBase base = (CommandBase) cmd.getConstructor().newInstance();
|
||||
DummyCommand dummy = new DummyCommand(plugin,
|
||||
base,
|
||||
info.name(),
|
@ -1,4 +1,4 @@
|
||||
package io.github.simplex;
|
||||
package io.github.simplex.cl;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
@ -1,4 +1,4 @@
|
||||
package io.github.simplex;
|
||||
package io.github.simplex.cl;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
6
src/main/java/io/github/simplex/cl/api/SubCommand.java
Normal file
6
src/main/java/io/github/simplex/cl/api/SubCommand.java
Normal file
@ -0,0 +1,6 @@
|
||||
package io.github.simplex.api;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SubCommand {
|
||||
void execute();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.github.simplex.api.annotations;
|
||||
package io.github.simplex.cl.api.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
28
src/main/java/io/github/simplex/cl/impl/ExampleCommand.java
Normal file
28
src/main/java/io/github/simplex/cl/impl/ExampleCommand.java
Normal file
@ -0,0 +1,28 @@
|
||||
package io.github.simplex.cl.impl;
|
||||
|
||||
import io.github.simplex.cl.CommandBase;
|
||||
import io.github.simplex.cl.api.annotations.Info;
|
||||
import io.github.simplex.msgutils.BasicColors;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Info(name = "example", description = "An example command implementation to see how this works.", usage = "/example [info]", aliases = "ex, impl")
|
||||
public final class ExampleCommand extends CommandBase {
|
||||
public ExampleCommand() {
|
||||
super("simplexcl.example",
|
||||
"You do not have permission to use this command!",
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args, boolean allowConsole) {
|
||||
if (args.length == 1) {
|
||||
subCommand("info",
|
||||
args,
|
||||
() -> sender.sendMessage(msg("SimplexCL was created by Simplex Development Group.", BasicColors.GOLD)));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(msg("This is an example command.", BasicColors.BLUE));
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
46
src/main/java/io/github/simplex/msgutils/AdvancedColors.java
Normal file
46
src/main/java/io/github/simplex/msgutils/AdvancedColors.java
Normal file
@ -0,0 +1,46 @@
|
||||
package io.github.simplex.msgutils;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public enum AdvancedColors {
|
||||
AMETHYST(TextColor.color(253, 103, 204)),
|
||||
AQUAMARINE(TextColor.color(127, 255, 212)),
|
||||
AZURE(TextColor.color(0, 127, 255)),
|
||||
BRONZE(TextColor.color(205, 127, 50)),
|
||||
BURLYWOOD(TextColor.color(222, 184, 135)),
|
||||
CHARTREUSE(TextColor.color(223, 255, 0)),
|
||||
CORAL(TextColor.color(255, 127, 80)),
|
||||
CORNFLOWER(TextColor.color(100, 149, 237)),
|
||||
CRIMSON(TextColor.color(220, 20, 60)),
|
||||
FUCHSIA(TextColor.color(255, 0, 255)),
|
||||
GOLDENROD(TextColor.color(218, 165, 32)),
|
||||
GRAPE(TextColor.color(111, 45, 168)),
|
||||
HONEYDEW(TextColor.color(240, 255, 240)),
|
||||
INDIGO(TextColor.color(75, 0, 130)),
|
||||
IVORY(TextColor.color(255, 255, 240)),
|
||||
MAROON(TextColor.color(128, 0 , 0)),
|
||||
MEDIUM_VIOLET_RED(TextColor.color(199, 21, 133)),
|
||||
MOCCASIN(TextColor.color(255, 228, 181)),
|
||||
OLIVE(TextColor.color(128, 128, 0)),
|
||||
PALE_VIOLET_RED(TextColor.color(219, 112, 147)),
|
||||
PLUM(TextColor.color(142, 69, 133)),
|
||||
SALMON(TextColor.color(250, 128, 114)),
|
||||
SEA_GREEN(TextColor.color(46, 139, 87)),
|
||||
SILVER(TextColor.color(192, 192, 192)),
|
||||
SLATE(TextColor.color(192, 194, 201)),
|
||||
SLATE_BLUE(TextColor.color(106, 90, 205)),
|
||||
STEEL_BLUE(TextColor.color(70, 130, 180)),
|
||||
TOMATO(TextColor.color(255, 99, 71)),
|
||||
TURQUOISE(TextColor.color(48, 213, 200)),
|
||||
WHEAT(TextColor.color(245, 222, 179));
|
||||
|
||||
final TextColor color;
|
||||
|
||||
AdvancedColors(TextColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public TextColor getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
32
src/main/java/io/github/simplex/msgutils/BasicColors.java
Normal file
32
src/main/java/io/github/simplex/msgutils/BasicColors.java
Normal file
@ -0,0 +1,32 @@
|
||||
package io.github.simplex.msgutils;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public enum BasicColors {
|
||||
RED(TextColor.color(255, 0, 0)),
|
||||
DARK_RED(TextColor.color(127, 0, 0)),
|
||||
ORANGE(TextColor.color(255, 165, 0)),
|
||||
DARK_ORANGE(TextColor.color(255, 140, 0)),
|
||||
YELLOW(TextColor.color(255, 255, 0)),
|
||||
GOLD(TextColor.color(255, 215, 0)),
|
||||
GREEN(TextColor.color(0, 255, 0)),
|
||||
DARK_GREEN(TextColor.color(0, 127, 0)),
|
||||
BLUE(TextColor.color(0, 0, 255)),
|
||||
DARK_BLUE(TextColor.color(0, 0, 127)),
|
||||
AQUA(TextColor.color(0, 255, 255)),
|
||||
DARK_AQUA(TextColor.color(0, 127, 127)),
|
||||
PURPLE(TextColor.color(255, 0, 255)),
|
||||
DARK_PURPLE(TextColor.color(127, 0, 127)),
|
||||
PINK(TextColor.color(255, 105, 180)),
|
||||
DARK_PINK(TextColor.color(231, 84, 128));
|
||||
|
||||
final TextColor color;
|
||||
|
||||
BasicColors(TextColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public TextColor getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user