Skip to content

Commit

Permalink
feat: implements npc queries
Browse files Browse the repository at this point in the history
  • Loading branch information
AIPTU committed Aug 23, 2024
1 parent a4ac7fb commit c8f63f3
Show file tree
Hide file tree
Showing 12 changed files with 899 additions and 13 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Smaccer is a powerful and easy-to-use PocketMine-MP plugin designed for managing
- **Teleport**: Quickly teleport to NPCs or move other players to NPCs.
- **Customizable Configuration**: Tailor the plugin's settings to fit your needs without restarting the server.
- **Manage Permissions**: Fine-tune permissions to control who can interact with and manage NPCs.
- **Server Queries**: Check the status of remote servers, including player counts and server uptime.
- **World Queries**: Monitor player counts and world statuses across multiple worlds.
- **Customizable Messages**: Define and customize the display messages for server and world queries through configuration files.
- **Asynchronous Tasks**: Perform server queries asynchronously to avoid blocking the main server thread.

## Commands

Expand Down Expand Up @@ -56,11 +60,39 @@ Smaccer offers a customizable configuration to tailor the NPC settings to your p
# Smaccer Configuration

# Do not change this (Only for internal use)!
config-version: 1.1
config-version: 1.2

# Enable or disable the auto update checker notifier.
update_notifier: true

# World Query Message Formats
# Customize how world information is displayed in the nametag.

# When all specified worlds are loaded.
# Placeholders:
# - {world_names}: Comma-separated list of loaded world names.
# - {count}: Total player count across loaded worlds.
world_message_format: "§aWorlds: §b{world_names} §a| Players: §e{count}"

# When some or all specified worlds are not loaded.
# Placeholders:
# - {world_names}: Comma-separated list of loaded world names.
# - {not_loaded_worlds}: Comma-separated list of worlds not loaded.
# - {count}: Total player count across loaded worlds.
world_not_loaded_format: "§cWorlds: §b{world_names} §c| Not Loaded: §7{not_loaded_worlds} §c| Players: §e{count}"

# Server Query Message Formats
# Customize how server information is displayed in the nametag.

# When the server is online.
# Placeholders:
# - {online}: Current number of players online.
# - {max_online}: Maximum number of players allowed online.
server_online_format: "§aServer: §b{online}§a/§b{max_online} §aonline"

# When the server is offline.
server_offline_format: "§cServer: Offline"

# Default settings for NPCs.
npc-default-settings:
# Cooldown settings for NPC commands.
Expand Down Expand Up @@ -125,6 +157,7 @@ npc-default-settings:
<img src="https://raw.githubusercontent.com/AIPTU/Smaccer/assets/image2.jpg" alt="" width="400" height="200">
<img src="https://raw.githubusercontent.com/AIPTU/Smaccer/assets/image3.jpg" alt="" width="350" height="250">
<img src="https://raw.githubusercontent.com/AIPTU/Smaccer/assets/image4.jpg" alt="" width="350" height="250">
<img src="https://raw.githubusercontent.com/AIPTU/Smaccer/assets/image5.jpg" alt="" width="400" height="250">

## Upcoming Features

Expand Down
30 changes: 29 additions & 1 deletion resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# Smaccer Configuration

# Do not change this (Only for internal use)!
config-version: 1.1
config-version: 1.2

# Enable or disable the auto update checker notifier.
update_notifier: true

# World Query Message Formats
# Customize how world information is displayed in the nametag.

# When all specified worlds are loaded.
# Placeholders:
# - {world_names}: Comma-separated list of loaded world names.
# - {count}: Total player count across loaded worlds.
world_message_format: "§aWorlds: §b{world_names} §a| Players: §e{count}"

# When some or all specified worlds are not loaded.
# Placeholders:
# - {world_names}: Comma-separated list of loaded world names.
# - {not_loaded_worlds}: Comma-separated list of worlds not loaded.
# - {count}: Total player count across loaded worlds.
world_not_loaded_format: "§cWorlds: §b{world_names} §c| Not Loaded: §7{not_loaded_worlds} §c| Players: §e{count}"

# Server Query Message Formats
# Customize how server information is displayed in the nametag.

# When the server is online.
# Placeholders:
# - {online}: Current number of players online.
# - {max_online}: Maximum number of players allowed online.
server_online_format: "§aServer: §b{online}§a/§b{max_online} §aonline"

# When the server is offline.
server_offline_format: "§cServer: Offline"

# Default settings for NPCs.
npc-default-settings:
# Cooldown settings for NPC commands.
Expand Down
52 changes: 51 additions & 1 deletion src/aiptu/smaccer/Smaccer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@
use function is_bool;
use function is_int;
use function is_numeric;
use function is_string;

