From f9a268c11ba4e050719f9095e93fcede60d96a26 Mon Sep 17 00:00:00 2001 From: Luke Darling Date: Tue, 29 Jul 2014 11:18:22 -0400 Subject: [PATCH] Update Area.php --- src/LDX/iProtector/Area.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/LDX/iProtector/Area.php b/src/LDX/iProtector/Area.php index 771dd38..085a6ad 100644 --- a/src/LDX/iProtector/Area.php +++ b/src/LDX/iProtector/Area.php @@ -2,13 +2,14 @@ namespace LDX\iProtector; use pocketmine\math\Vector3; class Area { - public function __construct($data) { + public function __construct($data,$plugin) { $this->name = strtolower($data["name"]); $this->flags = $data["flags"]; - $this->pos1 = $data["pos"][0]; - $this->pos2 = $data["pos"][1]; - $this->plugin = $data["plugin"]; + $this->pos1 = new Vector3($data["pos1"][0],$data["pos1"][1],$data["pos1"][2]); + $this->pos2 = new Vector3($data["pos2"][0],$data["pos2"][1],$data["pos2"][2]); + $this->plugin = $plugin; $this->save(); + $this->plugin->saveAreas(); } public function getName() { return $this->name; @@ -21,6 +22,8 @@ public function getFlag($flag) { } public function setFlag($flag,$value) { $this->flags[$flag] = $value; + $this->save(); + $this->plugin->saveAreas(); return $value; } public function contains($ppos) { @@ -32,23 +35,22 @@ public function contains($ppos) { } public function toggleFlag($flag) { $this->flags[$flag] = !$this->flags[$flag]; + $this->save(); + $this->plugin->saveAreas(); return $this->flags[$flag]; } - public function getPos() { - return array($this->pos1,$this->pos2); - } public function getData() { - return array("name" => $this->name,"flags" => $this->flags,"pos" => $this->getPos()); + return array("name" => $this->name,"flags" => $this->flags,"pos1" => array($this->pos1->getX(),$this->pos1->getY(),$this->pos1->getZ()),"pos2" => array($this->pos2->getX(),$this->pos2->getY(),$this->pos2->getZ())); } public function save() { $this->plugin->areas[$this->name] = $this; $this->plugin->areadata[$this->name] = $this->getData(); - $this->plugin->saveAreas(); } public function delete() { $name = $this->getName(); unset($this->plugin->areas[$name]); - unlink($this->plugin->getDataFolder() . "areas/$name.yml"); + unset($this->plugin->areadata[$name]); + $this->plugin->saveAreas(); } public function __destruct() { } }