Disable players to join while game is running

Discussion in 'Spigot Plugin Development' started by Drawethree, May 14, 2017.

  1. Question is above. I have premium bungee plugin and i need that, the player will be kicked / not joined to server if the game is in progress. How to do that ?
     
  2. Use PlayerPreJoinEvent on spigot, and on Bungeecord ServerSwitchEvent I believe
     
  3. Code (Text):
    @EventHandler
    public void cancelJoin(PlayerJoinEvent event) {
    // Check if Game has started already.
    event.getPlayer().kickPlayer("Your kick message here.");
    }
    You should use this code.
     
  4. Mas

    Mas

    That's a bad way to do it. You should listen to PlayerLoginEvent then set the result to KICK_OTHER with whatever kick message you want.
     
    • Agree Agree x 1
  5. I don't see any problems with this, it instantly activates the event and kicks the player.
     
  6. Mas

    Mas

    How is that any better than just cancelling the LoginEvent? Your "solution" has flaws whereas the appropriate way does not.
     
  7. You're actually right, this method registers the player already in the server/game before it gets kicked. Because it's listening to join, and when the player is in the server (joined) then the event will activate. And that's too late, not a good solution.

    Excuse me.
     
    • Winner Winner x 1
  8. Sigh...
    *PlayerPreLoginEvent*...
    Don't use PlayerLoginEvent or PlayerJoinEvent. Both are bad if you want to kick them straight afterwards just to check if server/game is running...
    //Don't give advice if you can't give good advice...
     
  9. I just forgot that PlayerPreLoginEvent event exist.

    Excuse me again.
     
    • Friendly Friendly x 2
  10. Lol I said it before you...
     
    • Like Like x 1
  11. Isnt much easier to use a boolean and playerpreloginevent? Also excuse and correct me, please.. If i am mistaking
     
  12. Mas

    Mas

    Their is no difference between using either PreLoginEvent or LoginEvent in this case.

    Don't look down on other's advice because you think your solution is better and for some reason like to comment forum posts not realizing it's making them you look really strange ;)
     
    • Optimistic Optimistic x 1
  13. AsyncPlayerPreLoginEvent *
     
  14. Make yourself a favor and recode your projects according to Java conventions ;)

    And don't tell other users their code is bad when yours one has newbie mistakes :)
     
  15. Sure?

    PlayerPreLoginEvent
    This event stores the following data:
    • result: Is the player allowed to login? (default "Allowed")
    • message: message to display on "kick"
    • name: Users name attempting to login
    • ipAddress: Address of user trying to login
    This is not a "player" event, and as such .getPlayer() doesn't exist.

    PlayerLoginEvent
    Now here's what I've been finding people do wrong, in my opinion. People use PlayerLogin as a place to set player information. Now, I could say this is alright, except that I must say this is completely wrong for you to do. This event should be used to validate the players login, and apply permissions to a player. What you should not try to do is set player information (eg: DisplayName). Yes, it is a convenient place for you to set the display name, but you should do this in the PlayerJoinEvent, where the player actually joins the server.
    The following data is stored:
    • Player: the player logging in
    • result: The result of login
      • ALLOWED
      • KICK_FULL (server full)
      • KICK_BANNED (banned ip/name)
      • KICK_WHITELIST (not on whitelist)
      • KICK_OTHER (other, can set by plugins)
    • message: The message to display on "kick
    PlayerJoinEvent
    This is where you should play around with the player information. Data stored:
    • Player: The player joining
    • Message: the message to broadcast on join. (set to null for no message)

    @darkshadow22mc Sssst :p I was on my mobile okay :p
     
    • Like Like x 1
    • Informative Informative x 1
  16. So I should do it via PlayerJoinEvent?
     
  17. PlayerLoginEvent, look at the reply of @TheBlackTeddy above your reply.
     
    • Useful Useful x 1
    • Optimistic Optimistic x 1
  18. AsyncPlayerPreLoginButBeforeJoiningAndAfterConnectingEvent
     
    • Funny Funny x 5
    • Agree Agree x 1
  19. [​IMG]
     
    • Funny Funny x 3
    • Optimistic Optimistic x 1
  20. Use the AsyncPlayerPreLoginEvent.
     
    • Winner Winner x 1