Cannot kick player more than once

Discussion in 'Spigot Plugin Development' started by Dragonphase, Jun 18, 2016.

  1. I need to kick a player when some certain conditions are met. These conditions and the kick need to take place asynchronously (specifically in AsyncPlayerChatEvent), but whenever a player is kicked, they can never be kicked again after they log back in. I receive "handleDisconnection() called twice" whenever I attempt to kick the player (when it kicks them the first time, and all times it attempts to kick them thereafter).

    Both of these methods of kicking do not solve the problem for me, and both have the same result:

    Code (Text):
    new BukkitRunnable() {

        public void run() {
    Code (Text):
    Bukkit.getScheduler().scheduleSyncDelayedTask(Chat.getInstance(), () -> player.kickPlayer(finalKickMessage), 1L);
    They can only be kicked once, and never after that.
    #1 Dragonphase, Jun 18, 2016
    Last edited: Jun 18, 2016
  2. you can't kick a player that's already offline
  3. I'm trying to kick them when they are online again.
  4. @Dragonphase what exactly are you trying to do? You can't kick the same player instance twice.
    • Agree Agree x 1
  5. I'm not attempting to kick them when they log back in. If you read my first post I state that this happens in an AsyncPlayerChatEvent. I am working on a censor feature to kick players whenever they mention something prohibited (such as advertisements).
  6. I am only kicking them once. I realised my question was a little vague, so I updated it and clarified that by "kicking them twice" i mean "kicking them again after logging back in if the same conditions are met in the chat event." So, if a player is to be kicked for saying something prohibited, and they log back in and say the same thing again, it should kick them again, but it doesn't.
  7. I have also done some logging and determined that the code is being reached correctly on every occasion. When it kicks the player, I receive the "handleDisconnection() called twice" warning in console. When it attempts to kick the player again at the same point when the same conditions are met after the player logged back in, I receive the same warning, but the player isn't kicked.
  8. @Dragonphase It's still a little vague for me, but I don't think this can be described easily. Mind showing your chat event?
  9. I do mind, but I solved my issue (somewhat). Basically, in my AsyncPlayerChatEvent, I am calling another event which uses the Component API instead of regular chat. Each player also has a "Profile" which stores a lot of data associated to each player. I also keep the player stored as an OfflinePlayer in the profile and I was using this to kick the player.

    What's confusing is that OfflinePlayer#getPlayer() should return the Player if they're online, and in all other cases, it works as intended, so I don't know why it isn't working for this.