Restructure commands #4

Open
opened 2014-12-26 17:41:18 +00:00 by jomo · 5 comments
jomo commented 2014-12-26 17:41:18 +00:00 (Migrated from github.com)

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:

  • NoPermissionError
  • InvalidArgsError
  • NotPlayerError
  • ...

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()
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: - `NoPermissionError` - `InvalidArgsError` - `NotPlayerError` - ... This would save us stuff like ``` Python 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 ``` Python def validate_player(sender): if not isinstance(sender, Player): raise MustBePlayerError() ``` ``` Python def whatever_command(sender, args): validate_player(sender) whatever() def foobar_command(sender, args): validate_player(sender) foobar() ```
Dico200 commented 2015-03-15 01:51:16 +00:00 (Migrated from github.com)
New Event URL: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerCommandPreprocessEvent.html There is no such CommandExecutor event btw?
Dico200 commented 2015-03-15 01:51:39 +00:00 (Migrated from github.com)

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

BTW: Console won't be able to use commands if we use the event up there ^
jomo commented 2015-03-15 02:03:01 +00:00 (Migrated from github.com)

there is, link fixed.

there is, link fixed.
Dico200 commented 2015-03-15 02:21:10 +00:00 (Migrated from github.com)

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

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 2015-05-14 02:12:01 +00:00 (Migrated from github.com)

Wtf xD

Wtf xD
This repo is archived. You cannot comment on issues.
No Milestone
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Redstoner/redstoner-utils#4
No description provided.