mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-07-13 02:08:34 +00:00
Adjust to better align with code specs
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package me.totalfreedom.command;
|
||||
|
||||
import jdk.jshell.MethodSnippet;
|
||||
import me.totalfreedom.api.Context;
|
||||
import me.totalfreedom.command.annotation.Subcommand;
|
||||
import me.totalfreedom.provider.ContextProvider;
|
||||
@ -14,11 +13,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class BukkitDelegator extends Command implements PluginIdentifiableCommand
|
||||
@ -41,7 +36,9 @@ public class BukkitDelegator extends Command implements PluginIdentifiableComman
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args)
|
||||
public boolean execute(@NotNull final CommandSender sender,
|
||||
@NotNull final String commandLabel,
|
||||
@NotNull final String[] args)
|
||||
{
|
||||
if (commandLabel.isEmpty() || !commandLabel.equalsIgnoreCase(getName()))
|
||||
return false;
|
||||
@ -63,23 +60,26 @@ public class BukkitDelegator extends Command implements PluginIdentifiableComman
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
ContextProvider provider = new ContextProvider();
|
||||
Set<Subcommand> nodes = command.getSubcommands().keySet();
|
||||
for (Subcommand node : nodes) {
|
||||
Class<?>[] argTypes = node.args();
|
||||
final ContextProvider provider = new ContextProvider();
|
||||
final Set<Subcommand> nodes = command.getSubcommands().keySet();
|
||||
for (final Subcommand node : nodes)
|
||||
{
|
||||
final Class<?>[] argTypes = node.args();
|
||||
if (argTypes.length != args.length)
|
||||
continue;
|
||||
|
||||
Object[] objects = new Object[0];
|
||||
|
||||
for (int i = 0; i < argTypes.length; i++) {
|
||||
Class<?> argType = argTypes[i];
|
||||
String arg = args[i];
|
||||
for (int i = 0; i < argTypes.length; i++)
|
||||
{
|
||||
final Class<?> argType = argTypes[i];
|
||||
final String arg = args[i];
|
||||
if (argType == String.class)
|
||||
continue;
|
||||
|
||||
Context<?> context = () -> provider.fromString(arg);
|
||||
if (!argType.isInstance(context.get())) {
|
||||
final Context<?> context = () -> provider.fromString(arg);
|
||||
if (!argType.isInstance(context.get()))
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
objects = Arrays.copyOf(objects, objects.length + 1);
|
||||
@ -98,7 +98,8 @@ public class BukkitDelegator extends Command implements PluginIdentifiableComman
|
||||
return false;
|
||||
}
|
||||
|
||||
if (command.getBaseMethodPair() != null) {
|
||||
if (command.getBaseMethodPair() != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
command.getBaseMethodPair().getValue().invoke(command, sender);
|
||||
|
@ -29,7 +29,7 @@ public abstract class CommandBase
|
||||
|
||||
if (this.getClass().isAnnotationPresent(Base.class))
|
||||
{
|
||||
Method method = Stream.of(this.getClass().getDeclaredMethods())
|
||||
final Method method = Stream.of(this.getClass().getDeclaredMethods())
|
||||
.filter(m -> m.isAnnotationPresent(Base.class))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Base annotation present but no method found."));
|
||||
|
@ -1,14 +1,13 @@
|
||||
package me.totalfreedom.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class CommandHandler
|
||||
{
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public CommandHandler(JavaPlugin plugin)
|
||||
public CommandHandler(final JavaPlugin plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -17,8 +16,9 @@ public class CommandHandler
|
||||
// We need to find a way to resolve PluginCommands so we can
|
||||
// set the executor and tab completer as necessary.
|
||||
// OR we need to find an alternative way to process tab completions.
|
||||
public <T extends CommandBase> void registerCommand(T command) {
|
||||
BukkitDelegator delegate = new BukkitDelegator(plugin, command);
|
||||
public <T extends CommandBase> void registerCommand(final T command)
|
||||
{
|
||||
final BukkitDelegator delegate = new BukkitDelegator(plugin, command);
|
||||
|
||||
Bukkit.getCommandMap().register(plugin.getName(), delegate);
|
||||
}
|
||||
|
Reference in New Issue
Block a user