Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

spam kick

Comments in 'Plugin Development' started by Artide, May 9, 2015.

  1. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Can someone show me an example on how to kick a player if the amount of messages is 2 in 1 second?
  2. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    Use ChatDefender -.-
    It not kick players, it block spammer messages.
  3. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    I think its either my server or api 1.12.0 doesn't support it, but it doesn't work for me.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    It needs fixed.
    iksaku likes this.
  5. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    But could this work?

    PHP:
    public function onChat(PlayerChatEvent $event){
    $p $event->getPlayer();
      If(
    $event->getMessage() === 2){
       
    $p->kick();
       return 
    true;
    }
    }
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Of course no... $event->getMessage() only returns the message.
    PHP:
    private $last=[];
    public function 
    onChat(PlayerChatEvent $e){
      
    $player=$event->getPlayer();
      
    $playerId=$player->getId(); // an identifier just for that player
      
    if(isset($this->last[$playerId]) and
        
    microtime(true)-$this->last[$playerId] < 0.5){ // if this is not the first message the player chatted, and the last message was sent less than 0.5 second ago
        
    $event->setCancelled();
        
    $player->kick();
        return;
      }
      
    $this->last[$playerId]=microtime(true); // save the current time as the time the player last chatted
    }
    Remember to unset the data when the player quits, or the memory will accumulate and overload.
    Andrey Nazarchuk and Artide like this.
  7. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    In microtime(true)-... It marks syntax error
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And what exactly is that syntax error?

Share This Page

Advertisement