Opening a workbench

Discussion in 'Plugin Development' started by UnpeeledBanana1, Aug 15, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    UnpeeledBanana1

    I've been developing my own plugin for a while now, and now I've come to making commands just for efficiency. However, I've come across a dilemma when trying to open a Workbench with a command, each time, no matter what method I use I always get told that there is an error...

    Here is the code that I am using:

    public boolean onCommand(CommandSender command, Command sender, String label,
    String[] args) {

    Player player = (Player) sender;

    player.openWorkbench(null, true);
    return false;


    In case if you are wondering, the command is simply /workbench.

    Does anyone know how to fix this??!
     
  2. Offline

    Tecno_Wizard

    @UnpeeledBanana1, few things.

    Check if the sender is a player before casting.
    Double check the documentation for openWorkbench and post the stack trace.
     
  3. Offline

    UnpeeledBanana1

  4. Offline

    caderape

  5. Offline

    UnpeeledBanana1

    @caderape it doesn't matter, player.openWorkbench(null, true); works just as well as it should do.
     
  6. Offline

    griffjack

    @caderape

    If the location is null, by default it uses the player location.
     
  7. Remember to put the Command in your plugin.yml.
    And where did you check if the command is /workbench?
    And you have a strange naming.
    You cannot cast sender to Player because sender is a string containg the Command, and Command is actually your sender.
    Code:
    public boolean onCommand(CommandSender command, Command sender, String label, String[] args)
    Then in the code you say
    Code:
    Player player = (Player)sender; 
    But sender is the Command! Your CommandSender is called command!
    I'd recommend to rename the Variables, to a more logical naming:
    Code:
    public boolean onCommand(CommandSendersender, Command command, String label, String[] args) 
    Now sender is the CommandSender and command is a String containing the command. Your code swapped that which causes its Errors.
    So now
    Code:
    Player player = (Player) sender; 
    works, but remember to check if the sender is a player!
    Then you can check if command is /workbench and then display the workbench.
     
Thread Status:
Not open for further replies.

Share This Page