Solved - Kick player in AsyncPlayerChatEvent

Discussion in 'Spigot Plugin Development' started by Script1996, May 6, 2015.

  1. Hey guys,

    since you know that you can't kick a player in the AsyncPlayerChatEvent, I wanted to ask how to kick a player if he's spamming. In the AsyncPlayerChatEvent I coded if a player has a counter (int x) and its on 10 he'll get kicked. It works if I'm using test system.out, but player.kickplayer() causes exception.

    How to do this?

    Greets
     
  2. Can you post source for reference?
     
  3. You can; use a bukkit runnable and kick the player on the main thread.
     
    • Winner Winner x 1
  4. You can; make a scheduleSyncRepeatingTask in onenable and check every mine then check if p has a counter then kick him?
     
  5. You could do something like this (extreme rough draft):

    Code (Text):
    HashMap<String, Long> time = new HashMap<Sting, Long>();
    HashMap<String, Integer> warnings = new HashMap<Sting, Long>();

    @EventHandler
    public void onChat(AsyncChatEvent e) {
      Player p = e.getPlayer();
      if(time.get(p) = null) {
         time.put(p, System.TimeInMillis);
    This is a really rough draft of the code. If you need the full one feel free to message.
     
  6. Thanks for that, it worked. I didn't know it would run in main, too :)