Skip to content

Commit

Permalink
Refactored some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
matcracker committed May 2, 2020
1 parent 3727906 commit fd29244
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/matcracker/BedcoreProtect/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function isInspector(CommandSender $inspector): bool
return self::$inspectors[self::getSenderUUID($inspector)]['enabled'] ?? false;
}

public static function cacheLogs(CommandSender $inspector, array $logs = []): void
public static function saveLogs(CommandSender $inspector, array $logs = []): void
{
self::$inspectors[self::getSenderUUID($inspector)]['logs'] = $logs;
}
Expand All @@ -100,12 +100,12 @@ public static function cacheLogs(CommandSender $inspector, array $logs = []): vo
*
* @return array
*/
public static function getCachedLogs(CommandSender $inspector): array
public static function getSavedLogs(CommandSender $inspector): array
{
return self::$inspectors[self::getSenderUUID($inspector)]['logs'] ?? [];
}

public static function clearCache(): void
public static function removeAll(): void
{
self::$inspectors = [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/matcracker/BedcoreProtect/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function onDisable(): void
$this->getScheduler()->cancelAllTasks();
$this->database->disconnect();

Inspector::clearCache();
Inspector::removeAll();
$this->bsHooked = false;
unset($this->database, $this->baseLang, $this->configParser, $this->oldConfigParser);
}
Expand Down
7 changes: 3 additions & 4 deletions src/matcracker/BedcoreProtect/commands/BCPCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
Await::f2c(
function () use ($sender, $lang) : Generator {
$description = $this->plugin->getDescription();

$pluginVersion = $this->plugin->getVersion();
$pluginVersion = $description->getVersion();
$dbVersion = (string)(yield $this->plugin->getDatabase()->getStatus())[0]["version"];

if (version_compare($pluginVersion, $dbVersion) > 0) {
//Database version could be minor respect the plugin, in this case I apply a BC suffix (Backward Compatibility)
$dbVersion .= ' (' . $lang->translateString("command.status.bc") . ')';
Expand All @@ -130,7 +130,7 @@ static function (): void {
if ($parser->parse()) {
$this->queryManager->getPluginQueries()->requestLookup($sender, $parser);
} else {
if (count($logs = Inspector::getCachedLogs($sender)) > 0) {
if (count($logs = Inspector::getSavedLogs($sender)) > 0) {
$page = 0;
$lines = 4;
$split = explode(":", $args[1]);
Expand Down Expand Up @@ -169,7 +169,6 @@ static function (): void {
$sender->sendMessage(TextFormat::colorize(Main::MESSAGE_PREFIX . $lang->translateString('command.purge.deleted-rows', [$affectedRows])));
});

return true;
} else {
$sender->sendMessage(TextFormat::colorize(Main::MESSAGE_PREFIX . "&c{$parser->getErrorMessage()}"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function requestLog(string $queryName, Player $inspector, Position $posi
'max_z' => $maxV->getZ(),
'world_name' => $position->getLevel()->getName()
], static function (array $rows) use ($inspector): void {
Inspector::cacheLogs($inspector, $rows);
Inspector::saveLogs($inspector, $rows);
Inspector::parseLogs($inspector, $rows);
});
}
Expand All @@ -87,7 +87,7 @@ public function requestLookup(CommandSender $sender, CommandParser $parser): voi
$parser->buildLookupQuery(),
[],
static function (array $rows) use ($sender): void {
Inspector::cacheLogs($sender, $rows);
Inspector::saveLogs($sender, $rows);
Inspector::parseLogs($sender, $rows);
}
);
Expand Down

0 comments on commit fd29244

Please sign in to comment.