RedstonerServer / redstoner-utils

Redstoner's plugins, written in Python.
MIT License
7 stars 3 forks source link

Restructure commands #4

Open jomo opened 9 years ago

jomo commented 9 years ago

It would be great to have a single class that listens to the [onCommand](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/command/CommandExecutor.html#onCommand%28org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[]%29) event and then calls our internal command methods (instead of creating tons of listeners for each command).

This would also allow us to throw our own error classes which we could catch, e.g:

This would save us stuff like

def whatever_command(sender, args):
  if not is_player(sender):
    msg(sender, "&cOnly players can do this")
    return True
  whatever()

def foobar_command(sender, args):
  if not is_player(sender):
    msg(sender, "&cOnly players can do this")
    return True
  foobar()

instead we would do something like

def validate_player(sender):
  if not isinstance(sender, Player):
    raise MustBePlayerError()
def whatever_command(sender, args):
  validate_player(sender)
  whatever()

def foobar_command(sender, args):
  validate_player(sender)
  foobar()
Dico200 commented 9 years ago

New Event URL: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerCommandPreprocessEvent.html

There is no such CommandExecutor event btw?

Dico200 commented 9 years ago

BTW: Console won't be able to use commands if we use the event up there ^

jomo commented 9 years ago

there is, link fixed.

Dico200 commented 9 years ago

Well now its not an event, its a CommandHandler but yeah that'll do :P I guess a command is still an event.

Dico200 commented 9 years ago

Wtf xD