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

Why doesn't this plugin work? The worst thing is there are no errors

Comments in 'Plugin Development' started by PEMapModder, Nov 19, 2013.

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Code:
    PHP:
    #Annoying opening deleted
        
    public function toggleSync($c,$p,$player){
            if(
    sizeof($p)!==or !($player instanceof Player)){
                
    $player->sendChat("[ERROR] Wrong usage of /$c");
                return;
            }if (
    $p[0]==="on") {
                
    $this->syncs[$player->username]=true;
            }elseif (
    $p[0]==="off") {
                
    $this->syncs[$player->username]=false;
            }else{
                
    $player->sendChat("[ERROR] Wrong usage of /$c");
            }
        }
        public function 
    blockTouch(&$data){
            if(
    $data["type"]!="break")return;
            
    $player=$this->api->player->get($data["player"]);
            
    $target=$data["target"];
            
    $tX=$target->x;
            
    $tY=$target->y;
            
    $tZ=$target->z;
            
    $tLevel=$player->entity->level->getName();
            
    $tId=$target->getID();
            if(
    $tLevel==="lobby2" and $tLevel!="lobby"){#just to ensure things
                
    if($data["type"]=="break"){
                    
    $this->editBlock($tX,$tY,$tZ,$tLevel,$tId,$player);
    #                return;
                
    }
            }
        }
        public function 
    playerJoin($player){
            
    $this->syncs[$player->username]=false;
        }
        public function 
    editBlock($x,$y,$z,$level,$id=0,$player){
            if(
    $this->syncOn($player->username)===false)return;
            
    $vT=new Vector3($x,$y,$z);
            
    $vX=new Vector3(255-$x,$y,$z);
            
    $vXZ=new Vector3(255-$x,$y,255-$z);
            
    $vZ=new Vector3($x,$y,255-$z);
    //aborted        $bT=$level->getBlock($vT);
            
    $bX=$level->getBlock($vX);
            
    $bXZ=$level->getBlock($vXZ);
            
    $bZ=$level->getBlock($vZ);
        
        }
        public function 
    blockPlace(&$data,$event){
            
    $player=$data["player"];
            
    $level=$player->entity->level;
            if (
    $level->getName()==="lobby2" and $this->syncOn($player->username)===true) {
                
    $oB=$data["target"];
                
    $vT=new Vector3($oB->x,$oB->y,$oB->z);
                
    $block=$level->getBlock(new Vector3($oB->x,$oB->y,$oB->z));
                
    $vX=new Vector3(255-$block->x,$block->y,$block->z);
                
    $vXZ=new Vector3($block->x,$block->y,255-$block->z);
                
    $vZ=new Vector3(255-$block->x,$block->y,255-$block->z);
                
    $level->setBlock($vX,$block);
                
    $level->setBlock($vXZ,$block);
                
    $level->setBlock($vZ,$block);
            }
        }
        public function 
    syncOn($ign){
            return 
    $this->syncs[$ign];
        }
    init() is not provided because of its annoymous nature and that level 4096 Params not callable error message does not appear.
    The purpose of the script is explained before, although nobody answered me.

    Another question:
    Why does the error dump say "Undefined method Entity::getItem()" in here?
    The point is, $murderer isn't even instanceof Entity but should be Player!
    PHP:
    private function addKill($murderer,$victim){
            
    $mEntity=$murderer->entity;
            
    $level=$victim->entity->level;
            
    $vEntity=$victim->entity;
            
    $this->tempKill[]=array(
                
    "murderer"=>array(
                        
    "username"    =>    $murderer->usernamedd,
                        
    "x"            =>    $mEntity->x,
                        
    "y"            =>    $mEntity->y,
                        
    "z"            =>    $mEntity->z,
                        
    "level"        =>    $level->getName(),
                        
    "ip"        =>    $murderer->ip,
                        
    "port"        =>    $murderer->port
                    
    ),
                
    "item"=>$murderer->getItem(),
    #etc
    error dump:
    PHP:
    'type' => 1,
      
    'message' => 'Call to undefined method Entity::getItem()',
      
    'file' => 'C:\\PocketMineModPE\\src\\API\\PluginAPI.php(87) : eval()\'d code',
      
    'line' => 64,
    Last edited: Nov 19, 2013
  2. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    But class should be there because it wont detectt it if its plugin or something
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It would say "Plugin abc.php doesn't use the Plugin interface" or something.
    And I am pretty sure the problem is here because other functions work well.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Added another question, not to spam the forum by another thread.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I made this because I was making a griefing log plugin.
  6. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    Entity format wrong, im bad at english, english is not my native language
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Me neither, but anyway, what entity format wrong?
  8. codmadnesspro
    Offline

    codmadnesspro Notable Member Plugin Developer

    Joined:
    Sep 11, 2013
    Posts:
    552
    Plugins:
    1
    Minecraft User:
    Codmadnesspro
    Ive looked at you code and it looks alright if you add the class at beginning.
    Just found something that might be wrong is that you haven't made the ending which it self destructs
  9. Qub1
    Offline

    Qub1 New Member

    Joined:
    Nov 6, 2013
    Posts:
    16
    Minecraft User:
    Qub1
    Regarding your second question: Players are treated as instances of the Entity class, and the getItem() function doesn't exist in there, so take a look at "src/world/Entity.php" and find the function you need.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I found that out too. Idk why I tried to use that function. :D
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But if we want to get the entity class of the player we use $player->entity. What is the difference, then, if Player is treated as Entity, (and automatically changed to Entity, as I understand)?
    What self-destruct?
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And the script ran well in a previous edit of it.
  13. Qub1
    Offline

    Qub1 New Member

    Joined:
    Nov 6, 2013
    Posts:
    16
    Minecraft User:
    Qub1
    Does the server crash or is the plugin simply not loaded? If the server crashes it might be useful to check the console log, sometimes errors aren't logged in ERROR files but in the console log they are.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Everything is all right. The other parts of the script works excellently. Only this part of the function has a problem. There are no error msgs
  15. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    Their is no function that will return the item that the player is holding, but you can use
    $murderer->getSlot($murderer->slot), and $murder needs to be the player object not the entity !

Share This Page

Advertisement