#Adds Commands without using the plugin.yml - Lcraft API

1 messages · Page 1 of 1 (latest)

ember axle
leaden pagoda
#

Its very possible

#

You need to inject into the Bukkits commandMap

#

one second i have a example of how to do this in my github project

ember axle
#

I have

#

A ModuleCommand Class

#

I also have a Manager for that

leaden pagoda
#

@ember axle Can you tell me exactly what files are doing the Command Handling so i dont have to code dive through the whole project

ember axle
#

Sp the ModuleCommand is for the Commands

#

Ande the Module CommandManager ist the Manager for every Module

#

The ModuleLoader is a Class, that gets Infos for it

#

Like onEnable

#

The ModuleManager is the Loader the Modules

#

It loads with a ZipFiles

#

The Listeners is only something to handle Listeners. After the commands I make this

#

The Utils is like the ItemBuilder or the ModuleConfig

#

But I want to add to the constructor of the ModuleCommand Class it

#

I extendet it with BukkitCommand

#

But how can I make something like Module?

ember axle
leaden pagoda
#

this.description is the commands description in /help, this.usageMessage is sent when the command syntax is incorrect and super(command) is the name of the command

ember axle
#

Ah, I found a way to make it

#
protected ModuleCommand(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases) {
        super(name, description, usageMessage, aliases);
    }

    public ModuleCommand(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases, Module m) {
        super(name, description, usageMessage, aliases);
        setModule(m);
    }
leaden pagoda
#

https://github.com/Burchard36/SpigotDragonZ/blob/master/src/main/java/com/myplugin/command/DragonBallCommand.java

This class is a really good example

And when you create a custom command with the Command class (EG When you extend it)

You Override those 2 abstract methods in the command class

GitHub

Dragon Ball Z Plugin for Minecraft servers! Contribute to Burchard36/SpigotDragonZ development by creating an account on GitHub.

leaden pagoda
#

so when you create commands extending your Command class it will basically look like this

#

And then you would inject QuestCommand int Bukkits CommandMap

ember axle
#

How can I register it now

leaden pagoda
ember axle
#

ah whanks

#

I test it right now

leaden pagoda
#

ofc ofc let me know if theres any issues with it

ember axle
#

What does it means with "usage"

leaden pagoda
# ember axle What does it means with "usage"

So basically usage is like the syntax message so if something is sent wrong

EX:

You have 2 arguments for your command (/help arg1 arg2)

And someone sends /help something

You just send this.usageMessage back to them

ember axle
#

Oh, didnt know that, that works. So is must there like "/test something"

#

And how can I return it?

leaden pagoda
#

this.usageMessage is accessible from both classes

#

since your extending the class extending BukkitCommand

#

like so

ember axle
#

So, when I dont need usage can I make ""

leaden pagoda
#

yep pretty much

ember axle
#

Ok

#

Thanks

leaden pagoda
#

whenever i do it i pretty much just make its value /<commandName> for simplicity but a empty string also works

ember axle
#

There is now an error, that is protected

#

TestCommand(de.lcraft.api.plugin.modules.Module)' has protected access in 'lcraft.api.testplugin.commands.TestCommand'

leaden pagoda
ember axle
#
package lcraft.api.testplugin.commands;

import de.lcraft.api.plugin.modules.Module;
import de.lcraft.api.plugin.modules.commands.ModuleCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

public class TestCommand extends ModuleCommand {

    protected TestCommand(Module m) {
        super("test", "Its tests something", "", m);
    }

    @Override
    public boolean onCommand(CommandSender s, String[] args) {
        Bukkit.broadcastMessage("Testing...");
        return false;
    }

}

package lcraft.api.testplugin;

import de.lcraft.api.plugin.modules.Module;
import lcraft.api.testplugin.commands.TestCommand;

public class Testplugin extends Module {

    public Testplugin() {
        super("Test Plugin", "lcraft.plugins.test");
    }

    @Override
    public void onLoad() {
        getModuleCommandManager().addCommand("test", new TestCommand(this));
        //getModuleCommandManager().addInvisibleCommand("invtest", new InvisibleTestCommand(this));
    }

    @Override
    public void onEnable() {

    }

    @Override
    public void onDisable() { }

}
leaden pagoda
#

needs to be public

ember axle
#

Thanks

#

Works

#

Thanks so much

ember axle
#

How can I use a CommandMap in BungeeCord?

ember axle
leaden pagoda
#

Ive never done this with BungeCord

ember axle
#

Why?

#

Its unmodifiable???

#

'getFile()' in 'org.bukkit.plugin.java.JavaPlugin' clashes with 'getFile()' in 'net.md_5.bungee.api.plugin.Plugin'; attempting to assign weaker access privileges ('protected'); was 'public'

#

How can I get in the plugin.yml if its bungeecord or spigot?

leaden pagoda
#

You typically have 2 classes when doing bungee and spigot in one plugin

ember axle
#

Yes I have now

#

But how can I see if its BungeeCord or Spigot?

leaden pagoda
ember axle
#

oh

#

nice

leaden pagoda
#

and when its on spigot it looks at spigot.yml and loads the spigot class

ember axle
#

I ever had a plugin.yml

leaden pagoda
#

i meant plugin.yml my bad not spigot.yml

chilly jasper
#

I've done the same with my command framework

#

and if you're loading it async

#

and then it registers sub commands and main commands

#

its def 100% possible as i've done it and it works like a god damn charm

#

^^ instead of that you could use Reflection as a library

leaden pagoda
chilly jasper
#

similar thing

#

just the command map is different

ember axle
#

BungeeCord Map dont work

chilly jasper
#

yeah no

#

it wont be like that

ember axle
#
final Field commandMapField;
        try {
            commandMapField = ProxyServer.getInstance().getClass().getDeclaredField("commandMap");
            commandMapField.setAccessible(true);
            ProxyServer.getInstance().getPluginManager().registerCommand(plugin, executor);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
chilly jasper
#

yeah that wont work

#

its a proxy not a bukkit

#

so you will need to look it up

ember axle
#

Do you know how to do that?

chilly jasper
#

nope

#

never worked with bungeecord

stoic bear
#

the bungee api is very different

#

youll just need to extends Command and then it'll yell at you until you get it right