Commands able to be executed by console

Discussion in 'Plugin Development' started by Nathan674329, Jun 24, 2017.

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

    Nathan674329

    https://pastebin.com/BmBX4nck

    I want console to be able to use /qlutch staffnotify so when someone is hacking, the console can use that command which sends a custom message to staff on the server, i got it all working but i dont know how to stop the error when console executes the command, only players can at the moment.
     
  2. Offline

    Zombie_Striker

    @Nathan674329
    Do not blindly cast send to a player. Like this example, the console can also send the message. Make sure the sender is a player before you cast.

    Also, none of those commands require the sender to be a player. Replace all references to "p" with "sender" and it will work fine.
     
    RcExtract likes this.
  3. Offline

    OverDodo

    you could ask if the sender has instance of a Player. If thats not true, use sender.
    if its true use p.
     
  4. Offline

    Horsey

    No point, Player extends CommandSender, you can use any CommandSender methods directly on a Player without casting.
     
  5. Offline

    OverDodo

    but if you have a function, only a Player can execute like teleporting or stuff, it will give you an error. :D
     
  6. Offline

    iCodeTits

    Code:java
    1. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "command");
     
Thread Status:
Not open for further replies.

Share This Page