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
defwhatever_command(sender,args):ifnotis_player(sender):msg(sender,"&cOnly players can do this")returnTruewhatever()deffoobar_command(sender,args):ifnotis_player(sender):msg(sender,"&cOnly players can do this")returnTruefoobar()
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()
```
New Event URL: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerCommandPreprocessEvent.html
There is no such CommandExecutor event btw?
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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:
NoPermissionErrorInvalidArgsErrorNotPlayerErrorThis would save us stuff like
instead we would do something like
New Event URL: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerCommandPreprocessEvent.html
There is no such CommandExecutor event btw?
BTW: Console won't be able to use commands if we use the event up there ^
there is, link fixed.
Well now its not an event, its a CommandHandler but yeah that'll do :P
I guess a command is still an event.
Wtf xD