class Smaccer extends PluginBase {
use SingletonTrait;

private const CONFIG_VERSION = 1.1;
private const CONFIG_VERSION = 1.2;

private bool $updateNotifierEnabled;
private NPCDefaultSettings $npcDefaultSettings;
private EmoteManager $emoteManager;

private string $worldMessageFormat;
private string $worldNotLoadedFormat;
private string $serverOnlineFormat;
private string $serverOfflineFormat;

protected function onEnable() : void {
self::setInstance($this);

Expand Down Expand Up @@ -86,6 +92,34 @@ private function loadConfig() : void {

$this->updateNotifierEnabled = $updateNotifierEnabled;

$worldMessageFormat = $config->get('world_message_format');
if (!is_string($worldMessageFormat)) {
throw new InvalidArgumentException("Invalid value for 'world_message_format'. Expected a string.");
}

$this->worldMessageFormat = $worldMessageFormat;

$worldNotLoadedFormat = $config->get('world_not_loaded_format');
if (!is_string($worldNotLoadedFormat)) {
throw new InvalidArgumentException("Invalid value for 'world_not_loaded_format'. Expected a string.");
}

$this->worldNotLoadedFormat = $worldNotLoadedFormat;

$serverOnlineFormat = $config->get('server_online_format');
if (!is_string($serverOnlineFormat)) {
throw new InvalidArgumentException("Invalid value for 'server_online_format'. Expected a string.");
}

$this->serverOnlineFormat = $serverOnlineFormat;

$serverOfflineFormat = $config->get('server_offline_format');
if (!is_string($serverOfflineFormat)) {
throw new InvalidArgumentException("Invalid value for 'server_offline_format'. Expected a string.");
}

$this->serverOfflineFormat = $serverOfflineFormat;

/**
* @var array{
* commandCooldown: array{enabled: bool, value: float|int},
Expand Down Expand Up @@ -223,4 +257,20 @@ public function getEmoteManager() : EmoteManager {
public function setEmoteManager(EmoteManager $emoteManager) : void {
$this->emoteManager = $emoteManager;
}

public function getWorldMessageFormat() : string {
return $this->worldMessageFormat;
}

public function getWorldNotLoadedFormat() : string {
return $this->worldNotLoadedFormat;
}

public function getServerOnlineFormat() : string {
return $this->serverOnlineFormat;
}

public function getServerOfflineFormat() : string {
return $this->serverOfflineFormat;
}
}
4 changes: 4 additions & 0 deletions src/aiptu/smaccer/entity/EntitySmaccer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use aiptu\smaccer\entity\trait\CommandTrait;
use aiptu\smaccer\entity\trait\CreatorTrait;
use aiptu\smaccer\entity\trait\NametagTrait;
use aiptu\smaccer\entity\trait\QueryTrait;
use aiptu\smaccer\entity\trait\RotationTrait;
use aiptu\smaccer\entity\trait\VisibilityTrait;
use aiptu\smaccer\entity\utils\EntityTag;
Expand All @@ -30,6 +31,7 @@ abstract class EntitySmaccer extends Entity {
use RotationTrait;
use VisibilityTrait;
use CommandTrait;
use QueryTrait;

public function __construct(Location $location, ?CompoundTag $nbt = null) {
if ($nbt instanceof CompoundTag) {
Expand All @@ -49,6 +51,7 @@ protected function initEntity(CompoundTag $nbt) : void {
$this->setNameTagVisible((bool) $nbt->getByte(EntityTag::NAMETAG_VISIBLE, 1));
$this->initializeVisibility($nbt);
$this->setHasGravity((bool) $nbt->getByte(EntityTag::GRAVITY, 1));
$this->initializeQuery($nbt);
}

public function saveNBT() : CompoundTag {
Expand All @@ -61,6 +64,7 @@ public function saveNBT() : CompoundTag {
$nbt->setByte(EntityTag::NAMETAG_VISIBLE, (int) $this->isNameTagVisible());
$this->saveVisibility($nbt);
$nbt->setByte(EntityTag::GRAVITY, (int) $this->hasGravity());
$this->saveQuery($nbt);

return $nbt;
}
Expand Down
4 changes: 4 additions & 0 deletions src/aiptu/smaccer/entity/HumanSmaccer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use aiptu\smaccer\entity\trait\EmoteTrait;
use aiptu\smaccer\entity\trait\InventoryTrait;
use aiptu\smaccer\entity\trait\NametagTrait;
use aiptu\smaccer\entity\trait\QueryTrait;
use aiptu\smaccer\entity\trait\RotationTrait;
use aiptu\smaccer\entity\trait\SkinTrait;
use aiptu\smaccer\entity\trait\SlapBackTrait;
Expand All @@ -38,6 +39,7 @@ class HumanSmaccer extends Human {
use CommandTrait;
use InventoryTrait;
use SkinTrait;
use QueryTrait;

public function __construct(Location $location, Skin $skin, ?CompoundTag $nbt = null) {
if ($nbt instanceof CompoundTag) {
Expand All @@ -59,6 +61,7 @@ protected function initEntity(CompoundTag $nbt) : void {
$this->initializeSlapBack($nbt);
$this->initializeEmote($nbt);
$this->setHasGravity((bool) $nbt->getByte(EntityTag::GRAVITY, 1));
$this->initializeQuery($nbt);
}

public function saveNBT() : CompoundTag {
Expand All @@ -73,6 +76,7 @@ public function saveNBT() : CompoundTag {
$this->saveEmote($nbt);
$this->saveSlapBack($nbt);
$nbt->setByte(EntityTag::GRAVITY, (int) $this->hasGravity());
$this->saveQuery($nbt);

return $nbt;
}
Expand Down
Loading

0 comments on commit c8f63f3

Please sign in to comment.