Skip to content
This repository has been archived by the owner on Oct 21, 2018. It is now read-only.

Commit

Permalink
Update Area.php
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeDarling committed Jul 29, 2014
1 parent e3dd03c commit f9a268c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/LDX/iProtector/Area.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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() { }
}
Expand Down

0 comments on commit f9a268c

Please sign in to comment.