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

Solved Problem with my personal plugin.

Comments in 'Plugin Development' started by Mat, Jul 13, 2015.

  1. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Hi guys, I'm doing a plugin that send messages when players join in my server but I have got this crash error in the console when the players join:
    PocketMine-MP Crash Dump Mon Jul 13 16:48:45 UTC 2015
    Error: Call to a member function sendMessage() on string
    File: /ItalianMOTD_v1.0.0.phar/src/matcracker/Main
    Line: 21
    Type: E_ERROR
    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: ItalianMOTD v1.0.0
    Code:
    Backtrace:
    #0 /src/pocketmine/Server__32bit(0): pocketmine\Server->crashDump()
    #1 /src/pocketmine/plugin/MethodEventExecutor(36): matcracker\Main->onPlayerJoin()
    #2 /src/pocketmine/plugin/RegisteredListener(96): pocketmine\plugin\MethodEventExecutor->execute()
    #3 /src/pocketmine/plugin/PluginManager(673): pocketmine\plugin\RegisteredListener->callEvent()
    #4 /src/pocketmine/Player__32bit(757): pocketmine\plugin\PluginManager->callEvent()
    #5 /src/pocketmine/Player__32bit(717): pocketmine\Player->doFirstSpawn()
    #6 /src/pocketmine/Player__32bit(1561): pocketmine\Player->sendNextChunk()
    #7 /src/pocketmine/Server__32bit(2506): pocketmine\Player->checkNetwork()
    #8 /src/pocketmine/Server__32bit(2306): pocketmine\Server->tick()
    #9 /src/pocketmine/Server__32bit(2184): pocketmine\Server->tickProcessor()
    #10 /src/pocketmine/Server__32bit(1784): pocketmine\Server->start()
    #11 /src/pocketmine/PocketMine(464): pocketmine\Server->__construct()
    #12 (1): ()
    #13 (0): {main}()

    Fatal error: Call to a member function sendMessage() on string in phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/plugins/NamePlugin_v1.0.0.phar/src/matcracker/Main.php on line 21
    Call Stack:
    0.0171 412104 1. {main}() C:\Users\Matt\Desktop\PocketMine-MultiServer\PocketMine-Servers_1.5\PocketMine-MP(Lobby)_1.5\PocketMine-MP.phar:0
    0.0200 407456 2. require('phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Matteo\Desktop\PocketMine-MultiServer\PocketMine-Servers_1.5\PocketMine-MP(Lobby)_1.5\PocketMine-MP.phar:1
    0.0491 549016 3. pocketmine\Server->__construct() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/PocketMine.php:464
    7.2571 18704200 4. pocketmine\Server->start() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:1784
    7.2605 18715688 5. pocketmine\Server->tickProcessor() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:2184
    9.0557 28483624 6. pocketmine\Server->tick() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:2306
    9.0638 28986136 7. pocketmine\Player->checkNetwork() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:2506
    9.0638 28986136 8. pocketmine\Player->sendNextChunk() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/Player__32bit.php:1561
    9.0638 28986696 9. pocketmine\Player->doFirstSpawn() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/Player__32bit.php:717
    9.0696 28997952 10. pocketmine\plugin\PluginManager->callEvent() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/Player__32bit.php:757
    9.5017 29256472 11. pocketmine\plugin\RegisteredListener->callEvent() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:673
    9.5017 29256472 12. pocketmine\plugin\MethodEventExecutor->execute() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/plugin/RegisteredListener.php:96
    9.5017 29256560 13. matcracker\Main->onPlayerJoin() phar://C:/Users/Matt/Desktop/PocketMine-MultiServer/PocketMine-Servers_1.5/PocketMine-MP(Lobby)_1.5/PocketMine-MP.phar/src/pocketmine/plugin/MethodEventExecutor.php:36

    My code is:
    PHP:
    <?php
    namespace matcracker;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Server;
    class 
    Main extends PluginBase implements Listener{
    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getLogger()->info(TextFormat::GREEN."PluginName on!");
     
    }
    public function 
    onPlayerJoin(PlayerJoinEvent $event){
    $player $event->getPlayer()->getName();
    $player->sendMessage(TextFormat::BLUE."Hi, ".$player.TextFormat::BLUE."!");
    $player->sendMessage(TextFormat::BLUE."Welcome in".TextFormat::GOLD." Server Name");
    $player->sendMessage(TextFormat::BLUE."Official Server TeamSpeak: ".TextFormat::GOLD."Ip TeamSpeak");
    $player->sendMessage(TextFormat::BLUE."Warps: ".TextFormat::GOLD."/warp");
    $player->sendMessage(TextFormat::BLUE."Digit ".TextFormat::GOLD."/help ".TextFormat::BLUE."for the commands list.");
    $player->sendMessage(TextFormat::BLUE."Players online: ");
    }
    public function 
    onDisable(){
    $this->getLogger()->info(TextFormat::RED."PluginName off!");
    }
    }
    Another question, if possible. How can I add a list of players online in the servers?
    PHP:
    $player->sendMessage(TextFormat::BLUE."Players online: ".player1.", " .player2", etc... );
    Thanks for helping me :)
  2. Intyre
    Offline

    Intyre Staff Member PocketMine Team

    Joined:
    Aug 24, 2013
    Posts:
    118
    Minecraft User:
    Intyre
    Please try to understand the error.

    Code:
    Fatal error: Call to a member function sendMessage() on string
    Code:
    $player = $event->getPlayer()->getName(); // remove ->getName()?
    $player->sendMessage(TextFormat::BLUE."Hi, ".$player.TextFormat::BLUE."!");
    
  3. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    $player = $event->getPlayer()->getName();
    $p = $event->getPlayer();
    $p->sendMessage(TextFormat::BLUE."Hi, ".$player.TextFormat::BLUE."!");
    PEMapModder likes this.
  4. Pman1220
    Offline

    Pman1220 Active Member Plugin Developer

    Joined:
    Nov 21, 2013
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Pman1220
    Code:
    $player = $event->getPlayer()->getName();
    Just remove ->getName()
    PEMapModder likes this.
  5. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Thanks to all! I do this:
    PHP:
    $player $event->getPlayer()
    $player->sendMessage(TextFormat::BLUE."Hi, ".$player->getName().TextFormat::BLUE."!");
    And for the "Players Online", how can I do?
  6. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  7. Pman1220
    Offline

    Pman1220 Active Member Plugin Developer

    Joined:
    Nov 21, 2013
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Pman1220
    Are you trying to get the number of online players or list every name of every player?
    Legoboy0215 likes this.
  8. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    The second :)
  9. Pman1220
    Offline

    Pman1220 Active Member Plugin Developer

    Joined:
    Nov 21, 2013
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Pman1220
    Im not 100% sure if this is the best method(probably isnt) but If it was me I would create a new file and as players join Id add their names to the file.
    Then Id send a message to the Joining player the players in that list. I looked through the Api and thats all I got. Give it a shot! If you need help with code let me know. But that would be my method
  10. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    I understand your way but I think there is a best way for do this.
    hoyinm14mc and LDX like this.
  11. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    The proper way is what @Xenturio said.

    hoyinm14mc, Mat and Xenturio like this.
  12. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Therefore... If I understand well:
    PHP:
    $online "";
    foreach(
    $this->getServer()->getOnlinePlayers() as $player){
      
    $online .= $player->getDisplayName() . ", ";
    }
    $player-> sendMessage ("Players Online: ".$online substr($online0, -2));

  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I would prefer this. Looks a bit nicer to me, although not much difference.

    PHP:
    $online implode(", "array_map(function($player){
      return 
    $player->getDisplayName();
    }, 
    $this->getServer()->getOnlinePlayers()));
    LDX likes this.

Share This Page

Advertisement