Hi! I'm fixing and changing stuffs on this WorldBorder plugin, i need help with the config.. Thanks PHP: <?phpnamespace WorldBorder;use pocketmine\plugin\PluginBase;use pocketmine\utils\TextFormat;use pocketmine\Player;use pocketmine\Server;use pocketmine\utils\Config;use pocketmine\level\Position;use pocketmine\level\Level;use pocketmine\block\Block;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\event\Listener;use pocketmine\math\Vector3 as Vector3;use pocketmine\math\Vector2 as Vector2;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\block\BlockPlaceEvent;class WorldBorder extends PluginBase implements Listener{ public $config; public $spawn; public function onEnable(){ @mkdir($this->getDataFolder()); $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML, [ "message" => "This is end of world" ]); $this->getLogger()->info(TextFormat::DARK_GREEN."WorldBorder Loaded!"); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onDisable(){ $this->getLogger()->info(TextFormat::DARK_RED."WorldBorder Unloaded!"); } public function onCommand(CommandSender $sender, Command $command, $label, array $args){ switch (strtolower($command->getName())) { case "worldborder": if ($sender->hasPermission("worldborder.command.worldborder")) { if (isset($args[0])) { switch (strtolower($args[0])) { case "add": if (isset($args[1]) && isset($args[2])) { if ($this->getServer()->isLevelLoaded($args[1])) { $worlds = $this->config->get("worlds"); //if ($args[2] > 199) { $this->config->set($args[1], ['blocks' => $args[2]]); $this->config->save(); $sender->sendMessage("[WorldBorder] You border world: ".$args[1]." in: ".$args[2]." blocks."); //} else { //$sender->sendMessage("[WorldBorder] Your block should be more than 200 to prevent lag!"); //} } } return true; break; } } else { $sender->sendMessage("[WorldBorder] /worldborder add [world] [blocks]"); } } return true; break; } } public function checkBorder($player, $e, $p) { $level = $this->getServer()->getLevelByName($player["level"]); $t = new Vector2($player["x"], $player["z"]); $s = new Vector2($level->getSpawnLocation()->getX(), $level->getSpawnLocation()->getZ()); if ($this->config->get($level) === true) { echo "Yep"; $cfg = $this->config->getAll(); return $cfg[$level]; } else { echo "Not found"; } } public function onPlayerMove(PlayerMoveEvent $event){ $player = $event->getPlayer(); $p = $event->getPlayer(); if($player instanceof Player){ $border = $this->checkBorder(array("level" => $player->getLevel()->getName(), "x" => round($player->getX()), "z" => round($player->getZ())), $event, $p); if($border && !$player->hasPermission("worldborder.event.worldborder")){ $event->setCancelled(true); $player->sendMessage("[WorldBorder] ".$this->config->get("message")); } } } public function onBlockPlace(BlockPlaceEvent $event){ $block = $event->getBlock(); $p = $event->getPlayer(); if($block instanceof Block){ $border = $this->checkBorder(array("level" => $block->getLevel()->getName(), "x" => round($block->getX()), "z" => round($block->getZ())), $event, $p); if($border && !$event->getPlayer()->hasPermission("worldborder.event.worldborder")){ $event->setCancelled(true); $event->getPlayer()->sendMessage("[WorldBorder] ".$this->config->get("message")); } } } public function onBlockBreak(BlockBreakEvent $event){ $block = $event->getBlock(); $p = $event->getPlayer(); if($block instanceof Block){ $border = $this->checkBorder(array("level" => $block->getLevel()->getName(), "x" => round($block->getX()), "z" => round($block->getZ())), $event, $p); if($border && !$event->getPlayer()->hasPermission("worldborder.event.worldborder")){ $event->setCancelled(true); $event->getPlayer()->sendMessage("[WorldBorder] ".$this->config->get("message")); } } } } Error: Code: Illegal offset type in isset or empty in phar://C:/Users/RTG/Desktop/TesterUnit/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 383 Not found
WTF? Seems like you don't understand PocketMine configs yet. Also this is in wrong section, should be in the facepalm section.
I believe the problem lies in you trying to Config->get a Level object in your checkBorder method. How can a Config file store an object? You probably meant to Config->get the Level's name, not the Level object. It's a simple fix, just use $player["level"] in your Config search instead of $this->getServer()->getLevelByName($player["level"])..
PocketMine though, phar://C:/Users/RTG/Desktop/TesterUnit/PocketMine-MP.phar/src/pocketmine/utils/Config.php on line 383
Please tell us where the error occurred in which line and please tell us everything so we dont need to go through the ask and respond sequence when you could have just provided it
sorry then, it's a illegal array accessing say $array = [1=>1,2=>2]; i do $array[3] that should cause the error try using isset before accessing it like is set $array[3] before actually accessing it
The error tells you that you are not passing the correct arguments to a pocketmine function. As Corytortoise says, the $level in $this->config->get($level) is an object returned by getLevelByName(), whereas you need to pass the level name to config->get() as a string. There might be other errors too, I haven't checked, but that needs fixing first!
There's no need to pass that $player array at all since you pass the Player object which contains all the data you need in checkBorder. As for calling that array $player... that's a terrible name for what is essentially a Position.
Honest question: Why? Why should he use it? How is it better? OP, I think Awzaw explained what I meant pretty well, but if you still need an example, I would be glad to provide one. While this might not cause errors, I discourage passing an Event object to your checkBorder method unnecessarily.