I have a problème with m'y code and console dont display error Already thank Code: https://pastebin.com/zy565y9n What I am trying to do: If a player is OP and in the world "world" then the player can break or place blocks The default player can not break blocks or place If there are players in world "world" then they may not be able to strike even if this one is OP
This should work: PHP: <?phppublic function onPlace(BlockPlaceEvent $event) { if (($player = $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) { $player->sendMessage("You aren't allowed to place blocks here!"); $player->getLevel()->addSound( new FizzSound( $player->getLocation())); $event->setCancelled(); }}public function onBreak(BlockPlaceEvent $event) { if (($player = $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) { $player->sendMessage("You aren't allowed to break blocks here!"); $player->getLevel()->addSound( new FizzSound( $player->getLocation())); $event->setCancelled(); }}public function onDamage(EntityDamageEvent $event) { if ($event->getEntity()->getLevel()->getName() === "world") { $event->setCancelled(); }}?>
But with this code: https://pastebin.com/NBC2fpKp Only the default players can place and break blocks while the OP can not
Because setCancelled(true) means you set it cancelled, while using setCancelled(false) means you explicitely uncancel it.
OP players can break or set blocks but they receive the message to the non-OP player. $player->sendMessage("You aren't allowed to break blocks here!"); $player->getLevel()->addSound( new FizzSound( $player->getLocation()));
PHP: public function onPlace(BlockPlaceEvent $event) { if(($player = $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) { // Checks if player is in level "world" and if player is NOT OP. $event->setCancel(true); // Cancel it because the player is NOT OP. $player->sendMessage(TextFormat::RED. "Vous ne pouvez rien placer!"); }else{ // Checks if player is in Level "world" and if the player IS OP. // $event->setCancelled(true); don't cancel the event as the player IS OP! } } public function onBreak(BlockBreakEvent $event) { if(($player = $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) { $event->setCancelled(true); $player->sendMessage(TextFormat::RED. "Vous ne pouvez rien casser!"); }else{ // $event->setCancelled(true); } }
2017-08-24 [11:56:57] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\block\BlockPlaceEvent' to 'HenoriaCore v1': Call to undefined method pocketmine\event\block\BlockPlaceEvent::setCancel() on armagadon\C 2017-08-24 [11:56:57] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\event\block\BlockPlaceEvent::setCancel()" (EXCEPTION) in "/plugins/HenoriaCoreSAVE/src/armagadon/C" at line 72 Fonction: }else{ // Checks if player is in Level "world" and if the player IS OP. // $event->setCancelled(true); don't cancel the event as the player IS OP!
Typo error, check your spelling at line 72 Spoiler It's PHP: $event->setCancelled(); and not PHP: $event->setCancel();
Development isn't magic. You can't just call any function you want and think it will work. Google could've easily answered that specific non-pocketmine issue you are facing. Why wait for someone to help you out when you can instantly get your answers from Google? I'm not targeting anyone specifically. I've come across many who think PHP errors can only be solved by posting them on the PocketMine forums. Just read the error. The solution is reading the error. It's not an error code. PHP is helping you by telling you whats wrong. What do you understand from the error? Call to undefined method pocketmine\event\block\BlockPlaceEvent::setCancel()
Also, you should use an IDE with the pocketmine src included so it will tell you about this kind of error and others as you type, or copy/paste...