Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugreport]: Commands not executed when executor type PLAYER_AND_CONSOLE is set #27

Closed
DSeeLP opened this issue Oct 4, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@DSeeLP
Copy link
Contributor

DSeeLP commented Oct 4, 2020

Describe the bug

A clear and concise description of what the bug is.

What do we have to do to reproduce this bug?

Steps to reproduce the behavior:

  1. Create a new command with the executor PLAYER_AND_CONSOLE
  2. allow custom parameters
  3. put this in the onCommand(KelpPlayer,String[]) method:
System.out.println(Arrays.toString(args));

What would you expect to happen?

When the executorType is PLAYER_AND_CONSOLE and you execute the command with parameters, you see nothing in the console. But when the executorType is PLAYER_ONLY then everything works and you see the args in the console.

Environment information

  • Operating system: Windows 10 20H1
  • Java-Version: 1.8
  • Kelp-Core-Version: v.0.0.3
  • Version-Implementation: 1.8
@DSeeLP DSeeLP added the bug Something isn't working label Oct 4, 2020
@PXAV PXAV changed the title [bugreport]: Your Bug report title [bugreport]: Commands not executed when executor type PLAYER_AND_CONSOLE is set Oct 4, 2020
@PXAV
Copy link
Member

PXAV commented Oct 4, 2020

Thank you for the bug report, I'll see how I can fix it!

@PXAV
Copy link
Member

PXAV commented Oct 21, 2020

I have now fixed the bug. Actually, it was not a real bug, as PLAYER_AND_CONSOLE only called the onCommand(ConsoleSender, args) method and not the player method, because the command should be the same for players and consoles. But I have now changed it so that you can have both onCommand methods and depending on the executor, the corresponding method will be called.

If you want to have the same command handler method for both player and console, then you could do something like that:

@CreateCommand(name = "helloworld", executorType = ExecutorType.PLAYER_AND_CONSOLE)
public class test extends KelpCommand {

  private KelpConsoleSenderFactory senderFactory;

  @Inject
  public test(KelpConsoleSenderFactory senderFactory) {
    this.senderFactory = senderFactory;
  }

  @Override
  public void onCommandRegister() {
    allowCustomParameters(true);
  }

  @Override
  public void onCommand(KelpConsoleSender consoleSender, String[] args) {
    System.out.println("command executed by either player or console " + Arrays.toString(args));
  }

  @Override
  public void onCommand(KelpPlayer player, String[] args) {
    CommandSender sender = player.getBukkitPlayer();
    this.onCommand(senderFactory.newKelpConsoleSender(sender), args);
  }

}

The fix will be released with v0.0.4

@PXAV PXAV closed this as completed Oct 21, 2020
PXAV added a commit that referenced this issue Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants