logging a command in a txt file.

Discussion in 'Plugin Development' started by bkleinman1, Nov 21, 2013.

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

    bkleinman1

    Title explains it all really, i have done this so far but with no success:

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. Player player = (Player) sender;
    3. String command = cmd.getName() + " " + Arrays.toString(args);
    4.  
    5. try {
    6. FileWriter fw = new FileWriter(commandlog, true);
    7. out.write(player.getName() + " - " + "/" + command);
    8. out.newLine();
    9. out.close();
    10. System.out.println("Command has been loged!");
    11. } catch(IOException ioe) {
    12. System.out.println("IOException: " + ioe.getMessage());
    13. }
    14.  
    15. return true;
    16. }
     
  2. Offline

    Chinwe

    Are you trying to listen to all commands? Using onCommand will only "listen" for your registered commands - use PlayerCommandPreprocessEvent if you want to log every command (though you should store them in a List/Collection/array and save them in batches instead of creating a new writer every time :)
     
  3. Offline

    BajanAmerican

  4. Offline

    bkleinman1

    Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page