Solved PlayerLoginEvent disallow console output

Discussion in 'Plugin Development' started by Robin Bi, Jan 1, 2015.

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

    Robin Bi

    Hey there :3


    So I'm currently working on a plugin that bans players in a special way. I won't add the players to a banlist so I can't let vanilla bukkit do its job. No, I think I'm gonna work with the PlayerLoginEvent.

    Code:
    @EventHandler
    public void onJoin(PlayerLoginEvent e) {
        if (API.isBanned(e.getPlayer())) {
            e.disallow(null, ChatColor.RED + "You have been banned.");
        }
    }
    This works perfectly fine. When I'm banned, I cannot connect to the server. But in the console, there's this ugly information paragraph:
    Code:
    [19:01:18 INFO]: Disconnecting net.minecraft.util.com.mojang.authlib.GameProfile
    @2f5f6176[id=MyUUID,name=MyName,properties={text
    ures=[net.minecraft.util.com.mojang.authlib.properties.Property@2119724]},legacy
    =false] (/127.0.0.1:52864): ºcYou have been banned.
    [19:01:18 INFO]: net.minecraft.util.com.mojang.authlib.GameProfile@2f5f6176[id=MyUUID,
    name=MyName,properties={textures=[net.minecraft.util.com.mojang.authlib.properties.
    Property@2119724]},legacy=false] (/127.0.0.1:52864) lost connection: ºcYou have been banned.
    This is very impractical for the end user, so I'd like to kinda @Echo off - but how can I do this in Java?



    I hope I could clarify my problem and someone can help me <3
     
  2. Offline

    567legodude

    When I did this I didn't use disallow(). This is what mine would look like the way yours is set up.
    Code:
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player pl = e.getPlayer();
        if (API.isBanned(pl)) {
            pl.kickPlayer("Your kick/ban message");
        }
    }
     
  3. Offline

    Robin Bi

    @567legodude Okay first, let me thank you for your quick answer <3


    I've tried it with your PlayerJoinEvent now, but as I supposed earlier, when I know try to enter the server while still being banned, there will be the joining / leaving message in chat.


    Fun-Fact: For whatever reason, it's not "Player joined the game. Player left the game." but the other way around!? :confused:


    Also, there's still an annoying console output:
    Code:
    [20:47:39 INFO]: MyName left the game.
    [20:47:43 INFO]: UUID of player MyName is MyUUID
    
    [20:47:43 INFO]: MyName lost connection: ºcYou have been banned.
    [20:47:43 INFO]: MyName left the game.


    Any other ideas? :3
     
  4. Offline

    567legodude

    The reason the join and leave messages are still happening is because they are joining the game, you are just kicking them real quick.
    The reason they are reversed is because you kick them before they actually join the server.
    Most of those console messages are automatic and can't be removed.

    Try this if you would like to remove the ingame messages.
    Code:
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player pl = e.getPlayer();
        if (API.isBanned(pl)) {
            e.setJoinMessage("");
            pl.kickPlayer("Your kick/ban message");
        }
    }
    
    @EventHandler
    public void onKick(PlayerKickEvent e) {
        if (e.getReason().equals("The same kick/ban message")) {
            e.setLeaveMessage("");
        }
    }
    Try that and see if it works. I typed it directly into bukkit so forgive me for mistakes.
     
  5. Offline

    Robin Bi

    @567legodude Okay, so I've tried it out.

    Code:
    String reason = "§cYou have been banned.";
    
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        if (API.isBanned(e.getPlayer())) {
            if (API.isBanExpired(e.getPlayer())) {
                API.unban(e.getPlayer());
            }
            else {
                e.setJoinMessage("");
                e.getPlayer().kickPlayer(reason);
            }
        }
    }
    
    @EventHandler
    public void onKick(PlayerKickEvent e) {
        System.out.println("BP1");
        if (e.getReason().equals(reason)) {
            System.out.println("BP2");
            e.setLeaveMessage("");
        }
    }
    Oddly enough, the PlayerKickEvent does not really work. BP1 is printed, BP2 isn't, even though the reason should be equal.



    Is it just me?
     
  6. Offline

    567legodude

    @Robin Bi Hmm. Well maybe you can change the kick event to look like this.
    Code:
    @EventHandler
    public void onQuit(PlayerQuitEvent e) {
        Player pl = e.getPlayer();
        if (API.isBanned(pl)) {
            e.setQuitMessage("");
        }
    }
     
    Robin Bi likes this.
  7. Offline

    Robin Bi

    @567legodude Thanks, although it does not really look like nice code, it works. ;)

    #Solved
     
  8. Offline

    Sneling

    Change this: e.setQuitMessage("");
    By this: e.setQuitMessage(null);
     
Thread Status:
Not open for further replies.

Share This Page