From 9ebdb802c1a62cea788e7721184dc5247f1b6a40 Mon Sep 17 00:00:00 2001 From: onebone Date: Sun, 12 Oct 2014 23:21:47 +0900 Subject: [PATCH] Fixed land protection is malfunctioning --- .../src/onebone/economyland/EconomyLand.php | 21 ++++++++++++------- .../economyland/database/SQLiteDatabase.php | 7 ++++--- .../economyland/database/YamlDatabase.php | 7 ++++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/EconomyLand/src/onebone/economyland/EconomyLand.php b/EconomyLand/src/onebone/economyland/EconomyLand.php index f03f8bb6..cc189c18 100644 --- a/EconomyLand/src/onebone/economyland/EconomyLand.php +++ b/EconomyLand/src/onebone/economyland/EconomyLand.php @@ -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); @@ -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){ diff --git a/EconomyLand/src/onebone/economyland/database/SQLiteDatabase.php b/EconomyLand/src/onebone/economyland/database/SQLiteDatabase.php index 8174b617..8c437a89 100644 --- a/EconomyLand/src/onebone/economyland/database/SQLiteDatabase.php +++ b/EconomyLand/src/onebone/economyland/database/SQLiteDatabase.php @@ -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){ diff --git a/EconomyLand/src/onebone/economyland/database/YamlDatabase.php b/EconomyLand/src/onebone/economyland/database/YamlDatabase.php index 1d94bd29..e86490ce 100644 --- a/EconomyLand/src/onebone/economyland/database/YamlDatabase.php +++ b/EconomyLand/src/onebone/economyland/database/YamlDatabase.php @@ -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){