FountainMC / FountainAPI

A 'simple but beautiful' Minecraft Server Plugin API
https://fountainmc.org/
MIT License
5 stars 5 forks source link

Dynamic commands and improved registration #20

Closed PizzaCrust closed 8 years ago

PizzaCrust commented 8 years ago

This commit adds registration handlers for implementations to handle command registration at any time, than just startup. This commit also adds dynamic commands called ICommand. It also fixes calling the same command name multiple times.

phase commented 8 years ago

What are the use of dynamic commands? I think having immutable ones would be safer.

PizzaCrust commented 8 years ago

Dynamic commands allows for plugins like Skript, to register commands dynamically after they parse the scripting language.

minecrafter commented 8 years ago

I suggest that interfaces not be used as they are not safe. Please use an immutable object instead.

PizzaCrust commented 8 years ago

Hmm. Probably like this:

Fountain.getServer().getCommandManager().newCommand("test-command").invokeHandler(() -> println("meow").register()
phase commented 8 years ago

Or an object. Objects are nice. We're using Java for a reason.

PizzaCrust commented 8 years ago

How would you propose to use an object for this?

phase commented 8 years ago

Not called Command but something like

public abstract class Command {

    public abstract String getName();

    public abstract void invoke(String[] args, CommandSender sender);

}

Which plugins can extend like

public class TestCommand extends Command {

    public String getName() { return "test"; }

    public void invoke(String args[], CommandSender sender) { System.out.println(Arrays.toString(args)); }

}
PizzaCrust commented 8 years ago

What's wrong with using builders?

Fountain.getServer().getCommandManager()
   .newCommand("test")
   .invokeHandler((args, sender) -> {})
   .generate();
PizzaCrust commented 8 years ago

Ok, removing builders.

PizzaCrust commented 8 years ago

Replaced with an abstract class.

PizzaCrust commented 8 years ago

Added the lines.

phase commented 8 years ago

Merged in https://github.com/FountainMC/FountainAPI/commit/73b702e2e72ceb808a32c8351d3032ffa93a0247