Hay, i have plugin on drop in stone. My code iś crash on line (rand) PHP: <?phpnamespace Flsmers;use pocketmine\plugin\PluginBase as P;use pocketmine\event\Listener as L;use pocketmine\utils\TextFormat;use pocketmine\utils\MainLogger;use pocketmine\event\block\BlockBreakEvent;use pocketmine\block\Block;use pocketmine\math\Vector3;use pocketmine\item\Item;class Main extends P implements L{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this,$this); $this->saveDefaultConfig(); $this->getServer()->getLogger()->info("Włączono - Drop"); } public function onBreak(BlockBreakEvent $e){ $p = $e->getPlayer(); $block = $e->getBlock(); $gracz = $e->getPlayer()->getName(); if($e->getBlock()->getId() == 1){ switch(rand(1,80) == 80)){ $p->sendMessage(" • [DROP] Znalazłeś - (1) Węgiel • "); $p->setDrops(array(Item:get(2, 4 ,2))); break; } } else{ } if($e->getBlock()->getId() == 1){ switch(rand(1,80) == 80)){ $p = $e->getPlayer(); $p->sendMessage(" • [DROP] Znalazłeś - (3) Węgiel • "); $p->setDrops(array(Item:get(2, 4 ,4))); break; } } else{ }
Edited PHP: <?phpnamespace Flsmers;use pocketmine\plugin\PluginBase; // why not try the easy wayuse pocketmine\event\Listener; // why not try the easy wayuse pocketmine\utils\TextFormat;use pocketmine\utils\MainLogger; // no such thing, use this:// use pocketmine\Server;use pocketmine\event\block\BlockBreakEvent;use pocketmine\block\Block;use pocketmine\math\Vector3;use pocketmine\item\Item;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this,$this); $this->saveDefaultConfig(); $this->getServer()->getLogger()->info("Włączono - Drop"); } public function onBreak(BlockBreakEvent $e){ $p = $e->getPlayer(); $block = $e->getBlock(); $gracz = $e->getPlayer()->getName(); if($e->getBlock()->getId() == 1){ switch(rand(1,80) == 80)){ $p->sendMessage(" • [DROP] Znalazłeś - (1) Węgiel • "); $p->setDrops(array(Item:get(2, 4 ,2))); break; } } else{ } if($e->getBlock()->getId() == 1){ switch(rand(1,80) == 80)){ $p = $e->getPlayer(); $p->sendMessage(" • [DROP] Znalazłeś - (3) Węgiel • "); $p->setDrops(array(Item:get(2, 4 ,4))); break; } } else{ } } // you forgot to close this} // closes Class
Using aliases is not a difficult way. It may make classes less readable, but this makes it easier to read and to write for the person who wrote it.