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

No-Steve

Comments in 'Plugin Development' started by Skullex, Mar 17, 2016.

  1. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    PHP:
    <?php

    namespace NoSteve;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\TextFormat as Color;

    class 
    Main extends PluginBase implements Listener {

    public function 
    onPreLogin(PlayerPreLoginEvent $event){
            
    $player $event->getPlayer();
            if(
    $player->getName() === "steve"){
              
    $player->close(Color::RED ."In order to join this server" .Color::YELLOW ."\nYou must change your name" .Color::AQUA ."\n \n \nTo something other" .Color::GREEN ."\nThan Steve!");
                
    $event->setCancelled(true);
            }
        }
    }
    This is not working, I need assistance!

    Thanks in advance :)
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Use $player->kick
    On PlayerLogIn and not prelogin
    Skullex likes this.
  3. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Hm, ok
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use $event->setCancelled() and then $event->setKickMessage(). Cancelling the event already kicks the player. You don't need to close the player explicitly, and you should not.

    Also, next time, use kick() rather than close(); close() is only a PocketMine internal function.

    There is nothing wrong using PlayerPreLoginEvent.

    Also, you should check strtolower($player->getName()) instead, because == and === are case-insensitive.
    applqpak, Nawaf_Craft1b and Skullex like this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There is nothing wrong using PlayerPreLoginEVent.
    applqpak likes this.
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    You can't do close on PreLogin
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is a PocketMine bug; we are finding the most graceful way to fix this. And this happens to both PlayerLoginEvent and PlayerPreLoginEvent.
    applqpak and Skullex like this.
  8. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    XD wow, thanks!!
  9. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Not register event?
    Vaivez66 likes this.

Share This Page

Advertisement