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

1. Offline

### FlabeActive Member

Joined:
Nov 17, 2015
Posts:
147
Minecraft User:
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. Offline ### PocketKillerNotable Member Joined: Jul 20, 2015 Posts: 741 SHOW The crashdump 3. Offline ### FlabeActive Member Joined: Nov 17, 2015 Posts: 147 Minecraft User: 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. Offline

### FlabeActive Member

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

### PocketKillerNotable 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. Offline

### FlabeActive Member

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

### FlabeActive Member

Joined:
Nov 17, 2015
Posts:
147
Minecraft User:
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. Offline

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

### FlabeActive Member

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

### XFuryMCPEActive MemberPlugin Developer

Joined:
Jun 19, 2015
Posts:
137
Plugins:
2
Minecraft User:
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. Offline

### Vaivez66Notable MemberPlugin Developer

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

### FlabeActive Member

Joined:
Nov 17, 2015
Posts:
147
Minecraft User:
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. Offline

### FlabeActive Member

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

### xBeastModeActive Member

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

### XFuryMCPEActive MemberPlugin Developer

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

### Vaivez66Notable MemberPlugin Developer

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

### XFuryMCPEActive MemberPlugin Developer

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

### Legoboy0215Notable Member

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

### FlabeActive Member

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

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
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.