1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Development Snippets

Discussion in 'Resources' started by Primus, Nov 24, 2016.

  1. Primus

    Primus Zombie Pigman

    Messages:
    749
    Smile! I hate doing the same stuff again and again for a long period of time, so do you. It would be awesome if we could share the snippets to boost our productivity a lot.

    Valid snippets are
    • Gist(s)
    • Sublime Text editor snippet file
    • PHP classes, interfaces, traits and functions or
    • anything that is reusable and not adjusted for individual use
    The format for posting snippets.

    Localizer (PHP Class)
    Easy to use language handler. (TODO: More descriptive).
    Instructions: Place this class anywhere inside your project. Correct the namespaces. Setup language directory.
    Code:
    /*
     * Instructions.
     *
     * Set your language folder structure like this
     *
     * languages
     * |
     *  `en (language code - ru, lv, ro, sv)
     *   |
     *    `foo.php (the language file)
     *   |
     *    `bar.php (another. these will be loaded automatically)
     *
     * language files (foo & bar .php, .yaml, .json) if php, must have only one statement
     * which returns assoc array (key => text)
     */
    [/SIZE]
    
    Example:
    PHP:
    /** @var Localizer */
    public $localizer;

    public function 
    onEnable() {
       
    // Load english data files from ~/plugins/pluginName/languages/en
       
    $this->localizer = new Localizer("en"$this->getDataFolder() . "languages");
       
    $this->getLogger()->info($this->localizer->translate('plugin.enabled'));
    }
    must be placed inside ~/plugins/pluginName/languages/en
    Code:
    {
       "enabled": "Enabled"
    }
    

    Localizer.php:


    Snippets can be as useful as plugins and can be anything like plugin.yml template, data providers, custom entities or custom/unimplemented packets.
     
    Last edited: Nov 24, 2016
    Muqsit and Reid like this.
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You should write libraries instead of copying code snippets.
     
    Primus and HBIDamian like this.
  3. Primus

    Primus Zombie Pigman

    Messages:
    749
    However I still see snippets very useful. Obviously library won't be library with one function. Sometimes using library is redundant if you need one of many its functionalities.
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Localization is apparently worth a whole library.
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    But there's currently no simple way to handle them
     
  6. Primus

    Primus Zombie Pigman

    Messages:
    749
    Idea about library hit me hard and for about two weeks I've been creating a libraries. So far so good
    These are the libraries I've made so far:
    • Dominate: PocketMine-MP Library for advanced command handling
    • Localizer: Simple to use locale manager for PocketMine-MP
    I use Simple-LibLoader to load them. However it's stupid. All it does is it loads all classes from folder or phar file.

    Can anyone make a (not plugin) similar thing, but bit more advanced?
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What do you think about Virions? I made a post about it on the General Discussion forum.
     
  8. Primus

    Primus Zombie Pigman

    Messages:
    749
    Exactly what I'm looking for. But I wonder if there won't be namespace conflicts if other plugin requires same library, but different version of it?
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    That's what Virion is for! Did you look into the details?
     
    Primus likes this.
  10. Primus

    Primus Zombie Pigman

    Messages:
    749
    #Blame it on me
     
    Ant likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.