Search in sources :

Example 1 with RoseCommandArgumentHandler

use of dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler in project RoseGarden by Rosewood-Development.

the class AbstractCommandManager method reload.

@Override
public final void reload() {
    if (this.commandWrappers == null) {
        this.commandWrappers = new ArrayList<>();
        for (Class<? extends RoseCommandWrapper> commandWrapperClass : this.getRootCommands()) {
            try {
                Constructor<? extends RoseCommandWrapper> constructor = commandWrapperClass.getConstructor(RosePlugin.class);
                RoseCommandWrapper commandWrapper = constructor.newInstance(this.rosePlugin);
                this.commandWrappers.add(commandWrapper);
            } catch (ReflectiveOperationException e) {
                e.printStackTrace();
            }
        }
    }
    try {
        // Load argument handlers
        List<Class<RoseCommandArgumentHandler>> argumentHandlerClasses = new ArrayList<>(ClassUtils.getClassesOf(this.rosePlugin, ARGUMENT_PACKAGE, RoseCommandArgumentHandler.class));
        this.getArgumentHandlerPackages().stream().map(x -> ClassUtils.getClassesOf(this.rosePlugin, x, RoseCommandArgumentHandler.class)).forEach(argumentHandlerClasses::addAll);
        for (Class<RoseCommandArgumentHandler> argumentHandlerClass : argumentHandlerClasses) {
            // Ignore abstract/interface classes
            if (Modifier.isAbstract(argumentHandlerClass.getModifiers()) || Modifier.isInterface(argumentHandlerClass.getModifiers()))
                continue;
            RoseCommandArgumentHandler<?> argumentHandler = argumentHandlerClass.getConstructor(RosePlugin.class).newInstance(this.rosePlugin);
            this.argumentHandlers.put(argumentHandlerClass, argumentHandler);
        }
    } catch (Exception e) {
        this.rosePlugin.getLogger().severe("Fatal error initializing command argument handlers");
        e.printStackTrace();
    }
    this.commandWrappers.forEach(RoseCommandWrapper::register);
    Bukkit.getOnlinePlayers().forEach(Player::updateCommands);
}
Also used : ClassUtils(dev.rosewood.rosegarden.utils.ClassUtils) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) EnumArgumentHandler(dev.rosewood.rosegarden.command.argument.EnumArgumentHandler) RoseGardenUtils(dev.rosewood.rosegarden.utils.RoseGardenUtils) Constructor(java.lang.reflect.Constructor) RosePlugin(dev.rosewood.rosegarden.RosePlugin) ArrayList(java.util.ArrayList) List(java.util.List) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) RoseCommandWrapper(dev.rosewood.rosegarden.command.framework.RoseCommandWrapper) Optional(java.util.Optional) RoseCommandArgumentHandler(dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler) Bukkit(org.bukkit.Bukkit) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) RoseCommandWrapper(dev.rosewood.rosegarden.command.framework.RoseCommandWrapper) RoseCommandArgumentHandler(dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler) RosePlugin(dev.rosewood.rosegarden.RosePlugin)

Aggregations

RosePlugin (dev.rosewood.rosegarden.RosePlugin)1 EnumArgumentHandler (dev.rosewood.rosegarden.command.argument.EnumArgumentHandler)1 RoseCommandArgumentHandler (dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler)1 RoseCommandWrapper (dev.rosewood.rosegarden.command.framework.RoseCommandWrapper)1 ClassUtils (dev.rosewood.rosegarden.utils.ClassUtils)1 RoseGardenUtils (dev.rosewood.rosegarden.utils.RoseGardenUtils)1 Constructor (java.lang.reflect.Constructor)1 Modifier (java.lang.reflect.Modifier)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bukkit (org.bukkit.Bukkit)1 Player (org.bukkit.entity.Player)1