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

I need help with my plugin. :(

Comments in 'Plugin Development' started by xktiverz, Jan 10, 2014.

  1. xktiverz
    Offline

    xktiverz Active Member

    Joined:
    Dec 20, 2013
    Posts:
    61
    Minecraft User:
    64FF00
    Hi, as you know, I'm just a useless programmer. :( I've been trying to make my own HOME plugin but i think it's not working properly. This /home command can teleport me to the home position perfectly, but it says that I couldn't teleport to there. Could you please check the errors in this plugin?

    Thank you so much for your help!



    PHP:

    <?php

    /*

    __PocketMine Plugin__
    name=IMANUSELESSPLUGIN
    description=USELESS Commands for you
    version=0.0.1
    author=XKTiVerz
    class=USELESS
    apiversion=11

    */

    /*

    This Plugin is just USELESS!

    */

    class USELESS implements Plugin
    {
        private 
    $api;

        public function 
    __construct(ServerAPI $api$server false)
        {
            
    $this->api $api;
        }

        public function 
    init()
        {
            if(!
    file_exists($this->api->plugin->configPath($this) ."HOMES.yml"))
            {
                
    $this->HOMES = new Config($this->api->plugin->configPath($this) . "HOMES.yml"CONFIG_YAML, array());
            }

            
    $this->HOMES $this->api->plugin->readYAML($this->api->plugin->configPath($this) . "XTi-HOMES.yml");

            
    $this->api->console->register("home""You can teleport to your home! (/hm)", array($this"CommandHandler"));
            
    $this->api->console->register("sethome""Set your home with your current position! (/shm)", array($this"CommandHandler"));

            
    $this->api->ban->cmdWhitelist("home");
            
    $this->api->ban->cmdWhitelist("sethome");

            
    $this->api->console->alias("hm","home");
            
    $this->api->console->alias("shm","sethome");

            
    console("[USELESS_INFO_FOR_YOU] Enabled IMANUSELESSPLUGIN for your server!");
        }

        public function 
    commandHandler($cmd$params$issuer$alias)
        {
            switch(
    $cmd)
            {
                case 
    "home":

                    if(!(
    $issuer instanceof Player))
                    {
                        return 
    "Please run this command in-game.";
                        break;
                    }

                    
    $pos = new Position($this->HOMES[$issuer->username]["X"], $this->HOMES[$issuer->username]["Y"], $this->HOMES[$issuer->username]["Z"], $issuer->entity->level);

                    if(
    $issuer->teleport($pos))
                    {
                        return 
    "[USELESS] Teleported to Your Home!";
                        break;
                    }
                    else
                    {
                        return 
    "[USELESS] Couldn't Teleport to Your Home.";
                        break;
                    }
      
                    break;
          
                case 
    "sethome":

                    if(!(
    $issuer instanceof Player))
                    {
                        return 
    "You can't run this command in-game.";
                        break;
                    }

                    
    $this->HOMES[$issuer->username] = array("X" => (int)$issuer->entity->x"Y" => (int)$issuer->entity->y"Z" => (int)$issuer->entity->z);

                    if(
    $this->api->plugin->writeYAML($this->api->plugin->configPath($this) ."XTi-HOMES.yml"$this->HOMES))
                    {
    return 
    "[USELESS] :O It worked!";
    break;
                    }
                    else
                    {
                        return 
    "[USELESS] :( It didn't work...";
                        break;
                    }
          
                    break;

                default:

                    return 
    "[USELESS] Invalid Command!";
                    break;
            }
        }

        public function 
    __destruct()
        {
        }
    }

    ?>
    Last edited: Jan 23, 2014
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    (First of all you don't need to put break after return, because when the return statement is executed, the whole thing jumps out of the function and the code immediately after it is dead.
    And you don't need to do the default case because: Well, in what cases would it be called? You didn't register the commands, so why should this code be called?

    Second why don't you save the level?

    IGNOREME_STARTS
    (Third in the end of the init() function it is not "enabled' the plugin. It is "enabled" when it was constructed. The fact is it finished initializing)
    IGNOREME_FINISH)
  3. xktiverz
    Offline

    xktiverz Active Member

    Joined:
    Dec 20, 2013
    Posts:
    61
    Minecraft User:
    64FF00
    :O Why did I put the default case there?

    Now I think I solved it! Anyway thanks for your help!

    Umm.. I'm sorry but how can I edit this thread title?
  4. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    Uh, have you tried not cutting yourself down? XD
    I've tried to make lots of plugins, but only three have actually worked in the end. ;) Keep trying, and you'll be a great programmer. :D
  5. Mason Gareis
    Offline

    Mason Gareis Active Member

    Joined:
    Jan 8, 2014
    Posts:
    53
    Minecraft User:
    MasonLovesMCPE
    "We gain strength, and courage, and confidence by each experience in which we really stop to look fear in the face... we must do that which we think we cannot."

    ~Eleanor Roosevelt
  6. xktiverz
    Offline

    xktiverz Active Member

    Joined:
    Dec 20, 2013
    Posts:
    61
    Minecraft User:
    64FF00
    Thank you so much, Mason & LDX! :D
    Last edited: Jan 12, 2014
    LDX and Mason Gareis like this.
  7. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    Quit updating your signature with even more depressing words. XD
    xktiverz likes this.
  8. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    And it should be "I'm just a useful programmer! :D"
    xktiverz likes this.
  9. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    i think "useless" is just a sense of humility. Look at @zhuowei. Even he is such an advanced programmer most of his releases of mods and tools start with "please help me test my ...". P.S. When I was at a stage when I thought I knew the pocketmine system very well I also did that default thing. But we really should listen to the default case, because its being called signifies a bug. If it is called, "take a warning son" (i am listening to music. the song Windflowers. and it really has such a sentence.
    LDX and xktiverz like this.
  11. xktiverz
    Offline

    xktiverz Active Member

    Joined:
    Dec 20, 2013
    Posts:
    61
    Minecraft User:
    64FF00
    I'm gonna change my signature XD
    LDX and PEMapModder like this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Lol
    xktiverz likes this.

Share This Page

Advertisement