Skip to content

Commit

Permalink
Merge pull request #2 from LixPL/main
Browse files Browse the repository at this point in the history
Added a configuration for the message
  • Loading branch information
antbag-dev authored May 19, 2024
2 parents 8d4a5b6 + cc86c90 commit 1b51e5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# its config you can edit owner plugin
messages:
join: "§8Welcome,§c {player}! §8You are the #§8 {number} §8player to join our server!"
10 changes: 8 additions & 2 deletions src/antbag/JoinCount/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
namespace antbag\JoinCount;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;

class Main extends PluginBase {

private $config;

public function onEnable(): void {
$listener = new PlayerJoinListener($this->getDataFolder() . "playerData.json");
$this->saveDefaultConfig();
$this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML);

$listener = new PlayerJoinListener($this->getDataFolder() . "playerData.json", $this->config);
$this->getServer()->getPluginManager()->registerEvents($listener, $this);
}
}
}
9 changes: 7 additions & 2 deletions src/antbag/JoinCount/PlayerJoinListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\Server;
use pocketmine\utils\Config;

class PlayerJoinListener implements Listener {

private $dataFile;
private $config;

public function __construct(string $dataFilePath) {
public function __construct(string $dataFilePath, Config $config) {
$this->dataFile = $dataFilePath;
$this->config = $config;
}

public function onPlayerJoin(PlayerJoinEvent $event) {
Expand All @@ -22,7 +25,9 @@ public function onPlayerJoin(PlayerJoinEvent $event) {
$data[$playerName] = true;
$this->saveData($data);
$totalPlayers = count($data);
Server::getInstance()->broadcastMessage("§8Welcome,§c $playerName! §8You are the #§8 $totalPlayers §8player to join our server!");
$message = str_replace("{player}", $playerName, $this->config->get("messages.join"));
$message = str_replace("{number}", $totalPlayers, $message);
Server::getInstance()->broadcastMessage($message);
}
}

Expand Down

0 comments on commit 1b51e5a

Please sign in to comment.