From 66013363d52402a05044243c8179e6d83611282e Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Sun, 5 Mar 2017 18:51:46 +0100 Subject: [PATCH] =?UTF-8?q?Bug=20fixing=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++++++++++- src/Ad5001/HideAndSeek/DataBase.php | 2 +- src/Ad5001/HideAndSeek/Game.php | 32 +++++++++++++------------- src/Ad5001/HideAndSeek/GameManager.php | 2 +- src/Ad5001/HideAndSeek/Main.php | 3 +++ 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a20b9e6..2f07477 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,15 @@ This is a recreation of this game for pocketmine ! Please note that this is still under development. Commands: -- /hideandseek <sub command> [parameters] \ No newline at end of file +- /hideandseek <sub command> [parameters] + +Sub Commands: +- creategame (or addgame): Creates a hide and seek +- deletegame (or delgame): Deletes the hide and seek +- setmaxplayers (or smp): Sets the maximum number of players +- setseekerspercentage (or ssp): Sets the percentage of players that will be seekers +- setwaittime (or swt): Sets the waiting time of players when 75 percents of the maximum players joined and the game starts +- setseektime (or sst): Sets the time seekers have to find all hiders before hiders wins +- setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek +- setseekersspawn(or sss): Sets the place where players will be tped to while hiders are hiding +Please note that all those subcommands are relative to the world where you execute the command in. \ No newline at end of file diff --git a/src/Ad5001/HideAndSeek/DataBase.php b/src/Ad5001/HideAndSeek/DataBase.php index 91bd844..bb9c8e0 100644 --- a/src/Ad5001/HideAndSeek/DataBase.php +++ b/src/Ad5001/HideAndSeek/DataBase.php @@ -99,7 +99,7 @@ class DataBase extends SQLite3 { */ protected static function setNumRows(\SQLite3Result &$result) { $n = 0; - while($result->fetchArray() !== false) $n++; + while($result->fetchArray()) $n++; $result->reset(); $result->num_rows = $n; } diff --git a/src/Ad5001/HideAndSeek/Game.php b/src/Ad5001/HideAndSeek/Game.php index 05d2b79..1cf010c 100644 --- a/src/Ad5001/HideAndSeek/Game.php +++ b/src/Ad5001/HideAndSeek/Game.php @@ -165,7 +165,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener $id = $this->getMain()->getDatabase()->get("*", ["table" => "Games"]); $v3 = $this->getLevel()->getSafeSpawn(); $v3Ser = $v3->x . "," . $v3->y . "," . $v3->z; // V32String - $this->getMain()->getDatabase()->insert("Games", [$this->getName(), $v3Ser, $v3Ser, $this->getMain()->getMaxPlayers(), $this->getMain()->getWaitTime(), $this->getMain()->getSeekTime(), $this->getMain()->getSeekersPercentage(), $id->num_rows]); // Inserting the db with new queries + $this->getMain()->getDatabase()->insert("Games", [$this->getName(), $v3Ser, $v3Ser, $this->getMain()->getMaxPlayers(), $this->getMain()->getWaitTime(), $this->getMain()->getSeekTime(), $this->getMain()->getSeekersPercentage(), $id->num_rows+1]); // Inserting the db with new queries } } else { throw new \Exception("Could not contact database."); @@ -212,7 +212,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @return \pocketmine\math\Vector3 */ public function getSpawn() : Vector3 { - $data = $this->getMain()->getDatabase()->get("spawnpoint", ["table" => "Games", "name" => $this->getName()]); + $data = $this->getMain()->getDatabase()->get("spawnpoint", ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; $data = explode(",", $data); return new Vector3($data[0], $data[1], $data[2]); } @@ -223,7 +223,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @return \pocketmine\math\Vector3 */ public function getSeekerSpawn() : Vector3 { - $data = $this->getMain()->getDatabase()->get("seekerspawn", ["table" => "Games", "name" => $this->getName()]); + $data = $this->getMain()->getDatabase()->get("seekerspawn", ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; $data = explode(",", $data); return new Vector3($data[0], $data[1], $data[2]); } @@ -294,7 +294,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @return int */ public function getMaxPlayers() : int { - return (int) $this->getMain()->getDatabase()->get("max_players", ["table" => "Games", "name" => $this->getName()])[0]; + return (int) $this->getMain()->getDatabase()->get("max_players", ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -302,7 +302,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @return int */ public function getWaitTime() : int { - return (int) $this->getMain()->getDatabase()->get("waiting_time", ["table" => "Games", "name" => $this->getName()]); + return (int) $this->getMain()->getDatabase()->get("waiting_time", ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -310,7 +310,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @return int */ public function getSeekTime() : int { - return (int) $this->getMain()->getDatabase()->get("seek_time", ["table" => "Games", "name" => $this->getName()]); + return (int) $this->getMain()->getDatabase()->get("seek_time", ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -318,7 +318,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @return int */ public function getSeekersPercentage() : int { - return (int) $this->getMain()->getDatabase()->get("seekers_percentage", ["table" => "Games", "name" => $this->getName()]); + return (int) $this->getMain()->getDatabase()->get("seekers_percentage", ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } // SET @@ -329,7 +329,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener */ public function setSpawn(Vector3 $v3) { $str = $v3->x . "," . $v3->y . "," . $v3->z; - return $this->getMain()->getDatabase()->set("spawnpoint", $str, ["table" => "Games", "name" => $this->getName()]); + return $this->getMain()->getDatabase()->set("spawnpoint", $str, ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -338,7 +338,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener */ public function setSeekerSpawn(Vector3 $v3) { $str = $v3->x . "," . $v3->y . "," . $v3->z; - return $this->getMain()->getDatabase()->set("seekerspawn", $str, ["table" => "Games", "name" => $this->getName()]); + return $this->getMain()->getDatabase()->set("seekerspawn", $str, ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -347,7 +347,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener */ public function setLevel(Level $level) { $this->level = $level; - return $this->getMain()->getDatabase()->set("name", $level->getName(), ["table" => "Games", "name" => $this->getName()]); + return $this->getMain()->getDatabase()->set("name", $level->getName(), ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -355,7 +355,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @param $int int */ public function setMaxPlayers(int $int) { - return $this->getMain()->getDatabase()->set("max_players", $level->getName(), ["table" => "Games", "name" => $this->getName()]); + return $this->getMain()->getDatabase()->set("max_players", $level->getName(), ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -363,7 +363,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @param $int int */ public function setWaitTime(int $int) { - return $this->getMain()->getDatabase()->set("waiting_time", $level->getName(), ["table" => "Games", "name" => $this->getName()]); + return $this->getMain()->getDatabase()->set("waiting_time", $level->getName(), ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -371,7 +371,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @param $int int */ public function setSeekTime(int $int) { - return $this->getMain()->getDatabase()->set("seek_time", $level->getName(), ["table" => "Games", "name" => $this->getName()]); + return $this->getMain()->getDatabase()->set("seek_time", $level->getName(), ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -379,7 +379,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @param $int int */ public function setSeekersPercentage(int $int) { - return $this->getMain()->getDatabase()->set("seekers_percentage", $level->getName(), ["table" => "Games", "name" => $this->getName()]); + return $this->getMain()->getDatabase()->set("seekers_percentage", $level->getName(), ["table" => "Games", "name" => $this->getName()])->fetchArray()[0]; } /* @@ -488,7 +488,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @param $event \pocketmine\event\block\BlockBreakEvent */ public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) { - if($event->getLevel()->getLevel() == $this->getName()) { + if($event->getBlock()->getLevel()->getLevel() == $this->getName()) { $event->setCancelled(); } } @@ -498,7 +498,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener @param $event \pocketmine\event\block\BlockPlaceEvent */ public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) { - if($event->getLevel()->getLevel() == $this->getName()) { + if($event->getBlock()->getLevel()->getLevel() == $this->getName()) { $event->setCancelled(); } } diff --git a/src/Ad5001/HideAndSeek/GameManager.php b/src/Ad5001/HideAndSeek/GameManager.php index 7af974b..c77342e 100644 --- a/src/Ad5001/HideAndSeek/GameManager.php +++ b/src/Ad5001/HideAndSeek/GameManager.php @@ -103,8 +103,8 @@ class GameManager { public function __unset(string $name) { if(!is_null($this->getGameByName($name))) { $this->getMain()->getDataBase()->delete("Games", ["name" => $name]); - unset($this->gamesNames[$name]); unset($this->games[$this->gamesNames[$name]]); + unset($this->gamesNames[$name]); } else { $this->getMain()->getDataBase()->delete("Games", ["name" => $this->games[$id]->getName()]); unset($this->games[$name]); diff --git a/src/Ad5001/HideAndSeek/Main.php b/src/Ad5001/HideAndSeek/Main.php index 3fc6414..2c223bb 100644 --- a/src/Ad5001/HideAndSeek/Main.php +++ b/src/Ad5001/HideAndSeek/Main.php @@ -178,6 +178,8 @@ A $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; + case "editmode": + break; default: $sender->sendMessage(str_ireplace(PHP_EOL, PHP_EOL . self::PREFIX,self::PREFIX. "§cSub-command {$args[0]} not found ! Possible subcommands: @@ -190,6 +192,7 @@ Possible subcommands: - setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek - setseekersspawn(or sss): Sets the place where players will be tped to while hiders are hiding Please note that all those subcommands are relative to the world where you execute the command in.")); + break; } return true; } else {