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

Correct my code please

Comments in 'Plugin Development' started by Flabe, Jan 21, 2016.

  1. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    Hello guys i tried to use this code but it crashes , is there any mistakes?? Can anyone correct me please?
    PHP:
    <?php
    namespace Oleg;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Player;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\level\Explosion;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\level\particle\EnchantmentTableParticle;
    use 
    pocketmine\inventory\PlayerInventory;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\entity\FallingSand;
    use 
    pocketmine\nbt\NBT;
    use 
    pocketmine\nbt\tag\Compound;
    use 
    pocketmine\nbt\tag\Double;
    use 
    pocketmine\nbt\tag\Enum;
    use 
    pocketmine\nbt\tag\Float;
    use 
    pocketmine\nbt\tag\Int;
    use 
    pocketmine\nbt\tag\Short;
    use 
    pocketmine\nbt\tag\String;
    use 
    pocketmine\event\entity\ExplosionPrimeEvent;
    use 
    pocketmine\event\player\PlayerDropItemEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\entity\DroppedItem;
    use 
    pocketmine\entity\Human;
    use 
    pocketmine\entity\Item;
    use 
    pocketmine\level\particle\LavaParticle;


    class 
    PixelTryPlugin extends PluginBase implements Listener{
     public 
    $disableBreak false;
     public 
    $disablePlace false;
     public function 
    onEnable(){$this->getLogger()->info("Плагин Pixelinfo запуск........");$this->getServer()->getPluginManager()->registerEvents($this,$this);
     }
     public function 
    onDisable(){$this->getLogger()->info("Плагин Pixelinfo отключение........");
     }
     public function 
    onEvent(PlayerInteractEvent $event)
     {
     foreach ( 
    $this->getServer ()->getOnlinePlayers () as $playrs){$player $event->getPlayer();
     if(
    $event->getAction() == PlayerInteractEvent::RIGHT_CLICK_AIR){
     if(
    $player->getInventory()->getItemInHand()->getId() == 1) {$speed 0.83;$pos $player->getPosition();$dir $player->getDirectionVector();$frontPos $player->add($player->getDirectionVector()->multiply(1));$dir->$dir->$speed;$dir->$dir->$speed;$dir->$dir->$speed;$item Item::get(Item::STONE);$itemTag NBT::putItemHelper($item);$itemTag->setName("Item");$nbt =
     new 
    Compound("",
     [
    "Pos" => new Enum("Pos",
     [new 
    Double(""$frontPos->x),
     new 
    Double(""$frontPos->y+1),
     new 
    Double(""$frontPos->z)]),"Motion" => new Enum("Motion",
     [new 
    Double("",$dir->x),
     new 
    Double("",$dir->y),
     new 
    Double("",$dir->z)]),"Rotation" => new Enum("Rotation",
     [new 
    Float(""0),
     new 
    Float(""0)])]);Entity::createEntity("Item",$pos->getLevel()->getChunk($pos->>> 4$pos->>> 4),$nbt)->spawnTo($playrs);
     }
     }
     }
     }
    }
    ?>
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    SHOW The crashdump
  3. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    PHP:
    ErrorCall to undefined method pocketmine\entity\Item::get()
    File: /PixelTryPlugin/src/Oleg/PixelTryPlugin
    Line
    60
    Type
    E_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN
    PixelTryPlugin v0.2

    Code
    :
    [
    51]         if($event->getAction() == PlayerInteractEvent::RIGHT_CLICK_AIR){
    [
    52]             if($player->getInventory()->getItemInHand()->getId() == 46) {
    [
    53]         $speed 0.83;
    [
    54]         $pos $player->getPosition();
    [
    55]         $dir $player->getDirectionVector();
    [
    56]         $frontPos $player->add($player->getDirectionVector()->multiply(1));
    [
    57]         $dir->$dir->$speed;
    [
    58]         $dir->$dir->$speed;
    [
    59]         $dir->$dir->$speed;
    [
    60]         $item Item::get(Item::STONE);
    [
    61]         $itemTag NBT::putItemHelper($item);
    [
    62]         $itemTag->setName("Item");
    [
    63]         $nbt =
    [
    64]             new Compound("",
    [
    65]                          ["Pos" => new Enum("Pos",
    [
    66]                             [new Double(""$frontPos->x),
    [
    67]                                 new Double(""$frontPos->y+1),
    [
    68]                                 new Double(""$frontPos->z)]),
    [
    69]                             "Motion" => new Enum("Motion",
    [
    70]                             [new Double("",$dir->x),

    Backtrace:
    #0 (): pocketmine\Server->crashDump(boolean)

    PocketMine-MP version1.7dev #15 [Protocol 38; API 1.13.1]
    Git commit0000000000000000000000000000000000000000
    uname 
    -aLinux pe2.24serv.pro 3.10.0-327.3.1.el7.x86_64 #1 SMP Wed Dec 9 14:09:15 UTC 2015 x86_64
    PHP Version5.6.2
    Zend version
    2.6.0
    OS 
    Linuxlinux
  4. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    Here you are)))
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    many useless imports,
    replace
    PHP:
    use pocketmine\entity\Item
    //to
    use pocketmine\item\Item;
    PEMapModder and applqpak like this.
  6. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    because its edited code all the imports are used in original code
  7. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    PHP:
    2016-01-21 [21:59:32] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'PixelTryPlugin v0.2': Argument 1 passed to pocketmine\utils\BinaryStream::putSlot() must be an instance of pocketmine\item\Item, null given, called in phar:///home/servs/srv3000/PocketMine-MP.phar/src/pocketmine/network/protocol/AddItemEntityPacket.php on line 43 and defined on Oleg\PixelTryPlugin"
    2016-01-21 [21:59:32] [Server thread/NOTICE]: InvalidArgumentException"Argument 1 passed to pocketmine\utils\BinaryStream::putSlot() must be an instance of pocketmine\item\Item, null given, called in phar:///home/servs/srv3000/PocketMine-MP.phar/src/pocketmine/network/protocol/AddItemEntityPacket.php on line 43 and defined" (E_RECOVERABLE_ERRORin "/src/pocketmine/utils/BinaryStream" at line 219
  8. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    not all.
  9. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    its the code i am using just don't care
    do you know why is the error?
  10. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    You can't expect to make a working plugin if you don't know PHP. codecademy.com can teach you php, then learn the PM API, copying code from other plugins isn't the answer.
    applqpak and PocketKiller like this.
  11. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Ugh... You don't care with your code? xD
    applqpak and PocketKiller like this.
  12. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    i learnt all lessons on codecademy i know php and oop i just trying to make some code and i don't know where to learn PM API i looked in other people plugins and on pocketmine's github and this code is just from pocket mine and other added is mine if you can help just do it. If you can't stop saying Learn php
  13. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    i said i am using code that i posted now.
  14. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    applqpak likes this.
  15. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    I honestly don't believe you. How can you PHP if you can't grammar?
    Hotshot_9930 likes this.
  16. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Lol, I can't grammar, but I can PHP -_-
    PocketKiller and XFuryMCPE like this.
  17. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    *claps* xD
    PocketKiller likes this.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    See, this is example of sams. Not the thread starters fault. I am going to reply, just wait.
  19. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    ok, thanks)
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    As a matter of fact, if you try to but cannot understand English grammar, one of the most systematic languages in the word, it is hard to believe that you can understand programming syntax.
    jojoe77777 likes this.

Share This Page

Advertisement