Hello everyone my code to get worlds in array doesnt work help me please here is my code PHP: public function getArenas() { array ("GD1", "GD2", "GD3". "GDHub"); } public function onBreak(BlockBreakEvent $e) { $p = $e->getPlayer(); if($p->getLevel()->getName() == $this->getArenas()) { $e->setCancelled(""); $p->sendMessage(Color::GREEN . "You can not break blocks!"); }}
Oh nevermind I already found out. You just make an array with the function getArenas, but you don't return it. Make the function do this: PHP: return array(/*blablabla*/);
Do not work PHP: public function getArenas(){ return array("GD1", "GD2", "GD3", "GDHub");}public function onBreak(BlockBreakEvent $e){ $p = $e->getPlayer(); if (in_array($p->getLevel()->getName(), $this->getArenas())) { $e->setCancelled(); $p->sendMessage(Color::GREEN . "You can not break blocks!"); }}
This should work: PHP: public function onBreak(BlockBreakEvent $event) { $player = $event->getPlayer(); $world = $player->getLevel()->getFolderName(); if (in_array($world, $this->worlds)) { $event->setCancelled(TRUE); } } *Create a public array with your worlds PHP: public $worlds = array();
PHP: ...class Main extends PluginBase implements Listener{ public $worlds = array("1", "world2"...); public function onEnable() {...public function onBreak(BlockBreakEvent $event) { $player = $event->getPlayer(); $world = $player->getLevel()->getFolderName(); if (in_array($world, $this->worlds)) { $event->setCancelled(TRUE); } }
PHP: ...class Main extends PluginBase implements Listener{ public $worlds = array("1", "world2"...); public function onEnable() {...public function onBreak(BlockBreakEvent $event) { $player = $event->getPlayer(); $world = $player->getLevel()->getFolderName(); if (in_array($world, $this->worlds)) { $event->setCancelled(TRUE); } }[QUOTE="VentroxStudio, post: 5952, member: 349"][PHP]...class Main extends PluginBase implements Listener{ public $worlds = array("1", "world2"...); public function onEnable() {...public function onBreak(BlockBreakEvent $event) { $player = $event->getPlayer(); $world = $player->getLevel()->getFolderName(); if (in_array($world, $this->worlds)) { $event->setCancelled(TRUE); } } [/QUOTE] Do you used it like this?
PHP: public function onBreak(BlockBreakEvent $e){ $p = $e->getPlayer(); $world = $p->getLevel()->getFolderName(); //if (in_array($p->getLevel()->getName(), $this->getArenas())) { if (in_array($world, $this->worlds)) { $e->setCancelled(); $p->sendMessage(Color::GREEN . "You can not break blocks!"); }}