Skip to content
This repository was archived by the owner on Feb 12, 2019. It is now read-only.
This repository was archived by the owner on Feb 12, 2019. It is now read-only.

Restructure commands #4

Description

@jomo

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()

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions