Solved Console Ban Messages

Discussion in 'Bukkit Help' started by Skrubzy, Nov 18, 2016.

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

    Skrubzy

    When a banned player joins the server, the console gets spammed with messages -
    Which are needed to display (To the banned player) Why they are banned and for how long

    I'm wondering if there's a way to get rid of these messages in console, but still notify the banned player why he was banned, who banned him, etc
    I still want a message in console saying that a banned player tried to join (And say their name) But I don't want it to spam my whole console; just have it on one line. 04a697045d592f9c08ceba5b1aa84127.png ae93ee3e33eaa479b1a58582d6604722.png
     
  2. Offline

    I Al Istannen

    @Skrubzy
    That is defined in the PlayerConnection class (and in the server LoginListener). You can add a custom filter to it using some NMS, to prevent this message from popping up and I have successsfully written some test code that proves it is possible.

    A side effect is that ALL "<player> lost connection: <anything>" will be suppressed, so also things that may be relevant for troubleshooting errors that occur to a player.
    I could make the regex definable, which would put the task of writing a regex only filtering ban messages on you.

    I will need to know exactly where this ban plugins sends the message from, but my current code may be enough we would need to test that.
    There are just a few points where the message can be send and each filter I add makes the plugin less stable (as I need to use some quite dirty methods to get it to work, which may break after an update).
     
  3. @Skrubzy @I Al Istannen You can also just wait for PlayerJoinEvent and kick the player IIRC it doesn't display the reason and will not "spam" the console.
     
  4. Offline

    Skrubzy

    How would I do about doing that?
    I'm using MaxBans
     
  5. Offline

    I Al Istannen

    @bwfcwalshy
    I thought that too. Then I tried it and reality hit me :p
    Inside the PlayerConnection class, which is called when you use "kickPlayer"
    Code:Java
    1. public void disconnect(String s) {
    2. if(!this.processedDisconnect) {
    3. String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game.";
    4. PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage);
    5. if(this.server.getServer().isRunning()) {
    6. this.server.getPluginManager().callEvent(event);
    7. }
    8.  
    9. if(!event.isCancelled()) {
    10. s = event.getReason();
    11. final ChatComponentText chatcomponenttext = new ChatComponentText(s);
    12. this.networkManager.sendPacket(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener() {
    13. public void operationComplete(Future future) throws Exception {
    14. PlayerConnection.this.networkManager.close(chatcomponenttext);
    15. }
    16. }, new GenericFutureListener[0]);
    17. // This bugger right here logs it
    18. this.a((IChatBaseComponent)chatcomponenttext);
    19. this.networkManager.stopReading();
    20. this.minecraftServer.postToMainThread(new Runnable() {
    21. public void run() {
    22. PlayerConnection.this.networkManager.handleDisconnection();
    23. }
    24. });
    25. }
    26. }
    27. }


    If you try to be clever and set the LoginAction to DENY, this happens (in LoginListener):
    Code:Java
    1. public void disconnect(String s) {
    2. try {
    3. // guess what this line does -.-
    4. c.info("Disconnecting {}: {}", new Object[]{this.d(), s});
    5. ChatComponentText exception = new ChatComponentText(s);
    6. this.networkManager.sendPacket(new PacketLoginOutDisconnect(exception));
    7. this.networkManager.close(exception);
    8. } catch (Exception var3) {
    9. c.error("Error whilst disconnecting player", var3);
    10. }
    11.  
    12. }


    So there seems to be now way around logging the message.


    @Skrubzy
    That would help if I wasn't too lazy to download and wade through it' whole code. Which would take a considerable amount of time.

    But based on the logged message, it seems like my current code may work.

    I will link a small demo of it here, which you can try. You may need to adjust the regex.
    Just unzip the zip and place the jar inside in your plugins folder.
    After every change to the regex, you WILL NEED TO RESTART YOUR SERVER.
     

    Attached Files:

  6. Offline

    Skrubzy

    It didn't work by default (Without changing the regex)
    What am I suppose to change in the regex though?
     
  7. Offline

    I Al Istannen

    @Skrubzy
    Any erorrs in the console?
    Does the "enabled" message is shown?
    What is your console log?

    A regex matching the whole ban text of any ban.

    Could you post the text in the console for a disconnect ("Disconnecting ...") in code tags please?
     
  8. Offline

    Skrubzy

    There aren't any errors, just the long message I get in the console when a banned player joins.
    Code:
    Disconnecting com.mojang.authlib.GameProfile@111d4dd[id=58e02b40-1c61-4207-ab39-74f3bb5a691c,name=Skrubzy,properties={textures=[com.mojang.authlib.properties.Property@d4b557]},legacy=false] (/127.0.0.1:23523): §fYou're banned!
    Reason: §a'Xray'§f
    By §askrubzy§f.
    www.Skylask.com/appeals
    Code:
    com.mojang.authlib.GameProfile@111d4dd[id=58e02b40-1c61-4207-ab39-74f3bb5a691c,name=Skrubzy,properties={textures=[com.mojang.authlib.properties.Property@d4b557]},legacy=false] (/127.0.0.1:23523) lost connection: §fYou're banned!
    Reason: §a'Xray'§f
    By §askrubzy§f.
    www.Skylask.com/appeals
    This is only for 1 ban message and 1 player (Me) because this includes my username and UUID.
    Unless you can make it so the UUID, username, and ban message all change depending on the player - I am the only one that won't set off a message in console.

    I'm still in the process of setting up my ban messages
     
  9. Offline

    I Al Istannen

    @Skrubzy
    Change the regex to this:
    Code:
    (Disconnecting com.mojang.authlib.GameProfile[\s\S]+You're banned[\s\S]+)|(com.mojang.authlib.GameProfile[\s\S]+You're banned[\s\S]+)
    You can see if your regex matches it by using a site like regexr.com.

    This basically says:
    1. Start with "Disconnecting com.mojang.authlib.GameProfile"
    2. Have any characters you wish
    3. Then have "You're banned"
    4. Have any other characters you wish
    The "|" is an or. The part behind does this:
    1. Start with "com.mojang.authlib.GameProfile"
    2. Have any characters you wish
    3. Then have "You're banned"
    4. Have any other characters you wish

    This will match the message you posted. See if this updated regex works.
     
  10. Offline

    Skrubzy

    Ok, I'll test it in a bit. I just noticed it's you again lol You always do everything for me <3

    EDIT: I got this error when I started my server
    Code:
    [18:33:51] [Server thread/ERROR]: Cannot load plugins\NoBanMessageLog\config.yml
    org.bukkit.configuration.InvalidConfigurationException: while scanning a double-quoted scalar
    in 'string', line 2, column 8:
        regex: "(Disconnecting com.mojang.authl ...
               ^
    found unknown escape character s(115)
    in 'string', line 2, column 56:
         ... com.mojang.authlib.GameProfile[\s\S]+You're banned[\s\S]+)|(com. ...
                                             ^
    
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:56) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:184) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:130) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:179) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:188) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:163) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at me.ialistannen.nobanmessagelog.NoBanMessageLog.getFilter(NoBanMessageLog.kt:54) [NoBanMessageLog.jar:1.0.5-2]
        at me.ialistannen.nobanmessagelog.NoBanMessageLog.applyFilters(NoBanMessageLog.kt:47) [NoBanMessageLog.jar:1.0.5-2]
        at me.ialistannen.nobanmessagelog.NoBanMessageLog.onEnable(NoBanMessageLog.kt:27) [NoBanMessageLog.jar:1.0.5-2]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.loadPlugin(CraftServer.java:362) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.enablePlugins(CraftServer.java:322) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at net.minecraft.server.v1_9_R2.MinecraftServer.t(MinecraftServer.java:416) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at net.minecraft.server.v1_9_R2.MinecraftServer.l(MinecraftServer.java:381) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at net.minecraft.server.v1_9_R2.MinecraftServer.a(MinecraftServer.java:336) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at net.minecraft.server.v1_9_R2.DedicatedServer.init(DedicatedServer.java:268) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:532) [spigot.jar:git-Spigot-8a048fe-5ff377a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a double-quoted scalar
    in 'string', line 2, column 8:
        regex: "(Disconnecting com.mojang.authl ...
               ^
    found unknown escape character s(115)
    in 'string', line 2, column 56:
         ... com.mojang.authlib.GameProfile[\s\S]+You're banned[\s\S]+)|(com. ...
                                             ^
    
        at org.yaml.snakeyaml.scanner.ScannerImpl.scanFlowScalarNonSpaces(ScannerImpl.java:1906) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.scanner.ScannerImpl.scanFlowScalar(ScannerImpl.java:1846) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchFlowScalar(ScannerImpl.java:1029) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDouble(ScannerImpl.java:1011) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:396) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:369) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:54) ~[spigot.jar:git-Spigot-8a048fe-5ff377a]
        ... 19 more
    [18:33:51] [Server thread/INFO]: [MaxBans] Enabling MaxBans v2.7
    And the message still shows up in console when a banned player tries to join
     
    Last edited: Nov 19, 2016
  11. Offline

    I Al Istannen

    @Skrubzy
    Whoops. I forgot that YAML uses the backslash too...
    Replace "[\s\S]" with "[\\s\\S]" and try again please.
     
  12. Offline

    I Al Istannen

    @bwfcwalshy
    Not that I am aware of actually.

    Works quite fine for me. I think that line was only there, as the error occurred inside the Double quotes.
     
  13. @I Al Istannen Ah last time I tried double quotes they didn't allow it yet single quotes worked. Probably a bug in that version or something.
     
  14. Offline

    Skrubzy

    I'm trying that now...
    EDIT: I still got the message in console ._.
    EDIT 2: I forgot to say, but the other error went away - So that's good.
    Should I add another line of code to test for? (I forgot what it's called) This is the message:
    Code:
    [11:43:13] [Server thread/WARN]: handleDisconnection() called twice
    [11:43:22] [Thread-10/WARN]: java.sql.SQLException: [SQLITE_CONSTRAINT]  Abort due to constraint violation (mutes.reason may not be NULL)
    [11:43:22] [Thread-10/WARN]:     at org.sqlite.DB.newSQLException(DB.java:383)
    [11:43:22] [Thread-10/WARN]:     at org.sqlite.DB.newSQLException(DB.java:387)
    [11:43:22] [Thread-10/WARN]:     at org.sqlite.DB.execute(DB.java:342)
    [11:43:22] [Thread-10/WARN]:     at org.sqlite.PrepStmt.execute(PrepStmt.java:65)
    [11:43:22] [Thread-10/WARN]:     at org.maxgamer.maxbans.database.SQLiteCore.flush(SQLiteCore.java:76)
    [11:43:22] [Thread-10/WARN]:     at org.maxgamer.maxbans.database.SQLiteCore$1.run(SQLiteCore.java:96)
    [11:43:23] [User Authenticator #3/INFO]: UUID of player Skrubzy is 58e02b40-1c61-4207-ab39-74f3bb5a691c
    [11:43:23] [Server thread/INFO]: Disconnecting com.mojang.authlib.GameProfile@1bee69f[id=58e02b40-1c61-4207-ab39-74f3bb5a691c,name=Skrubzy,properties={textures=[com.mojang.authlib.properties.Property@f1ddb2]},legacy=false] (/***MY IP***): §c§lSkylask Network
    §r §fYou Have Been Temporarily Banned!
    §fReason: §cReached Max Warnings§f
    §r
    §r §fBanned by: §cskrubzy
    §fExpires in: 4 days 23 hours 59 minutes 51 seconds
    §fAppeal at www.Skylask.com/appeals
    [11:43:23] [Server thread/INFO]: com.mojang.authlib.GameProfile@1bee69f[id=58e02b40-1c61-4207-ab39-74f3bb5a691c,name=Skrubzy,properties={textures=[com.mojang.authlib.properties.Property@f1ddb2]},legacy=false] (/***MY IP***) lost connection: §c§lSkylask Network
    §r §fYou Have Been Temporarily Banned!
    §fReason: §cReached Max Warnings§f
    §r
    §r §fBanned by: §cskrubzy
    §fExpires in: 4 days 23 hours 59 minutes 51 seconds
    §fAppeal at www.Skylask.com/appeals
     
    Last edited: Nov 20, 2016
  15. Offline

    I Al Istannen

    @Skrubzy
    Look at your message. There never is the word "You're banned" in there. Adjust the regex accordingly (maybe replace it to "Banned").
     
  16. Offline

    Skrubzy

    Ok it works perfectly now, thank you all for your help :)
     
  17. Offline

    I Al Istannen

    @Skrubzy
    Remember you need to change the regex when you change the ban message!

    It is more of a proof-of-concept than a plugin, but as long as it works...

    Thanks and have a nice day :)
     
Thread Status:
Not open for further replies.

Share This Page