1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Trying to make custom event

Discussion in 'Development' started by Khaled, Mar 24, 2018.

  1. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    my attempt:
    PHP:
    <?php

    namespace te;

    use 
    pocketmine\plugin\PluginBase;
    use 
    te\BadWordsEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\player\PlayerEvent;
    use 
    pocketmine\event\Cancellable;

    class 
    TestEvent extends PluginBase implements Listener{
     
        public 
    $badWords = [
            
    "fuck",
            
    "shit",
            
    "poop"
        
    ];
     
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
     
        public function 
    onChat(PlayerChatEvent $ev){
            if(
    in_array($ev->getMessage(), $this->badWords)){
                
    $ev->getPlayer()->sendMessage("§cBad Words are not allowed");
                
    $this->getServer()->getPluginManager()->callEvent(new BadWordsEvent($ev->getPlayer()));
            }     
        }
     
        public function 
    onBadWords(BadWordsEvent $e){
            
    $e->getPlayer()->sendMessage("§aIt Worked Khaled!");
        }
    }

    class 
    BadWordsEvent extends PlayerEvent implements Cancellable {
     
        protected 
    $player;
     
        public function 
    __construct(Player $player){
            
    $this->player $player;
        }
     
        public function 
    getPlayer() : Player {
            return 
    $this->player;
        }
    }
    ?>
    but it doesnt work when i chat with the bad words, it doesnt send the message: "It worked khaled!".
    so please someone help
     
    Last edited: Mar 24, 2018
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Khaled likes this.
  3. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
  4. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    no, but you can create your own "base event" with a getPlayer() function (just like in ServerSelector) if you have more player-based events.
    No problem, if you want you can drop a like :)
     
    Khaled likes this.
  6. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    of course
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.