Bukkit Command Logging

Discussion in 'Plugin Development' started by Panjab, Nov 18, 2012.

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

    Panjab

    Hey guys out there!

    Is there any way to change/cancel the message when a player types in a command?
    I mean this message:

    Code:
    [INFO] <player> issumed a command: /<command>
    :)
     
  2. Offline

    Panjab

    Bump? :)
     
  3. Offline

    Comphenix

    It's a good bet to search for the message in the source code if you want to change it. Looks like it's in the NetServerHandler class:
    Code:java
    1.  
    2. private void handleCommand(String s) {
    3. // CraftBukkit start
    4. // ...
    5. try {
    6. logger.info(event.getPlayer().getName() + " issued server command: " + event.getMessage()); // CraftBukkit
    7. if (this.server.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) {
    8. return;
    9. }
    10. } catch (org.bukkit.command.CommandException ex) {
    11. player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
    12. Logger.getLogger(NetServerHandler.class.getName()).log(Level.SEVERE, null, ex);
    13. return;
    14. }
    15. // CraftBukkit end
    16. // ...
    17. }
    18.  

    So, you have to somehow stop the message from being sent to the logger field (in the same class):
    Code:java
    1.  
    2. public static Logger logger = Logger.getLogger("Minecraft");
    3.  

    The easiest way then is to simply add a logging filter:
    Code:java
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. @Override
    3. public void onEnable() {
    4. NetServerHandler.logger.setFilter(new Filter() {
    5. @Override
    6. public boolean isLoggable(LogRecord line) {
    7. if (line.getMessage().contains("issued server command:"))
    8. return false;
    9. return true;
    10. }
    11. });
    12. }
    13.  
    14. @Override
    15. public void onDisable() {
    16. // Reset
    17. NetServerHandler.logger.setFilter(null);
    18. }
    19. }

    You could also limit the filter to only kick in for certain commands.
     
    tommycake50, fireblast709 and Panjab like this.
  4. Offline

    Panjab

    You are amazing! ;)
     
    Comphenix likes this.
  5. Offline

    mdcollins05

    Just thought I'd point out a small change. Unsure if this is due to a more recent version of Bukkit or not, but I had to use something similar to the following:

    Code:java
    1.  
    2. static final Logger log = Logger.getLogger("Minecraft"); //set up our logger
    3.  
    4. @Override
    5. public void onEnable() {
    6. log.setFilter(new Filter() {
    7. public boolean isLoggable(LogRecord line) {
    8. if (line.getMessage().contains("issued server command:")) {
    9. return false;
    10. }
    11. return true;
    12. }
    13. });
    14. }
    15.  
    16. @Override
    17. public void onDisable() {
    18. log.setFilter(null);
    19. }


    Hope this helps anyone out!
     
  6. Offline

    fireblast709

    Just saying, but the change you made is just a visual change :3 (though probably less error prone :p)
     
Thread Status:
Not open for further replies.

Share This Page