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

Improving my plugin much better

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

  1. xktiverz
    Offline

    xktiverz Active Member

    Joined:
    Dec 20, 2013
    Posts:
    61
    Minecraft User:
    64FF00
    Hi, That useless programmer is back again!

    I'm making this useless plugin for my server, and I think I can make it even better.

    Could you please help me to improve this code?

    PHP:
    <?php

    /*

    __PocketMine Plugin__
    name=Inferno
    description=I'm just a useless plugin!
    version=1.0.0
    author=XKTiVerz
    class=Inferno
    apiversion=11,12

    */

    /*

    DO NOT COPY MY CODE WITHOUT MY PERMISSION

    - XKTiVerz

    */

    class Inferno implements Plugin
    {
        private 
    $api;

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

        public function 
    init()
        {     
            
    $this->api->console->register("inferno""<radius> (/inf <radius>)", array($this"CommandHandler"));
         
            
    $this->api->console->alias("inf","inferno");
        }
     
        public function 
    CommandHandler($cmd$params$issuer$alias)
        {
            if(!(
    $issuer instanceof Player))
            {
                return 
    "Please run this command in-game.";
            }
         
            if(
    count($params) > 1)
            {
                return 
    "< [XTi-Server] > Usage: /inferno <radius> (/inf <radius>)";
            }
                 
            
    $rd = (int)$params[0];
         
            if(
    $params[0] == "")
            {
                
    $rd 3;
            }
         
            if(
    $rd <= || $rd 32)
            {
                return 
    "< [XTi-Server] > Error: Invalid Number!";
            }
         
            
    $fire $this->api->block->get(510);
         
            
    $x = (int)$issuer->entity->x;
            
    $y = (int)$issuer->entity->y;
            
    $z = (int)$issuer->entity->z;
         
            
    $px1 $x $rd;
            
    $px2 $x $rd;
            
    $pz1 $z $rd;
            
    $pz2 $z $rd;
         
            for(
    $tx $px1$tx <= $px2$tx++)
            {
                for(
    $tz $pz1$tz <= $pz2$tz++)
                {         
                    
    $pos = new Vector3($tx$y$tz);
                 
                    if((
    $pos != new Vector3($x 1$y$z 1)) and ($pos != new Vector3($x 1$y$z)) and ($pos != new Vector3($x 1$y$z 1)))
                    {
                        if((
    $pos != new Vector3($x$y$z 1)) and ($pos != new Vector3($x$y$z)) and ($pos != new Vector3($x$y$z 1)))
                        {
                            if((
    $pos != new Vector3($x 1$y$z 1)) and ($pos != new Vector3($x 1$y$z)) and ($pos != new Vector3($x 1$y$z 1)))
                            {
                                
    $issuer->level->setBlock($pos$fire$fire->getMetadata());
                            }
                        }
                    }
                }
            }
        }
     
        public function 
    __destruct()
        {
        }
    }

    ?>
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The problem at setBlock

    You were correct to use the Fire object, but if you want to specify the meta data of the block, you should define this when you construct the block. (BlockAPI::get($id, $metaData))

    BTW use the static function not the object function. This is not a must, but you better do so because this is shorter.
    xktiverz likes this.
  3. xktiverz
    Offline

    xktiverz Active Member

    Joined:
    Dec 20, 2013
    Posts:
    61
    Minecraft User:
    64FF00
    Wow, Thanks for your help!

Share This Page

Advertisement