Solved Kicking a player in the PlayerJoinEvent

Discussion in 'Plugin Development' started by Tecno_Wizard, Jul 4, 2015.

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

    Tecno_Wizard

    I was looking through something today and ran into a thread speaking about how Bukkit.kickPlayer() does not work in the PlayerJoinEvent. The issue with this for me (if it is even true) is that I have a perm in a plugin I am developing that denies a player's ability to log in without a specific perm. In other words, I need to deny a player's ability to join in the PlayerJoinEvent and not the login event because I need access to the player's perms.

    Is this an actual problem and what can I do as an alternative if it is? (I really don't want to have to schedule a task to kick them)
     
  2. Offline

    _Error

    Code:
    public void onJoin(PlayerJoinEvent e){
    Player p = e.getPlayer();
    if(!p.hasPermission("myplugin.mypermission")){
    p.kickPlayer("You can't join this server cause you dont have the following permission : myplugin.mypemission");
    }
    }
    
    This does not work?
     
  3. Offline

    Tecno_Wizard

    @_Error That's what I was told. Going to give it a shot myself.

    EDIT: They're right. It just crashes the client with an IO exception.

    And somehow I managed to make a plugin that ran without an error at it's first compile for the first time in forever.
     
    Last edited: Jul 4, 2015
  4. Offline

    ShadowWizardMC

    @Tecno_Wizard

    What about trying something like

    Code:
        @EventHandler
        public void onLogin(PlayerLoginEvent e){
            if(!e.getPlayer().hasPermission("whitelist.bypass")){
                e.setResult(PlayerLoginEvent.Result.KICK_OTHER);
                e.setKickMessage(ChatColor.RED + "Unfortunately you do not have permission to join the server at this moment.");
            }
        }
     
    CodePlaysMinecraft likes this.
  5. @Tecno_Wizard I actually use the PlayerLoginEvent instead of the PlayerJoinEvent. Works a lot better. Here's the actual code if you need it:
    Code:
        @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event) {
            Player player = event.getPlayer();
            PlayerMethods pMethods = new PlayerMethods(player.getUniqueId());
            if (pMethods.getBanned()) {
                event.disallow(Result.KICK_BANNED, ChatColor.RED
                        + "You are banned:" + "\n Banned by: " + ChatColor.AQUA
                        + pMethods.getBannedBy() + ChatColor.RED + "\n Reason: "
                        + ChatColor.AQUA + pMethods.getReason());
            }
        }
     
    ShadowWizardMC likes this.
  6. Offline

    Konato_K

    @Tecno_Wizard I think using LoginEvent is better, if you really need Join for one reason or another, delay the kick by 1 tick
     
  7. Offline

    Tecno_Wizard

  8. Offline

    ShadowWizardMC

    @Konato_K Probably not the best idea since schedulers are something that use resources and to have to every time a player join's could have a negative impact on the server probably not noticeable but it'll definitely be there.
     
  9. Offline

    Tecno_Wizard

    @ShadowWizardMC, exact reason I wanted to avoid it + spaghetti code
    And WOW there is a lot more fuctionality in the Login event. Why hasn't join been deprecated?
     
  10. Offline

    Konato_K

    @Tecno_Wizard Because join is fired when the player has fully logged in, and you can make some actions (like teleporting and so on) that you can't when the player is still login in.

    @ShadowWizardMC Why would he make a task for every player? Just for the ones that need to be kicked.
     
  11. Offline

    Tecno_Wizard

    @Konato_K, that in this instance could be a lot. We're talking 98% kick rate when it's kicking.
     
  12. Offline

    lilian58660

    Code:
      @EventHandler
      public void onPlayerPreLogin(PlayerPreLoginEvent event)
      {
          event.disallow(PlayerPreLoginEvent.Result.KICK_OTHER, "reason");
          event.setResult(PlayerPreLoginEvent.Result.KICK_OTHER);
       
      }
    Just use this :)
     
  13. Offline

    NeguinDaFarofa

    What would it be? If to take the id of the player could move me?
     
  14. Offline

    Tecno_Wizard

  15. @Tecno_Wizard I don't mean to keep bumping the thread, but Wallaby is asleep right now. Also, use the report button instead of tagging staff. It makes it easier for them. ;)
     
  16. Offline

    Tecno_Wizard

    CodePlaysMinecraft likes this.
Thread Status:
Not open for further replies.

Share This Page