Skip to content

Instantly share code, notes, and snippets.

@jasonw4331
Created April 29, 2019 21:27
Show Gist options
  • Save jasonw4331/4a60b66c03e0dbdae7feb3f5669db8b9 to your computer and use it in GitHub Desktop.
Save jasonw4331/4a60b66c03e0dbdae7feb3f5669db8b9 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
/**
* @name InformationBoard
* @main jasonwynn10\InformationBoard\Main
* @version 0.1.0
* @api 3.0.0
* @description A plugin script which counts deaths per join session
* @author jasonwynn10
*/
namespace jasonwynn10\InformationBoard {
use jasonwynn10\ScoreboardAPI\Scoreboard;
use jasonwynn10\ScoreboardAPI\ScoreboardAPI;
use jasonwynn10\ScoreboardAPI\ScoreboardEntry;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat;
class Main extends PluginBase implements Listener {
/** @var Scoreboard */
private $scoreboard;
/** @var ScoreboardEntry */
private $playerCountEntry;
public function onEnable() {
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->scoreboard = $scoreboard = ScoreboardAPI::getInstance()->createScoreboard("InformationBoard", TextFormat::LIGHT_PURPLE."Welcome!");
$entry = $scoreboard->createEntry(1, 1, ScoreboardEntry::TYPE_FAKE_PLAYER, "-------------");
$scoreboard->addEntry($entry);
$entry = $scoreboard->createEntry(2, 2, ScoreboardEntry::TYPE_FAKE_PLAYER, TextFormat::DARK_GREEN."Money");
$scoreboard->addEntry($entry);
$entry = $scoreboard->createEntry(3, 3, ScoreboardEntry::TYPE_FAKE_PLAYER, "1000.00"); // TODO: EconomyAPI support
$scoreboard->addEntry($entry);
$entry = $scoreboard->createEntry(4, 4, ScoreboardEntry::TYPE_FAKE_PLAYER, TextFormat::AQUA."Rank");
$scoreboard->addEntry($entry);
$entry = $scoreboard->createEntry(5, 5, ScoreboardEntry::TYPE_FAKE_PLAYER, "Guest"); // TODO: PurePerms support
$scoreboard->addEntry($entry);
$entry = $scoreboard->createEntry(6, 6, ScoreboardEntry::TYPE_FAKE_PLAYER, TextFormat::BLUE."Website");
$scoreboard->addEntry($entry);
$entry = $scoreboard->createEntry(7, 7, ScoreboardEntry::TYPE_FAKE_PLAYER, TextFormat::GOLD."Test.com");
$scoreboard->addEntry($entry);
$entry = $scoreboard->createEntry(8, 8, ScoreboardEntry::TYPE_FAKE_PLAYER, TextFormat::YELLOW."Player Count");
$scoreboard->addEntry($entry);
$players = count($this->getServer()->getOnlinePlayers());
$this->playerCountEntry = $entry = $scoreboard->createEntry(9, 9, ScoreboardEntry::TYPE_FAKE_PLAYER, "{$players}");
$scoreboard->addEntry($entry);
$scoreboard->padEntries();
}
/**
* @param PlayerJoinEvent $event
*/
public function onJoin(PlayerJoinEvent $event) {
$scoreboard = $this->scoreboard;
ScoreboardAPI::getInstance()->sendScoreboard($scoreboard, [$event->getPlayer()]);
foreach($scoreboard->getEntries() as $entry) {
$scoreboard->updateEntry($entry);
}
$entry = $this->playerCountEntry;
$players = count($this->getServer()->getOnlinePlayers()) + 1;
$entry->customName = "{$players}";
$scoreboard->updateEntry($entry);
$scoreboard->padEntries();
}
public function onDisable() {
ScoreboardAPI::getInstance()->removeScoreboard($this->scoreboard);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment