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

Solved Send a message to a player when they join in the Main.php

Comments in 'Plugin Development' started by DerpyMan101, Jan 30, 2016.

  1. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    ok then, since you told me that... you were also correct earlier.
    ( I only told you that just incase. )
  2. KubixQ
    Offline

    KubixQ Active Member

    Joined:
    Sep 13, 2015
    Posts:
    85
    Minecraft User:
    KubixQ
    If your plugin docs look like a: src\Events\Events.php
    in file Events.php you write namespace ::
    PHP:
    namespace Events\Events;
    BTW: When you posting a code (e. g. php) use
    Code:
    [PHP]#YOUR_CODE[/PHP]
    ;)
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    BTW, when posting something about BB codes use [PLAIN] [/PLAIN]
    KubixQ likes this.
  4. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Make a folder in this structure JoinMessage/src/JoinMessage/Main.php

    This should be you're Main.php
    PHP:
    <?php

    namespace JoinMessage;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;

    class 
    Events extends PluginBase implements Listener{

    public function 
    onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }

    public function 
    onJoin(PlayerJoinEvent $event){

    $event->getPlayer->sendMessage("Welcome to my server"); //Edit the message <  <
    }
    }
    This should be the plugin.yml , Place it on the root folder of the JoinMessage before the src.
    PHP:
    nameJoinMessage
    author
    IDK
    description
    Sends a message when player joins
    main
    JoinMessage\Main
    version
    1..0.0
    api
    1.0.0
    Anyway, player should recieve the message when they joined. Also remember the plugin.yml should be in the folder main root ex: JoinMessage/(plugin.yml here) then there should be a folder /src/JoinMessage/(Main.php should be here). I hope i helped. :p
    Last edited: Jan 31, 2016
  5. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    *quadruple FACEPALM*

    I already posted that registerEvents must implement Listener... Did you even read my post?
    Vaivez66 likes this.
  6. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    ononononnonononononononono u didn't help at all dude.

    PHP:
    class Events extends PluginBase {
    Didn't implement Listener
    Right code:
    PHP:
    class Events extends PluginBase implements Listener{
    .
    .
    PHP:
    public function onJoin(PlayerJoinEvent $event){

    $event->getPlayer->sendMessage("Welcome to my server")  //Edit the message <  <
    }
    }
    1. getPlayer() not getPlayer
    2. Missing a ; at the end of ("Welcome to my server")
    .
    .
    PHP:
    use pocketmine\utils\TextFormat as Color;
    Why are you using TextFormat? It isn't anywhere in your code.
    .
    .
    PHP:
    nameJoinMessage
    author
    IDK
    description
    Sends a message when player joins
    main
    JoinMessage\Main
    version
    1..0.0
    api
    1.0.0
    .
    .
    version could be shorter.. like "1.0", you added 2 dots between 1 and 0
    THE FILE NAME WAS "Events" NOT "Main" RIGHT???

    Smh I'm disappointed.
    PocketKiller and KubixQ like this.
  7. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    First of all, it doesn't matter if "Version" is 1.0 or 1.0.0 .Version 1.0.0 was include for an reason. Anyway both doesn't include an error.
    And second, i was trying to hurry and forgot the ; (includes the rest).
  8. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    Well, maybe instead of hurrying you should be correct. Now the person that everyone has been trying to help is going to see your mistakes.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, so this is your personal preference, then why force others...
    If you talk about personal preference, more people would like to stick to $e meaning an Exception. That's true common practice.
  10. DerpyMan101
    Offline

    DerpyMan101 New Member

    Joined:
    Jan 12, 2016
    Posts:
    10
    Minecraft User:
    DerpyMan101YT
    Its ok guys yall all helped me :) and it worked thx so much!

Share This Page

Advertisement