Bug fixing™

This commit is contained in:
Adsooi 2017-03-05 18:51:46 +01:00
parent 42dc29ed27
commit 66013363d5
No known key found for this signature in database
GPG key ID: F05C5A0D59BC40DD
5 changed files with 33 additions and 19 deletions

View file

@ -6,4 +6,15 @@ This is a recreation of this game for pocketmine !
Please note that this is still under development. Please note that this is still under development.
Commands: Commands:
- /hideandseek <sub command> [parameters] - /hideandseek <sub command> [parameters]
Sub Commands:
- creategame (or addgame): Creates a hide and seek
- deletegame (or delgame): Deletes the hide and seek
- setmaxplayers <number of players>(or smp): Sets the maximum number of players
- setseekerspercentage <percentage>(or ssp): Sets the percentage of players that will be seekers
- setwaittime <seconds to wait>(or swt): Sets the waiting time of players when 75 percents of the maximum players joined and the game starts
- setseektime <minutes to seek>(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.

View file

@ -99,7 +99,7 @@ class DataBase extends SQLite3 {
*/ */
protected static function setNumRows(\SQLite3Result &$result) { protected static function setNumRows(\SQLite3Result &$result) {
$n = 0; $n = 0;
while($result->fetchArray() !== false) $n++; while($result->fetchArray()) $n++;
$result->reset(); $result->reset();
$result->num_rows = $n; $result->num_rows = $n;
} }

View file

@ -165,7 +165,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener
$id = $this->getMain()->getDatabase()->get("*", ["table" => "Games"]); $id = $this->getMain()->getDatabase()->get("*", ["table" => "Games"]);
$v3 = $this->getLevel()->getSafeSpawn(); $v3 = $this->getLevel()->getSafeSpawn();
$v3Ser = $v3->x . "," . $v3->y . "," . $v3->z; // V32String $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 { } else {
throw new \Exception("Could not contact database."); 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 @return \pocketmine\math\Vector3
*/ */
public function getSpawn() : 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); $data = explode(",", $data);
return new Vector3($data[0], $data[1], $data[2]); 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 @return \pocketmine\math\Vector3
*/ */
public function getSeekerSpawn() : 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); $data = explode(",", $data);
return new Vector3($data[0], $data[1], $data[2]); 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 @return int
*/ */
public function getMaxPlayers() : 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 @return int
*/ */
public function getWaitTime() : 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 @return int
*/ */
public function getSeekTime() : 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 @return int
*/ */
public function getSeekersPercentage() : 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 // SET
@ -329,7 +329,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener
*/ */
public function setSpawn(Vector3 $v3) { public function setSpawn(Vector3 $v3) {
$str = $v3->x . "," . $v3->y . "," . $v3->z; $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) { public function setSeekerSpawn(Vector3 $v3) {
$str = $v3->x . "," . $v3->y . "," . $v3->z; $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) { public function setLevel(Level $level) {
$this->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 @param $int int
*/ */
public function setMaxPlayers(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 @param $int int
*/ */
public function setWaitTime(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 @param $int int
*/ */
public function setSeekTime(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 @param $int int
*/ */
public function setSeekersPercentage(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 @param $event \pocketmine\event\block\BlockBreakEvent
*/ */
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) { public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {
if($event->getLevel()->getLevel() == $this->getName()) { if($event->getBlock()->getLevel()->getLevel() == $this->getName()) {
$event->setCancelled(); $event->setCancelled();
} }
} }
@ -498,7 +498,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener
@param $event \pocketmine\event\block\BlockPlaceEvent @param $event \pocketmine\event\block\BlockPlaceEvent
*/ */
public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) { public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {
if($event->getLevel()->getLevel() == $this->getName()) { if($event->getBlock()->getLevel()->getLevel() == $this->getName()) {
$event->setCancelled(); $event->setCancelled();
} }
} }

View file

@ -103,8 +103,8 @@ class GameManager {
public function __unset(string $name) { public function __unset(string $name) {
if(!is_null($this->getGameByName($name))) { if(!is_null($this->getGameByName($name))) {
$this->getMain()->getDataBase()->delete("Games", ["name" => $name]); $this->getMain()->getDataBase()->delete("Games", ["name" => $name]);
unset($this->gamesNames[$name]);
unset($this->games[$this->gamesNames[$name]]); unset($this->games[$this->gamesNames[$name]]);
unset($this->gamesNames[$name]);
} else { } else {
$this->getMain()->getDataBase()->delete("Games", ["name" => $this->games[$id]->getName()]); $this->getMain()->getDataBase()->delete("Games", ["name" => $this->games[$id]->getName()]);
unset($this->games[$name]); unset($this->games[$name]);

View file

@ -178,6 +178,8 @@ A
$sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world.");
} }
break; break;
case "editmode":
break;
default: default:
$sender->sendMessage(str_ireplace(PHP_EOL, PHP_EOL . self::PREFIX,self::PREFIX. "§cSub-command {$args[0]} not found ! $sender->sendMessage(str_ireplace(PHP_EOL, PHP_EOL . self::PREFIX,self::PREFIX. "§cSub-command {$args[0]} not found !
Possible subcommands: Possible subcommands:
@ -190,6 +192,7 @@ Possible subcommands:
- setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek - 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 - 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.")); Please note that all those subcommands are relative to the world where you execute the command in."));
break;
} }
return true; return true;
} else { } else {