Skip to content

Commit

Permalink
Merge pull request #10 from carmelosantana/task-300-fix-autostart
Browse files Browse the repository at this point in the history
Fix autostart
  • Loading branch information
carmelosantana authored Sep 26, 2022
2 parents 98307f1 + 173f480 commit e7c1b1a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ender-hive.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Ender Hive
Plugin URI: https://enderhive.com/
Description: Minecraft server manager.
Version: 0.1.0-alpha.12
Version: 0.1.0-alpha.13
Author: Carmelo Santana
Author URI: https://carmelosantana.com/
License: GNU General Public License v2 or later
Expand Down
9 changes: 2 additions & 7 deletions src/Host/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ public function query(): array
try {
$query->ConnectBedrock($this->getIp(), $this->getPortIp4());
} catch (MinecraftQueryException $e) {
// Update status and last known state.
$this->updateStatus(Status::SERVICE_UNAVAILABLE);

return [];
}

Expand All @@ -230,17 +227,15 @@ public function updateStatus(int $status = 0): void
} else {
$this->status = Status::NO_CONTENT;
}

$this->updateLastKnownState();
}

/**
* Updates _last_known_state meta with the current status.
*
* @return void
*/
public function updateLastKnownState(): void
public function updateLastKnownState(int $status = 0): void
{
update_post_meta($this->post_id, '_last_known_state', $this->getStatus());
update_post_meta($this->post_id, '_last_known_state', ($status > 0 ? $status : $this->status));
}
}
23 changes: 10 additions & 13 deletions src/Host/PocketMineMP/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,59 +170,56 @@ public function start(): int
case 'publish':
case 'draft':
if (!$this->isRunning()) {
$status = $this->command()->start();
} else {
$status = Status::OK;
$this->status = $this->command()->start();
}
$status = Status::OK;
break;

default:
$status = Status::SERVICE_UNAVAILABLE;
break;
}

$this->updateStatus($status);
$this->updateLastKnownState($status);

return $this->getStatus();
}

public function startWait(): int
{
$status = $this->start();
$this->start();

// Wait for the server to start
while (!$this->isRunning()) {
usleep(250000);
}

$this->updateStatus(Status::OK);
$this->updateLastKnownState(Status::OK);

return $this->getStatus();
}
}

public function stop(): int
{
if ($this->isRunning()) {
$status = $this->command()->stop();
} else {
$status = Status::NO_CONTENT;
$this->status = $this->command()->stop();
}

$this->updateStatus($status);
$this->updateLastKnownState(Status::NO_CONTENT);

return $this->getStatus();
}

public function stopWait(): int
{
$status = $this->stop();
$this->stop();

// Wait for the server to stop
while ($this->isRunning()) {
usleep(250000);
}

$this->updateStatus(Status::NO_CONTENT);
$this->updateLastKnownState(Status::NO_CONTENT);

return $this->getStatus();
}
Expand Down
15 changes: 7 additions & 8 deletions src/Instance/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace CarmeloSantana\EnderHive\Instance;

use CarmeloSantana\EnderHive\Host\Server;
use CarmeloSantana\EnderHive\Tools\Utils;
use CarmeloSantana\EnderHive\Host\Status;
use stdClass;

class PostType
Expand Down Expand Up @@ -122,14 +122,13 @@ public function columnValues($column, $post_id): void
}
break;

case 'ipv6':

break;

case 'status':
$status = get_post_meta($post_id, '_last_known_state', true);
switch ($status) {
case 200:
switch ($this->server->getStatus()) {
case Status::ACCEPTED:
echo '<span class="dashicons dashicons-yes-alt status-202"></span>' . __('Working', ENDER_HIVE);
break;

case Status::OK:
echo '<span class="dashicons dashicons-yes-alt status-200"></span>' . __('Online', ENDER_HIVE);
break;

Expand Down

0 comments on commit e7c1b1a

Please sign in to comment.