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

Tutorial [New API]Set your own custom join messages

Comments in 'Resources' started by sebagius7110, Aug 10, 2014.

?

Did I help you?

  1. YES OF COURSE

    17 vote(s)
    60.7%
  2. NO LOL U FAILED ME

    11 vote(s)
    39.3%
  1. sebagius7110
    Offline

    sebagius7110 Active Member

    Joined:
    Jul 1, 2014
    Posts:
    66
    Minecraft User:
    sebagius7110
    Hello, today I am here for a tutorial on just how to set custom join messages to specific players! So first off you need to have [New API]DevTools installed, next run your server then stop it. Go into your plugins folder and create a folder called CustomJoining then open the folder, create another folder called src then in that folder create a folder with your minecraft username, and last create a folder with the plugin name. (In this tutorial it is CustomJoining). Now open up the IDE you use that ha s php linked with it (You can program in php with it) then create a new project from existing source. Now locate the CustomJoining folder in plugins. Now select that folder and press open, then it should show up in your IDE. Now Press Finish. Next go into your src folder, then your username folder, and last into CustomJoining folder. create a file called CustomJoining.php. Now onto some code.

    First up we need to make the start look like this:
    PHP:
    <?php

    namespace sebagius7110\CustomJoining;

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

    class 
    CustomJoining extends PluginBase implements Listener{
    }
    Now replace sebagius7110 with your username. Now we need to add our first function/method (NOTE this is a very important method/function). Add between the first {} this:

    PHP:
    public function onEnable() {
           
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
            
    $this->getLogger()->info("Everything loaded!");

        }
    The file should look like this:

    PHP:
    <?php
    namespace sebagius7110\StaffJoin;

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

    class 
    StaffJoin extends PluginBase implements Listener{
      
        public function 
    onEnable() {
          
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
           
            
    $this->getLogger()->info("Everything loaded!");
    Now to explain what onEnable does and what the code inside it does. Ok the function onEnable runs the code that is inside onEnable when the plugin is enabled. The first line in it:

    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    It just registers and enables the events.

    This line:

    PHP:
    $this->getLogger()->info("Everything loaded!");
    Just prints a message to the console saying Everything loaded when it is done the above code.

    Now next we add

    PHP:
    function onJoin(PlayerJoinEvent $event) {
    }
    And inside it we need to add:

    PHP:
    $player $event->getPlayer();
    $name $player->getDisplayName();
    Now this part is case sensitive, we are just going to set it for a player:

    PHP:
    if ($name == "sebagius7110") {
               
    Server::getInstance()->broadcastMessage("[SebaCrafty] Guys The Owner Joined The Game! [Owner]sebagius7110");
               
            }
    Now what this does is when sebagius7110 joins it will say to the chat [SebaCrafty] Guys The Owner Joined The Game! [Owner]sebagius7110 What you can do is replace the sebagius7110 with your name. And maybe delete the [SebaCrafty] Part too. Now if you want to add another username, you can do the same thing but, it needs to be
    PHP:
    else if ($name == "") {

    }
    Instead of 'if'. Now if you want custom joining messages for other players, do this:

    PHP:
    else {

    Server::getInstance()->broadcastMessage("Guys ".$name." Joined The Game!");
    }
    Now the file should look like this:

    PHP:
    <?php

    namespace sebagius7110\CustomJoining;

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

    class 
    StaffJoin extends PluginBase implements Listener{
       
        public function 
    onEnable() {
           
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
            
    $this->getLogger()->info("Everything loaded!");
        }
           
           
        }
       
        function 
    onJoin(PlayerJoinEvent $event) {
           
            
    $player $event->getPlayer();
            
    $name $player->getDisplayName();
           
            if (
    $name == "sebagius7110") {
               
                
    Server::getInstance()->broadcastMessage("[SebaCrafty] Guys The Owner Joined The Game! [Owner]sebagius7110");
               
            }
           
            else {
                        
    Server::getInstance()->broadcastMessage("Guys".$name."Joined The Game!");

           
        }
       
    }
    Now something else important. We need to create a plugin.yml file. Now where you see all the files in your project in your IDE, right click the Include Path and click on properties. A window should pop up and then press the private tab. Press Add folder, now download the pocketmine-MP-master from github. Extract the zip into a folder, then in the IDE where you need to select a folder, find the pocketmine-MP-master folder then add it. All your errors should go away. Now where your files are in the IDE you need to right click the 'Source Files' Folder and press New, then Other then press the Other File. Next find YAML File and double click that, copy and paste this into the file:

    Code:
    name: CustomJoining
    main: sebagius7110\CustomJoining\CustomJoining
    version: 1.0.0
    api: 1.1.0
    Like that, with the to CustomJoining\CustomJoining
    and replace sebagius7110 with your username.

    Now save everything, run your server and DevTools should load your plugin, next type in the console 'makeplugin CustomJoining' Without the quotes. It will make your plugin now, stop the server. Cut the folder CustomJoining from your plugins folder, to another place away from your server. Now go into the Dev Tools folder, there should be a .phar file called CustomJoining_v1.0.0.phar move that file from DevTools to your plugins folder, then run your server again. The plugin should be loaded, and now when you join the game, it will say the message you set in the code for your username. (Notice that it will still say <username> Joined The Game but it will say Guys The Owner Joined The Game: [Owner]<username>)

    Hope this tutorial helps, and sorry if it is toooooo long, but hope this helps, thanks

    -Seb

    P.S. If you want a tutorial on a different event too, post in the comments and I will try to make a tutorial.
    wasd-studios likes this.
  2. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Just as a note, you can also use $this->getServer()->broadcastMessage() instead of Server::getInstance(). This isn't an issue, but its another way.
    PEMapModder likes this.
  3. sebagius7110
    Offline

    sebagius7110 Active Member

    Joined:
    Jul 1, 2014
    Posts:
    66
    Minecraft User:
    sebagius7110
    Ok Thanks :D
    GlaciercreepsMC likes this.
  4. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    No problem! :p
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why must it be else if not if?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Anyway, I think this tutorial is after all too generic. This tutorial is just basically explaining what a custom join plugin contains, but you taught nothing about how it works. You are just like saying, "to cook a steak, buy some from the market and cook at at home and do i-dont-really-know-how blah blah. If you want to cook pork chop instead, tell me here and I will add that tutorial. If you want to cook anything else than steak, I will make another tutorial." And do you think this teaches one how to cook? No. You barely taught him how to cook steak, and the reader doesn't even know why you have to cook. Instead, you should teach the readers the basics, like the kitchen hygiene, and let them figure out that it is the same for pork chop.

    In our case, you should teach people why they have to do all these stuff. From what I see you have done, it is just the same as you made a custom join plugin and told people how to modify it to suit your own needs.
  7. sebagius7110
    Offline

    sebagius7110 Active Member

    Joined:
    Jul 1, 2014
    Posts:
    66
    Minecraft User:
    sebagius7110
    Ok sorry, should I delete the thread?, Or just try to edit it to make it better.
  8. sebagius7110
    Offline

    sebagius7110 Active Member

    Joined:
    Jul 1, 2014
    Posts:
    66
    Minecraft User:
    sebagius7110
    I just think it's a little more of a safer way to go? :p
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is a safer way to make yourself unaware of the bugs ;)
    GlaciercreepsMC likes this.
  10. sebagius7110
    Offline

    sebagius7110 Active Member

    Joined:
    Jul 1, 2014
    Posts:
    66
    Minecraft User:
    sebagius7110
    Thanks :D
  11. CookieSteve
    Offline

    CookieSteve Active Member

    Joined:
    Apr 22, 2014
    Posts:
    132
    Minecraft User:
    iStrqfeChris
    DevTools Wont Load The Source Plugin

    [INFO] Loading source plugin CustomJoining v1.0.0
    10:31:14 [WARNING] An E_USER_WARNING error happened: "Couldn't load source plugin CustomJoining: main class not found" in "/DevTools_v1.8.0-4c37f602.phar/src/FolderPluginLoader/FolderPluginLoader" at line 72
    10:31:14 [CRITICAL] Could not load plugin 'CustomJoining'

    Attached Files:

    • Main.php
      File size:
      945 bytes
      Views:
      30
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You put the main class at the wrong place.
    ctalbot2004 likes this.
  13. CookieSteve
    Offline

    CookieSteve Active Member

    Joined:
    Apr 22, 2014
    Posts:
    132
    Minecraft User:
    iStrqfeChris
    Thxs
  14. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Never use "Server::getInstance()" it's a bad practice :p
    PEMapModder likes this.
  15. TheLucyClub
    Offline

    TheLucyClub Banned

    Joined:
    Jan 31, 2015
    Posts:
    53
    Minecraft User:
    iCreepyKid
    I did exactly what it said in the tutorial i checked 4 times, and it didn't work.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't use Server::getInstance()
    And full code please?
  17. BorbingoBoy
    Offline

    BorbingoBoy New Member

    Joined:
    Apr 10, 2015
    Posts:
    5
    Minecraft User:
    BorbingoBoy
    This is so complicated if you don't have the final .phar :(

    And BTW LDX told me for this command:
    Player::sendPopup()
    And guess what it does!
    I recommend you to replace the Server::getInstance() with that one.
  18. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    What do you mean it's complicated if you don't have final .phar?
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And what do you mean by Player::sendPopup? It does something totally different from Server::getInstance... And it is a function not a command...
  20. LazerSoft
    Offline

    LazerSoft New Member

    Joined:
    Jul 22, 2015
    Posts:
    9
    This is incorrect. Just use
    PHP:
    $event->setJoinMessage();

Share This Page

Advertisement