#Adds Commands without using the plugin.yml - Lcraft API
1 messages · Page 1 of 1 (latest)
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
I havent looked into your API yet but basically
You need a class like this that extends BukkitCommand: https://github.com/Burchard36/SpigotDragonZ/blob/master/src/main/java/com/myplugin/command/DragonBallCommand.java
And when you register the command you need to inject it into CommandMap like so: https://github.com/Burchard36/SpigotDragonZ/blob/master/src/main/java/com/myplugin/SpigotDragonZ.java#L110
Let me look into your api just gimme a minute
@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
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?
How can I add something to the constructor?
You should be able to do it just like this if your extending your Command class with BukkitCommand:
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
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);
}
Is there only one constructor?
Yeah its a fairly simple class to make TBF you can even leave the constructor empty if you please
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
Ah thats brilliant
so when you create commands extending your Command class it will basically look like this
And then you would inject QuestCommand int Bukkits CommandMap
How can I register it now
Take a look into this method right here, i dont normally like to spoonfeed code but this is something thats kind of advanced since it involves Reflection so feel free to just copy/paste this method
ofc ofc let me know if theres any issues with it
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
Oh, didnt know that, that works. So is must there like "/test something"
And how can I return it?
You pretty much just send it to whoever the command sender is
this.usageMessage is accessible from both classes
since your extending the class extending BukkitCommand
like so
So, when I dont need usage can I make ""
yep pretty much
whenever i do it i pretty much just make its value /<commandName> for simplicity but a empty string also works
There is now an error, that is protected
TestCommand(de.lcraft.api.plugin.modules.Module)' has protected access in 'lcraft.api.testplugin.commands.TestCommand'
Hmm cand you send pastebins to all the code, or just send it straight in here since its a thread
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() { }
}
On your TestCommand you have your constructor set to protected
needs to be public
How can I use a CommandMap in BungeeCord?
And what is the CommandMap in BungeeCord?
I actually wouldnt know for that part actually
Ive never done this with BungeCord
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?
You typically have 2 classes when doing bungee and spigot in one plugin
You typically have a bungee.yml and spigot.yml
and when its on spigot it looks at spigot.yml and loads the spigot class
I ever had a plugin.yml
i meant plugin.yml my bad not spigot.yml
I've done the same with my command framework
https://img.olziedev.com/x166166MKO116666_JI.png reflection is pretty easy
and if you're loading it async
you will need to use syncCommands for 1.13+ https://img.olziedev.com/pglqndx87p878787n.png
https://img.olziedev.com/900900GaZp900KsH900k.png this is my command framework register
and then it registers sub commands and main commands
https://img.olziedev.com/lp525252528888ZELFm.png like this, this is a main command
https://img.olziedev.com/Fc881812212di812Aij.png and this is a parent of the main command
its def 100% possible as i've done it and it works like a god damn charm
https://img.olziedev.com/pFmSDjy777606076060zy.png this is my messy, i know i'm sorry. method for getting all the commands in the file that called .registerCommands()
^^ instead of that you could use Reflection as a library
https://img.olziedev.com/F231231ngqHGW231231y.png this is how u get the file of who called that methods. "incoming" is a .class of the main class
He needed it for the BungeeCord API though i think
BungeeCord Map dont work
final Field commandMapField;
try {
commandMapField = ProxyServer.getInstance().getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
ProxyServer.getInstance().getPluginManager().registerCommand(plugin, executor);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
Do you know how to do that?