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

Is my code ok?

Comments in 'Plugin Development' started by MhikeiMPC, Jul 11, 2016.

  1. MhikeiMPC
    Offline

    MhikeiMPC New Member

    Joined:
    Sep 10, 2015
    Posts:
    35
    Minecraft User:
    MhikeiMPC
    Hi im new to plugin development and so far i made this:

    PHP:
    <?php

    namespace MhikeiMPC12\customJoinMessages;

    use 
    pocketmine\plugin\PluginBase//Allows the plugin to use the files in /src.
    use pocketmine\plugin\PluginLoader//Allows the plugin to listen for an event, which triggers an action
    use pocketmine\command\Command;
    use 
    pocketmine\event\PlayerQuitEvent;
    use 
    pocketmine\event\PlayerJoinEvent;


    class 
    CustomJoinMessages extends PluginBase{
       
        public function 
    onLoad(){
                    
    $this->getLogger()->info("CustomJoinMsgs has been loaded!");
            }

            public function 
    onEnable(){
                    
    $this->getLogger()->info("CustomJoinMsgs has been Enabled!");
            }

            public function 
    onDisable(){
                    
    $this->getLogger()->info("CustomJoinMsgs has left :P");
            }
                   
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
            switch(
    $command->getName()) {
                case 
    "cusjoinmsg":
                    
    // do stuff
                    
    return true;
                case 
    "cusquitmsg":
                    if (
    count($args) == ){
                        return 
    false;
                    }
                    
    var_dump($args); // do stuff
                    
    return true;    
       
       
            }
        }
    }
    Its a plugin that allows the user to set a custom join and quit message. Its not finished, though.
  2. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I think the code is in its syntax correct, but you forgot to implement CommandSender (you have only implemented Command yet).
    MhikeiMPC likes this.
  3. MhikeiMPC
    Offline

    MhikeiMPC New Member

    Joined:
    Sep 10, 2015
    Posts:
    35
    Minecraft User:
    MhikeiMPC
    Ok, i changed it so you can only set the messages using the config only.

    PHP:
    <?php

    namespace MhikeiMPC12\customJoinMessages;

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


    class 
    CustomJoinMessages extends PluginBase{
      
        public function 
    onLoad(){
                    
    $this->getLogger()->info("CustomJoinMsgs has been loaded!");
            }

            public function 
    onEnable(){
                    
    $this->getLogger()->info("CustomJoinMsgs has been Enabled!");
                    
    $this->saveDefaultConfig();
                    
    $this->reloadConfig();
            }
            public function 
    onDisable(){
                    
    $this->getLogger()->info("CustomJoinMsgs has left :P");
            } 
        function 
    onJoin(PlayerJoinEvent $event) {
            
    $player $event->getPlayer();
            
    $name $player->getDisplayName();
        }

    }
  4. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    What's the purpose of that code? lol
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I predict that this is for learning
  6. MhikeiMPC
    Offline

    MhikeiMPC New Member

    Joined:
    Sep 10, 2015
    Posts:
    35
    Minecraft User:
    MhikeiMPC
    umm, im making a plugin..
  7. MhikeiMPC
    Offline

    MhikeiMPC New Member

    Joined:
    Sep 10, 2015
    Posts:
    35
    Minecraft User:
    MhikeiMPC
    I just made the beginning part, but just wanna make sure its ok
  8. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Don't you need to do

    class CustomJoinMessages extends PluginBase implements Listener {


    //Code

    }
  9. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Why do you need to implement CommandSender?
    And Command is a class, not an interface. How can you implement Command? Or if your definition of "implement" is to carry out something, I don't see how it is related to the code in the OP.
  10. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Wrong. This has no sense at all.

    Wrong. This is totally not related with events. And this line can be deleted safely.
    PocketKiller, Survingo and jojoe77777 like this.
  11. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    They mean import ("use e\t\c;").
  12. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    That's called alias declaration, or importing, or namespace-using, or macro-defining, or creeper-killing, or PocketMine-third-party-version-creating, or whatever you want to call that doesn't duplicate the term for something that technically exists and can be totally mistaken for another meaning. Implementing a type has another meaning (declare a class as an implementation of an interface), and you must not mix it with declaring an alias for a type. They are both verbs, and they both accept a type as an object, so they can be totally confused.
    jojoe77777 and PocketKiller like this.
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    As I said to you once, stop being a robot :p
    PocketKiller likes this.
  14. KenyGamer
    Offline

    KenyGamer New Member

    Joined:
    Mar 8, 2016
    Posts:
    9
    Minecraft User:
    kenygamer
    Why you are making a new plugin? There are two plugins in Pocketmine that makes custom join and left messages. And pocketmine.yml allows you to change the join and leave message, and even choosing if you want to display it like a tip, popup or a message.
    Primus likes this.
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    If you can't even make a private plugin like that, nobody can follow the Android developer training website to make a simple Hello World app anymore. https://developer.android.com/training/basics/firstapp/index.html

Share This Page

Advertisement