question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add 'addCheck' method to CommandManager

See original GitHub issue

In my opinion, the main problem with command frameworks is that you never have full control over them, which can result in either having to do some hacky methods to get it to do what you want, or just not using the framework but your own solution.

Issue #57 is a good example of this. If you want to add a default cooldown/per command cooldown, you’ll have to modify ACF for it to work. My idea is to add a method to the CommandManager, something along the lines of CommandManager#addCheck(Check), where Check is a functional interface which looks like this:

interface Check {
    boolean check(Sender sender, String name, String[] args, Method method);
}

Again, using Issue #57 as an example, you can do this:

myCommandManager.addCheck((sender, name, args, method) -> {
    boolean hasCooldown; //check if sender has cooldown
    if(hasCooldown) return false; //Command will not be executed
    
    int cooldown = method.getAnnotation(CommandCooldown.class).value(); //get cooldown (or default cooldown)
    //set cooldown for sender
   return true; //Command will be executed
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
aikarcommented, Jul 9, 2017

I’m trying to move away from Override style stuff. Precommand is close, but I am working on something for this, but the name will be Preconditions

1reaction
chickeneercommented, Jul 6, 2017

https://github.com/aikar/commands/blob/f900a739df7bfc0c1b6779be196541937209ddaf/core/src/main/java/co/aikar/commands/BaseCommand.java#L415

In the current version of ACF, one can override this method from BaseCommand to accomplish some of these ideas. The method is called here: https://github.com/aikar/commands/blob/8168122241d56fc6278ef4ab2197b0ef5ddd1dc0/core/src/main/java/co/aikar/commands/RegisteredCommand.java#L133

(Just giving the context for how this would fit into existing code).

Read more comments on GitHub >

github_iconTop Results From Across the Web

CommandManager - 2021 - SOLIDWORKS Help
Right-click the CommandManager tab and click Customize. In the Customize dialog box, on the Commands tab, select a category that contains tool buttons...
Read more >
CommandManager Class (System.Windows.Input)
Provides command related utility methods that register CommandBinding and InputBinding objects for class owners and commands, add and remove command event ...
Read more >
CHANGES — OpenStackClient CLI Base 2.7.0.dev6 ...
Add check for sdk_connection ... Remove commandmanager subclass ... Add test methods to compare formattable column values.
Read more >
SOLIDWORKS - How to Customize the Command Manager
Customization of the Command Manager and Toolbars is a great way to optimize your design workspace for part, assembly, and drawing.
Read more >
The CommandManager in SolidWorks - YouTube
The CommandManager is a context-sensitive toolbar that dynamically updates based on the toolbar you want to access.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found