Solved Modify all console output

Discussion in 'Plugin Development' started by maxim_game, May 10, 2015.

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

    maxim_game

    I am attempting to modify console output. I have redirected the stout through my own PrintStream class but this works for only some messages coming through the console.

    My class is very simple and extends PrintStream then overrides the print method with a simple check to determine if the text I want to filter is there and seems to work. But some instances it will not do this, like when a player connects with a username that should be filtered by the plugin.

    Why can I not filter some text if it is going through my own PrintStream class??

    my onEnable contains:
    System.setOut(new CustomPrintStream(System.out));


    And here is my class that should filter out what I need
    Code:
    public class CustomPrintStream extends PrintStream
    {
        String filterText = "game";
        String filterTo = "derp";
    
        public CustomPrintStream(OutputStream out)
        {
            super(out);
        }
    
        @Override
        public void print(String s)
        {
            if (s.contains(filterText))
            {
                s = s.replace(filterText, filterTo);
            }
            super.print(s);
        }
    }
    If someone's username contains a word I want to filter (ex. "game") the server will still output something along the lines of "[23:18:11] [Server thread/INFO]: Maxim_game[/127.0.0.1:59861] logged in with entity id 88 at ([world] -250.76477068056872, 64.0, 254.35331332025)" I would like to be able to filter this message in the console as well. The one running this server is younger and I would like to keep him away from text that could be hurtful to his mind :) Those with the text that I want filtered are kicked immediately and the in-game messages are not shown but this still comes through the console.

    Hopefully any way to fix this also involves the logs but if not it should be simple enough to rewrite parts of the log file periodically via the plugin or an outside process if need be.
     
  2. Offline

    RawCode

    log4j filter
     
  3. Offline

    maxim_game

    Thank you very much, works exactly as needed.
     
Thread Status:
Not open for further replies.

Share This Page