Help me i try $this->IronFarm($sender); but it didnt work! <?php namespace ZackyVNTM; use pocketmine\plugin\PluginBase; use pocketmine\utils\Config; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\event\block\BlockUpdateEvent; use pocketmine\item\Item; use pocketmine\event\Listener; use pocketmine\level\Level; use pocketmine\block\Block; use pocketmine\block\DiamondOre; use pocketmine\block\EmeraldOre; use pocketmine\block\Stone; use pocketmine\block\Water; use pocketmine\block\Fence; class Main extends PluginBase implements Listener{ public function onEnable () : void{ $this->getServer()->getLogger()->info("§l[§aUpgrade§r§l]§a Đã bật!"); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool{ if(!$sender instanceof Player){ $sender->sendMessage("§l[§aUpgrade§r§l]§r§c Vào máy chủ để chơi "); return false; } if($cmd == "upgrade"){ if(empty($args[0])){ $sender->sendMessage ("§c->§e Farms§a Upgrade§c <-"); $sender->sendMessage ("§lIron - 10 Coins"); return true; } if(!empty($args[0])){ switch($args[0]){ case "iron": $sender->sendMessage("§l[§aUpgrade§r§l]§a Bạn đã mua thành công Iron farms!"); $this->IronFarm($sender); break; default: $sender->sendMessage ("§c->§e Farms§a Upgrade§c <-"); $sender->sendMessage ("§lIron - 10 Coins"); break; } } } return true; } public function IronFarm(BlockUpdateEvent $event){ $block = $event->getBlock(); $water = false; $fence = false; for($i = 2; $i <= 5; $i++) { $nearBlock = $block->getSide($i); if ($nearBlock instanceof Water) { $water = true; }elseif($nearBlock instanceof Fence) { $fence = true; } if ($water && $fence) { $id = mt_rand(1, 3); switch($id){ case 50; $newBlock = new DiamondOre(); break; case 49; $newBlock = new EmeraldOre(); break; default: $newBlock = new Stone(); } $ironfarm = $event->getPlayer()->getBlock()->getLevel()->setBlock($block, $newBlock, true, false); return; } } } }
PHP: <?phpnamespace ZackyVNTM;use pocketmine\plugin\PluginBase;use pocketmine\utils\Config;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\ConsoleCommandSender;use pocketmine\math\Vector3;use pocketmine\Player;use pocketmine\event\block\BlockUpdateEvent;use pocketmine\item\Item;use pocketmine\event\Listener;use pocketmine\level\Level;use pocketmine\block\Block;use pocketmine\block\DiamondOre;use pocketmine\block\EmeraldOre;use pocketmine\block\Stone;use pocketmine\block\Water;use pocketmine\block\Fence;class Main extends PluginBase implements Listener{public function onEnable () : void{$this->getServer()->getLogger()->info("§l[§aUpgrade§r§l]§a Đã bật!");$this->getServer()->getPluginManager()->registerEvents($this, $this);}public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool{if(!$sender instanceof Player){$sender->sendMessage("§l[§aUpgrade§r§l]§r§c Vào máy chủ để chơi :D");return false;}if($cmd == "upgrade"){if(empty($args[0])){$sender->sendMessage ("§c->§e Farms§a Upgrade§c <-");$sender->sendMessage ("§lIron - 10 Coins");return true;}if(!empty($args[0])){switch($args[0]){case "iron":$sender->sendMessage("§l[§aUpgrade§r§l]§a Bạn đã mua thành công Iron farms!");$this->IronFarm($sender);break;default:$sender->sendMessage ("§c->§e Farms§a Upgrade§c <-");$sender->sendMessage ("§lIron - 10 Coins");break;}}}return true;}public function IronFarm(BlockUpdateEvent $event){$block = $event->getBlock();$water = false;$fence = false;for($i = 2; $i <= 5; $i++) {$nearBlock = $block->getSide($i);if ($nearBlock instanceof Water) {$water = true;}elseif($nearBlock instanceof Fence) {$fence = true;}if ($water && $fence) {$id = mt_rand(1, 3);switch($id){case 50;$newBlock = new DiamondOre();break;case 49;$newBlock = new EmeraldOre();break;default:$newBlock = new Stone();}$ironfarm = $event->getPlayer()->getBlock()->getLevel()->setBlock($block, $newBlock, true, false);return;}}}}
of course this won't work, you are passing a CommandSender to a function that wants a BlockUpdateEvent.