Skip to content

Commit

Permalink
Fixed land protection is malfunctioning
Browse files Browse the repository at this point in the history
  • Loading branch information
onebone committed Oct 12, 2014
1 parent c34e83a commit 9ebdb80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
21 changes: 13 additions & 8 deletions EconomyLand/src/onebone/economyland/EconomyLand.php
Expand Up @@ -378,6 +378,7 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $pa
$player = $this->getServer()->getPlayer($username);
if(!$player instanceof Player){
$sender->sendMessage($this->getMessage("player-not-connected", [$username, "%2", "%3"]));
return true;
}
// $info = $this->land->query("SELECT * FROM land WHERE ID = $landnum")->fetchArray(SQLITE3_ASSOC);
$info = $this->db->getLandById($landnum);
Expand Down Expand Up @@ -552,17 +553,21 @@ public function permissionCheck(BlockEvent $event){
$exist = false;
//$result = $this->land->query("SELECT owner,invitee FROM land WHERE level = '$level' AND endX > $x AND endZ > $z AND startX < $x AND startZ < $z");
//if(!is_array($info)) goto checkLand;
if(($info = $this->db->canTouch($x, $z, $level, $player)) === false){
$info = $this->db->canTouch($x, $z, $level, $player);
if($info === -1){
if($this->config->get("white-world-protection")){
if(in_array($level, $this->config->get("white-world-protection")) and !$player->hasPermission("economyland.land.modify.whiteland")){
$player->sendMessage($this->getMessage("not-owned"));
$event->setCancelled(true);
return false;
}
}
}elseif($info !== true){
$player->sendMessage($this->getMessage("no-permission", array($info["owner"], "", "")));
$event->setCancelled(true);
return;
}
if($this->config->get("white-world-protection")){
if(!$exist and in_array($level, $this->config->get("white-world-protection")) and !$player->hasPermission("economyland.land.modify.whiteland")){
$player->sendMessage($this->getMessage("not-owned"));
$event->setCancelled(true);
}
return false;
}

}

public function addLand($player, $startX, $startZ, $endX, $endZ, $level, $expires = null){
Expand Down
Expand Up @@ -105,14 +105,15 @@ public function removeLandById($id){
}

public function canTouch($x, $z, $level, Player $player){
if($player->hasPermission("economyland.land.modify.others")) return true;
if(!is_bool($land = $this->land->query("SELECT owner,invitee FROM land WHERE level = '$level' AND endX > $x AND endZ > $z AND startX < $x AND startZ < $z")->fetchArray(SQLITE3_ASSOC))){
if($player->getName() === $land["owner"] or stripos($player->getName().self::INVITEE_SEPERATOR, $land["invitee"])){
if($player->getName() === $land["owner"] or stripos($player->getName().self::INVITEE_SEPERATOR, $land["invitee"]) or $player->hasPermission("economyland.land.modify.others")){
return true;
}else{
return $land;
}
}
//return !in_array($level, $this->config["white-land"]) or $player->hasPermission("economyland.land.modify.whiteland");
return false;
return true;
}

public function checkOverlap($startX, $endX, $startZ, $endZ, $level){
Expand Down
7 changes: 4 additions & 3 deletions EconomyLand/src/onebone/economyland/database/YamlDatabase.php
Expand Up @@ -153,16 +153,17 @@ public function removeLandById($id){
}

public function canTouch($x, $z, $level, Player $player){
if($player->hasPermission("economyland.land.modify.others")) return true;
foreach($this->land as $land){
if($level === $land["level"] and $land["startX"] < $x and $land["endX"] > $x and $land["startZ"] < $z and $land["endZ"] > $z){
if($player->getName() === $land["owner"] or isset($land["invitee"][$player->getName()])){
if($player->getName() === $land["owner"] or isset($land["invitee"][$player->getName()]) or $player->hasPermission("economyland.land.modify.others")){ // If owner is correct
return true;
}else{ // If owner is not correct
return $land;
}
}
}
// return !in_array($level, $this->config["white-land"]) or $player->hasPermission("economyland.land.modify.whiteland");
return false;
return -1; // If no land found
}

public function checkOverlap($startX, $endX, $startZ, $endZ, $level){
Expand Down

0 comments on commit 9ebdb80

Please sign in to comment.