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

Making The Sign Live

Comments in 'Plugin Development' started by NIM, Jan 13, 2014.

  1. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    Here is the code, now how would I make it live? @Glitchmaster_PE
    An do I have any errors?
    PHP:
    <?php

    /* 
    __PocketMine Plugin__ 
    name=SignPro
    description= Live Signs at its best!
    version=1.0
    author=NIM
    class=Sign
    apiversion=11
    */

    class Sign implements Plugin{
        private 
    $api$server;
        public function 
    __construct(ServerAPI $api$server false){
            
    $this->api $api;
            
    $this->server ServerAPI::request();
        }

        public function 
    init(){
            
    $this->api->addHandler("tile.update", array($this"eventHandler"), 10);
        }

        public function 
    eventHandler($data$event){
            switch (
    $event) {
                case 
    "tile.update":
                    if (
    $data->class === TILE_SIGN) {
                        if (
    $data->data['Text1'] != "[Server]")
                      return;
                              
    $data->setText(".count($this->api->player->getAll())."/".$this->server->maxClients));
                                }
                            }
                        }
                       public function __destruct(){
        }
        }
  2. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    This only makes it, making it live is a whole new thing. If I do it for you, that takes the fun out of it ;)
  3. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    Tell Me what I need to add? :D
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Get a Tile object by TileAPI, then call the Tile's non-static function $tile->setText($text1,$text2,$text3,$text4)
  6. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    I have an idea. do you know how the autocommandbot plugin. maybe you can fit in the
    $this->api->schedule
    code in to the live sign plugin so it will check how much players are on every 5 seconds
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I am up to signs too recently. Here is a pre-release version of my API:
    NOTE: DO NOT REDISTRIBUTE THIS PLUGIN OR ANY OF ITS MODIFICATIONS. PEMapModder UPHOLDS ALL RIGHTS TO USE IT.
    PHP:
    <?php
    /*
    __PocketMine Plugin__
    author=PEMapModder
    name=DST_API
    description=DynamicSignTechnology API
    apiversion=10,11
    version=0.0.0.0
    class=DSTLoadable
    */
    /*
    @Copyright 2014 PEMapModder
    @author PEMapModder
    Do not redistribute this plugin or any modifications of it.
    However, you can make plugins that call function in this plugin by:
        ServerAPI::request()->api->plugin->get("DST_API")->registerDS(...)
    */
    /*
    ChangeLog
    Edition    |    Version    |    Build    |    Testant    |    Description
    0(alpha)|    0        |    0        |    0        |    Initial commit: only functions
                            1        |    0        |    Changed to an API-like thing
    */
    class DSTAPI implements Plugin{
        
    ////API////
        
    private $api,$b,$c,$p,$t,$pn,$s;
        
    ////DB////
        
    private $cfg;
        private 
    $db;
        
    ////RAM////
        
    private $signsUpdate=array();
    /*    public $dummyDsFullChange=array(
            "pos"=>new Position(0,0,0,LevelAPI::get("world")),
            "status"=>0,
            "partialLines"=>false,
            "texts"=>array(
                array(
                    "line0",
                    "line1",
                    "line2",
                    "line3"
                ),
                array(
                    "line0",
                    "line1",
                    "line2",
                    "line3"
                )
            )
        );
        public $dummyDsPartialChange=array(
            "pos"=>new Position(1,1,1,LevelAPI::get("world")),
            "status"=>0,
            "partialLines"=>true,
            "texts"=>array(
                array(
                    "line0",
                    "line1",
                    "line2",
                    "line3"
                ),
                array("newLine0","newLine1")
            )
        );
    */
        
    public function __construct(ServerAPI $a,$s=0){//**PMStuff
            
    $this->api=$a;
            
    $this->b=$a->block;
            
    $this->c=$a->console;
            
    $this->p=$a->player;
            
    $this->t=$a->tile;
            
    $this->pn=$a->plugin;
        }
        public function 
    init(){//**PMStuff
            
    $this->s=ServerAPI::request();
            
    $this->initCmds();
            
    $this->initEvts();
            
    $this->s->schedule(20,array($this,"secondTick"));
            
    $this->cfg=new Config($this->pn->configPath($this)."config.yml",CONFIG_YAML,array(
               
            ));
            
    $this->db=new Config($this->pn->configPath($this)."database.yml",CONFIG_YAML,array(
                
    "DSs"=>array()
            ));
            
    $dss=$this->db->get("DSs");
            if(
    $dss!==array())$this->importDSs($dss);
            
    $this->s->dhandle("dst.inited",array());
        }
        public function 
    __destruct(){//**PMStuff
            
    $this->save();
        }
        public function 
    initCmds(){//**PMStuff
           
        
    }
        public function 
    initEvts(){//**PMStuff
            
    $this->s->addHandler("player.block.touch",array($this,"evH"));
            
    $this->s->addHandler("dst.signdestroy",array($this,"evH"),1);
        }
        public function 
    secondTick(){//**PMStuff
            
    $this->updateSigns();
        }
        public function 
    importDss($dss){//**I/O utils
            
    foreach($dss as $ds){
                
    $p=$ds["pos"];
                
    $o=$ds;
                
    $o["pos"]=new Position($p[0],$p[1],$p[2],$p[3]);
                
    $this->signsUpdate[]=$o;
            }
        }
        public function 
    save(){//**I/O utils
            
    $out=array();
            foreach(
    $this->signsUpdate as $ds){
                
    $arr=$ds;
                
    $arr["pos"]=array($ds["pos"]->x,$ds["pos"]->y,$ds["pos"]->z,$ds["pos"]->level);
                
    $out[]=$arr;
            }
            
    $this->db->set("DSs",$out);
        }
        public function 
    updateSigns(){//**DST
            
    foreach($this->signsUpdate as $ds){
                if(!
    $ds["partialLines"]){
                    
    $ds["status"]++;
                    
    $l=$ds["texts"][$ds["status"]];
                    
    $this->t->get($ds["pos"])->setText($l[0],$l[1],$l[2],$l[3]);
                    continue;
                }
                
    $ds["status"]++;
                
    $l=$ds["texts"][0];
                foreach(
    $ds["texts"][1] as $line=>$text){
                    
    $l[($ds["status"]+$line)%4]=$text;
                }
                
    $this->t->get($ds["pos"])->setText($l[0],$l[1],$l[2],$l[3]);
            }
        }
        public function 
    registerDS(Position $pos,$extras,$isPartial=false){//**DST
            
    if($isPartial===false and count($extras)!==4)
                return 
    "INVALID_PARAMS:arg2 does not match arg1";
            if(
    count($extras)>4)
                return 
    "INVALID_PARAMS:arg1 too large";
            if(!isset(
    $this->t->get($pos)->data["Text1"]))return "$pos not a texts-defined tile";
            
    $texts=array($this->t->get($pos)->getText());
            foreach(
    $extras as $extra){
                
    $texts[]=$extra;
            }
            
    $this->signsUpdate[]=array("pos"=>$pos,"status"=>0,"partialLines"=>$isPartial,"texts"=>$texts);
        }
        public function 
    evH($d,$e){//
            
    switch($e){
                case 
    "player.block.touch":
                    if(
    $d["type"]==="break" and ($d["target"] instanceof SignPostBlock)){
                        foreach(
    $this->signsUpdate as $key=>$ds){
                            if(
    $ds["pos"]->x===$d["target"]->and
                                    
    $ds["pos"]->y===$d["target"]->and
                                    
    $ds["pos"]->z===$d["target"]->and
                                    
    $ds["pos"]->level===$d["target"]->level){
                                return 
    $this->onDestroySign($ds["pos"],$d["player"]);
                            }
                        }
                    }
                break;
                case 
    "dst.signdestroy":
                    
    $this->checkPower($d["player"]);
                break;
            }
        }
        public function 
    onDestroySign(Position $pos,Player $player){//**DST
            
    $handled=$this->s->handle("dst.signdestroy",array("pos"=>$pos,"player"=>$player));
            if(
    $handled!==true)return $handled;
           
        }
        public function 
    checkPower(Position $pos,Player $player){
            if(
    $this->checkPP()===false)return in_array($player->usernameexplode("\n"file_get_contents(FILE_PATH."ops.txt")));
            return 
    $this->s->dhandle("get.player.permission",$player->username);
        }
        public function 
    checkPP(){
            foreach(
    $this->pn->getList() as $p){
                if(
    $p["name"]==="PermissionsPlus" and $p["author"]==="Omattyao")return true;
            }
            return 
    false;
        }
    }
  8. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    that looks like a good API:)
  9. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Last edited: Jan 15, 2014
  10. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    so how would I make this dynamic?
    PHP:
    $data->setText(".count($this->api->player->getAll())."/".$this->server->maxClients));
    would I do
    PHP:
    $tile->setText(".count($this->api->player->getAll())."/".$this->server->maxClients));
  11. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    PHP:
    <?php

    /* 
    __PocketMine Plugin__ 
    name=SignPro
    description= Live Signs at its best!
    version=1.0
    author=NIM
    class=Sign
    apiversion=11
    */

    class Sign implements Plugin{
        private 
    $api$server;
        public function 
    __construct(ServerAPI $api$server false){
            
    $this->api $api;
        }

        public function 
    init(){
            
    $this->api->addHandler("tile.update", array($this"eventHandler"),);
            
    $this->api->schedule(5*20,array($this,"UpdateSign"),array(),true);
        }

        public function 
    eventHandler($data){
                    if (
    $data->class === TILE_SIGN) {
                        if (
    $data->data['Text1'] === "SignPro" || $data->data["Text1"] === (count($this->api->player->getAll())."/".$this->server->maxClients)["Line 1"]){
                                }
                            }
                         }
                            public function 
    UpdateSign(){
            if(isset(
    $this->sign)){
                
    $this->sign->setText(count($this->api->player->getAll())."/".$this->server->maxClients)["Line 1"]);
            }
        }
                       public function 
    __destruct(){
        }
    }
    @Glitchmaster_PE I looked at your plugin for some help, I added the update function, should the sign be live now?
  12. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Just run it and you would see that it doesn't work.
    You use $this->sign->setText, but you never define $this->sign
    Last edited: Jan 18, 2014
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The most serious issue is, do not use so generic names like Sign. If everyone uses it, plugin loading WILL fail
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I mean the class name.

    Or someone should make a class name list for plugins?

    Because then you will understand why the online plugin generator generates classes names with random/sequential numbers.

    Although there is no class in the source called Sign. Only Tile and SignPostBlock and WallSignBlock.
  15. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    Whats Should I name it? I think tile will be good, but what else is wrong with the plugin, I will put the updated version up.
  16. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=SignPro
    description= Live Signs at its best!
    version=1.0
    author=NIM
    class=LiveSign
    apiversion=11
    */

    class LiveSign implements Plugin{

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

        public function 
    init(){
            
    $this->api->addHandler("tile.update", array($this"eventHandler"), 10);
            
    $this->api->schedule(5*20,array($this,"UpdateSign"),array(),true);
        }

        public function 
    eventHandler($data){
                    if (
    $data->class === TILE_SIGN) {
                        if (
    $data->data['Text1'] === "SignPro" || $data->data["Text1"] === (count($this->api->player-            >getAll())."/".$this->server->maxClients)["Line 1"]){
                                }
                            }
                         }
                            public function 
    UpdateSign(){
            if(isset(
    $this->sign)){
                
    $this->sign->setText(count($this->api->player->getAll())."/".$this->server->maxClients)["Line 1"]);
            }
        }
                       public function 
    __destruct(){
        }
    }
    Last edited: Jan 18, 2014
  17. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Tile already exists. Use LiveSign or something similar
  18. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    Fixed! What else is wrong? I think I will be able to release it soon.
  19. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    A lot.
    For example you never defined $this->sign
    Take a look at @Glitchmaster_PE his dynamicsigns plugin.
  20. NIM
    Offline

    NIM Active Member

    Joined:
    Nov 28, 2013
    Posts:
    74
    Minecraft User:
    NIMGamingPRO
    Can you name everything that needs fixed? And I don't think Glitch defined it, I will look a again.

Share This Page

Advertisement