PreLoginEvent Kick Message?

Discussion in 'BungeeCord Plugin Development' started by Inkzzz, May 27, 2015.

  1. Inkzzz

    Resource Staff

    Hello, I'm trying to kick a player from the server for a reason. It's kicking them, but not kicking them with the set reason.

    When they get kicked they get this message:
    http://gyazo.com/48c6fba25ea6031d17a6bea5a9db8b72

    My code for preloginevent:
    Code (Text):
    package Listener;

    import me.bungee.bm.Inkzzz.Main;
    import net.md_5.bungee.api.ChatColor;
    import net.md_5.bungee.api.connection.ProxiedPlayer;
    import net.md_5.bungee.api.event.PostLoginEvent;
    import net.md_5.bungee.api.plugin.Listener;
    import net.md_5.bungee.event.EventHandler;

    public class PostLogin implements Listener {

        @SuppressWarnings("deprecation")
        @EventHandler
        public void onLogin(PostLoginEvent e) {
            ProxiedPlayer p = e.getPlayer();
            if (Main.getInstance().getConfig().getConfig()
                    .getBoolean("Maintenance")) {
                if (p.hasPermission("fatality.admin")) {
                    p.sendMessage(ChatColor
                            .translateAlternateColorCodes('&',
                                    "&b&lFatalityMC &8&l» &7We're currently undergoing maintenance!"));
                } else {
                    String kickmsg = ChatColor
                            .translateAlternateColorCodes(
                                    '&',
                                    "&b&lFatalityMC\n&7Sorry, but we're currently undergoing maintenance.\n&7For more information visit &ehttp://www.fatalitymc.net&7.");
                    p.disconnect(kickmsg);
                }
            }
        }

    }
     
    Would a delayed task work?
     
  2. JamesJ

    Supporter

    Use the Login event, then you can use #setCancelled(boolean) and #setCancelReason("msg");
     
  3. Inkzzz

    Resource Staff

    Yes, but I want to allow players with permissions in?
     
  4. JamesJ

    Supporter

    Yes, AFAIK you can get the connection and use #hasPermission
     
  5. Inkzzz

    Resource Staff

    This isn't working?
    Code (Text):
        @EventHandler
        public void onLogin(LoginEvent e) {
            ProxiedPlayer p = (ProxiedPlayer) e.getConnection();
            if (Main.getInstance().getConfig().getConfig()
                    .getBoolean("Maintenance")) {
                if (p.hasPermission("fatality.admin")) {
                    p.sendMessage(ChatColor
                            .translateAlternateColorCodes('&',
                                    "&b&lFatalityMC &8&l» &7We're currently undergoing maintenance!"));
                } else {
                    e.setCancelled(true);
                    String kickmsg = ChatColor
                            .translateAlternateColorCodes(
                                    '&',
                                    "&b&lFatalityMC\n&7Sorry, but we're currently undergoing maintenance.\n&7For more information visit &ehttp://www.fatalitymc.net&7.");
                    e.setCancelReason(kickmsg);
                }
            }
        }
     
  6. JamesJ

    Supporter

    Don't cast the connection, because AFAIK the Connection isn't a ProxiedPlayer yet.
     
  7. Inkzzz

    Resource Staff

    You cannot get Connections #hasPermission.
     
  8. I don't think that's possible since the ProxiedPlayer object is created at the PostLoginEvent and then you can't kick the player.
    The hasPermission is related to bungeecord permissions anyway so your best bet is to use the api of your permissions manager.
    If you really want to check for basic bungeecord permissions then you can maybe read the config file, but you probably need to register an intent and make it async then.
     
    • Like Like x 1